diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index 2c52423..342776f 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -18,6 +18,7 @@ public class ContentController : Controller { private MissionStoreSingleton missionStore; private MissionService missionService; private RoomService roomService; + private PartyService partyService; private AchievementService achievementService; private InventoryService inventoryService; private GameDataService gameDataService; @@ -34,6 +35,7 @@ public class ContentController : Controller { MissionStoreSingleton missionStore, MissionService missionService, RoomService roomService, + PartyService partyService, AchievementService achievementService, InventoryService inventoryService, GameDataService gameDataService, @@ -48,6 +50,7 @@ public class ContentController : Controller { this.missionStore = missionStore; this.missionService = missionService; this.roomService = roomService; + this.partyService = partyService; this.achievementService = achievementService; this.inventoryService = inventoryService; this.gameDataService = gameDataService; @@ -1489,15 +1492,9 @@ public class ContentController : Controller { uint gameID = ClientVersion.GetGameID(apiKey); - PartiesInfo data = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("parties_info")); - PartyInfo? info = data.Parties.FirstOrDefault(p => p.GameID == gameID && p.Type == partyType); + PartyInfo? info = partyService.GetParty(gameID, partyType); if (info == null) return Ok(null); - if (info.Location == null) { - Console.WriteLine($"Unsupported partyType \"{partyType}\" for gameid 0x{gameID:X8}"); - return Ok(null); - } - // check if party already exists if (viking.Parties.Any(e => e.Location == info.Location)) return Ok(null); @@ -1505,7 +1502,7 @@ public class ContentController : Controller { Party party = new Party { Location = info.Location, IconAsset = info.Icon, - LocationIconAsset = data.LocationIcons.GetValueOrDefault(info.Location, ""), + LocationIconAsset = partyService.GetLocation(info) ?? "", AssetBundle = info.Bundle, PrivateParty = false, GameID = gameID, diff --git a/src/Program.cs b/src/Program.cs index 91cbbaa..f16b331 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -30,6 +30,7 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); diff --git a/src/Services/PartyService.cs b/src/Services/PartyService.cs new file mode 100644 index 0000000..1cd792b --- /dev/null +++ b/src/Services/PartyService.cs @@ -0,0 +1,33 @@ +using sodoff.Schema; +using sodoff.Util; + +namespace sodoff.Services; + +public class PartyService { + PartiesInfo parties; + Dictionary> partyData = new Dictionary>(); + + public PartyService() { + parties = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("parties_info")); + + foreach (PartyInfo party in parties.Parties) { + if (partyData.TryGetValue(party.GameID, out Dictionary? partyDict)) { + partyDict.TryAdd(party.Type, party); + } else { + partyDict = new Dictionary(); + partyData.Add(party.GameID, partyDict); + } + } + } + + public PartyInfo? GetParty(uint gameID, string partyType) { + if (!partyData.TryGetValue(gameID, out Dictionary? partyDict)) return null; + partyDict.TryGetValue(partyType, out PartyInfo? party); + return party; + } + + public string? GetLocation(PartyInfo party) { + parties.LocationIcons.TryGetValue(party.Location, out string? value); + return value; + } +} \ No newline at end of file