From 4b157363f822b7286cf2b35dda14543d49920fa6 Mon Sep 17 00:00:00 2001 From: Kyle873 Date: Sun, 22 Dec 2024 02:47:01 -0500 Subject: [PATCH] initial equip leveling impl --- EpinelPS/GameData/GameData.cs | 16 ++++ EpinelPS/GameData/JsonStaticData.cs | 54 +++++++++++++- .../Inventory/IncreaseEquipmentExp.cs | 74 +++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 EpinelPS/LobbyServer/Inventory/IncreaseEquipmentExp.cs diff --git a/EpinelPS/GameData/GameData.cs b/EpinelPS/GameData/GameData.cs index ac4aff5..ef0d80a 100644 --- a/EpinelPS/GameData/GameData.cs +++ b/EpinelPS/GameData/GameData.cs @@ -35,6 +35,8 @@ namespace EpinelPS.StaticInfo public Dictionary tutorialTable; public Dictionary itemEquipTable; public Dictionary itemMaterialTable; + public Dictionary itemEquipExpTable; + public Dictionary ItemEquipGradeExpTable; private Dictionary FieldMapData = new Dictionary(); // Fixed initialization private Dictionary LevelData = new Dictionary(); // Fixed initialization private Dictionary TacticAcademyLessons = new Dictionary(); // Fixed initialization @@ -96,6 +98,8 @@ namespace EpinelPS.StaticInfo tutorialTable = []; itemEquipTable = []; itemMaterialTable = []; + itemEquipExpTable = []; + ItemEquipGradeExpTable = []; characterStatTable = []; skillInfoTable = []; costTable = []; @@ -327,6 +331,18 @@ namespace EpinelPS.StaticInfo this.itemMaterialTable.Add(obj.id, obj); } + var itemEquipExpTable = await LoadZip("ItemEquipExpTable.json", progress); + foreach (var obj in itemEquipExpTable.records) + { + this.itemEquipExpTable.Add(obj.id, obj); + } + + var ItemEquipGradeExpTable = await LoadZip("ItemEquipGradeExpTable.json", progress); + foreach (var obj in ItemEquipGradeExpTable.records) + { + this.ItemEquipGradeExpTable.Add(obj.id, obj); + } + var characterLevelTable = await LoadZip("CharacterLevelTable.json", progress); foreach (JToken item in characterLevelTable) diff --git a/EpinelPS/GameData/JsonStaticData.cs b/EpinelPS/GameData/JsonStaticData.cs index 9ebe2ad..244914b 100644 --- a/EpinelPS/GameData/JsonStaticData.cs +++ b/EpinelPS/GameData/JsonStaticData.cs @@ -172,7 +172,32 @@ public class ItemEquipRecord { public int id; - public string item_sub_type = ""; + public string name_localkey; + public string description_localkey; + public string resource_id; + public string item_type; + public string item_sub_type; + public string @class; + public string item_rare; + public int grade_core_id; + public int grow_grade; + public List stat; + public List option_slot; + public int option_cost; + public int option_change_cost; + public int option_lock_cost; + } + + public class Stat + { + public string stat_type = ""; + public int stat_value; + } + + public class OptionSlot + { + public int option_slot; + public int option_slot_success_ratio; } public class ItemEquipTable { @@ -571,4 +596,31 @@ { public List records = []; } + + public class ItemEquipExpRecord + { + public int id; + public int level; + public int exp; + public string item_rare; + public int grade_core_id; + } + + public class ItemEquipExpTable + { + public List records = []; + } + + public class ItemEquipGradeExpRecord + { + public int id; + public int exp; + public string item_rare; + public int grade_core_id; + } + + public class ItemEquipGradeExpTable + { + public List records = []; + } } diff --git a/EpinelPS/LobbyServer/Inventory/IncreaseEquipmentExp.cs b/EpinelPS/LobbyServer/Inventory/IncreaseEquipmentExp.cs new file mode 100644 index 0000000..d16c8ce --- /dev/null +++ b/EpinelPS/LobbyServer/Inventory/IncreaseEquipmentExp.cs @@ -0,0 +1,74 @@ +using EpinelPS.Database; +using EpinelPS.StaticInfo; +using EpinelPS.Utils; + +namespace EpinelPS.LobbyServer.Inventory +{ + [PacketPath("/inventory/increaseexpequipment")] + public class IncreaseEquipmentExp : LobbyMsgHandler + { + protected override async Task HandleAsync() + { + var req = await ReadData(); + var user = GetUser(); + var response = new ResIncreaseExpEquip(); + var destItem = user.Items.FirstOrDefault(x => x.Isn == req.Isn); + int goldCost = 0; + + foreach (var srcItem in req.ItemList) + { + var item = user.Items.FirstOrDefault(x => x.Isn == srcItem.Isn); + item.Count -= srcItem.Count; + + goldCost += AddExp(srcItem, destItem); + + response.Items.Add(NetUtils.ToNet(item)); + } + + response.Currency = new NetUserCurrencyData + { + Type = (int)CurrencyType.Gold, + Value = user.GetCurrencyVal(CurrencyType.Gold) - goldCost + }; + + // we NEED to make sure the target item itself is in the delta list, or the UI won't update! + response.Items.Add(NetUtils.ToNet(destItem)); + + JsonDb.Save(); + + await WriteDataAsync(response); + } + + int AddExp(NetItemData srcItem, ItemData destItem) + { + var srcEquipRecord = GameData.Instance.itemEquipTable.Values.FirstOrDefault(x => x.id == srcItem.Tid); + var destEquipRecord = GameData.Instance.itemEquipTable.Values.FirstOrDefault(x => x.id == destItem.ItemType); + var levelRecord = GameData.Instance.ItemEquipGradeExpTable.Values.FirstOrDefault(x => x.grade_core_id == srcEquipRecord.grade_core_id); + int[] maxLevel = { 0, 0, 3, 3, 4, 4, 5, 5, 5, 5 }; + int[] expNextTable = GameData.Instance.itemEquipExpTable.Values + .Where(x => x.item_rare == destEquipRecord.item_rare) + .Select(x => x.exp) + .OrderBy(x => x) // order from lowest to highest + .ToArray(); + int exp = levelRecord.exp * srcItem.Count; + + destItem.Exp += exp * srcItem.Count; + + // TODO: double-check this. is this a thing? + // destItem.Exp += GetUser().Items.FirstOrDefault(x => x.Isn == srcItem.Isn).Exp; + + while (destItem.Exp >= expNextTable[destItem.Level + 1] && destItem.Level < maxLevel[destEquipRecord.grade_core_id - 1]) + { + destItem.Exp -= expNextTable[destItem.Level - 1]; + destItem.Level++; + } + + if (destItem.Level >= maxLevel[destEquipRecord.grade_core_id - 1]) + { + destItem.Exp = 0; + } + + return exp; + } + } +}