diff --git a/Maple2.Server.Game/Commands/PlayerCommand.cs b/Maple2.Server.Game/Commands/PlayerCommand.cs index ce4f91191..d8d3889a8 100644 --- a/Maple2.Server.Game/Commands/PlayerCommand.cs +++ b/Maple2.Server.Game/Commands/PlayerCommand.cs @@ -22,6 +22,68 @@ public PlayerCommand(GameSession session, AchievementMetadataStorage achievement AddCommand(new CurrencyCommand(session)); AddCommand(new InventoryCommand(session)); AddCommand(new TrophyCommand(session, achievementMetadataStorage)); + AddCommand(new MasteryCommand(session)); + } + + private class MasteryCommand : Command { + public MasteryCommand(GameSession session) : base("mastery", "Set player mastery.") { + AddCommand(new MasteryExpCommand(session)); + AddCommand(new MasteryLevelCommand(session)); + } + + private class MasteryExpCommand : Command { + private readonly GameSession session; + + public MasteryExpCommand(GameSession session) : base("exp", "Set player mastery experience.") { + this.session = session; + + var masteryCode = new Argument("mastery", "MasteryType of the player."); + var exp = new Argument("exp", "Experience points to add."); + + AddArgument(masteryCode); + AddArgument(exp); + this.SetHandler(Handle, masteryCode, exp); + } + + private void Handle(InvocationContext ctx, MasteryType masteryType, int exp) { + try { + session.Mastery[masteryType] = exp; + ctx.ExitCode = 0; + } catch (SystemException ex) { + ctx.Console.Error.WriteLine(ex.Message); + ctx.ExitCode = 1; + } + } + } + + private class MasteryLevelCommand : Command { + private readonly GameSession session; + + public MasteryLevelCommand(GameSession session) : base("level", "Set player mastery level.") { + this.session = session; + + var masteryCode = new Argument("mastery", "MasteryType of the player."); + var level = new Argument("level", "Level of the mastery."); + + AddArgument(masteryCode); + AddArgument(level); + this.SetHandler(Handle, masteryCode, level); + } + + private void Handle(InvocationContext ctx, MasteryType masteryType, int level) { + try { + int exp = 0; + if (session.TableMetadata.MasteryRewardTable.Entries.TryGetValue(masteryType, out IReadOnlyDictionary? masteryRewardMetadata)) { + exp = masteryRewardMetadata.OrderByDescending(mastery => mastery.Key).FirstOrDefault(mastery => level >= mastery.Key).Value.Value; + } + session.Mastery[masteryType] = exp; + ctx.ExitCode = 0; + } catch (SystemException ex) { + ctx.Console.Error.WriteLine(ex.Message); + ctx.ExitCode = 1; + } + } + } } private class LevelCommand : Command {