From f368e36c698110367cef10ac11d1f9550170393d Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 30 Oct 2024 17:47:47 -0400 Subject: [PATCH] update event data and improve event code --- EpinelPS/GameData/GameData.cs | 196 +++++++++--------- .../LobbyServer/Msgs/Campaign/ObtainItem.cs | 15 +- .../LobbyServer/Msgs/Event/EnterEventField.cs | 8 + EpinelPS/LobbyServer/Msgs/Event/ListEvents.cs | 18 +- EpinelPS/Utils/ColorConsoleLoggerProvider.cs | 2 + 5 files changed, 140 insertions(+), 99 deletions(-) diff --git a/EpinelPS/GameData/GameData.cs b/EpinelPS/GameData/GameData.cs index 986b0b8..cad4e76 100644 --- a/EpinelPS/GameData/GameData.cs +++ b/EpinelPS/GameData/GameData.cs @@ -43,10 +43,10 @@ namespace EpinelPS.StaticInfo public Dictionary OutpostBattle = new Dictionary(); // Fixed initialization public Dictionary jukeboxListDataRecords; private Dictionary jukeboxThemeDataRecords; - public Dictionary gachaTypes = new Dictionary(); // Fixed initialization - public Dictionary eventManagers = new Dictionary(); - public Dictionary lwptablemgrs = new Dictionary(); // Fixed initialization - private Dictionary albumResourceRecords = new Dictionary(); + public Dictionary gachaTypes = new Dictionary(); // Fixed initialization + public Dictionary eventManagers = new Dictionary(); + public Dictionary lwptablemgrs = new Dictionary(); // Fixed initialization + private Dictionary albumResourceRecords = new Dictionary(); @@ -349,61 +349,63 @@ namespace EpinelPS.StaticInfo foreach (ZipEntry item in MainZip) { - if (item.Name.StartsWith("CampaignMap/")) + if (item.Name.StartsWith("CampaignMap/") || item.Name.StartsWith("EventMap/")) { var x = await LoadZip(item.Name, progress); var items = x[0]["ItemSpawner"]; - foreach (var item2 in items) - { - var id = item2["positionId"].ToObject(); - var reward = item2["itemId"].ToObject(); - if (!PositionReward.ContainsKey(id)) - PositionReward.Add(id, reward); - } + if (items != null) + foreach (var item2 in items) + { + var id = item2["positionId"].ToObject(); + var reward = item2["itemId"].ToObject(); + + if (!PositionReward.ContainsKey(id)) + PositionReward.Add(id, reward); + } } } - var fieldItems = await LoadZip("FieldItemTable.json", progress); + var fieldItems = await LoadZip("FieldItemTable.json", progress); foreach (var obj in fieldItems.records) { FieldItems.Add(obj.id, obj); } - var battleOutpostTable = await LoadZip("OutpostBattleTable.json", progress); - foreach (var obj in battleOutpostTable.records) - { - OutpostBattle.Add(obj.id, obj); - } - - var gachaTypeTable = await LoadZip("GachaTypeTable.json", progress); + var battleOutpostTable = await LoadZip("OutpostBattleTable.json", progress); + foreach (var obj in battleOutpostTable.records) + { + OutpostBattle.Add(obj.id, obj); + } - // Add the records to the dictionary - foreach (var obj in gachaTypeTable.records) - { - gachaTypes.Add(obj.id, obj); // Use obj.id as the key and obj (the GachaType) as the value - } - - var eventManagerTable = await LoadZip("EventManagerTable.json", progress); + var gachaTypeTable = await LoadZip("GachaTypeTable.json", progress); - // Add the records to the dictionary - foreach (var obj in eventManagerTable.records) - { - eventManagers.Add(obj.id, obj); // Use obj.id as the key and obj (the EventManager) as the value - } + // Add the records to the dictionary + foreach (var obj in gachaTypeTable.records) + { + gachaTypes.Add(obj.id, obj); // Use obj.id as the key and obj (the GachaType) as the value + } - var lwptable = await LoadZip("LiveWallpaperTable.json", progress); + var eventManagerTable = await LoadZip("EventManagerTable.json", progress); - // Add the records to the dictionary - foreach (var obj in lwptable.records) - { - lwptablemgrs.Add(obj.id, obj); // Use obj.id as the key and obj (the LiveWallpaperRecord) as the value - } + // Add the records to the dictionary + foreach (var obj in eventManagerTable.records) + { + eventManagers.Add(obj.id, obj); // Use obj.id as the key and obj (the EventManager) as the value + } - var albumResourceTable = await LoadZip("AlbumResourceTable.json", progress); - foreach (var obj in albumResourceTable.records) - { - albumResourceRecords.Add(obj.id, obj); // Now refers to the class-level field - } + var lwptable = await LoadZip("LiveWallpaperTable.json", progress); + + // Add the records to the dictionary + foreach (var obj in lwptable.records) + { + lwptablemgrs.Add(obj.id, obj); // Use obj.id as the key and obj (the LiveWallpaperRecord) as the value + } + + var albumResourceTable = await LoadZip("AlbumResourceTable.json", progress); + foreach (var obj in albumResourceTable.records) + { + albumResourceRecords.Add(obj.id, obj); // Now refers to the class-level field + } // Load Jukebox data await LoadJukeboxListData(progress); await LoadJukeboxThemeData(progress); @@ -421,11 +423,11 @@ namespace EpinelPS.StaticInfo } } } - - public Dictionary GetJukeboxListDataRecords() - { - return jukeboxListDataRecords; - } + + public Dictionary GetJukeboxListDataRecords() + { + return jukeboxListDataRecords; + } public async Task LoadJukeboxThemeData(ProgressBar bar) { @@ -598,65 +600,65 @@ namespace EpinelPS.StaticInfo jukeboxThemeDataRecords.TryGetValue(id, out var record); return record; } - - public IEnumerable GetScenarioStageIdsForChapter(int chapterNumber) - { - - return albumResourceRecords.Values.Where(record => record.target_chapter == chapterNumber && !string.IsNullOrEmpty(record.scenario_group_id)).Select(record => record.scenario_group_id); - } - public bool IsValidScenarioStage(string scenarioGroupId, int targetChapter, int targetStage) - { - // Only process stages that belong to the main quest - if (!scenarioGroupId.StartsWith("d_main_")) - { - return false; // Exclude stages that don't belong to the main quest - } - // Example regular stage format: "d_main_26_08" - // Example bonus stage format: "d_main_18af_06" - // Example stage with suffix format: "d_main_01_01_s" or "d_main_01_01_e" + public IEnumerable GetScenarioStageIdsForChapter(int chapterNumber) + { - var parts = scenarioGroupId.Split('_'); + return albumResourceRecords.Values.Where(record => record.target_chapter == chapterNumber && !string.IsNullOrEmpty(record.scenario_group_id)).Select(record => record.scenario_group_id); + } + public bool IsValidScenarioStage(string scenarioGroupId, int targetChapter, int targetStage) + { + // Only process stages that belong to the main quest + if (!scenarioGroupId.StartsWith("d_main_")) + { + return false; // Exclude stages that don't belong to the main quest + } - if (parts.Length < 4) - { - return false; // If it doesn't have at least 4 parts, it's not a valid stage - } + // Example regular stage format: "d_main_26_08" + // Example bonus stage format: "d_main_18af_06" + // Example stage with suffix format: "d_main_01_01_s" or "d_main_01_01_e" - string chapterPart = parts[2]; // This could be "26", "18af", "01" - string stagePart = parts[3]; // This is the stage part, e.g., "08", "01_s", or "01_e" + var parts = scenarioGroupId.Split('_'); - // Remove any suffixes like "_s", "_e" from the stage part for comparison - string cleanedStagePart = stagePart.Split('_')[0]; // Removes "_s", "_e", etc. + if (parts.Length < 4) + { + return false; // If it doesn't have at least 4 parts, it's not a valid stage + } - // Handle bonus stages (ending in "af" or having "_s", "_e" suffix) - bool isBonusStage = chapterPart.EndsWith("af") || stagePart.Contains("_s") || stagePart.Contains("_e"); + string chapterPart = parts[2]; // This could be "26", "18af", "01" + string stagePart = parts[3]; // This is the stage part, e.g., "08", "01_s", or "01_e" - // Extract chapter number (remove "af" if present) - string chapterNumberStr = isBonusStage && chapterPart.EndsWith("af") - ? chapterPart.Substring(0, chapterPart.Length - 2) // Remove "af" - : chapterPart; + // Remove any suffixes like "_s", "_e" from the stage part for comparison + string cleanedStagePart = stagePart.Split('_')[0]; // Removes "_s", "_e", etc. - // Parse chapter and stage numbers - if (int.TryParse(chapterNumberStr, out int chapter) && int.TryParse(cleanedStagePart, out int stage)) - { - // Check if it's a bonus stage with a suffix - bool isSpecialStage = stagePart.Contains("_s") || stagePart.Contains("_e"); + // Handle bonus stages (ending in "af" or having "_s", "_e" suffix) + bool isBonusStage = chapterPart.EndsWith("af") || stagePart.Contains("_s") || stagePart.Contains("_e"); - // Only accept stages if they are: - // 1. In a chapter less than the target chapter - // 2. OR in the target chapter but with a stage number less than or equal to the target stage - // 3. OR it's a special stage (with "_s" or "_e") in the target chapter and target stage - if (chapter < targetChapter || - (chapter == targetChapter && (stage < targetStage || (stage == targetStage && isSpecialStage)))) - { - return true; - } - } + // Extract chapter number (remove "af" if present) + string chapterNumberStr = isBonusStage && chapterPart.EndsWith("af") + ? chapterPart.Substring(0, chapterPart.Length - 2) // Remove "af" + : chapterPart; + + // Parse chapter and stage numbers + if (int.TryParse(chapterNumberStr, out int chapter) && int.TryParse(cleanedStagePart, out int stage)) + { + // Check if it's a bonus stage with a suffix + bool isSpecialStage = stagePart.Contains("_s") || stagePart.Contains("_e"); + + // Only accept stages if they are: + // 1. In a chapter less than the target chapter + // 2. OR in the target chapter but with a stage number less than or equal to the target stage + // 3. OR it's a special stage (with "_s" or "_e") in the target chapter and target stage + if (chapter < targetChapter || + (chapter == targetChapter && (stage < targetStage || (stage == targetStage && isSpecialStage)))) + { + return true; + } + } + + return false; + } - return false; - } - } } diff --git a/EpinelPS/LobbyServer/Msgs/Campaign/ObtainItem.cs b/EpinelPS/LobbyServer/Msgs/Campaign/ObtainItem.cs index 3a2d3b8..15e1157 100644 --- a/EpinelPS/LobbyServer/Msgs/Campaign/ObtainItem.cs +++ b/EpinelPS/LobbyServer/Msgs/Campaign/ObtainItem.cs @@ -18,7 +18,20 @@ namespace EpinelPS.LobbyServer.Msgs.Campaign var chapter = GameData.Instance.GetNormalChapterNumberFromFieldName(req.MapId); var mod = req.MapId.Contains("hard") ? "Hard" : "Normal"; var key = chapter + "_" + mod; - var field = user.FieldInfoNew[key]; + + if (chapter == -1) + { + Console.WriteLine("Warning: unknown chapter id for " + req.MapId); + key = req.MapId; + } + + FieldInfoNew field; + + if (!user.FieldInfoNew.TryGetValue(key, out field)) + { + field = new FieldInfoNew(); + user.FieldInfoNew.Add(key, field); + } foreach (var item in field.CompletedObjects) diff --git a/EpinelPS/LobbyServer/Msgs/Event/EnterEventField.cs b/EpinelPS/LobbyServer/Msgs/Event/EnterEventField.cs index 0ac695a..c37d7b0 100644 --- a/EpinelPS/LobbyServer/Msgs/Event/EnterEventField.cs +++ b/EpinelPS/LobbyServer/Msgs/Event/EnterEventField.cs @@ -8,11 +8,19 @@ namespace EpinelPS.LobbyServer.Msgs.Event protected override async Task HandleAsync() { var req = await ReadData(); + var user = GetUser(); var response = new ResEnterEventField(); // TOOD + response.Field = new(); + + if (user.MapJson.TryGetValue(req.MapId, out string mapJson)) + { + response.Json = mapJson; + } + await WriteDataAsync(response); } } diff --git a/EpinelPS/LobbyServer/Msgs/Event/ListEvents.cs b/EpinelPS/LobbyServer/Msgs/Event/ListEvents.cs index c24d35c..ecdbc03 100644 --- a/EpinelPS/LobbyServer/Msgs/Event/ListEvents.cs +++ b/EpinelPS/LobbyServer/Msgs/Event/ListEvents.cs @@ -9,8 +9,10 @@ namespace EpinelPS.LobbyServer.Msgs.Event { var req = await ReadData(); - var response = new ResGetEventList(); + // 10: FieldHubEvent + var response = new ResGetEventList(); +/* response.EventList.Add(new NetEventData() { Id = 81301, @@ -117,6 +119,20 @@ namespace EpinelPS.LobbyServer.Msgs.Event EventEndDate = DateTime.Now.AddDays(20).Ticks, EventDisableDate = DateTime.Now.AddDays(20).Ticks, }); + +*/ + // Old tales +response.EventList.Add(new NetEventData() + { + Id = 81600, + EventSystemType = 10, + EventVisibleDate = DateTime.UtcNow.Subtract(TimeSpan.FromDays(7)).Ticks, + EventStartDate = DateTime.UtcNow.Subtract(TimeSpan.FromDays(1)).Ticks, + EventEndDate = DateTime.Now.AddDays(20).Ticks, + EventDisableDate = DateTime.Now.AddDays(20).Ticks, + }); + + //response.EventList.Add(new NetEventData() //{ // Id = 40054, diff --git a/EpinelPS/Utils/ColorConsoleLoggerProvider.cs b/EpinelPS/Utils/ColorConsoleLoggerProvider.cs index 277c1bf..4d63c8e 100644 --- a/EpinelPS/Utils/ColorConsoleLoggerProvider.cs +++ b/EpinelPS/Utils/ColorConsoleLoggerProvider.cs @@ -73,6 +73,8 @@ namespace EpinelPS.Utils Console.ForegroundColor = config.LogLevelToColorMap[logLevel]; Console.Write($"{msg}"); + if (exception != null) + Console.WriteLine(exception.ToString()); Console.ForegroundColor = originalColor; Console.WriteLine();