about summary refs log tree commit diff stats
path: root/AnodyneArchipelago/ArchipelagoManager.cs
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-05-22 12:45:43 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-22 12:45:43 -0400
commitf717a556a909b831cb6965bcd2f8e057053e5161 (patch)
tree3c4b963dfa517bd79c0a0f5bfa2fb325144217d8 /AnodyneArchipelago/ArchipelagoManager.cs
parent07ba77d448cc54d4f2b149b31652fff156efdb40 (diff)
downloadanodyne-archipelago-f717a556a909b831cb6965bcd2f8e057053e5161.tar.gz
anodyne-archipelago-f717a556a909b831cb6965bcd2f8e057053e5161.tar.bz2
anodyne-archipelago-f717a556a909b831cb6965bcd2f8e057053e5161.zip
Start sending and receiving items
Diffstat (limited to 'AnodyneArchipelago/ArchipelagoManager.cs')
-rw-r--r--AnodyneArchipelago/ArchipelagoManager.cs110
1 files changed, 109 insertions, 1 deletions
diff --git a/AnodyneArchipelago/ArchipelagoManager.cs b/AnodyneArchipelago/ArchipelagoManager.cs index 8c107a3..4ffa3af 100644 --- a/AnodyneArchipelago/ArchipelagoManager.cs +++ b/AnodyneArchipelago/ArchipelagoManager.cs
@@ -1,12 +1,21 @@
1using Archipelago.MultiClient.Net; 1using AnodyneSharp.Entities;
2using AnodyneSharp.Registry;
3using Archipelago.MultiClient.Net;
2using Archipelago.MultiClient.Net.Enums; 4using Archipelago.MultiClient.Net.Enums;
5using Archipelago.MultiClient.Net.Models;
6using Archipelago.MultiClient.Net.Packets;
3using System; 7using System;
8using System.Collections.Generic;
9using System.Linq;
4 10
5namespace AnodyneArchipelago 11namespace AnodyneArchipelago
6{ 12{
7 internal class ArchipelagoManager 13 internal class ArchipelagoManager
8 { 14 {
9 private static ArchipelagoSession _session; 15 private static ArchipelagoSession _session;
16 private static int _itemIndex = 0;
17
18 private static readonly Queue<NetworkItem> _itemsToCollect = new();
10 19
11 public static void Connect(string url, string slotName, string password) 20 public static void Connect(string url, string slotName, string password)
12 { 21 {
@@ -38,6 +47,105 @@ namespace AnodyneArchipelago
38 47
39 return; 48 return;
40 } 49 }
50
51 _itemIndex = 0;
52 _itemsToCollect.Clear();
53 }
54
55 public static void Disconnect()
56 {
57 if (_session == null)
58 {
59 return;
60 }
61
62 _session.Socket.DisconnectAsync();
63 _session = null;
64 }
65
66 public static void SendLocation(string location)
67 {
68 if (_session == null)
69 {
70 Plugin.Instance.Log.LogError("Attempted to send location while disconnected");
71 return;
72 }
73
74 _session.Locations.CompleteLocationChecks(_session.Locations.GetLocationIdFromName("Anodyne", location));
75 }
76
77 public static void Update()
78 {
79 if (_session == null)
80 {
81 // We're not connected.
82 return;
83 }
84
85 if (_session.Items.AllItemsReceived.Count > _itemIndex)
86 {
87 for (int i = _itemIndex; i < _session.Items.AllItemsReceived.Count; i++)
88 {
89 string itemKey = $"ArchipelagoItem-{i}";
90 if (GlobalState.events.GetEvent(itemKey) != 0)
91 {
92 continue;
93 }
94
95 GlobalState.events.SetEvent(itemKey, 1);
96
97 NetworkItem item = _session.Items.AllItemsReceived[i];
98 _itemsToCollect.Enqueue(item);
99 }
100 }
101
102 if (_itemsToCollect.Count > 0)
103 {
104 NetworkItem item = _itemsToCollect.Dequeue();
105 HandleItem(item);
106 }
107 }
108
109 private static string GetMapNameForDungeon(string dungeon)
110 {
111 switch (dungeon)
112 {
113 case "Temple of the Seeing One": return "BEDROOM";
114 case "Apartment": return "APARTMENT";
115 case "Mountain Cavern": return "CROWD";
116 case "Hotel": return "HOTEL";
117 case "Red Grotto": return "REDCAVE";
118 case "Circus": return "CIRCUS";
119 default: return "STREET";
120 }
121 }
122
123 private static void HandleItem(NetworkItem item)
124 {
125 string itemName = _session.Items.GetItemName(item.Item);
126
127 if (itemName.StartsWith("Small Key"))
128 {
129 string dungeonName = itemName.Substring(11);
130 dungeonName = dungeonName.Substring(0, dungeonName.Length - 1);
131
132 string mapName = GetMapNameForDungeon(dungeonName);
133 GlobalState.inventory.AddMapKey(mapName, 1);
134 } else if (itemName == "Green Key")
135 {
136 GlobalState.inventory.BigKeyStatus[0] = true;
137 }
138 else if (itemName == "Blue Key")
139 {
140 GlobalState.inventory.BigKeyStatus[2] = true;
141 }
142 else if (itemName == "Red Key")
143 {
144 GlobalState.inventory.BigKeyStatus[1] = true;
145 } else if (itemName == "Jump Shoes")
146 {
147 GlobalState.inventory.CanJump = true;
148 }
41 } 149 }
42 } 150 }
43} 151}