From c6d7af45fa044bbc3749c8012beb5bcc022e41a2 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 26 May 2024 12:50:11 -0400 Subject: Scout locations for personal chest icons --- AnodyneArchipelago/ArchipelagoManager.cs | 32 +++++++++++ AnodyneArchipelago/ArchipelagoTreasure.cs | 76 ++++++++++++++++++++++++++- AnodyneArchipelago/Patches/GameplayPatches.cs | 2 +- 3 files changed, 108 insertions(+), 2 deletions(-) (limited to 'AnodyneArchipelago') diff --git a/AnodyneArchipelago/ArchipelagoManager.cs b/AnodyneArchipelago/ArchipelagoManager.cs index e4ccf36..94085f0 100644 --- a/AnodyneArchipelago/ArchipelagoManager.cs +++ b/AnodyneArchipelago/ArchipelagoManager.cs @@ -25,6 +25,8 @@ namespace AnodyneArchipelago private readonly Queue _itemsToCollect = new(); private readonly Queue _messages = new(); + private Task> _scoutTask; + public long EndgameCardRequirement => _endgameCardRequirement; public async Task Connect(string url, string slotName, string password) @@ -54,6 +56,8 @@ namespace AnodyneArchipelago _endgameCardRequirement = (long)login.SlotData["endgame_card_requirement"]; } + _scoutTask = Task.Run(() => ScoutAllLocations()); + return result; } @@ -73,6 +77,34 @@ namespace AnodyneArchipelago _session = null; } + private async Task> ScoutAllLocations() + { + LocationInfoPacket locationInfo = await _session.Locations.ScoutLocationsAsync(_session.Locations.AllLocations.ToArray()); + + Dictionary result = new(); + foreach (NetworkItem networkItem in locationInfo.Locations) + { + result[_session.Locations.GetLocationNameFromId(networkItem.Location)] = networkItem; + } + + return result; + } + + public NetworkItem? GetScoutedLocation(string locationName) + { + if (_scoutTask == null || !_scoutTask.IsCompleted || !_scoutTask.Result.ContainsKey(locationName)) + { + return null; + } + + return _scoutTask.Result[locationName]; + } + + public string GetItemName(long id) + { + return _session.Items.GetItemName(id); + } + public string GetSeed() { return _seedName; diff --git a/AnodyneArchipelago/ArchipelagoTreasure.cs b/AnodyneArchipelago/ArchipelagoTreasure.cs index 9074108..b160f0d 100644 --- a/AnodyneArchipelago/ArchipelagoTreasure.cs +++ b/AnodyneArchipelago/ArchipelagoTreasure.cs @@ -1,6 +1,7 @@ using AnodyneSharp.Entities; using AnodyneSharp.Entities.Gadget.Treasures; using AnodyneSharp.Registry; +using Archipelago.MultiClient.Net.Models; using Microsoft.Xna.Framework; namespace AnodyneArchipelago @@ -9,7 +10,80 @@ namespace AnodyneArchipelago { private string _location; - public ArchipelagoTreasure(string location, Vector2 pos) : base("archipelago", pos, 0, -1) + private static (string, int) GetSprite(string location) + { + NetworkItem? item = Plugin.ArchipelagoManager.GetScoutedLocation(location); + if (item == null) + { + return ("archipelago", 0); + } + + if (item?.Player != Plugin.ArchipelagoManager.GetPlayer()) + { + return ("archipelago", 0); + } + + string itemName = Plugin.ArchipelagoManager.GetItemName(item?.Item ?? 0); + if (itemName.StartsWith("Small Key")) + { + return ("key", 0); + } + else if (itemName == "Green Key") + { + return ("key_green", 0); + } + else if (itemName == "Blue Key") + { + return ("key_green", 4); + } + else if (itemName == "Red Key") + { + return ("key_green", 2); + } + else if (itemName == "Jump Shoes") + { + return ("item_jump_shoes", 0); + } + else if (itemName == "Health Cicada") + { + return ("life_cicada", 0); + } + else if (itemName == "Heal") + { + return ("small_health_pickup", 0); + } + else if (itemName == "Swap") + { + return ("item_tranformer", 0); + } + else if (itemName == "Extend") + { + return ("item_long_attack", 0); + } + else if (itemName == "Widen") + { + return ("item_wide_attack", 0); + } + else if (itemName == "Cardboard Box") + { + return ("fields_npcs", 31); + } + else if (itemName == "Biking Shoes") + { + return ("item_jump_shoes", 0); + } + + return ("archipelago", 0); + } + + public static ArchipelagoTreasure Create(string location, Vector2 pos) + { + (string textureName, int frame) = GetSprite(location); + + return new(location, pos, textureName, frame); + } + + private ArchipelagoTreasure(string location, Vector2 pos, string textureName, int frame) : base(textureName, pos, frame, -1) { _location = location; } diff --git a/AnodyneArchipelago/Patches/GameplayPatches.cs b/AnodyneArchipelago/Patches/GameplayPatches.cs index 056a855..6a7b621 100644 --- a/AnodyneArchipelago/Patches/GameplayPatches.cs +++ b/AnodyneArchipelago/Patches/GameplayPatches.cs @@ -37,7 +37,7 @@ namespace AnodyneArchipelago.Patches Guid entityId = PatchHelper.GetEntityPreset(typeof(TreasureChest), __instance).EntityID; if (Locations.LocationsByGuid.ContainsKey(entityId)) { - BaseTreasure treasure = new ArchipelagoTreasure(Locations.LocationsByGuid[entityId], __instance.Position); + BaseTreasure treasure = ArchipelagoTreasure.Create(Locations.LocationsByGuid[entityId], __instance.Position); FieldInfo treasureField = typeof(TreasureChest).GetField("_treasure", BindingFlags.NonPublic | BindingFlags.Instance); treasureField.SetValue(__instance, treasure); -- cgit 1.4.1