diff --git a/EpinelPS/GameData/GameData.cs b/EpinelPS/GameData/GameData.cs index 412f4b2..10df7cf 100644 --- a/EpinelPS/GameData/GameData.cs +++ b/EpinelPS/GameData/GameData.cs @@ -3,6 +3,7 @@ using ICSharpCode.SharpZipLib.Zip; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Diagnostics; +using System.Reflection; using System.Security.Cryptography; namespace EpinelPS.StaticInfo @@ -25,12 +26,14 @@ namespace EpinelPS.StaticInfo private ZipFile MainZip; private MemoryStream ZipStream; - private Dictionary questDataRecords; + + + private Dictionary questDataRecords = []; private Dictionary stageDataRecords; private Dictionary rewardDataRecords; - private JArray userExpDataRecords; + private Dictionary userExpDataRecords; private Dictionary chapterCampaignData; - private JArray characterCostumeTable; + private Dictionary characterCostumeTable; public Dictionary characterTable; public Dictionary tutorialTable; public Dictionary itemEquipTable; @@ -38,9 +41,9 @@ namespace EpinelPS.StaticInfo public Dictionary itemEquipExpTable; public Dictionary ItemEquipGradeExpTable; private Dictionary FieldMapData = new Dictionary(); // Fixed initialization - private Dictionary LevelData = new Dictionary(); // Fixed initialization + private Dictionary LevelData = []; private Dictionary TacticAcademyLessons = new Dictionary(); // Fixed initialization - public Dictionary SidestoryRewardTable = new Dictionary(); // Fixed initialization + public Dictionary SidestoryRewardTable = []; public Dictionary PositionReward = new Dictionary(); // Fixed initialization public Dictionary FieldItems = new Dictionary(); // Fixed initialization public Dictionary OutpostBattle = new Dictionary(); // Fixed initialization @@ -280,6 +283,17 @@ namespace EpinelPS.StaticInfo { using var progress = new ProgressBar(); + var fieldsWhereGameData = GetType().GetProperties().Where(x => x.GetCustomAttribute() != null); + totalFiles = fieldsWhereGameData.Count(); + + foreach (var attribs in fieldsWhereGameData) + { + var attrib = attribs.GetCustomAttribute(); + + + } + + var questDataRecords = await LoadZip("MainQuestTable.json", progress); foreach (var obj in questDataRecords.records) { @@ -304,8 +318,17 @@ namespace EpinelPS.StaticInfo this.chapterCampaignData.Add(obj.chapter, obj); } - userExpDataRecords = await LoadZip("UserExpTable.json", progress); - characterCostumeTable = await LoadZip("CharacterCostumeTable.json", progress); + var userExpDataRecords = await LoadZip("UserExpTable.json", progress); + foreach (var obj in userExpDataRecords.records) + { + this.userExpDataRecords.Add(obj.level, obj); + } + + var characterCostumeTable = await LoadZip("CharacterCostumeTable.json", progress); + foreach (var obj in characterCostumeTable.records) + { + this.characterCostumeTable.Add(obj.id, obj); + } var characterTable = await LoadZip("CharacterTable.json", progress); foreach (var obj in characterTable.records) @@ -343,15 +366,10 @@ namespace EpinelPS.StaticInfo this.ItemEquipGradeExpTable.Add(obj.id, obj); } - var characterLevelTable = await LoadZip("CharacterLevelTable.json", progress); - - foreach (JToken item in characterLevelTable) + var characterLevelTable = await LoadZip("CharacterLevelTable.json", progress); + foreach (var obj in characterLevelTable.records) { - var obj = item.ToObject(); - if (obj != null) - LevelData.Add(obj.level, obj); - else - Console.WriteLine("failed to read character level table entry"); + LevelData.Add(obj.level, obj); } var tacticLessonTable = await LoadZip("TacticAcademyFunctionTable.json", progress); @@ -360,24 +378,12 @@ namespace EpinelPS.StaticInfo TacticAcademyLessons.Add(obj.id, obj); } - var sideStoryTable = await LoadZip("SideStoryStageTable.json", progress); - - foreach (JToken item in sideStoryTable) + var sidestoryTable = await LoadZip("SideStoryStageTable.json", progress); + foreach (var obj in sidestoryTable.records) { - var idRaw = item["id"]; - var rewardIdRaw = item["first_clear_reward"]; - - if (idRaw == null) throw new InvalidDataException(); - if (rewardIdRaw != null) - { - var id2 = idRaw.ToObject(); - var reward = rewardIdRaw.ToObject(); - - SidestoryRewardTable.Add(id2, reward); - } + SidestoryRewardTable.Add(obj.id, obj); } - foreach (ZipEntry item in MainZip) { if (item.Name.StartsWith("CampaignMap/") || item.Name.StartsWith("EventMap/")) @@ -482,9 +488,18 @@ namespace EpinelPS.StaticInfo { albumResourceRecords.Add(obj.id, obj); // Now refers to the class-level field } - // Load Jukebox data - await LoadJukeboxListData(progress); - await LoadJukeboxThemeData(progress); + + var jukeboxListData = await LoadZip("JukeboxListTable.json", progress); + foreach (var obj in jukeboxListData.records) + { + jukeboxListDataRecords.Add(obj.id, obj); // Now refers to the class-level field + } + + var jukeboxThemeData = await LoadZip("JukeboxThemeTable.json", progress); + foreach (var obj in jukeboxThemeData.records) + { + jukeboxThemeDataRecords.Add(obj.id, obj); // Now refers to the class-level field + } var characterStatTable = await LoadZip("CharacterStatTable.json", progress); foreach (var obj in characterStatTable.records) @@ -517,37 +532,11 @@ namespace EpinelPS.StaticInfo } } - public async Task LoadJukeboxListData(ProgressBar bar) - { - var jukeboxListData = await LoadZip("JukeboxListTable.json", bar); - foreach (JObject obj in jukeboxListData) - { - var record = obj.ToObject(); - if (record != null) - { - jukeboxListDataRecords.Add(record.id, record); - } - } - } - public Dictionary GetJukeboxListDataRecords() { return jukeboxListDataRecords; } - public async Task LoadJukeboxThemeData(ProgressBar bar) - { - var jukeboxThemeData = await LoadZip("JukeboxThemeTable.json", bar); - foreach (JObject obj in jukeboxThemeData) - { - var record = obj.ToObject(); - if (record != null) - { - jukeboxThemeDataRecords.Add(record.id, record); - } - } - } - public MainQuestCompletionRecord? GetMainQuestForStageClearCondition(int stage) { foreach (var item in questDataRecords) @@ -582,20 +571,14 @@ namespace EpinelPS.StaticInfo { int prevLevel = 0; int prevValue = 0; - for (int i = 0; i < userExpDataRecords.Count; i++) + for (int i = 1; i < userExpDataRecords.Count + 1; i++) { var item = userExpDataRecords[i]; - var level = item["level"] ?? throw new Exception("expected level field in user exp table data"); - int levelValue = level.ToObject(); - - var exp = item["exp"] ?? throw new Exception("expected exp field in user exp table data"); - int expValue = exp.ToObject(); - if (prevValue < targetExp) { - prevLevel = levelValue; - prevValue = expValue; + prevLevel = item.level; + prevValue = item.exp; } else { @@ -606,21 +589,13 @@ namespace EpinelPS.StaticInfo } public int GetUserMinXpForLevel(int targetLevel) { - for (int i = 0; i < userExpDataRecords.Count; i++) + for (int i = 1; i < userExpDataRecords.Count + 1; i++) { var item = userExpDataRecords[i]; - var level = item["level"]; - if (level == null) throw new Exception("expected level field in user exp table data"); - - int levelValue = level.ToObject(); - if (targetLevel == levelValue) + if (targetLevel == item.level) { - var exp = item["exp"]; - if (exp == null) throw new Exception("expected exp field in user exp table data"); - - int expValue = exp.ToObject(); - return expValue; + return item.exp; } } return -1; @@ -644,13 +619,9 @@ namespace EpinelPS.StaticInfo } public IEnumerable GetAllCostumes() { - foreach (JObject item in characterCostumeTable) + foreach (var item in characterCostumeTable) { - var id = item["id"]; - if (id == null) throw new Exception("expected id field in reward data"); - - int value = id.ToObject(); - yield return value; + yield return item.Value.id; } } @@ -690,19 +661,6 @@ namespace EpinelPS.StaticInfo return TacticAcademyLessons[lessonId]; } - // Methods to access Jukebox data - public JukeboxListRecord? GetJukeboxListRecordById(int id) - { - jukeboxListDataRecords.TryGetValue(id, out var record); - return record; - } - - public JukeboxThemeRecord? GetJukeboxThemeRecordById(int id) - { - jukeboxThemeDataRecords.TryGetValue(id, out var record); - return record; - } - public IEnumerable GetScenarioStageIdsForChapter(int chapterNumber) { @@ -760,8 +718,6 @@ namespace EpinelPS.StaticInfo return false; } - - } public enum TriggerType diff --git a/EpinelPS/GameData/JsonStaticData.cs b/EpinelPS/GameData/JsonStaticData.cs index 244914b..e86e951 100644 --- a/EpinelPS/GameData/JsonStaticData.cs +++ b/EpinelPS/GameData/JsonStaticData.cs @@ -94,6 +94,10 @@ /// public int character_exp2 = 0; } + public class CharacterLevelTable + { + public List records = []; + } public class TacticAcademyLessonReward { @@ -623,4 +627,35 @@ { public List records = []; } + + public class UserExpRecord + { + public int level; + public int exp; + public int reward_id; + } + public class UserExpTable + { + public List records = []; + } + + public class CharacterCostumeRecord + { + public int id; + } + public class CharacterCostumeTable + { + public List records = []; + } + + public class SideStoryStageRecord + { + public int id; + public int first_clear_reward; + } + + public class SideStoryStageTable + { + public List records = []; + } } diff --git a/EpinelPS/LobbyServer/Sidestory/ClearSideStoryStage.cs b/EpinelPS/LobbyServer/Sidestory/ClearSideStoryStage.cs index 7193327..a9c72a9 100644 --- a/EpinelPS/LobbyServer/Sidestory/ClearSideStoryStage.cs +++ b/EpinelPS/LobbyServer/Sidestory/ClearSideStoryStage.cs @@ -21,7 +21,7 @@ namespace EpinelPS.LobbyServer.Sidestory if (GameData.Instance.SidestoryRewardTable.ContainsKey(req.SideStoryStageId)) { - var rewardData = GameData.Instance.GetRewardTableEntry(GameData.Instance.SidestoryRewardTable[req.SideStoryStageId]); + var rewardData = GameData.Instance.GetRewardTableEntry(GameData.Instance.SidestoryRewardTable[req.SideStoryStageId].first_clear_reward); if (rewardData != null) response.Reward = RewardUtils.RegisterRewardsForUser(user, rewardData); diff --git a/EpinelPS/LobbyServer/Stage/ClearStage.cs b/EpinelPS/LobbyServer/Stage/ClearStage.cs index a372cea..fa0a184 100644 --- a/EpinelPS/LobbyServer/Stage/ClearStage.cs +++ b/EpinelPS/LobbyServer/Stage/ClearStage.cs @@ -147,11 +147,13 @@ namespace EpinelPS.LobbyServer.Stage private static void DoQuestSpecificUserOperations(Database.User user, int clearedStageId) { - var quest = GameData.Instance.GetMainQuestForStageClearCondition(clearedStageId) ?? throw new Exception("cannot find quest from cleared stage id"); - - user.SetQuest(quest.id, false); - user.AddTrigger(TriggerType.CampaignClear, 1, clearedStageId); - user.AddTrigger(TriggerType.MainQuestClear, 1, quest.id); + var quest = GameData.Instance.GetMainQuestForStageClearCondition(clearedStageId); + if (quest != null) + { + user.SetQuest(quest.id, false); + user.AddTrigger(TriggerType.CampaignClear, 1, clearedStageId); + user.AddTrigger(TriggerType.MainQuestClear, 1, quest.id); + } // TODO: Is this the right place to add default characters? // Stage 1-4 BOSS