diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-02-13 01:19:02 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-02-13 01:19:02 -0500 |
commit | 845fbaab12a040464e403aa693a0eaaa9c55c9ae (patch) | |
tree | 88bfbd053d5ead2d6b8f6689607a51c096c04ca6 /src | |
parent | 0441d0843c65775bc72377e32ed4b3b5ee0b8f75 (diff) | |
download | SMAPI-845fbaab12a040464e403aa693a0eaaa9c55c9ae.tar.gz SMAPI-845fbaab12a040464e403aa693a0eaaa9c55c9ae.tar.bz2 SMAPI-845fbaab12a040464e403aa693a0eaaa9c55c9ae.zip |
migrate TrainerMod to new API (#199)
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 2 | ||||
-rw-r--r-- | src/TrainerMod/TrainerMod.cs | 1027 |
2 files changed, 468 insertions, 561 deletions
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index ff0dff29..58b86e8f 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -578,7 +578,7 @@ namespace StardewModdingAPI if (result == null) Program.Monitor.Log("There's no command with that name.", LogLevel.Error); else - Program.Monitor.Log($"{result.Name}: {result.Documentation} [added by {result.ModName}]", LogLevel.Info); + Program.Monitor.Log($"{result.Name}: {result.Documentation}\n(Added by {result.ModName}.)", LogLevel.Info); } else Program.Monitor.Log("Commands: " + string.Join(", ", Program.CommandManager.GetAll().Select(p => p.Name)), LogLevel.Info); diff --git a/src/TrainerMod/TrainerMod.cs b/src/TrainerMod/TrainerMod.cs index a7cedb6a..1690d5b5 100644 --- a/src/TrainerMod/TrainerMod.cs +++ b/src/TrainerMod/TrainerMod.cs @@ -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,634 +73,541 @@ 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("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>Register all trainer commands.</summary> + /// <param name="helper">Provides simplified APIs for writing mods.</param> + private void RegisterCommands(IModHelper helper) + { + helper.ConsoleCommands + .Add("types", "Lists all value types.", this.HandleCommand) + .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_changecolour", "Sets the colour of a player feature.\n\nUsage: player_changecolor <target> <colour>\n- target: what to change (one of 'hair', 'eyes', or 'pants').\n- colour: a colour 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) or 1 (freeze).", 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="name">The command name.</param> + /// <param name="args">The command arguments.</param> + private void HandleCommand(string name, string[] args) + { + switch (name) + { + case "type": + 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); + break; - /// <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(); - } + case "save": + SaveGame.Save(); + break; - /// <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(); - } + case "load": + Game1.hasLoadedGame = false; + Game1.activeClickableMenu = new LoadGameMenu(); + break; - /// <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) - { - string target = e.Command.CalledArgs[0]; - string[] validTargets = { "player", "pet", "farm" }; - if (validTargets.Contains(target)) - { - switch (target) + 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]; + break; + case "farm": + Game1.player.farmName = args[1]; + break; + } + } + else + this.LogObjectInvalid(); } - } - else - this.LogObjectInvalid(); - } - else - this.LogObjectValueNotSpecified(); - } + else + this.LogObjectValueNotSpecified(); + 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; + else + { + this.InfiniteMoney = false; + int amount; + if (int.TryParse(amountStr, out amount)) + { + Game1.player.Money = amount; + this.Monitor.Log($"Set {Game1.player.Name}'s money to {Game1.player.Money}", LogLevel.Info); + } + else + this.LogValueNotInt32(); + } } else - this.LogValueNotInt32(); - } - } - else - this.LogValueNotSpecified(); - } + this.LogValueNotSpecified(); + 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 "playet_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; + else + { + this.InfiniteStamina = false; + int amount; + if (int.TryParse(amountStr, out amount)) + { + Game1.player.Stamina = amount; + this.Monitor.Log($"Set {Game1.player.Name}'s stamina to {Game1.player.Stamina}", LogLevel.Info); + } + else + this.LogValueNotInt32(); + } } else - this.LogValueNotInt32(); - } - } - else - this.LogValueNotSpecified(); - } + this.LogValueNotSpecified(); + 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(); - } - - /// <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_setmaxstamina": + if (args.Any()) { - switch (skill) + int amount; + if (int.TryParse(args[0], out amount)) { - 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; + 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.LogValueNotInt32(); - } - else - this.Monitor.Log("<skill> is invalid", LogLevel.Error); - } - else - this.Monitor.Log("<skill> and <value> must be specified", LogLevel.Error); - } + this.LogValueNotSpecified(); + 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(); - } - - /// <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_setlevel": + if (args.Length > 1) { - var color = new Color(colorHexes[0].ToInt(), colorHexes[1].ToInt(), colorHexes[2].ToInt()); - switch (target) + string skill = args[0]; + string[] skills = { "luck", "mining", "combat", "farming", "fishing", "foraging" }; + if (skills.Contains(skill)) { - case "hair": - Game1.player.hairstyleColor = color; - break; - case "eyes": - Game1.player.changeEyeColor(color); - break; - case "pants": - Game1.player.pantsColor = color; - break; + int level; + if (int.TryParse(args[1], out level)) + { + switch (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; + } + } + else + this.LogValueNotInt32(); } + else + this.Monitor.Log("<skill> is invalid", LogLevel.Error); } 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.Monitor.Log("<skill> and <value> must be specified", LogLevel.Error); + 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_setspeed": + if (args.Any()) { - var styleID = e.Command.CalledArgs[1].ToInt(); - switch (target) + string amountStr = args[0]; + if (amountStr.IsInt()) { - 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; + 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.LogValueInvalid(); - } - else - this.LogObjectInvalid(); - } - else - this.LogObjectValueNotSpecified(); - } + this.LogValueNotSpecified(); + 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 "player_changecolour": + if (args.Length > 1) { - this.FreezeTime = value == 1; - this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0; - this.Monitor.Log("Time is now " + (this.FreezeTime ? "frozen" : "thawed"), LogLevel.Info); + string target = args[0]; + string[] validTargets = { "hair", "eyes", "pants" }; + if (validTargets.Contains(target)) + { + string[] colorHexes = args[1].Split(new[] { ',' }, 3); + if (colorHexes[0].IsInt() && colorHexes[1].IsInt() && colorHexes[2].IsInt()) + { + var color = new Color(colorHexes[0].ToInt(), colorHexes[1].ToInt(), colorHexes[2].ToInt()); + switch (target) + { + case "hair": + Game1.player.hairstyleColor = color; + break; + case "eyes": + Game1.player.changeEyeColor(color); + break; + case "pants": + Game1.player.pantsColor = color; + break; + } + } + else + this.Monitor.Log("<colour> is invalid", LogLevel.Error); + } + else + this.LogObjectInvalid(); } else - this.Monitor.Log("<value> should be 0 or 1", LogLevel.Error); - } - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } + this.Monitor.Log("<object> and <colour> must be specified", LogLevel.Error); + 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 "player_changestyle": + if (args.Length > 1) + { + string target = args[0]; + string[] validTargets = { "hair", "shirt", "skin", "acc", "shoe", "swim", "gender" }; + if (validTargets.Contains(target)) + { + if (args[1].IsInt()) + { + var styleID = args[1].ToInt(); + switch (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; + } + } + else + this.LogValueInvalid(); + } + else + this.LogObjectInvalid(); + } + else + this.LogObjectValueNotSpecified(); + break; - if (time <= 2600 && time >= 600) + case "world_freezetime": + 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 valueStr = args[0]; + if (valueStr.IsInt()) + { + int value = valueStr.ToInt(); + if (value == 0 || value == 1) + { + this.FreezeTime = value == 1; + this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0; + this.Monitor.Log("Time is now " + (this.FreezeTime ? "frozen" : "thawed"), LogLevel.Info); + } + else + this.Monitor.Log("<value> should be 0 or 1", LogLevel.Error); + } + else + this.LogValueNotInt32(); } 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.LogValueNotSpecified(); + 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 "world_settime": + if (args.Any()) + { + string timeStr = args[0]; + if (timeStr.IsInt()) + { + int time = timeStr.ToInt(); - if (dayStr.IsInt()) - { - int day = dayStr.ToInt(); - if (day <= 28 && day > 0) - Game1.dayOfMonth = day; + if (time <= 2600 && time >= 600) + { + Game1.timeOfDay = args[0].ToInt(); + this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0; + this.Monitor.Log($"Time set to: {Game1.timeOfDay}", LogLevel.Info); + } + 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.Monitor.Log("<value> must be between 1 and 28", LogLevel.Error); - } - else - this.LogValueNotInt32(); - } - else - this.LogValueNotSpecified(); - } - - /// <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(); - } + this.LogValueNotSpecified(); + break; - /// <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 "world_setday": + if (args.Any()) + { + string dayStr = args[0]; - if (amountStr == "inf") - this.InfiniteHealth = true; - else - { - this.InfiniteHealth = false; - if (amountStr.IsInt()) - Game1.player.health = amountStr.ToInt(); + if (dayStr.IsInt()) + { + int day = dayStr.ToInt(); + if (day <= 28 && day > 0) + Game1.dayOfMonth = day; + else + this.Monitor.Log("<value> must be between 1 and 28", LogLevel.Error); + } + else + this.LogValueNotInt32(); + } else - this.LogValueNotInt32(); - } - } - else - this.LogValueNotSpecified(); - } - - /// <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(); - } + this.LogValueNotSpecified(); + break; - /// <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(); - } + case "world_setseason": + if (args.Any()) + { + string season = args[0]; + string[] validSeasons = { "winter", "spring", "summer", "fall" }; + if (validSeasons.Contains(season)) + Game1.currentSeason = season; + else + this.LogValueInvalid(); + } + else + this.LogValueNotSpecified(); + 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_sethealth": + if (args.Any()) { - if (e.Command.CalledArgs[1].IsInt()) - count = e.Command.CalledArgs[1].ToInt(); + string amountStr = args[0]; + + if (amountStr == "inf") + this.InfiniteHealth = true; else { - this.Monitor.Log("[count] is invalid", LogLevel.Error); - return; + this.InfiniteHealth = false; + if (amountStr.IsInt()) + Game1.player.health = amountStr.ToInt(); + else + this.LogValueNotInt32(); } + } + else + this.LogValueNotSpecified(); + break; + + case "player_setmaxhealth": + if (args.Any()) + { + string amountStr = args[0]; + if (amountStr.IsInt()) + Game1.player.maxHealth = amountStr.ToInt(); + else + this.LogValueNotInt32(); + } + else + this.LogValueNotSpecified(); + break; + + case "player_setimmunity": + if (args.Any()) + { + string amountStr = args[0]; + if (amountStr.IsInt()) + Game1.player.immunity = amountStr.ToInt(); + else + this.LogValueNotInt32(); + } + else + this.LogValueNotSpecified(); + break; - if (e.Command.CalledArgs.Length > 2) + case "player_additem": + if (args.Any()) + { + string itemIdStr = args[0]; + if (itemIdStr.IsInt()) { - if (e.Command.CalledArgs[2].IsInt()) - quality = e.Command.CalledArgs[2].ToInt(); - else + int itemID = itemIdStr.ToInt(); + int count = 1; + int quality = 0; + if (args.Length > 1) { - this.Monitor.Log("[quality] is invalid", LogLevel.Error); - return; + if (args[1].IsInt()) + count = args[1].ToInt(); + else + { + this.Monitor.Log("[count] is invalid", LogLevel.Error); + return; + } + + if (args.Length > 2) + { + if (args[2].IsInt()) + quality = args[2].ToInt(); + else + { + this.Monitor.Log("[quality] is invalid", LogLevel.Error); + return; + } + } } + + var item = new Object(itemID, count) { quality = quality }; + + Game1.player.addItemByMenuIfNecessary(item); } + else + this.Monitor.Log("<item> is invalid", LogLevel.Error); } + else + this.LogObjectValueNotSpecified(); + break; - var item = new Object(itemID, count) { quality = quality }; + case "player_addmelee": + if (args.Any()) + { + if (args[0].IsInt()) + { + MeleeWeapon weapon = new MeleeWeapon(args[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(); + break; - Game1.player.addItemByMenuIfNecessary(item); - } - else - this.Monitor.Log("<item> is invalid", LogLevel.Error); - } - else - this.LogObjectValueNotSpecified(); - } + case "player_addring": + if (args.Any()) + { + if (args[0].IsInt()) + { + Ring ring = new Ring(args[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(); + 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 "list_items": + { + var matches = this.GetItems(args).ToArray(); - /// <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(); - } + // 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 '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 "world_downminelevel": + Game1.nextMineLevel(); + 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 "world_setminelevel": + if (args.Any()) + { + if (args[0].IsInt()) + Game1.enterMine(true, args[0].ToInt(), ""); + else + this.LogValueNotInt32(); + } + else + this.LogValueNotSpecified(); + 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(); - } - else - this.LogValueNotSpecified(); - } + case "show_game_files": + Process.Start(Constants.ExecutionPath); + break; - /// <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); - } + case "show_data_files": + Process.Start(Constants.DataPath); + break; - /// <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); + default: + throw new NotImplementedException($"TrainerMod received unknown command '{name}'."); + } } /**** |