Moved Party data to service.

This commit is contained in:
Hipposgrumm 2025-10-19 20:10:55 -06:00
parent 8905d84bc6
commit 5c9879b515
3 changed files with 39 additions and 8 deletions

View File

@ -18,6 +18,7 @@ public class ContentController : Controller {
private MissionStoreSingleton missionStore; private MissionStoreSingleton missionStore;
private MissionService missionService; private MissionService missionService;
private RoomService roomService; private RoomService roomService;
private PartyService partyService;
private AchievementService achievementService; private AchievementService achievementService;
private InventoryService inventoryService; private InventoryService inventoryService;
private GameDataService gameDataService; private GameDataService gameDataService;
@ -34,6 +35,7 @@ public class ContentController : Controller {
MissionStoreSingleton missionStore, MissionStoreSingleton missionStore,
MissionService missionService, MissionService missionService,
RoomService roomService, RoomService roomService,
PartyService partyService,
AchievementService achievementService, AchievementService achievementService,
InventoryService inventoryService, InventoryService inventoryService,
GameDataService gameDataService, GameDataService gameDataService,
@ -48,6 +50,7 @@ public class ContentController : Controller {
this.missionStore = missionStore; this.missionStore = missionStore;
this.missionService = missionService; this.missionService = missionService;
this.roomService = roomService; this.roomService = roomService;
this.partyService = partyService;
this.achievementService = achievementService; this.achievementService = achievementService;
this.inventoryService = inventoryService; this.inventoryService = inventoryService;
this.gameDataService = gameDataService; this.gameDataService = gameDataService;
@ -1489,15 +1492,9 @@ public class ContentController : Controller {
uint gameID = ClientVersion.GetGameID(apiKey); uint gameID = ClientVersion.GetGameID(apiKey);
PartiesInfo data = XmlUtil.DeserializeXml<PartiesInfo>(XmlUtil.ReadResourceXmlString("parties_info")); PartyInfo? info = partyService.GetParty(gameID, partyType);
PartyInfo? info = data.Parties.FirstOrDefault(p => p.GameID == gameID && p.Type == partyType);
if (info == null) return Ok(null); 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 // check if party already exists
if (viking.Parties.Any(e => e.Location == info.Location)) return Ok(null); if (viking.Parties.Any(e => e.Location == info.Location)) return Ok(null);
@ -1505,7 +1502,7 @@ public class ContentController : Controller {
Party party = new Party { Party party = new Party {
Location = info.Location, Location = info.Location,
IconAsset = info.Icon, IconAsset = info.Icon,
LocationIconAsset = data.LocationIcons.GetValueOrDefault(info.Location, ""), LocationIconAsset = partyService.GetLocation(info) ?? "",
AssetBundle = info.Bundle, AssetBundle = info.Bundle,
PrivateParty = false, PrivateParty = false,
GameID = gameID, GameID = gameID,

View File

@ -30,6 +30,7 @@ builder.Services.AddSingleton<ItemService>();
builder.Services.AddSingleton<StoreService>(); builder.Services.AddSingleton<StoreService>();
builder.Services.AddSingleton<DisplayNamesService>(); builder.Services.AddSingleton<DisplayNamesService>();
builder.Services.AddSingleton<MMOConfigService>(); builder.Services.AddSingleton<MMOConfigService>();
builder.Services.AddSingleton<PartyService>();
builder.Services.AddSingleton<WorldIdService>(); builder.Services.AddSingleton<WorldIdService>();
builder.Services.AddScoped<KeyValueService>(); builder.Services.AddScoped<KeyValueService>();

View File

@ -0,0 +1,33 @@
using sodoff.Schema;
using sodoff.Util;
namespace sodoff.Services;
public class PartyService {
PartiesInfo parties;
Dictionary<uint, Dictionary<string, PartyInfo>> partyData = new Dictionary<uint, Dictionary<string, PartyInfo>>();
public PartyService() {
parties = XmlUtil.DeserializeXml<PartiesInfo>(XmlUtil.ReadResourceXmlString("parties_info"));
foreach (PartyInfo party in parties.Parties) {
if (partyData.TryGetValue(party.GameID, out Dictionary<string, PartyInfo>? partyDict)) {
partyDict.TryAdd(party.Type, party);
} else {
partyDict = new Dictionary<string, PartyInfo>();
partyData.Add(party.GameID, partyDict);
}
}
}
public PartyInfo? GetParty(uint gameID, string partyType) {
if (!partyData.TryGetValue(gameID, out Dictionary<string, PartyInfo>? 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;
}
}