summaryrefslogtreecommitdiff
path: root/src/TrainerMod/Framework/Commands/Player
diff options
context:
space:
mode:
Diffstat (limited to 'src/TrainerMod/Framework/Commands/Player')
-rw-r--r--src/TrainerMod/Framework/Commands/Player/AddFlooringCommand.cs47
-rw-r--r--src/TrainerMod/Framework/Commands/Player/AddItemCommand.cs68
-rw-r--r--src/TrainerMod/Framework/Commands/Player/AddRingCommand.cs47
-rw-r--r--src/TrainerMod/Framework/Commands/Player/AddWallpaperCommand.cs47
-rw-r--r--src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs88
-rw-r--r--src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs120
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetColorCommand.cs79
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetHealthCommand.cs72
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetImmunityCommand.cs40
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetLevelCommand.cs73
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs40
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetMaxStaminaCommand.cs40
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetMoneyCommand.cs72
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetNameCommand.cs47
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs40
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetStaminaCommand.cs72
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetStyleCommand.cs102
17 files changed, 1094 insertions, 0 deletions
diff --git a/src/TrainerMod/Framework/Commands/Player/AddFlooringCommand.cs b/src/TrainerMod/Framework/Commands/Player/AddFlooringCommand.cs
new file mode 100644
index 00000000..57bd39e3
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/AddFlooringCommand.cs
@@ -0,0 +1,47 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+using StardewValley.Objects;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which adds a floor item to the player inventory.</summary>
+ internal class AddFlooringCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public AddFlooringCommand()
+ : base("player_addflooring", "Gives the player a flooring item.\n\nUsage: player_addflooring <flooring>\n- flooring: the flooring ID (ranges from 0 to 39).") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+ if (!int.TryParse(args[0], out int floorID))
+ {
+ this.LogArgumentNotInt(monitor, command);
+ return;
+ }
+ if (floorID < 0 || floorID > 39)
+ {
+ monitor.Log("There is no such flooring ID (must be between 0 and 39).", LogLevel.Error);
+ return;
+ }
+
+ // handle
+ Wallpaper wallpaper = new Wallpaper(floorID, isFloor: true);
+ Game1.player.addItemByMenuIfNecessary(wallpaper);
+ monitor.Log($"OK, added flooring {floorID} to your inventory.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/AddItemCommand.cs b/src/TrainerMod/Framework/Commands/Player/AddItemCommand.cs
new file mode 100644
index 00000000..6d3cf968
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/AddItemCommand.cs
@@ -0,0 +1,68 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which adds an item to the player inventory.</summary>
+ internal class AddItemCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public AddItemCommand()
+ : base("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).") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+ if (!int.TryParse(args[0], out int itemID))
+ {
+ this.LogUsageError(monitor, "The item ID must be an integer.", command);
+ return;
+ }
+
+ // parse arguments
+ int count = 1;
+ int quality = 0;
+ if (args.Length > 1)
+ {
+ if (!int.TryParse(args[1], out count))
+ {
+ this.LogUsageError(monitor, "The optional count is invalid.", command);
+ return;
+ }
+ }
+ if (args.Length > 2)
+ {
+ if (!int.TryParse(args[2], out quality))
+ {
+ this.LogUsageError(monitor, "The optional quality is invalid.", command);
+ return;
+ }
+ }
+
+ // spawn item
+ var item = new Object(itemID, count) { quality = quality };
+ if (item.Name == "Error Item")
+ {
+ monitor.Log("There is no such item ID.", LogLevel.Error);
+ return;
+ }
+
+ // add to inventory
+ Game1.player.addItemByMenuIfNecessary(item);
+ monitor.Log($"OK, added {item.Name} to your inventory.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/AddRingCommand.cs b/src/TrainerMod/Framework/Commands/Player/AddRingCommand.cs
new file mode 100644
index 00000000..d62d8b5b
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/AddRingCommand.cs
@@ -0,0 +1,47 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+using StardewValley.Objects;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which adds a ring to the player inventory.</summary>
+ internal class AddRingCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public AddRingCommand()
+ : base("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).") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+ if (!int.TryParse(args[0], out int ringID))
+ {
+ monitor.Log("<item> is invalid", LogLevel.Error);
+ return;
+ }
+ if (ringID < Ring.ringLowerIndexRange || ringID > Ring.ringUpperIndexRange)
+ {
+ monitor.Log($"There is no such ring ID (must be between {Ring.ringLowerIndexRange} and {Ring.ringUpperIndexRange}).", LogLevel.Error);
+ return;
+ }
+
+ // handle
+ Ring ring = new Ring(ringID);
+ Game1.player.addItemByMenuIfNecessary(ring);
+ monitor.Log($"OK, added {ring.Name} to your inventory.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/AddWallpaperCommand.cs b/src/TrainerMod/Framework/Commands/Player/AddWallpaperCommand.cs
new file mode 100644
index 00000000..e02b05a4
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/AddWallpaperCommand.cs
@@ -0,0 +1,47 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+using StardewValley.Objects;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which adds a wallpaper item to the player inventory.</summary>
+ internal class AddWallpaperCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public AddWallpaperCommand()
+ : base("player_addwallpaper", "Gives the player a wallpaper.\n\nUsage: player_addwallpaper <wallpaper>\n- wallpaper: the wallpaper ID (ranges from 0 to 111).") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+ if (!int.TryParse(args[0], out int wallpaperID))
+ {
+ this.LogArgumentNotInt(monitor, command);
+ return;
+ }
+ if (wallpaperID < 0 || wallpaperID > 111)
+ {
+ monitor.Log("There is no such wallpaper ID (must be between 0 and 111).", LogLevel.Error);
+ return;
+ }
+
+ // handle
+ Wallpaper wallpaper = new Wallpaper(wallpaperID);
+ Game1.player.addItemByMenuIfNecessary(wallpaper);
+ monitor.Log($"OK, added wallpaper {wallpaperID} to your inventory.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs b/src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs
new file mode 100644
index 00000000..ee94093f
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs
@@ -0,0 +1,88 @@
+using System.Collections.Generic;
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+using StardewValley.Tools;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which adds a weapon to the player inventory.</summary>
+ internal class AddWeaponCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public AddWeaponCommand()
+ : base("player_addweapon", "Gives the player a weapon.\n\nUsage: player_addweapon <item>\n- item: the weapon ID (use the 'list_items' command to see a list).") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+ if (!int.TryParse(args[0], out int weaponID))
+ {
+ this.LogUsageError(monitor, "The weapon ID must be an integer.", command);
+ return;
+ }
+
+ // get raw weapon data
+ if (!Game1.content.Load<Dictionary<int, string>>("Data\\weapons").TryGetValue(weaponID, out string data))
+ {
+ monitor.Log("There is no such weapon ID.", LogLevel.Error);
+ return;
+ }
+
+ // get raw weapon type
+ int type;
+ {
+ string[] fields = data.Split('/');
+ string typeStr = fields.Length > 8 ? fields[8] : null;
+ if (!int.TryParse(typeStr, out type))
+ {
+ monitor.Log("Could not parse the data for the weapon with that ID.", LogLevel.Error);
+ return;
+ }
+ }
+
+ // get weapon
+ Tool weapon;
+ switch (type)
+ {
+ case MeleeWeapon.stabbingSword:
+ case MeleeWeapon.dagger:
+ case MeleeWeapon.club:
+ case MeleeWeapon.defenseSword:
+ weapon = new MeleeWeapon(weaponID);
+ break;
+
+ case 4:
+ weapon = new Slingshot(weaponID);
+ break;
+
+ default:
+ monitor.Log($"The specified weapon has unknown type '{type}' in the game data.", LogLevel.Error);
+ return;
+ }
+
+ // validate weapon
+ if (weapon.Name == null)
+ {
+ monitor.Log("That weapon doesn't seem to be valid.", LogLevel.Error);
+ return;
+ }
+
+ // add weapon
+ Game1.player.addItemByMenuIfNecessary(weapon);
+ monitor.Log($"OK, added {weapon.Name} to your inventory.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs b/src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs
new file mode 100644
index 00000000..a1b9aceb
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+using StardewValley.Objects;
+using TrainerMod.Framework.ItemData;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which list items available to spawn.</summary>
+ internal class ListItemsCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public ListItemsCommand()
+ : base("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.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ var matches = this.GetItems(args).ToArray();
+
+ // show matches
+ string summary = "Searching...\n";
+ if (matches.Any())
+ monitor.Log(summary + this.GetTableString(matches, new[] { "type", "id", "name" }, val => new[] { val.Type.ToString(), val.ID.ToString(), val.Name }), LogLevel.Info);
+ else
+ monitor.Log(summary + "No items found", LogLevel.Info);
+ }
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Get all items which can be searched and added to the player's inventory through the console.</summary>
+ /// <param name="searchWords">The search string to find.</param>
+ private IEnumerable<ISearchItem> GetItems(string[] searchWords)
+ {
+ // normalise search term
+ searchWords = searchWords?.Where(word => !string.IsNullOrWhiteSpace(word)).ToArray();
+ if (searchWords?.Any() == false)
+ searchWords = null;
+
+ // find matches
+ return (
+ from item in this.GetItems()
+ let term = $"{item.ID}|{item.Type}|{item.Name}"
+ where searchWords == null || searchWords.All(word => term.IndexOf(word, StringComparison.CurrentCultureIgnoreCase) != -1)
+ select item
+ );
+ }
+
+ /// <summary>Get all items which can be searched and added to the player's inventory through the console.</summary>
+ private IEnumerable<ISearchItem> GetItems()
+ {
+ // objects
+ foreach (int id in Game1.objectInformation.Keys)
+ {
+ ISearchItem obj = id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange
+ ? new SearchableRing(id)
+ : (ISearchItem)new SearchableObject(id);
+ if (obj.IsValid)
+ yield return obj;
+ }
+
+ // weapons
+ foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\weapons").Keys)
+ {
+ ISearchItem weapon = new SearchableWeapon(id);
+ if (weapon.IsValid)
+ yield return weapon;
+ }
+ }
+
+ /// <summary>Get an ASCII table for a set of tabular data.</summary>
+ /// <typeparam name="T">The data type.</typeparam>
+ /// <param name="data">The data to display.</param>
+ /// <param name="header">The table header.</param>
+ /// <param name="getRow">Returns a set of fields for a data value.</param>
+ private string GetTableString<T>(IEnumerable<T> data, string[] header, Func<T, string[]> getRow)
+ {
+ // get table data
+ int[] widths = header.Select(p => p.Length).ToArray();
+ string[][] rows = data
+ .Select(item =>
+ {
+ string[] fields = getRow(item);
+ if (fields.Length != widths.Length)
+ throw new InvalidOperationException($"Expected {widths.Length} columns, but found {fields.Length}: {string.Join(", ", fields)}");
+
+ for (int i = 0; i < fields.Length; i++)
+ widths[i] = Math.Max(widths[i], fields[i].Length);
+
+ return fields;
+ })
+ .ToArray();
+
+ // render fields
+ List<string[]> lines = new List<string[]>(rows.Length + 2)
+ {
+ header,
+ header.Select((value, i) => "".PadRight(widths[i], '-')).ToArray()
+ };
+ lines.AddRange(rows);
+
+ return string.Join(
+ Environment.NewLine,
+ lines.Select(line => string.Join(" | ",
+ line.Select((field, i) => field.PadRight(widths[i], ' ')).ToArray())
+ )
+ );
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetColorCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetColorCommand.cs
new file mode 100644
index 00000000..00907fba
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetColorCommand.cs
@@ -0,0 +1,79 @@
+using Microsoft.Xna.Framework;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the color of a player feature.</summary>
+ internal class SetColorCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetColorCommand()
+ : base("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).") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (args.Length <= 2)
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+ if (!this.TryParseColor(args[1], out Color color))
+ {
+ this.LogUsageError(monitor, "The color should be an RBG value like '255,150,0'.", command);
+ return;
+ }
+
+ // handle
+ switch (args[0])
+ {
+ case "hair":
+ Game1.player.hairstyleColor = color;
+ monitor.Log("OK, your hair color is updated.", LogLevel.Info);
+ break;
+
+ case "eyes":
+ Game1.player.changeEyeColor(color);
+ monitor.Log("OK, your eye color is updated.", LogLevel.Info);
+ break;
+
+ case "pants":
+ Game1.player.pantsColor = color;
+ monitor.Log("OK, your pants color is updated.", LogLevel.Info);
+ break;
+
+ default:
+ this.LogArgumentsInvalid(monitor, command);
+ break;
+ }
+ }
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Try to parse a color from a string.</summary>
+ /// <param name="input">The input string.</param>
+ /// <param name="color">The color to set.</param>
+ private bool TryParseColor(string input, out Color color)
+ {
+ string[] colorHexes = input.Split(new[] { ',' }, 3);
+ if (int.TryParse(colorHexes[0], out int r) && int.TryParse(colorHexes[1], out int g) && int.TryParse(colorHexes[2], out int b))
+ {
+ color = new Color(r, g, b);
+ return true;
+ }
+
+ color = Color.Transparent;
+ return false;
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetHealthCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetHealthCommand.cs
new file mode 100644
index 00000000..d3f06459
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetHealthCommand.cs
@@ -0,0 +1,72 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the player's current health.</summary>
+ internal class SetHealthCommand : TrainerCommand
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Whether to keep the player's health at its maximum.</summary>
+ private bool InfiniteHealth;
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Whether the command needs to perform logic when the game updates.</summary>
+ public override bool NeedsUpdate => this.InfiniteHealth;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetHealthCommand()
+ : base("player_sethealth", "Sets the player's health.\n\nUsage: player_sethealth [value]\n- value: an integer amount, or 'inf' for infinite health.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ monitor.Log($"You currently have {(this.InfiniteHealth ? "infinite" : Game1.player.health.ToString())} health. Specify a value to change it.", LogLevel.Info);
+ return;
+ }
+
+ // handle
+ string amountStr = args[0];
+ if (amountStr == "inf")
+ {
+ this.InfiniteHealth = true;
+ monitor.Log("OK, you now have infinite health.", LogLevel.Info);
+ }
+ else
+ {
+ this.InfiniteHealth = false;
+ if (int.TryParse(amountStr, out int amount))
+ {
+ Game1.player.health = amount;
+ monitor.Log($"OK, you now have {Game1.player.health} health.", LogLevel.Info);
+ }
+ else
+ this.LogArgumentNotInt(monitor, command);
+ }
+ }
+
+ /// <summary>Perform any logic needed on update tick.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ public override void Update(IMonitor monitor)
+ {
+ if (this.InfiniteHealth)
+ Game1.player.health = Game1.player.maxHealth;
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetImmunityCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetImmunityCommand.cs
new file mode 100644
index 00000000..ff74f981
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetImmunityCommand.cs
@@ -0,0 +1,40 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the player's current immunity.</summary>
+ internal class SetImmunityCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetImmunityCommand()
+ : base("player_setimmunity", "Sets the player's immunity.\n\nUsage: player_setimmunity [value]\n- value: an integer amount.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ monitor.Log($"You currently have {Game1.player.immunity} immunity. Specify a value to change it.", LogLevel.Info);
+ return;
+ }
+
+ // handle
+ if (int.TryParse(args[0], out int amount))
+ {
+ Game1.player.immunity = amount;
+ monitor.Log($"OK, you now have {Game1.player.immunity} immunity.", LogLevel.Info);
+ }
+ else
+ this.LogArgumentNotInt(monitor, command);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetLevelCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetLevelCommand.cs
new file mode 100644
index 00000000..4982a0b8
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetLevelCommand.cs
@@ -0,0 +1,73 @@
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the player's current level for a skill.</summary>
+ internal class SetLevelCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetLevelCommand()
+ : base("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).") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (args.Length <= 2)
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+ if (!int.TryParse(args[1], out int level))
+ {
+ this.LogArgumentNotInt(monitor, command);
+ return;
+ }
+
+ // handle
+ switch (args[0])
+ {
+ case "luck":
+ Game1.player.LuckLevel = level;
+ monitor.Log($"OK, your luck skill is now {Game1.player.LuckLevel}.", LogLevel.Info);
+ break;
+
+ case "mining":
+ Game1.player.MiningLevel = level;
+ monitor.Log($"OK, your mining skill is now {Game1.player.MiningLevel}.", LogLevel.Info);
+ break;
+
+ case "combat":
+ Game1.player.CombatLevel = level;
+ monitor.Log($"OK, your combat skill is now {Game1.player.CombatLevel}.", LogLevel.Info);
+ break;
+
+ case "farming":
+ Game1.player.FarmingLevel = level;
+ monitor.Log($"OK, your farming skill is now {Game1.player.FarmingLevel}.", LogLevel.Info);
+ break;
+
+ case "fishing":
+ Game1.player.FishingLevel = level;
+ monitor.Log($"OK, your fishing skill is now {Game1.player.FishingLevel}.", LogLevel.Info);
+ break;
+
+ case "foraging":
+ Game1.player.ForagingLevel = level;
+ monitor.Log($"OK, your foraging skill is now {Game1.player.ForagingLevel}.", LogLevel.Info);
+ break;
+
+ default:
+ this.LogUsageError(monitor, "That isn't a valid skill.", command);
+ break;
+ }
+ }
+ }
+}
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
+{
+ /// <summary>A command which edits the player's maximum health.</summary>
+ internal class SetMaxHealthCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetMaxHealthCommand()
+ : base("player_setmaxhealth", "Sets the player's max health.\n\nUsage: player_setmaxhealth [value]\n- value: an integer amount.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ 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);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetMaxStaminaCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetMaxStaminaCommand.cs
new file mode 100644
index 00000000..c21f6592
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetMaxStaminaCommand.cs
@@ -0,0 +1,40 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the player's maximum stamina.</summary>
+ internal class SetMaxStaminaCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetMaxStaminaCommand()
+ : base("player_setmaxstamina", "Sets the player's max stamina.\n\nUsage: player_setmaxstamina [value]\n- value: an integer amount.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ monitor.Log($"You currently have {Game1.player.MaxStamina} max stamina. Specify a value to change it.", LogLevel.Info);
+ return;
+ }
+
+ // handle
+ if (int.TryParse(args[0], out int amount))
+ {
+ Game1.player.MaxStamina = amount;
+ monitor.Log($"OK, you now have {Game1.player.MaxStamina} max stamina.", LogLevel.Info);
+ }
+ else
+ this.LogArgumentNotInt(monitor, command);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetMoneyCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetMoneyCommand.cs
new file mode 100644
index 00000000..ad74499d
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetMoneyCommand.cs
@@ -0,0 +1,72 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the player's current money.</summary>
+ internal class SetMoneyCommand : TrainerCommand
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Whether to keep the player's money at a set value.</summary>
+ private bool InfiniteMoney;
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Whether the command needs to perform logic when the game updates.</summary>
+ public override bool NeedsUpdate => this.InfiniteMoney;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetMoneyCommand()
+ : base("player_setmoney", "Sets the player's money.\n\nUsage: player_setmoney <value>\n- value: an integer amount, or 'inf' for infinite money.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ monitor.Log($"You currently have {(this.InfiniteMoney ? "infinite" : Game1.player.Money.ToString())} gold. Specify a value to change it.", LogLevel.Info);
+ return;
+ }
+
+ // handle
+ string amountStr = args[0];
+ if (amountStr == "inf")
+ {
+ this.InfiniteMoney = true;
+ monitor.Log("OK, you now have infinite money.", LogLevel.Info);
+ }
+ else
+ {
+ this.InfiniteMoney = false;
+ if (int.TryParse(amountStr, out int amount))
+ {
+ Game1.player.Money = amount;
+ monitor.Log($"OK, you now have {Game1.player.Money} gold.", LogLevel.Info);
+ }
+ else
+ this.LogArgumentNotInt(monitor, command);
+ }
+ }
+
+ /// <summary>Perform any logic needed on update tick.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ public override void Update(IMonitor monitor)
+ {
+ if (this.InfiniteMoney)
+ Game1.player.money = 999999;
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetNameCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetNameCommand.cs
new file mode 100644
index 00000000..8284d882
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetNameCommand.cs
@@ -0,0 +1,47 @@
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the player's name.</summary>
+ internal class SetNameCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetNameCommand()
+ : base("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.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (args.Length <= 1)
+ {
+ monitor.Log($"Your name is currently '{Game1.player.Name}'. Type 'help player_setname' for usage.", LogLevel.Info);
+ return;
+ }
+
+ // handle
+ string target = args[0];
+ switch (target)
+ {
+ case "player":
+ Game1.player.Name = args[1];
+ monitor.Log($"OK, your player's name is now {Game1.player.Name}.", LogLevel.Info);
+ break;
+ case "farm":
+ Game1.player.farmName = args[1];
+ monitor.Log($"OK, your farm's name is now {Game1.player.Name}.", LogLevel.Info);
+ break;
+ default:
+ this.LogArgumentsInvalid(monitor, command);
+ break;
+ }
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs
new file mode 100644
index 00000000..a8c05d0c
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs
@@ -0,0 +1,40 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the player's current added speed.</summary>
+ internal class SetSpeedCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetSpeedCommand()
+ : base("player_setspeed", "Sets the player's added speed to the specified value.\n\nUsage: player_setspeed <value>\n- value: an integer amount (0 is normal).") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ monitor.Log($"You currently have {Game1.player.addedSpeed} added speed. Specify a value to change it.", LogLevel.Info);
+ return;
+ }
+ if (!int.TryParse(args[0], out int addedSpeed))
+ {
+ this.LogArgumentNotInt(monitor, command);
+ return;
+ }
+
+ // handle
+ Game1.player.addedSpeed = addedSpeed;
+ monitor.Log($"OK, your added speed is now {Game1.player.addedSpeed}.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetStaminaCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetStaminaCommand.cs
new file mode 100644
index 00000000..55a55eab
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetStaminaCommand.cs
@@ -0,0 +1,72 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits the player's current stamina.</summary>
+ internal class SetStaminaCommand : TrainerCommand
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Whether to keep the player's stamina at its maximum.</summary>
+ private bool InfiniteStamina;
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Whether the command needs to perform logic when the game updates.</summary>
+ public override bool NeedsUpdate => this.InfiniteStamina;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetStaminaCommand()
+ : base("player_setstamina", "Sets the player's stamina.\n\nUsage: player_setstamina [value]\n- value: an integer amount, or 'inf' for infinite stamina.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (!args.Any())
+ {
+ monitor.Log($"You currently have {(this.InfiniteStamina ? "infinite" : Game1.player.Stamina.ToString())} stamina. Specify a value to change it.", LogLevel.Info);
+ return;
+ }
+
+ // handle
+ string amountStr = args[0];
+ if (amountStr == "inf")
+ {
+ this.InfiniteStamina = true;
+ monitor.Log("OK, you now have infinite stamina.", LogLevel.Info);
+ }
+ else
+ {
+ this.InfiniteStamina = false;
+ if (int.TryParse(amountStr, out int amount))
+ {
+ Game1.player.Stamina = amount;
+ monitor.Log($"OK, you now have {Game1.player.Stamina} stamina.", LogLevel.Info);
+ }
+ else
+ this.LogArgumentNotInt(monitor, command);
+ }
+ }
+
+ /// <summary>Perform any logic needed on update tick.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ public override void Update(IMonitor monitor)
+ {
+ if (this.InfiniteStamina)
+ Game1.player.stamina = Game1.player.MaxStamina;
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetStyleCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetStyleCommand.cs
new file mode 100644
index 00000000..9ef5f88b
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetStyleCommand.cs
@@ -0,0 +1,102 @@
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which edits a player style.</summary>
+ internal class SetStyleCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetStyleCommand()
+ : base("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.") { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, string[] args)
+ {
+ // validate
+ if (args.Length <= 1)
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+ if (!int.TryParse(args[1], out int styleID))
+ {
+ this.LogArgumentsInvalid(monitor, command);
+ return;
+ }
+
+ // handle
+ switch (args[0])
+ {
+ case "hair":
+ Game1.player.changeHairStyle(styleID);
+ monitor.Log("OK, your hair style is updated.", LogLevel.Info);
+ break;
+
+ case "shirt":
+ Game1.player.changeShirt(styleID);
+ monitor.Log("OK, your shirt style is updated.", LogLevel.Info);
+ break;
+
+ case "acc":
+ Game1.player.changeAccessory(styleID);
+ monitor.Log("OK, your accessory style is updated.", LogLevel.Info);
+ break;
+
+ case "skin":
+ Game1.player.changeSkinColor(styleID);
+ monitor.Log("OK, your skin color is updated.", LogLevel.Info);
+ break;
+
+ case "shoe":
+ Game1.player.changeShoeColor(styleID);
+ monitor.Log("OK, your shoe style is updated.", LogLevel.Info);
+ break;
+
+ case "swim":
+ switch (styleID)
+ {
+ case 0:
+ Game1.player.changeOutOfSwimSuit();
+ monitor.Log("OK, you're no longer in your swimming suit.", LogLevel.Info);
+ break;
+ case 1:
+ Game1.player.changeIntoSwimsuit();
+ monitor.Log("OK, you're now in your swimming suit.", LogLevel.Info);
+ break;
+ default:
+ this.LogUsageError(monitor, "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);
+ monitor.Log("OK, you're now male.", LogLevel.Info);
+ break;
+ case 1:
+ Game1.player.changeGender(false);
+ monitor.Log("OK, you're now female.", LogLevel.Info);
+ break;
+ default:
+ this.LogUsageError(monitor, "The gender value should be 0 (male) or 1 (female).", command);
+ break;
+ }
+ break;
+
+ default:
+ this.LogArgumentsInvalid(monitor, command);
+ break;
+ }
+ }
+ }
+}