From 9f9ec8f5f8c37be5295b6aff28759558e41d216d Mon Sep 17 00:00:00 2001 From: SELEKCJONER Date: Sun, 22 Sep 2024 15:06:14 +0200 Subject: [PATCH] Add SetCoreLevel command --- EpinelPS/Program.cs | 150 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/EpinelPS/Program.cs b/EpinelPS/Program.cs index 3e347d2..24618d1 100644 --- a/EpinelPS/Program.cs +++ b/EpinelPS/Program.cs @@ -212,6 +212,7 @@ namespace EpinelPS Console.WriteLine(" SetLevel (level) - Set all characters' level (between 1 and 999 takes effect on game and server restart)"); Console.WriteLine(" SetSkillLevel (level) - Set all characters' skill levels between 1 and 10 (takes effect on game and server restart)"); Console.WriteLine(" addallcharacters - Add all missing characters to the selected user with default levels and skills (takes effect on game and server restart)"); + Console.WriteLine(" SetGrade (grade) - Set all characters' grades based on the input (from 0 to 11)"); } else if (input == "ls /users") @@ -299,6 +300,129 @@ namespace EpinelPS } } } + else if (input.StartsWith("SetCoreLevel")) + { + if (selectedUser == 0) + { + Console.WriteLine("No user selected"); + } + else + { + var user = JsonDb.Instance.Users.FirstOrDefault(x => x.ID == selectedUser); + if (user == null) + { + Console.WriteLine("Selected user does not exist"); + selectedUser = 0; + prompt = "# "; + } + else if (args.Length == 2 && int.TryParse(args[1], out int inputGrade) && inputGrade >= 0 && inputGrade <= 11) + { + foreach (var character in user.Characters) + { + // Get current character's Tid + int tid = character.Tid; + + // Get the character data from the character table + if (!GameData.Instance.characterTable.TryGetValue(tid, out var charData)) + { + Console.WriteLine($"Character data not found for Tid {tid}"); + continue; + } + + int currentGradeCoreId = charData.grade_core_id; + int nameCode = charData.name_code; + string originalRare = charData.original_rare; + + // Skip characters with original_rare == "R" + if (originalRare == "R" || nameCode == 3999) + { + continue; + } + + // Now handle normal SR and SSR characters + int maxGradeCoreId = 0; + + // If the character is "SSR", it can have a grade_core_id from 1 to 11 + if (originalRare == "SSR") + { + maxGradeCoreId = 11; // SSR characters can go from 1 to 11 + + // Calculate the new grade_core_id within the bounds + int newGradeCoreId = Math.Min(inputGrade + 1, maxGradeCoreId); // +1 because inputGrade starts from 0 for SSRs + + // Find the character with the same name_code and new grade_core_id + var newCharData = GameData.Instance.characterTable.Values.FirstOrDefault(c => + c.name_code == nameCode && c.grade_core_id == newGradeCoreId); + + if (newCharData != null) + { + // Update the character's Tid and Grade + character.Tid = newCharData.id; + character.Grade = inputGrade; + } + + } + + // If the character is "SR", it can have a grade_core_id from 101 to 103 + else if (originalRare == "SR") + { + maxGradeCoreId = 103; // SR characters can go from 101 to 103 + + // Start from 101 and increment based on inputGrade (inputGrade 0 -> grade_core_id 101) + int newGradeCoreId = Math.Min(101 + inputGrade, maxGradeCoreId); // Starts at 101 + + // Find the character with the same name_code and new grade_core_id + var newCharData = GameData.Instance.characterTable.Values.FirstOrDefault(c => + c.name_code == nameCode && c.grade_core_id == newGradeCoreId); + + if (newCharData != null) + { + // Update the character's Tid and Grade + character.Tid = newCharData.id; + character.Grade = inputGrade; + } + + } + + } + Console.WriteLine($"Core level of all characters have been set to {inputGrade}"); + JsonDb.Save(); + } + else + { + Console.WriteLine("Invalid argument. Core level must be between 0 and 11."); + } + } + //code above WILL change tids in user.characters so this will update them in representation team + foreach (var user in JsonDb.Instance.Users) + { + // Check if RepresentationTeamData exists and has slots + if (user.RepresentationTeamData != null && user.RepresentationTeamData.Slots != null) + { + // Iterate through RepresentationTeamData slots + foreach (var slot in user.RepresentationTeamData.Slots) + { + // Find the character in user's character list that matches the slot's Csn + var correspondingCharacter = user.Characters.FirstOrDefault(c => c.Csn == slot.Csn); + + if (correspondingCharacter != null) + { + // Update the Tid value if it differs + if (slot.Tid != correspondingCharacter.Tid) + { + slot.Tid = correspondingCharacter.Tid; + } + } + } + } + } + + // Save the updated data + JsonDb.Save(); + + } + + else if (input == "sickpulls") { @@ -364,6 +488,32 @@ namespace EpinelPS Console.WriteLine("Invalid argument. Level must be between 1 and 999."); } } + //code above WILL change levels in user.characters so this will update them in representation team + foreach (var user in JsonDb.Instance.Users) + { + // Check if RepresentationTeamData exists and has slots + if (user.RepresentationTeamData != null && user.RepresentationTeamData.Slots != null) + { + // Iterate through RepresentationTeamData slots + foreach (var slot in user.RepresentationTeamData.Slots) + { + // Find the character in user's character list that matches the slot's Csn + var correspondingCharacter = user.Characters.FirstOrDefault(c => c.Csn == slot.Csn); + + if (correspondingCharacter != null) + { + // Update the Level value if it differs + if (slot.Level != correspondingCharacter.Level) + { + slot.Level = correspondingCharacter.Level; + } + } + } + } + } + + // Save the updated data + JsonDb.Save(); } else if (input.StartsWith("SetSkillLevel")) {