Skip to content

Commit a1f4d77

Browse files
Merge pull request ArchipelagoMW#4 from Extra-2-Dew/bug-fixes-and-cleanup
Bug fixes and cleanup
2 parents d455be2 + e883f26 commit a1f4d77

18 files changed

+537
-226
lines changed

ArchipelagoRandomizer.csproj

+33
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,36 @@
3131
<Reference Include="$(GameDataPath)\BepInEx\plugins\ModCore\ModCore.dll">
3232
<Private>false</Private>
3333
</Reference>
34+
<None Update="c-wspp.dll">
35+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
36+
</None>
37+
<None Update="Assets\APFiller.png">
38+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
39+
</None>
40+
<None Update="Assets\APProgression.png">
41+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
42+
</None>
43+
<None Update="Assets\APTrap.png">
44+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
45+
</None>
46+
<None Update="Assets\APUseful.png">
47+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
48+
</None>
49+
<None Update="Assets\Roll.png">
50+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
51+
</None>
52+
<None Update="Assets\Stick.png">
53+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
54+
</None>
55+
<None Update="Assets\SuitApaFrog.png">
56+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
57+
</None>
58+
<None Update="Assets\SuitJennyBerry.png">
59+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
60+
</None>
61+
<None Update="Assets\SuitThatGuy.png">
62+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
63+
</None>
3464

3565
<None Update="Data\itemData.json">
3666
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -45,6 +75,9 @@
4575
<None Update="thumbnail.png">
4676
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4777
</None>
78+
<None Update="websocket-sharp.dll">
79+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
80+
</None>
4881

4982
<Publicize Include="Assembly-CSharp" />
5083
</ItemGroup>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Code/APHandler.cs

+50-24
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
using Archipelago.MultiClient.Net.Models;
66
using ModCore;
77
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
810

911
namespace ArchipelagoRandomizer
1012
{
1113
public class APHandler
1214
{
1315
private static APHandler instance;
1416
private const int baseId = 238492834;
15-
private ArchipelagoSession session;
16-
private PlayerInfo currentPlayer;
17+
private List<ScoutedItemInfo> scoutedItems;
1718

1819
public static APHandler Instance { get { return instance; } }
19-
public static ArchipelagoSession Session { get { return instance.session; } }
20-
public PlayerInfo CurrentPlayer { get { return currentPlayer; } }
20+
public static ArchipelagoSession Session { get; private set; }
21+
public PlayerInfo CurrentPlayer { get; private set; }
2122

2223
public APHandler()
2324
{
@@ -26,13 +27,13 @@ public APHandler()
2627

2728
public bool TryCreateSession(string url, string slot, string password, out string message)
2829
{
29-
if (session != null)
30+
if (Session != null)
3031
{
31-
session.MessageLog.OnMessageReceived -= OnReceiveMessage;
32+
Session.MessageLog.OnMessageReceived -= OnReceiveMessage;
3233
}
3334
try
3435
{
35-
session = ArchipelagoSessionFactory.CreateSession(url);
36+
Session = ArchipelagoSessionFactory.CreateSession(url);
3637
}
3738
catch (Exception ex)
3839
{
@@ -44,7 +45,7 @@ public bool TryCreateSession(string url, string slot, string password, out strin
4445

4546
try
4647
{
47-
result = session.TryConnectAndLogin("Ittle Dew 2", slot, ItemsHandlingFlags.AllItems, password: password);
48+
result = Session.TryConnectAndLogin("Ittle Dew 2", slot, ItemsHandlingFlags.AllItems, password: password);
4849
}
4950
catch (Exception ex)
5051
{
@@ -68,38 +69,63 @@ public bool TryCreateSession(string url, string slot, string password, out strin
6869
}
6970

7071
var loginSuccess = (LoginSuccessful)result;
71-
currentPlayer = session.Players.GetPlayerInfo(session.ConnectionInfo.Slot);
72-
session.MessageLog.OnMessageReceived += OnReceiveMessage;
73-
message = "Successfully connected!\n" +
74-
"Now that you are connected, you can use !help to list commands to run via the server.";
75-
session.Items.ItemReceived += OnReceivedItem;
72+
CurrentPlayer = Session.Players.GetPlayerInfo(Session.ConnectionInfo.Slot);
73+
Session.MessageLog.OnMessageReceived += OnReceiveMessage;
74+
Session.Locations.CheckedLocationsUpdated += OnLocationChecked;
75+
Session.Items.ItemReceived += OnReceivedItem;
76+
message = "Successfully connected!\nNow that you are connected, you can use !help to list commands to run via the server.";
77+
ScoutLocations();
7678
return true;
7779
}
7880

81+
public void LocationChecked(int offset)
82+
{
83+
if (Session == null)
84+
{
85+
Plugin.Log.LogError("Error in APHandler.LocationChecked(): No session exists yet!");
86+
return;
87+
}
88+
89+
Session.Locations.CompleteLocationChecks(baseId + offset);
90+
}
91+
92+
private void OnLocationChecked(System.Collections.ObjectModel.ReadOnlyCollection<long> newCheckedLocations)
93+
{
94+
long id = newCheckedLocations[newCheckedLocations.Count - 1];
95+
string locationName = Session.Locations.GetLocationNameFromId(id);
96+
ScoutedItemInfo item = scoutedItems.FirstOrDefault(x => x.LocationId == id);
97+
98+
// If sending item
99+
if (item != null && item.Player.Slot != CurrentPlayer.Slot)
100+
ItemRandomizer.Instance.ItemSent(item.ItemDisplayName, item.Player.Name);
101+
102+
Plugin.Log.LogInfo($"Checked location: {locationName}");
103+
}
104+
79105
private void OnReceivedItem(ReceivedItemsHelper helper)
80106
{
81-
ItemInfo receivedItem = session.Items.AllItemsReceived[session.Items.AllItemsReceived.Count - 1];
107+
ItemInfo receivedItem = Session.Items.AllItemsReceived[Session.Items.AllItemsReceived.Count - 1];
82108
int itemOffset = (int)receivedItem.ItemId - baseId;
83-
ItemRandomizer.Instance.ItemReceived(itemOffset, receivedItem.Player.Name);
109+
ItemRandomizer.Instance.ItemReceived(itemOffset, receivedItem.ItemDisplayName, receivedItem.Player.Name);
84110
}
85111

86-
public void LocationChecked(int offset)
112+
private void ScoutLocations()
87113
{
88-
if (session == null)
114+
if (Session == null)
89115
{
90-
Plugin.Log.LogError("Attempted to interact with Archipelago server, but no session has been started yet!");
116+
Plugin.Log.LogError($"Error in APHandler.ScoutLocations(): No session exists yet!");
91117
return;
92118
}
93119

94-
int id = baseId + offset;
95-
session.Locations.CompleteLocationChecksAsync((completed) =>
120+
scoutedItems = new();
121+
122+
Session.Locations.ScoutLocationsAsync((scoutResult) =>
96123
{
97-
if (completed)
124+
foreach (ScoutedItemInfo item in scoutResult.Values)
98125
{
99-
string locationName = session.Locations.GetLocationNameFromId(id);
100-
Plugin.Log.LogInfo($"Checked location: {locationName} ({offset})");
126+
scoutedItems.Add(item);
101127
}
102-
}, id);
128+
}, Session.Locations.AllLocations.ToArray());
103129
}
104130

105131
private void OnReceiveMessage(LogMessage message)

0 commit comments

Comments
 (0)