From f9482906ae7ce4dfd41bb4236e094be5d4fa7689 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 Jul 2017 01:32:07 -0400 Subject: split TrainerMod commands into separate classes (#302) --- .../Commands/Player/SetMaxHealthCommand.cs | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs (limited to 'src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs') diff --git a/src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs new file mode 100644 index 00000000..73ba252a --- /dev/null +++ b/src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs @@ -0,0 +1,40 @@ +using System.Linq; +using StardewModdingAPI; +using StardewValley; + +namespace TrainerMod.Framework.Commands.Player +{ + /// A command which edits the player's maximum health. + internal class SetMaxHealthCommand : TrainerCommand + { + /********* + ** Public methods + *********/ + /// Construct an instance. + public SetMaxHealthCommand() + : base("player_setmaxhealth", "Sets the player's max health.\n\nUsage: player_setmaxhealth [value]\n- value: an integer amount.") { } + + /// Handle the command. + /// Writes messages to the console and log file. + /// The command name. + /// The command arguments. + public override void Handle(IMonitor monitor, string command, string[] args) + { + // validate + if (!args.Any()) + { + monitor.Log($"You currently have {Game1.player.maxHealth} max health. Specify a value to change it.", LogLevel.Info); + return; + } + + // handle + if (int.TryParse(args[0], out int maxHealth)) + { + Game1.player.maxHealth = maxHealth; + monitor.Log($"OK, you now have {Game1.player.maxHealth} max health.", LogLevel.Info); + } + else + this.LogArgumentNotInt(monitor, command); + } + } +} -- cgit