diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-05 14:55:46 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-05 14:55:46 -0400 |
commit | dbb9bd84306830456032778fc11fb9a34dd140c7 (patch) | |
tree | 0219cab065bfffbbbb9b048b6a30044f510be2c5 /src/TrainerMod/TrainerMod.cs | |
parent | 9c9833c9086b758589dafee10243e3bf47e12d73 (diff) | |
parent | 4675da0600edf6781cd740549ad0a175b606fc1e (diff) | |
download | SMAPI-dbb9bd84306830456032778fc11fb9a34dd140c7.tar.gz SMAPI-dbb9bd84306830456032778fc11fb9a34dd140c7.tar.bz2 SMAPI-dbb9bd84306830456032778fc11fb9a34dd140c7.zip |
Merge branch 'develop-1.9' into stable
Diffstat (limited to 'src/TrainerMod/TrainerMod.cs')
-rw-r--r-- | src/TrainerMod/TrainerMod.cs | 1145 |
1 files changed, 553 insertions, 592 deletions
diff --git a/src/TrainerMod/TrainerMod.cs b/src/TrainerMod/TrainerMod.cs index c76bb78c..7187a358 100644 --- a/src/TrainerMod/TrainerMod.cs +++ b/src/TrainerMod/TrainerMod.cs @@ -6,10 +6,10 @@ using Microsoft.Xna.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; +using StardewValley.Locations; using StardewValley.Menus; using StardewValley.Objects; using StardewValley.Tools; -using TrainerMod.Framework; using TrainerMod.ItemData; using Object = StardewValley.Object; @@ -44,7 +44,7 @@ namespace TrainerMod /// <param name="helper">Provides simplified APIs for writing mods.</param> public override void Entry(IModHelper helper) { - this.RegisterCommands(); + this.RegisterCommands(helper); GameEvents.UpdateTick += this.ReceiveUpdateTick; } @@ -73,646 +73,615 @@ namespace TrainerMod Game1.timeOfDay = this.FrozenTime; } - /// <summary>Register all trainer commands.</summary> - private void RegisterCommands() - { - Command.RegisterCommand("types", "Lists all value types | types").CommandFired += this.HandleTypes; - - Command.RegisterCommand("save", "Saves the game? Doesn't seem to work. | save").CommandFired += this.HandleSave; - Command.RegisterCommand("load", "Shows the load screen | load").CommandFired += this.HandleLoad; - - Command.RegisterCommand("exit", "Closes the game | exit").CommandFired += this.HandleExit; - Command.RegisterCommand("stop", "Closes the game | stop").CommandFired += this.HandleExit; - - Command.RegisterCommand("player_setname", "Sets the player's name | player_setname <object> <value>", new[] { "(player, pet, farm)<object> (String)<value> The target name" }).CommandFired += this.HandlePlayerSetName; - Command.RegisterCommand("player_setmoney", "Sets the player's money | player_setmoney <value>|inf", new[] { "(Int32)<value> The target money" }).CommandFired += this.HandlePlayerSetMoney; - Command.RegisterCommand("player_setstamina", "Sets the player's stamina | player_setstamina <value>|inf", new[] { "(Int32)<value> The target stamina" }).CommandFired += this.HandlePlayerSetStamina; - Command.RegisterCommand("player_setmaxstamina", "Sets the player's max stamina | player_setmaxstamina <value>", new[] { "(Int32)<value> The target max stamina" }).CommandFired += this.HandlePlayerSetMaxStamina; - Command.RegisterCommand("player_sethealth", "Sets the player's health | player_sethealth <value>|inf", new[] { "(Int32)<value> The target health" }).CommandFired += this.HandlePlayerSetHealth; - Command.RegisterCommand("player_setmaxhealth", "Sets the player's max health | player_setmaxhealth <value>", new[] { "(Int32)<value> The target max health" }).CommandFired += this.HandlePlayerSetMaxHealth; - Command.RegisterCommand("player_setimmunity", "Sets the player's immunity | player_setimmunity <value>", new[] { "(Int32)<value> The target immunity" }).CommandFired += this.HandlePlayerSetImmunity; - - Command.RegisterCommand("player_setlevel", "Sets the player's specified skill to the specified value | player_setlevel <skill> <value>", new[] { "(luck, mining, combat, farming, fishing, foraging)<skill> (1-10)<value> The target level" }).CommandFired += this.HandlePlayerSetLevel; - Command.RegisterCommand("player_setspeed", "Sets the player's speed to the specified value?", new[] { "(Int32)<value> The target speed [0 is normal]" }).CommandFired += this.HandlePlayerSetSpeed; - Command.RegisterCommand("player_changecolour", "Sets the player's colour of the specified object | player_changecolor <object> <colour>", new[] { "(hair, eyes, pants)<object> (r,g,b)<colour>" }).CommandFired += this.HandlePlayerChangeColor; - Command.RegisterCommand("player_changestyle", "Sets the player's style of the specified object | player_changecolor <object> <value>", new[] { "(hair, shirt, skin, acc, shoe, swim, gender)<object> (Int32)<value>" }).CommandFired += this.HandlePlayerChangeStyle; - - Command.RegisterCommand("player_additem", "Gives the player an item | player_additem <item> [count] [quality]", new[] { "(Int32)<id> (Int32)[count] (Int32)[quality]" }).CommandFired += this.HandlePlayerAddItem; - Command.RegisterCommand("player_addmelee", "Gives the player a melee item | player_addmelee <item>", new[] { "?<item>" }).CommandFired += this.HandlePlayerAddMelee; - Command.RegisterCommand("player_addring", "Gives the player a ring | player_addring <item>", new[] { "?<item>" }).CommandFired += this.HandlePlayerAddRing; - - Command.RegisterCommand("list_items", "Lists items in the game data | list_items [search]", new[] { "(String)<search>" }).CommandFired += this.HandleListItems; - - Command.RegisterCommand("world_settime", "Sets the time to the specified value | world_settime <value>", new[] { "(Int32)<value> The target time [06:00 AM is 600]" }).CommandFired += this.HandleWorldSetTime; - Command.RegisterCommand("world_freezetime", "Freezes or thaws time | world_freezetime <value>", new[] { "(0 - 1)<value> Whether or not to freeze time. 0 is thawed, 1 is frozen" }).CommandFired += this.HandleWorldFreezeTime; - Command.RegisterCommand("world_setday", "Sets the day to the specified value | world_setday <value>", new[] { "(Int32)<value> The target day [1-28]" }).CommandFired += this.world_setDay; - Command.RegisterCommand("world_setseason", "Sets the season to the specified value | world_setseason <value>", new[] { "(winter, spring, summer, fall)<value> The target season" }).CommandFired += this.HandleWorldSetSeason; - Command.RegisterCommand("world_downminelevel", "Goes down one mine level? | world_downminelevel", new[] { "" }).CommandFired += this.HandleWorldDownMineLevel; - Command.RegisterCommand("world_setminelevel", "Sets mine level? | world_setminelevel", new[] { "(Int32)<value> The target level" }).CommandFired += this.HandleWorldSetMineLevel; - - Command.RegisterCommand("show_game_files", "Opens the game folder. | show_game_files").CommandFired += this.HandleShowGameFiles; - Command.RegisterCommand("show_data_files", "Opens the folder containing the save and log files. | show_data_files").CommandFired += this.HandleShowDataFiles; - } - /**** - ** Command handlers + ** Command definitions ****/ - /// <summary>The event raised when the 'types' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleTypes(object sender, EventArgsCommand e) - { - this.Monitor.Log($"[Int32: {int.MinValue} - {int.MaxValue}], [Int64: {long.MinValue} - {long.MaxValue}], [String: \"raw text\"], [Colour: r,g,b (EG: 128, 32, 255)]", LogLevel.Info); - } - - /// <summary>The event raised when the 'save' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleSave(object sender, EventArgsCommand e) - { - SaveGame.Save(); - } - - /// <summary>The event raised when the 'load' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleLoad(object sender, EventArgsCommand e) - { - Game1.hasLoadedGame = false; - Game1.activeClickableMenu = new LoadGameMenu(); - } - - /// <summary>The event raised when the 'exit' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleExit(object sender, EventArgsCommand e) - { - Program.gamePtr.Exit(); - Environment.Exit(0); - } - - /// <summary>The event raised when the 'player_setName' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetName(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 1) + /// <summary>Register all trainer commands.</summary> + /// <param name="helper">Provides simplified APIs for writing mods.</param> + private void RegisterCommands(IModHelper helper) + { + helper.ConsoleCommands + .Add("save", "Saves the game? Doesn't seem to work.", this.HandleCommand) + .Add("load", "Shows the load screen.", this.HandleCommand) + .Add("player_setname", "Sets the player's name.\n\nUsage: player_setname <target> <name>\n- target: what to rename (one of 'player' or 'farm').\n- name: the new name to set.", this.HandleCommand) + .Add("player_setmoney", "Sets the player's money.\n\nUsage: player_setmoney <value>\n- value: an integer amount, or 'inf' for infinite money.", this.HandleCommand) + .Add("player_setstamina", "Sets the player's stamina.\n\nUsage: player_setstamina [value]\n- value: an integer amount, or 'inf' for infinite stamina.", this.HandleCommand) + .Add("player_setmaxstamina", "Sets the player's max stamina.\n\nUsage: player_setmaxstamina [value]\n- value: an integer amount.", this.HandleCommand) + .Add("player_sethealth", "Sets the player's health.\n\nUsage: player_sethealth [value]\n- value: an integer amount, or 'inf' for infinite health.", this.HandleCommand) + .Add("player_setmaxhealth", "Sets the player's max health.\n\nUsage: player_setmaxhealth [value]\n- value: an integer amount.", this.HandleCommand) + .Add("player_setimmunity", "Sets the player's immunity.\n\nUsage: player_setimmunity [value]\n- value: an integer amount.", this.HandleCommand) + + .Add("player_setlevel", "Sets the player's specified skill to the specified value.\n\nUsage: player_setlevel <skill> <value>\n- skill: the skill to set (one of 'luck', 'mining', 'combat', 'farming', 'fishing', or 'foraging').\n- value: the target level (a number from 1 to 10).", this.HandleCommand) + .Add("player_setspeed", "Sets the player's speed to the specified value?\n\nUsage: player_setspeed <value>\n- value: an integer amount (0 is normal).", this.HandleCommand) + .Add("player_changecolor", "Sets the color of a player feature.\n\nUsage: player_changecolor <target> <color>\n- target: what to change (one of 'hair', 'eyes', or 'pants').\n- color: a color value in RGB format, like (255,255,255).", this.HandleCommand) + .Add("player_changestyle", "Sets the style of a player feature.\n\nUsage: player_changecolor <target> <value>.\n- target: what to change (one of 'hair', 'shirt', 'skin', 'acc', 'shoe', 'swim', or 'gender').\n- value: the integer style ID.", this.HandleCommand) + + .Add("player_additem", $"Gives the player an item.\n\nUsage: player_additem <item> [count] [quality]\n- item: the item ID (use the 'list_items' command to see a list).\n- count (optional): how many of the item to give.\n- quality (optional): one of {Object.lowQuality} (normal), {Object.medQuality} (silver), {Object.highQuality} (gold), or {Object.bestQuality} (iridium).", this.HandleCommand) + .Add("player_addmelee", "Gives the player a melee weapon.\n\nUsage: player_addmelee <item>\n- item: the melee weapon ID (use the 'list_items' command to see a list).", this.HandleCommand) + .Add("player_addring", "Gives the player a ring.\n\nUsage: player_addring <item>\n- item: the ring ID (use the 'list_items' command to see a list).", this.HandleCommand) + + .Add("list_items", "Lists and searches items in the game data.\n\nUsage: list_items [search]\n- search (optional): an arbitrary search string to filter by.", this.HandleCommand) + + .Add("world_settime", "Sets the time to the specified value.\n\nUsage: world_settime <value>\n- value: the target time in military time (like 0600 for 6am and 1800 for 6pm)", this.HandleCommand) + .Add("world_freezetime", "Freezes or resumes time.\n\nUsage: world_freezetime [value]\n- value: one of 0 (resume), 1 (freeze), or blank (toggle).", this.HandleCommand) + .Add("world_setday", "Sets the day to the specified value.\n\nUsage: world_setday <value>.\n- value: the target day (a number from 1 to 28).", this.HandleCommand) + .Add("world_setseason", "Sets the season to the specified value.\n\nUsage: world_setseason <season>\n- value: the target season (one of 'spring', 'summer', 'fall', 'winter').", this.HandleCommand) + .Add("world_downminelevel", "Goes down one mine level?", this.HandleCommand) + .Add("world_setminelevel", "Sets the mine level?\n\nUsage: world_setminelevel <value>\n- value: The target level (a number between 1 and 120).", this.HandleCommand) + + .Add("show_game_files", "Opens the game folder.", this.HandleCommand) + .Add("show_data_files", "Opens the folder containing the save and log files.", this.HandleCommand); + } + + /// <summary>Handle a TrainerMod command.</summary> + /// <param name="command">The command name.</param> + /// <param name="args">The command arguments.</param> + private void HandleCommand(string command, string[] args) + { + switch (command) { - string target = e.Command.CalledArgs[0]; - string[] validTargets = { "player", "pet", "farm" }; - if (validTargets.Contains(target)) - { - switch (target) + case "save": + this.Monitor.Log("Saving the game...", LogLevel.Info); + SaveGame.Save(); + break; + + case "load": + this.Monitor.Log("Triggering load menu...", LogLevel.Info); + Game1.hasLoadedGame = false; + Game1.activeClickableMenu = new LoadGameMenu(); + break; + + case "player_setname": + if (args.Length > 1) { - case "player": - Game1.player.Name = e.Command.CalledArgs[1]; - break; - case "pet": - this.Monitor.Log("Pets cannot currently be renamed.", LogLevel.Info); - break; - case "farm": - Game1.player.farmName = e.Command.CalledArgs[1]; - break; + string target = args[0]; + string[] validTargets = { "player", "farm" }; + if (validTargets.Contains(target)) + { + switch (target) + { + case "player": + Game1.player.Name = args[1]; + this.Monitor.Log($"OK, your player's name is now {Game1.player.Name}.", LogLevel.Info); + break; + case "farm": + Game1.player.farmName = args[1]; + this.Monitor.Log($"OK, your farm's name is now {Game1.player.Name}.", LogLevel.Info); + break; + } + } + else + this.LogArgumentsInvalid(command); } - } - else - this.LogObjectInvalid(); - } - else - this.LogObjectValueNotSpecified(); - } + else + this.Monitor.Log($"Your name is currently '{Game1.player.Name}'. Type 'help player_setname' for usage.", LogLevel.Info); + break; - /// <summary>The event raised when the 'player_setMoney' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetMoney(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string amountStr = e.Command.CalledArgs[0]; - if (amountStr == "inf") - this.InfiniteMoney = true; - else - { - this.InfiniteMoney = false; - int amount; - if (int.TryParse(amountStr, out amount)) + case "player_setmoney": + if (args.Any()) { - Game1.player.Money = amount; - this.Monitor.Log($"Set {Game1.player.Name}'s money to {Game1.player.Money}", LogLevel.Info); + string amountStr = args[0]; + if (amountStr == "inf") + { + this.InfiniteMoney = true; + this.Monitor.Log("OK, you now have infinite money.", LogLevel.Info); + } + else + { + this.InfiniteMoney = false; + int amount; + if (int.TryParse(amountStr, out amount)) + { + Game1.player.Money = amount; + this.Monitor.Log($"OK, you now have {Game1.player.Money} gold.", LogLevel.Info); + } + else + this.LogArgumentNotInt(command); + } } else - this.LogValueNotInt32(); - } - } - else - this.LogValueNotSpecified(); - } + this.Monitor.Log($"You currently have {(this.InfiniteMoney ? "infinite" : Game1.player.Money.ToString())} gold. Specify a value to change it.", LogLevel.Info); + break; - /// <summary>The event raised when the 'player_setStamina' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetStamina(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string amountStr = e.Command.CalledArgs[0]; - if (amountStr == "inf") - this.InfiniteStamina = true; - else - { - this.InfiniteStamina = false; - int amount; - if (int.TryParse(amountStr, out amount)) + case "player_setstamina": + if (args.Any()) { - Game1.player.Stamina = amount; - this.Monitor.Log($"Set {Game1.player.Name}'s stamina to {Game1.player.Stamina}", LogLevel.Info); + string amountStr = args[0]; + if (amountStr == "inf") + { + this.InfiniteStamina = true; + this.Monitor.Log("OK, you now have infinite stamina.", LogLevel.Info); + } + else + { + this.InfiniteStamina = false; + int amount; + if (int.TryParse(amountStr, out amount)) + { + Game1.player.Stamina = amount; + this.Monitor.Log($"OK, you now have {Game1.player.Stamina} stamina.", LogLevel.Info); + } + else + this.LogArgumentNotInt(command); + } } else - this.LogValueNotInt32(); - } - } - else - this.LogValueNotSpecified(); - } + this.Monitor.Log($"You currently have {(this.InfiniteStamina ? "infinite" : Game1.player.Stamina.ToString())} stamina. Specify a value to change it.", LogLevel.Info); + break; - /// <summary>The event raised when the 'player_setMaxStamina' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetMaxStamina(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - int amount; - if (int.TryParse(e.Command.CalledArgs[0], out amount)) - { - Game1.player.MaxStamina = amount; - this.Monitor.Log($"Set {Game1.player.Name}'s max stamina to {Game1.player.MaxStamina}", LogLevel.Info); - } - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } + case "player_setmaxstamina": + if (args.Any()) + { + int amount; + if (int.TryParse(args[0], out amount)) + { + Game1.player.MaxStamina = amount; + this.Monitor.Log($"OK, you now have {Game1.player.MaxStamina} max stamina.", LogLevel.Info); + } + else + this.LogArgumentNotInt(command); + } + else + this.Monitor.Log($"You currently have {Game1.player.MaxStamina} max stamina. Specify a value to change it.", LogLevel.Info); + break; - /// <summary>The event raised when the 'player_setLevel' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetLevel(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 1) - { - string skill = e.Command.CalledArgs[0]; - string[] skills = { "luck", "mining", "combat", "farming", "fishing", "foraging" }; - if (skills.Contains(skill)) - { - int level; - if (int.TryParse(e.Command.CalledArgs[1], out level)) + case "player_setlevel": + if (args.Length > 1) { - switch (skill) + string skill = args[0]; + string[] skills = { "luck", "mining", "combat", "farming", "fishing", "foraging" }; + if (skills.Contains(skill)) { - case "luck": - Game1.player.LuckLevel = level; - break; - case "mining": - Game1.player.MiningLevel = level; - break; - case "combat": - Game1.player.CombatLevel = level; - break; - case "farming": - Game1.player.FarmingLevel = level; - break; - case "fishing": - Game1.player.FishingLevel = level; - break; - case "foraging": - Game1.player.ForagingLevel = level; - break; + int level; + if (int.TryParse(args[1], out level)) + { + switch (skill) + { + case "luck": + Game1.player.LuckLevel = level; + this.Monitor.Log($"OK, your luck skill is now {Game1.player.LuckLevel}.", LogLevel.Info); + break; + case "mining": + Game1.player.MiningLevel = level; + this.Monitor.Log($"OK, your mining skill is now {Game1.player.MiningLevel}.", LogLevel.Info); + break; + case "combat": + Game1.player.CombatLevel = level; + this.Monitor.Log($"OK, your combat skill is now {Game1.player.CombatLevel}.", LogLevel.Info); + break; + case "farming": + Game1.player.FarmingLevel = level; + this.Monitor.Log($"OK, your farming skill is now {Game1.player.FarmingLevel}.", LogLevel.Info); + break; + case "fishing": + Game1.player.FishingLevel = level; + this.Monitor.Log($"OK, your fishing skill is now {Game1.player.FishingLevel}.", LogLevel.Info); + break; + case "foraging": + Game1.player.ForagingLevel = level; + this.Monitor.Log($"OK, your foraging skill is now {Game1.player.ForagingLevel}.", LogLevel.Info); + break; + } + } + else + this.LogArgumentNotInt(command); } + else + this.LogUsageError("That isn't a valid skill.", command); } else - this.LogValueNotInt32(); - } - else - this.Monitor.Log("<skill> is invalid", LogLevel.Error); - } - else - this.Monitor.Log("<skill> and <value> must be specified", LogLevel.Error); - } + this.LogArgumentsInvalid(command); + break; - /// <summary>The event raised when the 'player_setSpeed' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetSpeed(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string amountStr = e.Command.CalledArgs[0]; - if (amountStr.IsInt()) - { - Game1.player.addedSpeed = amountStr.ToInt(); - this.Monitor.Log($"Set {Game1.player.Name}'s added speed to {Game1.player.addedSpeed}", LogLevel.Info); - } - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } + case "player_setspeed": + if (args.Any()) + { + int addedSpeed; + if (int.TryParse(args[0], out addedSpeed)) + { + Game1.player.addedSpeed = addedSpeed; + this.Monitor.Log($"OK, your added speed is now {Game1.player.addedSpeed}.", LogLevel.Info); + } + else + this.LogArgumentNotInt(command); + } + else + this.Monitor.Log($"You currently have {Game1.player.addedSpeed} added speed. Specify a value to change it.", LogLevel.Info); + break; - /// <summary>The event raised when the 'player_changeColour' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerChangeColor(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 1) - { - string target = e.Command.CalledArgs[0]; - string[] validTargets = { "hair", "eyes", "pants" }; - if (validTargets.Contains(target)) - { - string[] colorHexes = e.Command.CalledArgs[1].Split(new[] { ',' }, 3); - if (colorHexes[0].IsInt() && colorHexes[1].IsInt() && colorHexes[2].IsInt()) + case "player_changecolor": + if (args.Length > 1) { - var color = new Color(colorHexes[0].ToInt(), colorHexes[1].ToInt(), colorHexes[2].ToInt()); - switch (target) + string target = args[0]; + string[] validTargets = { "hair", "eyes", "pants" }; + if (validTargets.Contains(target)) { - case "hair": - Game1.player.hairstyleColor = color; - break; - case "eyes": - Game1.player.changeEyeColor(color); - break; - case "pants": - Game1.player.pantsColor = color; - break; + string[] colorHexes = args[1].Split(new[] { ',' }, 3); + int r, g, b; + if (int.TryParse(colorHexes[0], out r) && int.TryParse(colorHexes[1], out g) && int.TryParse(colorHexes[2], out b)) + { + Color color = new Color(r, g, b); + switch (target) + { + case "hair": + Game1.player.hairstyleColor = color; + this.Monitor.Log("OK, your hair color is updated.", LogLevel.Info); + break; + case "eyes": + Game1.player.changeEyeColor(color); + this.Monitor.Log("OK, your eye color is updated.", LogLevel.Info); + break; + case "pants": + Game1.player.pantsColor = color; + this.Monitor.Log("OK, your pants color is updated.", LogLevel.Info); + break; + } + } + else + this.LogUsageError("The color should be an RBG value like '255,150,0'.", command); } + else + this.LogArgumentsInvalid(command); } else - this.Monitor.Log("<colour> is invalid", LogLevel.Error); - } - else - this.LogObjectInvalid(); - } - else - this.Monitor.Log("<object> and <colour> must be specified", LogLevel.Error); - } + this.LogArgumentsInvalid(command); + break; - /// <summary>The event raised when the 'player_changeStyle' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerChangeStyle(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 1) - { - string target = e.Command.CalledArgs[0]; - string[] validTargets = { "hair", "shirt", "skin", "acc", "shoe", "swim", "gender" }; - if (validTargets.Contains(target)) - { - if (e.Command.CalledArgs[1].IsInt()) + case "player_changestyle": + if (args.Length > 1) { - var styleID = e.Command.CalledArgs[1].ToInt(); - switch (target) + string target = args[0]; + string[] validTargets = { "hair", "shirt", "skin", "acc", "shoe", "swim", "gender" }; + if (validTargets.Contains(target)) { - case "hair": - Game1.player.changeHairStyle(styleID); - break; - case "shirt": - Game1.player.changeShirt(styleID); - break; - case "acc": - Game1.player.changeAccessory(styleID); - break; - case "skin": - Game1.player.changeSkinColor(styleID); - break; - case "shoe": - Game1.player.changeShoeColor(styleID); - break; - case "swim": - if (styleID == 0) - Game1.player.changeOutOfSwimSuit(); - else if (styleID == 1) - Game1.player.changeIntoSwimsuit(); - else - this.Monitor.Log("<value> must be 0 or 1 for this <object>", LogLevel.Error); - break; - case "gender": - if (styleID == 0) - Game1.player.changeGender(true); - else if (styleID == 1) - Game1.player.changeGender(false); - else - this.Monitor.Log("<value> must be 0 or 1 for this <object>", LogLevel.Error); - break; + int styleID; + if (int.TryParse(args[1], out styleID)) + { + switch (target) + { + case "hair": + Game1.player.changeHairStyle(styleID); + this.Monitor.Log("OK, your hair style is updated.", LogLevel.Info); + break; + case "shirt": + Game1.player.changeShirt(styleID); + this.Monitor.Log("OK, your shirt style is updated.", LogLevel.Info); + break; + case "acc": + Game1.player.changeAccessory(styleID); + this.Monitor.Log("OK, your accessory style is updated.", LogLevel.Info); + break; + case "skin": + Game1.player.changeSkinColor(styleID); + this.Monitor.Log("OK, your skin color is updated.", LogLevel.Info); + break; + case "shoe": + Game1.player.changeShoeColor(styleID); + this.Monitor.Log("OK, your shoe style is updated.", LogLevel.Info); + break; + case "swim": + switch (styleID) + { + case 0: + Game1.player.changeOutOfSwimSuit(); + this.Monitor.Log("OK, you're no longer in your swimming suit.", LogLevel.Info); + break; + case 1: + Game1.player.changeIntoSwimsuit(); + this.Monitor.Log("OK, you're now in your swimming suit.", LogLevel.Info); + break; + default: + this.LogUsageError("The swim value should be 0 (no swimming suit) or 1 (swimming suit).", command); + break; + } + break; + case "gender": + switch (styleID) + { + case 0: + Game1.player.changeGender(true); + this.Monitor.Log("OK, you're now male.", LogLevel.Info); + break; + case 1: + Game1.player.changeGender(false); + this.Monitor.Log("OK, you're now female.", LogLevel.Info); + break; + default: + this.LogUsageError("The gender value should be 0 (male) or 1 (female).", command); + break; + } + break; + } + } + else + this.LogArgumentsInvalid(command); } + else + this.LogArgumentsInvalid(command); } else - this.LogValueInvalid(); - } - else - this.LogObjectInvalid(); - } - else - this.LogObjectValueNotSpecified(); - } + this.LogArgumentsInvalid(command); + break; - /// <summary>The event raised when the 'world_freezeTime' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleWorldFreezeTime(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string valueStr = e.Command.CalledArgs[0]; - if (valueStr.IsInt()) - { - int value = valueStr.ToInt(); - if (value == 0 || value == 1) + case "world_freezetime": + if (args.Any()) + { + int value; + if (int.TryParse(args[0], out value)) + { + if (value == 0 || value == 1) + { + this.FreezeTime = value == 1; + this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0; + this.Monitor.Log($"OK, time is now {(this.FreezeTime ? "frozen" : "resumed")}.", LogLevel.Info); + } + else + this.LogUsageError("The value should be 0 (not frozen), 1 (frozen), or empty (toggle).", command); + } + else + this.LogArgumentNotInt(command); + } + else { - this.FreezeTime = value == 1; + this.FreezeTime = !this.FreezeTime; this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0; - this.Monitor.Log("Time is now " + (this.FreezeTime ? "frozen" : "thawed"), LogLevel.Info); + this.Monitor.Log($"OK, time is now {(this.FreezeTime ? "frozen" : "resumed")}.", LogLevel.Info); + } + break; + + case "world_settime": + if (args.Any()) + { + int time; + if (int.TryParse(args[0], out time)) + { + if (time <= 2600 && time >= 600) + { + Game1.timeOfDay = time; + this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0; + this.Monitor.Log($"OK, the time is now {Game1.timeOfDay.ToString().PadLeft(4, '0')}.", LogLevel.Info); + } + else + this.LogUsageError("That isn't a valid time.", command); + } + else + this.LogArgumentNotInt(command); } else - this.Monitor.Log("<value> should be 0 or 1", LogLevel.Error); - } - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } + this.Monitor.Log($"The current time is {Game1.timeOfDay}. Specify a value to change it.", LogLevel.Info); + break; - /// <summary>The event raised when the 'world_setTime' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleWorldSetTime(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string timeStr = e.Command.CalledArgs[0]; - if (timeStr.IsInt()) - { - int time = timeStr.ToInt(); + case "world_setday": + if (args.Any()) + { + int day; + if (int.TryParse(args[0], out day)) + { + if (day <= 28 && day > 0) + { + Game1.dayOfMonth = day; + this.Monitor.Log($"OK, the date is now {Game1.currentSeason} {Game1.dayOfMonth}.", LogLevel.Info); + } + else + this.LogUsageError("That isn't a valid day.", command); + } + else + this.LogArgumentNotInt(command); + } + else + this.Monitor.Log($"The current date is {Game1.currentSeason} {Game1.dayOfMonth}. Specify a value to change the day.", LogLevel.Info); + break; - if (time <= 2600 && time >= 600) + case "world_setseason": + if (args.Any()) { - Game1.timeOfDay = e.Command.CalledArgs[0].ToInt(); - this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0; - this.Monitor.Log($"Time set to: {Game1.timeOfDay}", LogLevel.Info); + string season = args[0]; + string[] validSeasons = { "winter", "spring", "summer", "fall" }; + if (validSeasons.Contains(season)) + { + Game1.currentSeason = season; + this.Monitor.Log($"OK, the date is now {Game1.currentSeason} {Game1.dayOfMonth}.", LogLevel.Info); + } + else + this.LogUsageError("That isn't a valid season name.", command); } else - this.Monitor.Log("<value> should be between 600 and 2600 (06:00 AM - 02:00 AM [NEXT DAY])", LogLevel.Error); - } - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } + this.Monitor.Log($"The current season is {Game1.currentSeason}. Specify a value to change it.", LogLevel.Info); + break; - /// <summary>The event raised when the 'world_setDay' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void world_setDay(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string dayStr = e.Command.CalledArgs[0]; + case "player_sethealth": + if (args.Any()) + { + string amountStr = args[0]; - if (dayStr.IsInt()) - { - int day = dayStr.ToInt(); - if (day <= 28 && day > 0) - Game1.dayOfMonth = day; + if (amountStr == "inf") + { + this.InfiniteHealth = true; + this.Monitor.Log("OK, you now have infinite health.", LogLevel.Info); + } + else + { + this.InfiniteHealth = false; + int amount; + if (int.TryParse(amountStr, out amount)) + { + Game1.player.health = amount; + this.Monitor.Log($"OK, you now have {Game1.player.health} health.", LogLevel.Info); + } + else + this.LogArgumentNotInt(command); + } + } else - this.Monitor.Log("<value> must be between 1 and 28", LogLevel.Error); - } - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } + this.Monitor.Log($"You currently have {(this.InfiniteHealth ? "infinite" : Game1.player.health.ToString())} health. Specify a value to change it.", LogLevel.Info); + break; - /// <summary>The event raised when the 'world_setSeason' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleWorldSetSeason(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string season = e.Command.CalledArgs[0]; - string[] validSeasons = { "winter", "spring", "summer", "fall" }; - if (validSeasons.Contains(season)) - Game1.currentSeason = season; - else - this.LogValueInvalid(); - } - else - this.LogValueNotSpecified(); - } - - /// <summary>The event raised when the 'player_setHealth' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetHealth(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string amountStr = e.Command.CalledArgs[0]; + case "player_setmaxhealth": + if (args.Any()) + { + int maxHealth; + if (int.TryParse(args[0], out maxHealth)) + { + Game1.player.maxHealth = maxHealth; + this.Monitor.Log($"OK, you now have {Game1.player.maxHealth} max health.", LogLevel.Info); + } + else + this.LogArgumentNotInt(command); + } + else + this.Monitor.Log($"You currently have {Game1.player.maxHealth} max health. Specify a value to change it.", LogLevel.Info); + break; - if (amountStr == "inf") - this.InfiniteHealth = true; - else - { - this.InfiniteHealth = false; - if (amountStr.IsInt()) - Game1.player.health = amountStr.ToInt(); + case "player_setimmunity": + if (args.Any()) + { + int amount; + if (int.TryParse(args[0], out amount)) + { + Game1.player.immunity = amount; + this.Monitor.Log($"OK, you now have {Game1.player.immunity} immunity.", LogLevel.Info); + } + else + this.LogArgumentNotInt(command); + } else - this.LogValueNotInt32(); - } - } - else - this.LogValueNotSpecified(); - } + this.Monitor.Log($"You currently have {Game1.player.immunity} immunity. Specify a value to change it.", LogLevel.Info); + break; - /// <summary>The event raised when the 'player_setMaxHealth' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetMaxHealth(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string amountStr = e.Command.CalledArgs[0]; - if (amountStr.IsInt()) - Game1.player.maxHealth = amountStr.ToInt(); - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } + case "player_additem": + if (args.Any()) + { + int itemID; + if (int.TryParse(args[0], out itemID)) + { + int count = 1; + int quality = 0; + if (args.Length > 1) + { + if (!int.TryParse(args[1], out count)) + { + this.LogUsageError("The optional count is invalid.", command); + return; + } + + if (args.Length > 2 && !int.TryParse(args[2], out quality)) + { + this.LogUsageError("The optional quality is invalid.", command); + return; + } + } - /// <summary>The event raised when the 'player_setImmunity' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerSetImmunity(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string amountStr = e.Command.CalledArgs[0]; - if (amountStr.IsInt()) - Game1.player.immunity = amountStr.ToInt(); - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } + var item = new Object(itemID, count) { quality = quality }; + if (item.Name == "Error Item") + this.Monitor.Log("There is no such item ID.", LogLevel.Error); + else + { + Game1.player.addItemByMenuIfNecessary(item); + this.Monitor.Log($"OK, added {item.Name} to your inventory.", LogLevel.Info); + } + } + else + this.LogUsageError("The item ID must be an integer.", command); + } + else + this.LogArgumentsInvalid(command); + break; - /// <summary>The event raised when the 'player_addItem' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerAddItem(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - string itemIdStr = e.Command.CalledArgs[0]; - if (itemIdStr.IsInt()) - { - int itemID = itemIdStr.ToInt(); - int count = 1; - int quality = 0; - if (e.Command.CalledArgs.Length > 1) + case "player_addmelee": + if (args.Any()) { - if (e.Command.CalledArgs[1].IsInt()) - count = e.Command.CalledArgs[1].ToInt(); - else + int weaponID; + if (int.TryParse(args[0], out weaponID)) { - this.Monitor.Log("[count] is invalid", LogLevel.Error); - return; + MeleeWeapon weapon = new MeleeWeapon(weaponID); + if (weapon.Name == null) + this.Monitor.Log("There is no such weapon ID.", LogLevel.Error); + else + { + Game1.player.addItemByMenuIfNecessary(weapon); + this.Monitor.Log($"OK, added {weapon.Name} to your inventory.", LogLevel.Info); + } } + else + this.LogUsageError("The weapon ID must be an integer.", command); + } + else + this.LogArgumentsInvalid(command); + break; - if (e.Command.CalledArgs.Length > 2) + case "player_addring": + if (args.Any()) + { + int ringID; + if (int.TryParse(args[0], out ringID)) { - if (e.Command.CalledArgs[2].IsInt()) - quality = e.Command.CalledArgs[2].ToInt(); + if (ringID < Ring.ringLowerIndexRange || ringID > Ring.ringUpperIndexRange) + this.Monitor.Log($"There is no such ring ID (must be between {Ring.ringLowerIndexRange} and {Ring.ringUpperIndexRange}).", LogLevel.Error); else { - this.Monitor.Log("[quality] is invalid", LogLevel.Error); - return; + Ring ring = new Ring(ringID); + Game1.player.addItemByMenuIfNecessary(ring); + this.Monitor.Log($"OK, added {ring.Name} to your inventory.", LogLevel.Info); } } + else + this.Monitor.Log("<item> is invalid", LogLevel.Error); } + else + this.LogArgumentsInvalid(command); + break; - var item = new Object(itemID, count) { quality = quality }; + case "list_items": + { + var matches = this.GetItems(args).ToArray(); - Game1.player.addItemByMenuIfNecessary(item); - } - else - this.Monitor.Log("<item> is invalid", LogLevel.Error); - } - else - this.LogObjectValueNotSpecified(); - } + // show matches + string summary = "Searching...\n"; + if (matches.Any()) + this.Monitor.Log(summary + this.GetTableString(matches, new[] { "type", "id", "name" }, val => new[] { val.Type.ToString(), val.ID.ToString(), val.Name }), LogLevel.Info); + else + this.Monitor.Log(summary + "No items found", LogLevel.Info); + } + break; - /// <summary>The event raised when the 'player_addMelee' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerAddMelee(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - if (e.Command.CalledArgs[0].IsInt()) - { - MeleeWeapon weapon = new MeleeWeapon(e.Command.CalledArgs[0].ToInt()); - Game1.player.addItemByMenuIfNecessary(weapon); - this.Monitor.Log($"Gave {weapon.Name} to {Game1.player.Name}", LogLevel.Info); - } - else - this.Monitor.Log("<item> is invalid", LogLevel.Error); - } - else - this.LogObjectValueNotSpecified(); - } + case "world_downminelevel": + { + int level = (Game1.currentLocation as MineShaft)?.mineLevel ?? 0; + this.Monitor.Log($"OK, warping you to mine level {level + 1}.", LogLevel.Info); + Game1.enterMine(false, level + 1, ""); + break; + } - /// <summary>The event raised when the 'player_addRing' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandlePlayerAddRing(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - if (e.Command.CalledArgs[0].IsInt()) - { - Ring ring = new Ring(e.Command.CalledArgs[0].ToInt()); - Game1.player.addItemByMenuIfNecessary(ring); - this.Monitor.Log($"Gave {ring.Name} to {Game1.player.Name}", LogLevel.Info); - } - else - this.Monitor.Log("<item> is invalid", LogLevel.Error); - } - else - this.LogObjectValueNotSpecified(); - } + case "world_setminelevel": + if (args.Any()) + { + int level; + if (int.TryParse(args[0], out level)) + { + level = Math.Max(1, level); + this.Monitor.Log($"OK, warping you to mine level {level}.", LogLevel.Info); + Game1.enterMine(true, level, ""); + } + else + this.LogArgumentNotInt(command); + } + else + this.LogArgumentsInvalid(command); + break; - /// <summary>The event raised when the 'list_items' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleListItems(object sender, EventArgsCommand e) - { - var matches = this.GetItems(e.Command.CalledArgs).ToArray(); - - // show matches - string summary = "Searching...\n"; - if (matches.Any()) - this.Monitor.Log(summary + this.GetTableString(matches, new[] { "type", "id", "name" }, val => new[] { val.Type.ToString(), val.ID.ToString(), val.Name }), LogLevel.Info); - else - this.Monitor.Log(summary + "No items found", LogLevel.Info); - } + case "show_game_files": + Process.Start(Constants.ExecutionPath); + this.Monitor.Log($"OK, opening {Constants.ExecutionPath}.", LogLevel.Info); + break; - /// <summary>The event raised when the 'world_downMineLevel' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleWorldDownMineLevel(object sender, EventArgsCommand e) - { - Game1.nextMineLevel(); - } + case "show_data_files": + Process.Start(Constants.DataPath); + this.Monitor.Log($"OK, opening {Constants.DataPath}.", LogLevel.Info); + break; - /// <summary>The event raised when the 'world_setMineLevel' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleWorldSetMineLevel(object sender, EventArgsCommand e) - { - if (e.Command.CalledArgs.Length > 0) - { - if (e.Command.CalledArgs[0].IsInt()) - Game1.enterMine(true, e.Command.CalledArgs[0].ToInt(), ""); - else - this.LogValueNotInt32(); + default: + throw new NotImplementedException($"TrainerMod received unknown command '{command}'."); } - else - this.LogValueNotSpecified(); - } - - /// <summary>The event raised when the 'show_game_files' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleShowGameFiles(object sender, EventArgsCommand e) - { - Process.Start(Constants.ExecutionPath); - } - - /// <summary>The event raised when the 'show_data_files' command is triggered.</summary> - /// <param name="sender">The event sender.</param> - /// <param name="e">The event arguments.</param> - private void HandleShowDataFiles(object sender, EventArgsCommand e) - { - Process.Start(Constants.DataPath); } /**** @@ -800,34 +769,26 @@ namespace TrainerMod /**** ** Logging ****/ - /// <summary>Log an error indicating a value must be specified.</summary> - public void LogValueNotSpecified() + /// <summary>Log an error indicating incorrect usage.</summary> + /// <param name="error">A sentence explaining the problem.</param> + /// <param name="command">The name of the command.</param> + private void LogUsageError(string error, string command) { - this.Monitor.Log("<value> must be specified", LogLevel.Error); + this.Monitor.Log($"{error} Type 'help {command}' for usage.", LogLevel.Error); } - /// <summary>Log an error indicating a target and value must be specified.</summary> - public void LogObjectValueNotSpecified() + /// <summary>Log an error indicating a value must be an integer.</summary> + /// <param name="command">The name of the command.</param> + private void LogArgumentNotInt(string command) { - this.Monitor.Log("<object> and <value> must be specified", LogLevel.Error); + this.LogUsageError("The value must be a whole number.", command); } /// <summary>Log an error indicating a value is invalid.</summary> - public void LogValueInvalid() - { - this.Monitor.Log("<value> is invalid", LogLevel.Error); - } - - /// <summary>Log an error indicating a target is invalid.</summary> - public void LogObjectInvalid() - { - this.Monitor.Log("<object> is invalid", LogLevel.Error); - } - - /// <summary>Log an error indicating a value must be an integer.</summary> - public void LogValueNotInt32() + /// <param name="command">The name of the command.</param> + private void LogArgumentsInvalid(string command) { - this.Monitor.Log("<value> must be a whole number (Int32)", LogLevel.Error); + this.LogUsageError("The arguments are invalid.", command); } } } |