about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--AnodyneArchipelago/ArchipelagoManager.cs49
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 @@
1using AnodyneSharp.Entities; 1using AnodyneSharp.Entities;
2using AnodyneSharp.Entities.Enemy.Redcave; 2using AnodyneSharp.Entities.Enemy.Redcave;
3using AnodyneSharp.Registry; 3using AnodyneSharp.Registry;
4using AnodyneSharp.Sounds;
4using Archipelago.MultiClient.Net; 5using Archipelago.MultiClient.Net;
5using Archipelago.MultiClient.Net.Enums; 6using Archipelago.MultiClient.Net.Enums;
7using Archipelago.MultiClient.Net.MessageLog.Messages;
6using Archipelago.MultiClient.Net.Models; 8using Archipelago.MultiClient.Net.Models;
7using Archipelago.MultiClient.Net.Packets; 9using Archipelago.MultiClient.Net.Packets;
8using System; 10using 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}