diff options
Diffstat (limited to 'AnodyneArchipelago')
-rw-r--r-- | AnodyneArchipelago/ArchipelagoManager.cs | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/AnodyneArchipelago/ArchipelagoManager.cs b/AnodyneArchipelago/ArchipelagoManager.cs index c16978a..781a335 100644 --- a/AnodyneArchipelago/ArchipelagoManager.cs +++ b/AnodyneArchipelago/ArchipelagoManager.cs | |||
@@ -1,8 +1,10 @@ | |||
1 | using AnodyneSharp.Entities; | 1 | using AnodyneSharp.Entities; |
2 | using AnodyneSharp.Entities.Enemy.Redcave; | 2 | using AnodyneSharp.Entities.Enemy.Redcave; |
3 | using AnodyneSharp.Registry; | 3 | using AnodyneSharp.Registry; |
4 | using AnodyneSharp.Sounds; | ||
4 | using Archipelago.MultiClient.Net; | 5 | using Archipelago.MultiClient.Net; |
5 | using Archipelago.MultiClient.Net.Enums; | 6 | using Archipelago.MultiClient.Net.Enums; |
7 | using Archipelago.MultiClient.Net.MessageLog.Messages; | ||
6 | using Archipelago.MultiClient.Net.Models; | 8 | using Archipelago.MultiClient.Net.Models; |
7 | using Archipelago.MultiClient.Net.Packets; | 9 | using Archipelago.MultiClient.Net.Packets; |
8 | using System; | 10 | using System; |
@@ -24,6 +26,7 @@ namespace AnodyneArchipelago | |||
24 | try | 26 | try |
25 | { | 27 | { |
26 | _session = ArchipelagoSessionFactory.CreateSession(url); | 28 | _session = ArchipelagoSessionFactory.CreateSession(url); |
29 | _session.MessageLog.OnMessageReceived += OnMessageReceived; | ||
27 | result = _session.TryConnectAndLogin("Anodyne", slotName, ItemsHandlingFlags.AllItems, null, null, null, password == "" ? null : password); | 30 | result = _session.TryConnectAndLogin("Anodyne", slotName, ItemsHandlingFlags.AllItems, null, null, null, password == "" ? null : password); |
28 | } | 31 | } |
29 | catch (Exception e) | 32 | catch (Exception e) |
@@ -100,7 +103,7 @@ namespace AnodyneArchipelago | |||
100 | } | 103 | } |
101 | } | 104 | } |
102 | 105 | ||
103 | if (_itemsToCollect.Count > 0) | 106 | if (_itemsToCollect.Count > 0 && (GlobalState.Dialogue == null || GlobalState.Dialogue == "") && !GlobalState.ScreenTransition) |
104 | { | 107 | { |
105 | NetworkItem item = _itemsToCollect.Dequeue(); | 108 | NetworkItem item = _itemsToCollect.Dequeue(); |
106 | HandleItem(item); | 109 | HandleItem(item); |
@@ -123,6 +126,17 @@ namespace AnodyneArchipelago | |||
123 | 126 | ||
124 | private static void HandleItem(NetworkItem item) | 127 | private static void HandleItem(NetworkItem item) |
125 | { | 128 | { |
129 | if (item.Player == _session.ConnectionInfo.Slot) | ||
130 | { | ||
131 | string itemKey = $"ArchipelagoLocation-{item.Location}"; | ||
132 | if (GlobalState.events.GetEvent(itemKey) > 0) | ||
133 | { | ||
134 | return; | ||
135 | } | ||
136 | |||
137 | GlobalState.events.SetEvent(itemKey, 1); | ||
138 | } | ||
139 | |||
126 | string itemName = _session.Items.GetItemName(item.Item); | 140 | string itemName = _session.Items.GetItemName(item.Item); |
127 | 141 | ||
128 | if (itemName.StartsWith("Small Key")) | 142 | if (itemName.StartsWith("Small Key")) |
@@ -175,6 +189,39 @@ namespace AnodyneArchipelago | |||
175 | { | 189 | { |
176 | GlobalState.events.IncEvent("ProgressiveRedGrotto"); | 190 | GlobalState.events.IncEvent("ProgressiveRedGrotto"); |
177 | } | 191 | } |
192 | |||
193 | string message; | ||
194 | if (item.Player == _session.ConnectionInfo.Slot) | ||
195 | { | ||
196 | message = $"Found {itemName}!"; | ||
197 | } | ||
198 | else | ||
199 | { | ||
200 | string otherPlayer = _session.Players.GetPlayerAlias(item.Player); | ||
201 | message = $"Received {itemName} from {otherPlayer}."; | ||
202 | } | ||
203 | |||
204 | GlobalState.Dialogue = message; | ||
205 | } | ||
206 | |||
207 | private static void OnMessageReceived(LogMessage message) | ||
208 | { | ||
209 | switch (message) | ||
210 | { | ||
211 | case ItemSendLogMessage itemSendLogMessage: | ||
212 | if (itemSendLogMessage.IsSenderTheActivePlayer && !itemSendLogMessage.IsReceiverTheActivePlayer) | ||
213 | { | ||
214 | string itemName = _session.Items.GetItemName(itemSendLogMessage.Item.Item); | ||
215 | |||
216 | string messageText; | ||
217 | string otherPlayer = _session.Players.GetPlayerAlias(itemSendLogMessage.Receiver.Slot); | ||
218 | messageText = $"Sent {itemName} to {otherPlayer}."; | ||
219 | |||
220 | SoundManager.PlaySoundEffect("gettreasure"); | ||
221 | GlobalState.Dialogue = messageText; | ||
222 | } | ||
223 | break; | ||
224 | } | ||
178 | } | 225 | } |
179 | } | 226 | } |
180 | } | 227 | } |