mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-11-27 10:06:53 -08:00
Moved Party data to service.
This commit is contained in:
parent
8905d84bc6
commit
5c9879b515
@ -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,
|
||||||
|
|||||||
@ -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>();
|
||||||
|
|||||||
33
src/Services/PartyService.cs
Normal file
33
src/Services/PartyService.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user