summaryrefslogtreecommitdiff
path: root/src/TrainerMod
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-07-08 12:54:06 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-07-08 12:54:06 -0400
commit1edd98aef027faa768f56cf0b3591e64e20ba096 (patch)
treeaec210e2b44c9654f29572dd084206a4598896e1 /src/TrainerMod
parent36930ffd7d363d6afd7f8cac4918c7d1c1c3e339 (diff)
parent8743c4115aa142113d791f2d2cd9ba811dcada2c (diff)
downloadSMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.tar.gz
SMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.tar.bz2
SMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/TrainerMod')
-rw-r--r--src/TrainerMod/Framework/Commands/ArgumentParser.cs159
-rw-r--r--src/TrainerMod/Framework/Commands/ITrainerCommand.cs34
-rw-r--r--src/TrainerMod/Framework/Commands/Other/DebugCommand.cs33
-rw-r--r--src/TrainerMod/Framework/Commands/Other/ShowDataFilesCommand.cs26
-rw-r--r--src/TrainerMod/Framework/Commands/Other/ShowGameFilesCommand.cs26
-rw-r--r--src/TrainerMod/Framework/Commands/Player/AddCommand.cs81
-rw-r--r--src/TrainerMod/Framework/Commands/Player/ListItemTypesCommand.cs53
-rw-r--r--src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs76
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetColorCommand.cs76
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetHealthCommand.cs72
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetImmunityCommand.cs38
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetLevelCommand.cs63
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs38
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetMaxStaminaCommand.cs38
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetMoneyCommand.cs72
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetNameCommand.cs52
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs31
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetStaminaCommand.cs72
-rw-r--r--src/TrainerMod/Framework/Commands/Player/SetStyleCommand.cs92
-rw-r--r--src/TrainerMod/Framework/Commands/Saves/LoadCommand.cs28
-rw-r--r--src/TrainerMod/Framework/Commands/Saves/SaveCommand.cs27
-rw-r--r--src/TrainerMod/Framework/Commands/TrainerCommand.cs103
-rw-r--r--src/TrainerMod/Framework/Commands/World/DownMineLevelCommand.cs28
-rw-r--r--src/TrainerMod/Framework/Commands/World/FreezeTimeCommand.cs67
-rw-r--r--src/TrainerMod/Framework/Commands/World/SetDayCommand.cs39
-rw-r--r--src/TrainerMod/Framework/Commands/World/SetMineLevelCommand.cs33
-rw-r--r--src/TrainerMod/Framework/Commands/World/SetSeasonCommand.cs46
-rw-r--r--src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs40
-rw-r--r--src/TrainerMod/Framework/Commands/World/SetYearCommand.cs39
-rw-r--r--src/TrainerMod/Framework/ItemData/ItemType.cs39
-rw-r--r--src/TrainerMod/Framework/ItemData/SearchableItem.cs41
-rw-r--r--src/TrainerMod/Framework/ItemRepository.cs179
-rw-r--r--src/TrainerMod/ItemData/ISearchItem.cs21
-rw-r--r--src/TrainerMod/ItemData/ItemType.cs15
-rw-r--r--src/TrainerMod/ItemData/SearchableObject.cs48
-rw-r--r--src/TrainerMod/ItemData/SearchableRing.cs48
-rw-r--r--src/TrainerMod/ItemData/SearchableWeapon.cs48
-rw-r--r--src/TrainerMod/TrainerMod.cs851
-rw-r--r--src/TrainerMod/TrainerMod.csproj37
-rw-r--r--src/TrainerMod/manifest.json4
40 files changed, 1902 insertions, 1011 deletions
diff --git a/src/TrainerMod/Framework/Commands/ArgumentParser.cs b/src/TrainerMod/Framework/Commands/ArgumentParser.cs
new file mode 100644
index 00000000..6bcd3ff8
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/ArgumentParser.cs
@@ -0,0 +1,159 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using StardewModdingAPI;
+
+namespace TrainerMod.Framework.Commands
+{
+ /// <summary>Provides methods for parsing command-line arguments.</summary>
+ internal class ArgumentParser : IReadOnlyList<string>
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The command name for errors.</summary>
+ private readonly string CommandName;
+
+ /// <summary>The arguments to parse.</summary>
+ private readonly string[] Args;
+
+ /// <summary>Writes messages to the console and log file.</summary>
+ private readonly IMonitor Monitor;
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Get the number of arguments.</summary>
+ public int Count => this.Args.Length;
+
+ /// <summary>Get the argument at the specified index in the list.</summary>
+ /// <param name="index">The zero-based index of the element to get.</param>
+ public string this[int index] => this.Args[index];
+
+ /// <summary>A method which parses a string argument into the given value.</summary>
+ /// <typeparam name="T">The expected argument type.</typeparam>
+ /// <param name="input">The argument to parse.</param>
+ /// <param name="output">The parsed value.</param>
+ /// <returns>Returns whether the argument was successfully parsed.</returns>
+ public delegate bool ParseDelegate<T>(string input, out T output);
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="commandName">The command name for errors.</param>
+ /// <param name="args">The arguments to parse.</param>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ public ArgumentParser(string commandName, string[] args, IMonitor monitor)
+ {
+ this.CommandName = commandName;
+ this.Args = args;
+ this.Monitor = monitor;
+ }
+
+ /// <summary>Try to read a string argument.</summary>
+ /// <param name="index">The argument index.</param>
+ /// <param name="name">The argument name for error messages.</param>
+ /// <param name="value">The parsed value.</param>
+ /// <param name="required">Whether to show an error if the argument is missing.</param>
+ /// <param name="oneOf">Require that the argument match one of the given values (case-insensitive).</param>
+ public bool TryGet(int index, string name, out string value, bool required = true, string[] oneOf = null)
+ {
+ value = null;
+
+ // validate
+ if (this.Args.Length < index + 1)
+ {
+ if (required)
+ this.LogError($"Argument {index} ({name}) is required.");
+ return false;
+ }
+ if (oneOf?.Any() == true && !oneOf.Contains(this.Args[index], StringComparer.InvariantCultureIgnoreCase))
+ {
+ this.LogError($"Argument {index} ({name}) must be one of {string.Join(", ", oneOf)}.");
+ return false;
+ }
+
+ // get value
+ value = this.Args[index];
+ return true;
+ }
+
+ /// <summary>Try to read an integer argument.</summary>
+ /// <param name="index">The argument index.</param>
+ /// <param name="name">The argument name for error messages.</param>
+ /// <param name="value">The parsed value.</param>
+ /// <param name="required">Whether to show an error if the argument is missing.</param>
+ /// <param name="min">The minimum value allowed.</param>
+ /// <param name="max">The maximum value allowed.</param>
+ public bool TryGetInt(int index, string name, out int value, bool required = true, int? min = null, int? max = null)
+ {
+ value = 0;
+
+ // get argument
+ if (!this.TryGet(index, name, out string raw, required))
+ return false;
+
+ // parse
+ if (!int.TryParse(raw, out value))
+ {
+ this.LogIntFormatError(index, name, min, max);
+ return false;
+ }
+
+ // validate
+ if ((min.HasValue && value < min) || (max.HasValue && value > max))
+ {
+ this.LogIntFormatError(index, name, min, max);
+ return false;
+ }
+
+ return true;
+ }
+
+ /// <summary>Returns an enumerator that iterates through the collection.</summary>
+ /// <returns>An enumerator that can be used to iterate through the collection.</returns>
+ public IEnumerator<string> GetEnumerator()
+ {
+ return ((IEnumerable<string>)this.Args).GetEnumerator();
+ }
+
+ /// <summary>Returns an enumerator that iterates through a collection.</summary>
+ /// <returns>An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.</returns>
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return this.GetEnumerator();
+ }
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Log a usage error.</summary>
+ /// <param name="message">The message describing the error.</param>
+ private void LogError(string message)
+ {
+ this.Monitor.Log($"{message} Type 'help {this.CommandName}' for usage.", LogLevel.Error);
+ }
+
+ /// <summary>Print an error for an invalid int argument.</summary>
+ /// <param name="index">The argument index.</param>
+ /// <param name="name">The argument name for error messages.</param>
+ /// <param name="min">The minimum value allowed.</param>
+ /// <param name="max">The maximum value allowed.</param>
+ private void LogIntFormatError(int index, string name, int? min, int? max)
+ {
+ if (min.HasValue && max.HasValue)
+ this.LogError($"Argument {index} ({name}) must be an integer between {min} and {max}.");
+ else if (min.HasValue)
+ this.LogError($"Argument {index} ({name}) must be an integer and at least {min}.");
+ else if (max.HasValue)
+ this.LogError($"Argument {index} ({name}) must be an integer and at most {max}.");
+ else
+ this.LogError($"Argument {index} ({name}) must be an integer.");
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/ITrainerCommand.cs b/src/TrainerMod/Framework/Commands/ITrainerCommand.cs
new file mode 100644
index 00000000..3d97e799
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/ITrainerCommand.cs
@@ -0,0 +1,34 @@
+using StardewModdingAPI;
+
+namespace TrainerMod.Framework.Commands
+{
+ /// <summary>A TrainerMod command to register.</summary>
+ internal interface ITrainerCommand
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The command name the user must type.</summary>
+ string Name { get; }
+
+ /// <summary>The command description.</summary>
+ string Description { get; }
+
+ /// <summary>Whether the command needs to perform logic when the game updates.</summary>
+ bool NeedsUpdate { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <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>
+ void Handle(IMonitor monitor, string command, ArgumentParser args);
+
+ /// <summary>Perform any logic needed on update tick.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ void Update(IMonitor monitor);
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Other/DebugCommand.cs b/src/TrainerMod/Framework/Commands/Other/DebugCommand.cs
new file mode 100644
index 00000000..8c6e9f3b
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Other/DebugCommand.cs
@@ -0,0 +1,33 @@
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Other
+{
+ /// <summary>A command which sends a debug command to the game.</summary>
+ internal class DebugCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public DebugCommand()
+ : base("debug", "Run one of the game's debug commands; for example, 'debug warp FarmHouse 1 1' warps the player to the farmhouse.") { }
+
+ /// <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, ArgumentParser args)
+ {
+ // submit command
+ string debugCommand = string.Join(" ", args);
+ string oldOutput = Game1.debugOutput;
+ Game1.game1.parseDebugInput(debugCommand);
+
+ // show result
+ monitor.Log(Game1.debugOutput != oldOutput
+ ? $"> {Game1.debugOutput}"
+ : "Sent debug command to the game, but there was no output.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Other/ShowDataFilesCommand.cs b/src/TrainerMod/Framework/Commands/Other/ShowDataFilesCommand.cs
new file mode 100644
index 00000000..367a70c6
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Other/ShowDataFilesCommand.cs
@@ -0,0 +1,26 @@
+using System.Diagnostics;
+using StardewModdingAPI;
+
+namespace TrainerMod.Framework.Commands.Other
+{
+ /// <summary>A command which shows the data files.</summary>
+ internal class ShowDataFilesCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public ShowDataFilesCommand()
+ : base("show_data_files", "Opens the folder containing the save and log files.") { }
+
+ /// <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, ArgumentParser args)
+ {
+ Process.Start(Constants.DataPath);
+ monitor.Log($"OK, opening {Constants.DataPath}.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Other/ShowGameFilesCommand.cs b/src/TrainerMod/Framework/Commands/Other/ShowGameFilesCommand.cs
new file mode 100644
index 00000000..67fa83a3
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Other/ShowGameFilesCommand.cs
@@ -0,0 +1,26 @@
+using System.Diagnostics;
+using StardewModdingAPI;
+
+namespace TrainerMod.Framework.Commands.Other
+{
+ /// <summary>A command which shows the game files.</summary>
+ internal class ShowGameFilesCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public ShowGameFilesCommand()
+ : base("show_game_files", "Opens the game folder.") { }
+
+ /// <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, ArgumentParser args)
+ {
+ Process.Start(Constants.ExecutionPath);
+ monitor.Log($"OK, opening {Constants.ExecutionPath}.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/AddCommand.cs b/src/TrainerMod/Framework/Commands/Player/AddCommand.cs
new file mode 100644
index 00000000..47840202
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/AddCommand.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+using TrainerMod.Framework.ItemData;
+using Object = StardewValley.Object;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which adds an item to the player inventory.</summary>
+ internal class AddCommand : TrainerCommand
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Provides methods for searching and constructing items.</summary>
+ private readonly ItemRepository Items = new ItemRepository();
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public AddCommand()
+ : base("player_add", AddCommand.GetDescription())
+ { }
+
+ /// <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, ArgumentParser args)
+ {
+ // read arguments
+ if (!args.TryGet(0, "item type", out string rawType, oneOf: Enum.GetNames(typeof(ItemType))))
+ return;
+ if (!args.TryGetInt(1, "item ID", out int id, min: 0))
+ return;
+ if (!args.TryGetInt(2, "count", out int count, min: 1, required: false))
+ count = 1;
+ if (!args.TryGetInt(3, "quality", out int quality, min: Object.lowQuality, max: Object.bestQuality, required: false))
+ quality = Object.lowQuality;
+ ItemType type = (ItemType)Enum.Parse(typeof(ItemType), rawType, ignoreCase: true);
+
+ // find matching item
+ SearchableItem match = this.Items.GetAll().FirstOrDefault(p => p.Type == type && p.ID == id);
+ if (match == null)
+ {
+ monitor.Log($"There's no {type} item with ID {id}.", LogLevel.Error);
+ return;
+ }
+
+ // apply count & quality
+ match.Item.Stack = count;
+ if (match.Item is Object obj)
+ obj.quality = quality;
+
+ // add to inventory
+ Game1.player.addItemByMenuIfNecessary(match.Item);
+ monitor.Log($"OK, added {match.Name} ({match.Type} #{match.ID}) to your inventory.", LogLevel.Info);
+ }
+
+ /*********
+ ** Private methods
+ *********/
+ private static string GetDescription()
+ {
+ string[] typeValues = Enum.GetNames(typeof(ItemType));
+ return "Gives the player an item.\n"
+ + "\n"
+ + "Usage: player_add <type> <item> [count] [quality]\n"
+ + $"- type: the item type (one of {string.Join(", ", typeValues)}).\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).\n"
+ + "\n"
+ + "This example adds the galaxy sword to your inventory:\n"
+ + " player_add weapon 4";
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/ListItemTypesCommand.cs b/src/TrainerMod/Framework/Commands/Player/ListItemTypesCommand.cs
new file mode 100644
index 00000000..5f14edbb
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/ListItemTypesCommand.cs
@@ -0,0 +1,53 @@
+using System.Linq;
+using StardewModdingAPI;
+using TrainerMod.Framework.ItemData;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which list item types.</summary>
+ internal class ListItemTypesCommand : TrainerCommand
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Provides methods for searching and constructing items.</summary>
+ private readonly ItemRepository Items = new ItemRepository();
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public ListItemTypesCommand()
+ : base("list_item_types", "Lists item types you can filter in other commands.\n\nUsage: list_item_types") { }
+
+ /// <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, ArgumentParser args)
+ {
+ // validate
+ if (!Context.IsWorldReady)
+ {
+ monitor.Log("You need to load a save to use this command.", LogLevel.Error);
+ return;
+ }
+
+ // handle
+ ItemType[] matches =
+ (
+ from item in this.Items.GetAll()
+ orderby item.Type.ToString()
+ select item.Type
+ )
+ .Distinct()
+ .ToArray();
+ string summary = "Searching...\n";
+ if (matches.Any())
+ monitor.Log(summary + this.GetTableString(matches, new[] { "type" }, val => new[] { val.ToString() }), LogLevel.Info);
+ else
+ monitor.Log(summary + "No item types found.", 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..7f4f454c
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using StardewModdingAPI;
+using TrainerMod.Framework.ItemData;
+
+namespace TrainerMod.Framework.Commands.Player
+{
+ /// <summary>A command which list items available to spawn.</summary>
+ internal class ListItemsCommand : TrainerCommand
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Provides methods for searching and constructing items.</summary>
+ private readonly ItemRepository Items = new ItemRepository();
+
+
+ /*********
+ ** 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, ArgumentParser args)
+ {
+ // validate
+ if (!Context.IsWorldReady)
+ {
+ monitor.Log("You need to load a save to use this command.", LogLevel.Error);
+ return;
+ }
+
+ // handle
+ SearchableItem[] matches =
+ (
+ from item in this.GetItems(args.ToArray())
+ orderby item.Type.ToString(), item.Name
+ select item
+ )
+ .ToArray();
+ string summary = "Searching...\n";
+ if (matches.Any())
+ monitor.Log(summary + this.GetTableString(matches, new[] { "type", "name", "id" }, val => new[] { val.Type.ToString(), val.Name, val.ID.ToString() }), 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<SearchableItem> 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.Items.GetAll()
+ let term = $"{item.ID}|{item.Type}|{item.Name}|{item.DisplayName}"
+ where searchWords == null || searchWords.All(word => term.IndexOf(word, StringComparison.CurrentCultureIgnoreCase) != -1)
+ select item
+ );
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetColorCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetColorCommand.cs
new file mode 100644
index 00000000..28ace0df
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetColorCommand.cs
@@ -0,0 +1,76 @@
+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, ArgumentParser args)
+ {
+ // parse arguments
+ if (!args.TryGet(0, "target", out string target, oneOf: new[] { "hair", "eyes", "pants" }))
+ return;
+ if (!args.TryGet(1, "color", out string rawColor))
+ return;
+
+ // parse color
+ if (!this.TryParseColor(rawColor, out Color color))
+ {
+ this.LogUsageError(monitor, "Argument 1 (color) must be an RBG value like '255,150,0'.");
+ return;
+ }
+
+ // handle
+ switch (target)
+ {
+ 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;
+ }
+ }
+
+
+ /*********
+ ** 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..f64e9035
--- /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, ArgumentParser args)
+ {
+ // no-argument mode
+ 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);
+ }
+ }
+
+ /// <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..59b28a3c
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetImmunityCommand.cs
@@ -0,0 +1,38 @@
+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, ArgumentParser 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 (args.TryGetInt(0, "amount", out int amount, min: 0))
+ {
+ Game1.player.immunity = amount;
+ monitor.Log($"OK, you now have {Game1.player.immunity} immunity.", LogLevel.Info);
+ }
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetLevelCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetLevelCommand.cs
new file mode 100644
index 00000000..b223aa9f
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetLevelCommand.cs
@@ -0,0 +1,63 @@
+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, ArgumentParser args)
+ {
+ // validate
+ if (!args.TryGet(0, "skill", out string skill, oneOf: new[] { "luck", "mining", "combat", "farming", "fishing", "foraging" }))
+ return;
+ if (!args.TryGetInt(1, "level", out int level, min: 0, max: 10))
+ return;
+
+ // handle
+ switch (skill)
+ {
+ 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;
+ }
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs
new file mode 100644
index 00000000..4b9d87dc
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetMaxHealthCommand.cs
@@ -0,0 +1,38 @@
+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, ArgumentParser 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 (args.TryGetInt(0, "amount", out int amount, min: 1))
+ {
+ Game1.player.maxHealth = amount;
+ monitor.Log($"OK, you now have {Game1.player.maxHealth} max health.", LogLevel.Info);
+ }
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetMaxStaminaCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetMaxStaminaCommand.cs
new file mode 100644
index 00000000..3997bb1b
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetMaxStaminaCommand.cs
@@ -0,0 +1,38 @@
+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, ArgumentParser 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 (args.TryGetInt(0, "amount", out int amount, min: 1))
+ {
+ Game1.player.MaxStamina = amount;
+ monitor.Log($"OK, you now have {Game1.player.MaxStamina} max stamina.", LogLevel.Info);
+ }
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Player/SetMoneyCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetMoneyCommand.cs
new file mode 100644
index 00000000..55e069a4
--- /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, ArgumentParser 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);
+ }
+ }
+
+ /// <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..3fd4475c
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetNameCommand.cs
@@ -0,0 +1,52 @@
+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, ArgumentParser args)
+ {
+ // parse arguments
+ if (!args.TryGet(0, "target", out string target, oneOf: new[] { "player", "farm" }))
+ return;
+ args.TryGet(1, "name", out string name, required: false);
+
+ // handle
+ switch (target)
+ {
+ case "player":
+ if (!string.IsNullOrWhiteSpace(name))
+ {
+ Game1.player.Name = args[1];
+ monitor.Log($"OK, your name is now {Game1.player.Name}.", LogLevel.Info);
+ }
+ else
+ monitor.Log($"Your name is currently '{Game1.player.Name}'. Type 'help player_setname' for usage.", LogLevel.Info);
+ break;
+
+ case "farm":
+ if (!string.IsNullOrWhiteSpace(name))
+ {
+ Game1.player.farmName = args[1];
+ monitor.Log($"OK, your farm's name is now {Game1.player.farmName}.", LogLevel.Info);
+ }
+ else
+ monitor.Log($"Your farm's name is currently '{Game1.player.farmName}'. Type 'help player_setname' for usage.", LogLevel.Info);
+ 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..40b87b62
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs
@@ -0,0 +1,31 @@
+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, ArgumentParser args)
+ {
+ // parse arguments
+ if (!args.TryGetInt(0, "added speed", out int amount, min: 0))
+ return;
+
+ // handle
+ Game1.player.addedSpeed = amount;
+ 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..d44d1370
--- /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, ArgumentParser 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);
+ }
+ }
+
+ /// <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..96e34af2
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Player/SetStyleCommand.cs
@@ -0,0 +1,92 @@
+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, ArgumentParser args)
+ {
+ // parse arguments
+ if (!args.TryGet(0, "target", out string target, oneOf: new[] { "hair", "shirt", "acc", "skin", "shoe", "swim", "gender" }))
+ return;
+ if (!args.TryGetInt(1, "style ID", out int styleID))
+ return;
+
+ // handle
+ switch (target)
+ {
+ 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).");
+ 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).");
+ break;
+ }
+ break;
+ }
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Saves/LoadCommand.cs b/src/TrainerMod/Framework/Commands/Saves/LoadCommand.cs
new file mode 100644
index 00000000..121ad9a6
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Saves/LoadCommand.cs
@@ -0,0 +1,28 @@
+using StardewModdingAPI;
+using StardewValley;
+using StardewValley.Menus;
+
+namespace TrainerMod.Framework.Commands.Saves
+{
+ /// <summary>A command which shows the load screen.</summary>
+ internal class LoadCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public LoadCommand()
+ : base("load", "Shows the load screen.") { }
+
+ /// <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, ArgumentParser args)
+ {
+ monitor.Log("Triggering load menu...", LogLevel.Info);
+ Game1.hasLoadedGame = false;
+ Game1.activeClickableMenu = new LoadGameMenu();
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/Saves/SaveCommand.cs b/src/TrainerMod/Framework/Commands/Saves/SaveCommand.cs
new file mode 100644
index 00000000..5f6941e9
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/Saves/SaveCommand.cs
@@ -0,0 +1,27 @@
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.Saves
+{
+ /// <summary>A command which saves the game.</summary>
+ internal class SaveCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SaveCommand()
+ : base("save", "Saves the game? Doesn't seem to work.") { }
+
+
+ /// <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, ArgumentParser args)
+ {
+ monitor.Log("Saving the game...", LogLevel.Info);
+ SaveGame.Save();
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/TrainerCommand.cs b/src/TrainerMod/Framework/Commands/TrainerCommand.cs
new file mode 100644
index 00000000..abe9ee41
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/TrainerCommand.cs
@@ -0,0 +1,103 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using StardewModdingAPI;
+
+namespace TrainerMod.Framework.Commands
+{
+ /// <summary>The base implementation for a trainer command.</summary>
+ internal abstract class TrainerCommand : ITrainerCommand
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The command name the user must type.</summary>
+ public string Name { get; }
+
+ /// <summary>The command description.</summary>
+ public string Description { get; }
+
+ /// <summary>Whether the command needs to perform logic when the game updates.</summary>
+ public virtual bool NeedsUpdate { get; } = false;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <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 abstract void Handle(IMonitor monitor, string command, ArgumentParser args);
+
+ /// <summary>Perform any logic needed on update tick.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ public virtual void Update(IMonitor monitor) { }
+
+
+ /*********
+ ** Protected methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="name">The command name the user must type.</param>
+ /// <param name="description">The command description.</param>
+ protected TrainerCommand(string name, string description)
+ {
+ this.Name = name;
+ this.Description = description;
+ }
+
+ /// <summary>Log an error indicating incorrect usage.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="error">A sentence explaining the problem.</param>
+ protected void LogUsageError(IMonitor monitor, string error)
+ {
+ monitor.Log($"{error} Type 'help {this.Name}' for usage.", LogLevel.Error);
+ }
+
+ /// <summary>Log an error indicating a value must be an integer.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ protected void LogArgumentNotInt(IMonitor monitor)
+ {
+ this.LogUsageError(monitor, "The value must be a whole number.");
+ }
+
+ /// <summary>Get an ASCII table to show tabular data in the console.</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>
+ protected 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/World/DownMineLevelCommand.cs b/src/TrainerMod/Framework/Commands/World/DownMineLevelCommand.cs
new file mode 100644
index 00000000..4e62cf77
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/World/DownMineLevelCommand.cs
@@ -0,0 +1,28 @@
+using StardewModdingAPI;
+using StardewValley;
+using StardewValley.Locations;
+
+namespace TrainerMod.Framework.Commands.World
+{
+ /// <summary>A command which moves the player to the next mine level.</summary>
+ internal class DownMineLevelCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public DownMineLevelCommand()
+ : base("world_downminelevel", "Goes down one mine level.") { }
+
+ /// <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, ArgumentParser args)
+ {
+ int level = (Game1.currentLocation as MineShaft)?.mineLevel ?? 0;
+ monitor.Log($"OK, warping you to mine level {level + 1}.", LogLevel.Info);
+ Game1.enterMine(false, level + 1, "");
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/World/FreezeTimeCommand.cs b/src/TrainerMod/Framework/Commands/World/FreezeTimeCommand.cs
new file mode 100644
index 00000000..13d08398
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/World/FreezeTimeCommand.cs
@@ -0,0 +1,67 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.World
+{
+ /// <summary>A command which freezes the current time.</summary>
+ internal class FreezeTimeCommand : TrainerCommand
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The time of day at which to freeze time.</summary>
+ internal static int FrozenTime;
+
+ /// <summary>Whether to freeze time.</summary>
+ private bool FreezeTime;
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Whether the command needs to perform logic when the game updates.</summary>
+ public override bool NeedsUpdate => this.FreezeTime;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public FreezeTimeCommand()
+ : base("world_freezetime", "Freezes or resumes time.\n\nUsage: world_freezetime [value]\n- value: one of 0 (resume), 1 (freeze), or blank (toggle).") { }
+
+ /// <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, ArgumentParser args)
+ {
+ if (args.Any())
+ {
+ // parse arguments
+ if (!args.TryGetInt(0, "value", out int value, min: 0, max: 1))
+ return;
+
+ // handle
+ this.FreezeTime = value == 1;
+ FreezeTimeCommand.FrozenTime = Game1.timeOfDay;
+ monitor.Log($"OK, time is now {(this.FreezeTime ? "frozen" : "resumed")}.", LogLevel.Info);
+ }
+ else
+ {
+ this.FreezeTime = !this.FreezeTime;
+ FreezeTimeCommand.FrozenTime = Game1.timeOfDay;
+ monitor.Log($"OK, time is now {(this.FreezeTime ? "frozen" : "resumed")}.", LogLevel.Info);
+ }
+ }
+
+ /// <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.FreezeTime)
+ Game1.timeOfDay = FreezeTimeCommand.FrozenTime;
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/World/SetDayCommand.cs b/src/TrainerMod/Framework/Commands/World/SetDayCommand.cs
new file mode 100644
index 00000000..54267384
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/World/SetDayCommand.cs
@@ -0,0 +1,39 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.World
+{
+ /// <summary>A command which sets the current day.</summary>
+ internal class SetDayCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetDayCommand()
+ : base("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).") { }
+
+ /// <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, ArgumentParser args)
+ {
+ // no-argument mode
+ if (!args.Any())
+ {
+ monitor.Log($"The current date is {Game1.currentSeason} {Game1.dayOfMonth}. Specify a value to change the day.", LogLevel.Info);
+ return;
+ }
+
+ // parse arguments
+ if (!args.TryGetInt(0, "day", out int day, min: 1, max: 28))
+ return;
+
+ // handle
+ Game1.dayOfMonth = day;
+ monitor.Log($"OK, the date is now {Game1.currentSeason} {Game1.dayOfMonth}.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/World/SetMineLevelCommand.cs b/src/TrainerMod/Framework/Commands/World/SetMineLevelCommand.cs
new file mode 100644
index 00000000..225ec091
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/World/SetMineLevelCommand.cs
@@ -0,0 +1,33 @@
+using System;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.World
+{
+ /// <summary>A command which moves the player to the given mine level.</summary>
+ internal class SetMineLevelCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetMineLevelCommand()
+ : base("world_setminelevel", "Sets the mine level?\n\nUsage: world_setminelevel <value>\n- value: The target level (a number starting at 1).") { }
+
+ /// <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, ArgumentParser args)
+ {
+ // parse arguments
+ if (!args.TryGetInt(0, "mine level", out int level, min: 1))
+ return;
+
+ // handle
+ level = Math.Max(1, level);
+ monitor.Log($"OK, warping you to mine level {level}.", LogLevel.Info);
+ Game1.enterMine(true, level, "");
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/World/SetSeasonCommand.cs b/src/TrainerMod/Framework/Commands/World/SetSeasonCommand.cs
new file mode 100644
index 00000000..96c3d920
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/World/SetSeasonCommand.cs
@@ -0,0 +1,46 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.World
+{
+ /// <summary>A command which sets the current season.</summary>
+ internal class SetSeasonCommand : TrainerCommand
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The valid season names.</summary>
+ private readonly string[] ValidSeasons = { "winter", "spring", "summer", "fall" };
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetSeasonCommand()
+ : base("world_setseason", "Sets the season to the specified value.\n\nUsage: world_setseason <season>\n- season: the target season (one of 'spring', 'summer', 'fall', 'winter').") { }
+
+ /// <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, ArgumentParser args)
+ {
+ // no-argument mode
+ if (!args.Any())
+ {
+ monitor.Log($"The current season is {Game1.currentSeason}. Specify a value to change it.", LogLevel.Info);
+ return;
+ }
+
+ // parse arguments
+ if (!args.TryGet(0, "season", out string season, oneOf: this.ValidSeasons))
+ return;
+
+ // handle
+ Game1.currentSeason = season;
+ monitor.Log($"OK, the date is now {Game1.currentSeason} {Game1.dayOfMonth}.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs b/src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs
new file mode 100644
index 00000000..c827ea5e
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs
@@ -0,0 +1,40 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.World
+{
+ /// <summary>A command which sets the current time.</summary>
+ internal class SetTimeCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetTimeCommand()
+ : base("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).") { }
+
+ /// <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, ArgumentParser args)
+ {
+ // no-argument mode
+ if (!args.Any())
+ {
+ monitor.Log($"The current time is {Game1.timeOfDay}. Specify a value to change it.", LogLevel.Info);
+ return;
+ }
+
+ // parse arguments
+ if (!args.TryGetInt(0, "time", out int time, min: 600, max: 2600))
+ return;
+
+ // handle
+ Game1.timeOfDay = time;
+ FreezeTimeCommand.FrozenTime = Game1.timeOfDay;
+ monitor.Log($"OK, the time is now {Game1.timeOfDay.ToString().PadLeft(4, '0')}.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/Commands/World/SetYearCommand.cs b/src/TrainerMod/Framework/Commands/World/SetYearCommand.cs
new file mode 100644
index 00000000..760fc170
--- /dev/null
+++ b/src/TrainerMod/Framework/Commands/World/SetYearCommand.cs
@@ -0,0 +1,39 @@
+using System.Linq;
+using StardewModdingAPI;
+using StardewValley;
+
+namespace TrainerMod.Framework.Commands.World
+{
+ /// <summary>A command which sets the current year.</summary>
+ internal class SetYearCommand : TrainerCommand
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public SetYearCommand()
+ : base("world_setyear", "Sets the year to the specified value.\n\nUsage: world_setyear <year>\n- year: the target year (a number starting from 1).") { }
+
+ /// <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, ArgumentParser args)
+ {
+ // no-argument mode
+ if (!args.Any())
+ {
+ monitor.Log($"The current year is {Game1.year}. Specify a value to change the year.", LogLevel.Info);
+ return;
+ }
+
+ // parse arguments
+ if (!args.TryGetInt(0, "year", out int year, min: 1))
+ return;
+
+ // handle
+ Game1.year = year;
+ monitor.Log($"OK, the year is now {Game1.year}.", LogLevel.Info);
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/ItemData/ItemType.cs b/src/TrainerMod/Framework/ItemData/ItemType.cs
new file mode 100644
index 00000000..423455e9
--- /dev/null
+++ b/src/TrainerMod/Framework/ItemData/ItemType.cs
@@ -0,0 +1,39 @@
+namespace TrainerMod.Framework.ItemData
+{
+ /// <summary>An item type that can be searched and added to the player through the console.</summary>
+ internal enum ItemType
+ {
+ /// <summary>A big craftable object in <see cref="StardewValley.Game1.bigCraftablesInformation"/></summary>
+ BigCraftable,
+
+ /// <summary>A <see cref="Boots"/> item.</summary>
+ Boots,
+
+ /// <summary>A fish item.</summary>
+ Fish,
+
+ /// <summary>A <see cref="Wallpaper"/> flooring item.</summary>
+ Flooring,
+
+ /// <summary>A <see cref="Furniture"/> item.</summary>
+ Furniture,
+
+ /// <summary>A <see cref="Hat"/> item.</summary>
+ Hat,
+
+ /// <summary>Any object in <see cref="StardewValley.Game1.objectInformation"/> (except rings).</summary>
+ Object,
+
+ /// <summary>A <see cref="Ring"/> item.</summary>
+ Ring,
+
+ /// <summary>A <see cref="Tool"/> tool.</summary>
+ Tool,
+
+ /// <summary>A <see cref="Wallpaper"/> wall item.</summary>
+ Wallpaper,
+
+ /// <summary>A <see cref="StardewValley.Tools.MeleeWeapon"/> or <see cref="StardewValley.Tools.Slingshot"/> item.</summary>
+ Weapon
+ }
+}
diff --git a/src/TrainerMod/Framework/ItemData/SearchableItem.cs b/src/TrainerMod/Framework/ItemData/SearchableItem.cs
new file mode 100644
index 00000000..146da1a8
--- /dev/null
+++ b/src/TrainerMod/Framework/ItemData/SearchableItem.cs
@@ -0,0 +1,41 @@
+using StardewValley;
+
+namespace TrainerMod.Framework.ItemData
+{
+ /// <summary>A game item with metadata.</summary>
+ internal class SearchableItem
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The item type.</summary>
+ public ItemType Type { get; }
+
+ /// <summary>The item instance.</summary>
+ public Item Item { get; }
+
+ /// <summary>The item's unique ID for its type.</summary>
+ public int ID { get; }
+
+ /// <summary>The item's default name.</summary>
+ public string Name => this.Item.Name;
+
+ /// <summary>The item's display name for the current language.</summary>
+ public string DisplayName => this.Item.DisplayName;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="type">The item type.</param>
+ /// <param name="id">The unique ID (if different from the item's parent sheet index).</param>
+ /// <param name="item">The item instance.</param>
+ public SearchableItem(ItemType type, int id, Item item)
+ {
+ this.Type = type;
+ this.ID = id;
+ this.Item = item;
+ }
+ }
+}
diff --git a/src/TrainerMod/Framework/ItemRepository.cs b/src/TrainerMod/Framework/ItemRepository.cs
new file mode 100644
index 00000000..96d3159e
--- /dev/null
+++ b/src/TrainerMod/Framework/ItemRepository.cs
@@ -0,0 +1,179 @@
+using System.Collections.Generic;
+using Microsoft.Xna.Framework;
+using StardewValley;
+using StardewValley.Objects;
+using StardewValley.Tools;
+using TrainerMod.Framework.ItemData;
+using SObject = StardewValley.Object;
+
+namespace TrainerMod.Framework
+{
+ /// <summary>Provides methods for searching and constructing items.</summary>
+ internal class ItemRepository
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The custom ID offset for items don't have a unique ID in the game.</summary>
+ private readonly int CustomIDOffset = 1000;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Get all spawnable items.</summary>
+ public IEnumerable<SearchableItem> GetAll()
+ {
+ // get tools
+ for (int quality = Tool.stone; quality <= Tool.iridium; quality++)
+ {
+ yield return new SearchableItem(ItemType.Tool, ToolFactory.axe, ToolFactory.getToolFromDescription(ToolFactory.axe, quality));
+ yield return new SearchableItem(ItemType.Tool, ToolFactory.hoe, ToolFactory.getToolFromDescription(ToolFactory.hoe, quality));
+ yield return new SearchableItem(ItemType.Tool, ToolFactory.pickAxe, ToolFactory.getToolFromDescription(ToolFactory.pickAxe, quality));
+ yield return new SearchableItem(ItemType.Tool, ToolFactory.wateringCan, ToolFactory.getToolFromDescription(ToolFactory.wateringCan, quality));
+ if (quality != Tool.iridium)
+ yield return new SearchableItem(ItemType.Tool, ToolFactory.fishingRod, ToolFactory.getToolFromDescription(ToolFactory.fishingRod, quality));
+ }
+ yield return new SearchableItem(ItemType.Tool, this.CustomIDOffset, new MilkPail()); // these don't have any sort of ID, so we'll just assign some arbitrary ones
+ yield return new SearchableItem(ItemType.Tool, this.CustomIDOffset + 1, new Shears());
+ yield return new SearchableItem(ItemType.Tool, this.CustomIDOffset + 2, new Pan());
+
+ // wallpapers
+ for (int id = 0; id < 112; id++)
+ yield return new SearchableItem(ItemType.Wallpaper, id, new Wallpaper(id));
+
+ // flooring
+ for (int id = 0; id < 40; id++)
+ yield return new SearchableItem(ItemType.Flooring, id, new Wallpaper(id, isFloor: true));
+
+ // equipment
+ foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\Boots").Keys)
+ yield return new SearchableItem(ItemType.Boots, id, new Boots(id));
+ foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\hats").Keys)
+ yield return new SearchableItem(ItemType.Hat, id, new Hat(id));
+ foreach (int id in Game1.objectInformation.Keys)
+ {
+ if (id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange)
+ yield return new SearchableItem(ItemType.Ring, id, new Ring(id));
+ }
+
+ // weapons
+ foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\weapons").Keys)
+ {
+ Item weapon = (id >= 32 && id <= 34)
+ ? (Item)new Slingshot(id)
+ : new MeleeWeapon(id);
+ yield return new SearchableItem(ItemType.Weapon, id, weapon);
+ }
+
+ // furniture
+ foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\Furniture").Keys)
+ {
+ if (id == 1466 || id == 1468)
+ yield return new SearchableItem(ItemType.Furniture, id, new TV(id, Vector2.Zero));
+ else
+ yield return new SearchableItem(ItemType.Furniture, id, new Furniture(id, Vector2.Zero));
+ }
+
+ // fish
+ foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\Fish").Keys)
+ yield return new SearchableItem(ItemType.Fish, id, new SObject(id, 999));
+
+ // craftables
+ foreach (int id in Game1.bigCraftablesInformation.Keys)
+ yield return new SearchableItem(ItemType.BigCraftable, id, new SObject(Vector2.Zero, id));
+
+ // objects
+ foreach (int id in Game1.objectInformation.Keys)
+ {
+ if (id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange)
+ continue; // handled separated
+
+ SObject item = new SObject(id, 1);
+ yield return new SearchableItem(ItemType.Object, id, item);
+
+ // fruit products
+ if (item.category == SObject.FruitsCategory)
+ {
+ yield return new SearchableItem(ItemType.Object, this.CustomIDOffset + id, new SObject(348, 1)
+ {
+ name = $"{item.Name} Wine",
+ price = item.price * 3,
+ preserve = SObject.PreserveType.Wine,
+ preservedParentSheetIndex = item.parentSheetIndex
+ });
+ yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 2 + id, new SObject(344, 1)
+ {
+ name = $"{item.Name} Jelly",
+ price = 50 + item.Price * 2,
+ preserve = SObject.PreserveType.Jelly,
+ preservedParentSheetIndex = item.parentSheetIndex
+ });
+ }
+
+ // vegetable products
+ else if (item.category == SObject.VegetableCategory)
+ {
+ yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 3 + id, new SObject(350, 1)
+ {
+ name = $"{item.Name} Juice",
+ price = (int)(item.price * 2.25d),
+ preserve = SObject.PreserveType.Juice,
+ preservedParentSheetIndex = item.parentSheetIndex
+ });
+ yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 4 + id, new SObject(342, 1)
+ {
+ name = $"Pickled {item.Name}",
+ price = 50 + item.Price * 2,
+ preserve = SObject.PreserveType.Pickle,
+ preservedParentSheetIndex = item.parentSheetIndex
+ });
+ }
+
+ // flower honey
+ else if (item.category == SObject.flowersCategory)
+ {
+ // get honey type
+ SObject.HoneyType? type = null;
+ switch (item.parentSheetIndex)
+ {
+ case 376:
+ type = SObject.HoneyType.Poppy;
+ break;
+ case 591:
+ type = SObject.HoneyType.Tulip;
+ break;
+ case 593:
+ type = SObject.HoneyType.SummerSpangle;
+ break;
+ case 595:
+ type = SObject.HoneyType.FairyRose;
+ break;
+ case 597:
+ type = SObject.HoneyType.BlueJazz;
+ break;
+ case 421: // sunflower standing in for all other flowers
+ type = SObject.HoneyType.Wild;
+ break;
+ }
+
+ // yield honey
+ if (type != null)
+ {
+ SObject honey = new SObject(Vector2.Zero, 340, item.Name + " Honey", false, true, false, false)
+ {
+ name = "Wild Honey",
+ honeyType = type
+ };
+ if (type != SObject.HoneyType.Wild)
+ {
+ honey.name = $"{item.Name} Honey";
+ honey.price += item.price * 2;
+ }
+ yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 5 + id, honey);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/TrainerMod/ItemData/ISearchItem.cs b/src/TrainerMod/ItemData/ISearchItem.cs
deleted file mode 100644
index b2f7c2b8..00000000
--- a/src/TrainerMod/ItemData/ISearchItem.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace TrainerMod.ItemData
-{
- /// <summary>An item that can be searched and added to the player's inventory through the console.</summary>
- internal interface ISearchItem
- {
- /*********
- ** Accessors
- *********/
- /// <summary>Whether the item is valid.</summary>
- bool IsValid { get; }
-
- /// <summary>The item ID.</summary>
- int ID { get; }
-
- /// <summary>The item name.</summary>
- string Name { get; }
-
- /// <summary>The item type.</summary>
- ItemType Type { get; }
- }
-} \ No newline at end of file
diff --git a/src/TrainerMod/ItemData/ItemType.cs b/src/TrainerMod/ItemData/ItemType.cs
deleted file mode 100644
index 2e049aa1..00000000
--- a/src/TrainerMod/ItemData/ItemType.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-namespace TrainerMod.ItemData
-{
- /// <summary>An item type that can be searched and added to the player through the console.</summary>
- internal enum ItemType
- {
- /// <summary>Any object in <see cref="StardewValley.Game1.objectInformation"/> (except rings).</summary>
- Object,
-
- /// <summary>A ring in <see cref="StardewValley.Game1.objectInformation"/>.</summary>
- Ring,
-
- /// <summary>A weapon from <c>Data\weapons</c>.</summary>
- Weapon
- }
-}
diff --git a/src/TrainerMod/ItemData/SearchableObject.cs b/src/TrainerMod/ItemData/SearchableObject.cs
deleted file mode 100644
index 30362f54..00000000
--- a/src/TrainerMod/ItemData/SearchableObject.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using StardewValley;
-
-namespace TrainerMod.ItemData
-{
- /// <summary>An object that can be searched and added to the player's inventory through the console.</summary>
- internal class SearchableObject : ISearchItem
- {
- /*********
- ** Properties
- *********/
- /// <summary>The underlying item.</summary>
- private readonly Item Item;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Whether the item is valid.</summary>
- public bool IsValid => this.Item != null && this.Item.Name != "Broken Item";
-
- /// <summary>The item ID.</summary>
- public int ID => this.Item.parentSheetIndex;
-
- /// <summary>The item name.</summary>
- public string Name => this.Item.Name;
-
- /// <summary>The item type.</summary>
- public ItemType Type => ItemType.Object;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="id">The item ID.</param>
- public SearchableObject(int id)
- {
- try
- {
- this.Item = new Object(id, 1);
- }
- catch
- {
- // invalid
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/TrainerMod/ItemData/SearchableRing.cs b/src/TrainerMod/ItemData/SearchableRing.cs
deleted file mode 100644
index 7751e6aa..00000000
--- a/src/TrainerMod/ItemData/SearchableRing.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using StardewValley.Objects;
-
-namespace TrainerMod.ItemData
-{
- /// <summary>A ring that can be searched and added to the player's inventory through the console.</summary>
- internal class SearchableRing : ISearchItem
- {
- /*********
- ** Properties
- *********/
- /// <summary>The underlying item.</summary>
- private readonly Ring Ring;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Whether the item is valid.</summary>
- public bool IsValid => this.Ring != null;
-
- /// <summary>The item ID.</summary>
- public int ID => this.Ring.parentSheetIndex;
-
- /// <summary>The item name.</summary>
- public string Name => this.Ring.Name;
-
- /// <summary>The item type.</summary>
- public ItemType Type => ItemType.Ring;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="id">The ring ID.</param>
- public SearchableRing(int id)
- {
- try
- {
- this.Ring = new Ring(id);
- }
- catch
- {
- // invalid
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/TrainerMod/ItemData/SearchableWeapon.cs b/src/TrainerMod/ItemData/SearchableWeapon.cs
deleted file mode 100644
index cc9ef459..00000000
--- a/src/TrainerMod/ItemData/SearchableWeapon.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using StardewValley.Tools;
-
-namespace TrainerMod.ItemData
-{
- /// <summary>A weapon that can be searched and added to the player's inventory through the console.</summary>
- internal class SearchableWeapon : ISearchItem
- {
- /*********
- ** Properties
- *********/
- /// <summary>The underlying item.</summary>
- private readonly MeleeWeapon Weapon;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Whether the item is valid.</summary>
- public bool IsValid => this.Weapon != null;
-
- /// <summary>The item ID.</summary>
- public int ID => this.Weapon.initialParentTileIndex;
-
- /// <summary>The item name.</summary>
- public string Name => this.Weapon.Name;
-
- /// <summary>The item type.</summary>
- public ItemType Type => ItemType.Weapon;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="id">The weapon ID.</param>
- public SearchableWeapon(int id)
- {
- try
- {
- this.Weapon = new MeleeWeapon(id);
- }
- catch
- {
- // invalid
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/TrainerMod/TrainerMod.cs b/src/TrainerMod/TrainerMod.cs
index 9a3a8d0b..5db02cd6 100644
--- a/src/TrainerMod/TrainerMod.cs
+++ b/src/TrainerMod/TrainerMod.cs
@@ -1,17 +1,9 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
-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.ItemData;
-using Object = StardewValley.Object;
+using TrainerMod.Framework.Commands;
namespace TrainerMod
{
@@ -21,20 +13,8 @@ namespace TrainerMod
/*********
** Properties
*********/
- /// <summary>The time of day at which to freeze time.</summary>
- private int FrozenTime;
-
- /// <summary>Whether to keep the player's health at its maximum.</summary>
- private bool InfiniteHealth;
-
- /// <summary>Whether to keep the player's stamina at its maximum.</summary>
- private bool InfiniteStamina;
-
- /// <summary>Whether to keep the player's money at a set value.</summary>
- private bool InfiniteMoney;
-
- /// <summary>Whether to freeze time.</summary>
- private bool FreezeTime;
+ /// <summary>The commands to handle.</summary>
+ private ITrainerCommand[] Commands;
/*********
@@ -44,829 +24,52 @@ namespace TrainerMod
/// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper)
{
- this.RegisterCommands(helper);
- GameEvents.UpdateTick += this.ReceiveUpdateTick;
+ // register commands
+ this.Commands = this.ScanForCommands().ToArray();
+ foreach (ITrainerCommand command in this.Commands)
+ helper.ConsoleCommands.Add(command.Name, command.Description, (name, args) => this.HandleCommand(command, name, args));
+
+ // hook events
+ GameEvents.UpdateTick += this.GameEvents_UpdateTick;
}
/*********
** Private methods
*********/
- /****
- ** Implementation
- ****/
/// <summary>The method invoked when the game updates its state.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
- private void ReceiveUpdateTick(object sender, EventArgs e)
+ private void GameEvents_UpdateTick(object sender, EventArgs e)
{
- if (Game1.player == null)
+ if (!Context.IsWorldReady)
return;
- if (this.InfiniteHealth)
- Game1.player.health = Game1.player.maxHealth;
- if (this.InfiniteStamina)
- Game1.player.stamina = Game1.player.MaxStamina;
- if (this.InfiniteMoney)
- Game1.player.money = 999999;
- if (this.FreezeTime)
- Game1.timeOfDay = this.FrozenTime;
- }
-
- /****
- ** Command definitions
- ****/
- /// <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_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).", 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_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_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_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- season: the target season (one of 'spring', 'summer', 'fall', 'winter').", this.HandleCommand)
- .Add("world_setyear", "Sets the year to the specified value.\n\nUsage: world_setyear <year>\n- year: the target year (a number starting from 1).", 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)
-
- .Add("debug", "Run one of the game's debug commands; for example, 'debug warp FarmHouse 1 1' warps the player to the farmhouse.", this.HandleCommand);
+ foreach (ITrainerCommand command in this.Commands)
+ {
+ if (command.NeedsUpdate)
+ command.Update(this.Monitor);
+ }
}
/// <summary>Handle a TrainerMod command.</summary>
- /// <param name="command">The command name.</param>
+ /// <param name="command">The command to invoke.</param>
+ /// <param name="commandName">The command name specified by the user.</param>
/// <param name="args">The command arguments.</param>
- private void HandleCommand(string command, string[] args)
+ private void HandleCommand(ITrainerCommand command, string commandName, string[] args)
{
- switch (command)
- {
- case "debug":
- // submit command
- string debugCommand = string.Join(" ", args);
- string oldOutput = Game1.debugOutput;
- Game1.game1.parseDebugInput(debugCommand);
-
- // show result
- this.Monitor.Log(Game1.debugOutput != oldOutput
- ? $"> {Game1.debugOutput}"
- : "Sent debug command to the game, but there was no output.", LogLevel.Info);
- break;
-
- 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)
- {
- 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.Monitor.Log($"Your name is currently '{Game1.player.Name}'. Type 'help player_setname' for usage.", LogLevel.Info);
- break;
-
- case "player_setmoney":
- if (args.Any())
- {
- 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.Monitor.Log($"You currently have {(this.InfiniteMoney ? "infinite" : Game1.player.Money.ToString())} gold. Specify a value to change it.", LogLevel.Info);
- break;
-
- case "player_setstamina":
- if (args.Any())
- {
- 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.Monitor.Log($"You currently have {(this.InfiniteStamina ? "infinite" : Game1.player.Stamina.ToString())} stamina. Specify a value to change it.", LogLevel.Info);
- break;
-
- 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;
-
- case "player_setlevel":
- if (args.Length > 1)
- {
- string skill = args[0];
- string[] skills = { "luck", "mining", "combat", "farming", "fishing", "foraging" };
- if (skills.Contains(skill))
- {
- 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.LogArgumentsInvalid(command);
- break;
-
- 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;
-
- case "player_changecolor":
- if (args.Length > 1)
- {
- string target = args[0];
- string[] validTargets = { "hair", "eyes", "pants" };
- if (validTargets.Contains(target))
- {
- 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.LogArgumentsInvalid(command);
- break;
-
- case "player_changestyle":
- if (args.Length > 1)
- {
- string target = args[0];
- string[] validTargets = { "hair", "shirt", "skin", "acc", "shoe", "swim", "gender" };
- if (validTargets.Contains(target))
- {
- 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.LogArgumentsInvalid(command);
- break;
-
- 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 = !this.FreezeTime;
- this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0;
- 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($"The current time is {Game1.timeOfDay}. Specify a value to change it.", LogLevel.Info);
- break;
-
- 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;
-
- case "world_setseason":
- if (args.Any())
- {
- 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($"The current season is {Game1.currentSeason}. Specify a value to change it.", LogLevel.Info);
- break;
-
- case "world_setyear":
- if (args.Any())
- {
- int year;
- if (int.TryParse(args[0], out year))
- {
- if (year >= 1)
- {
- Game1.year = year;
- this.Monitor.Log($"OK, the year is now {Game1.year}.", LogLevel.Info);
- }
- else
- this.LogUsageError("That isn't a valid year.", command);
- }
- else
- this.LogArgumentNotInt(command);
- }
- else
- this.Monitor.Log($"The current year is {Game1.year}. Specify a value to change the year.", LogLevel.Info);
- break;
-
- case "player_sethealth":
- if (args.Any())
- {
- string amountStr = args[0];
-
- 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($"You currently have {(this.InfiniteHealth ? "infinite" : Game1.player.health.ToString())} health. Specify a value to change it.", LogLevel.Info);
- break;
-
- 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;
-
- 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.Monitor.Log($"You currently have {Game1.player.immunity} immunity. Specify a value to change it.", LogLevel.Info);
- break;
-
- 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;
- }
- }
-
- 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;
-
- case "player_addweapon":
- if (args.Any())
- {
- int weaponID;
- if (int.TryParse(args[0], out weaponID))
- {
- // get raw weapon data
- string data;
- if (!Game1.content.Load<Dictionary<int, string>>("Data\\weapons").TryGetValue(weaponID, out data))
- {
- this.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))
- {
- this.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:
- this.Monitor.Log($"The specified weapon has unknown type '{type}' in the game data.", LogLevel.Error);
- return;
- }
-
- // validate
- if (weapon.Name == null)
- {
- this.Monitor.Log("That weapon doesn't seem to be valid.", LogLevel.Error);
- return;
- }
-
- // add weapon
- 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;
-
- case "player_addring":
- if (args.Any())
- {
- int ringID;
- if (int.TryParse(args[0], out ringID))
- {
- 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
- {
- 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;
-
- case "list_items":
- {
- var matches = this.GetItems(args).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);
- }
- break;
-
- 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;
- }
-
- 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;
-
- case "show_game_files":
- Process.Start(Constants.ExecutionPath);
- this.Monitor.Log($"OK, opening {Constants.ExecutionPath}.", LogLevel.Info);
- break;
-
- case "show_data_files":
- Process.Start(Constants.DataPath);
- this.Monitor.Log($"OK, opening {Constants.DataPath}.", LogLevel.Info);
- break;
-
- default:
- throw new NotImplementedException($"TrainerMod received unknown command '{command}'.");
- }
+ ArgumentParser argParser = new ArgumentParser(commandName, args, this.Monitor);
+ command.Handle(this.Monitor, commandName, argParser);
}
- /****
- ** Helpers
- ****/
- /// <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)
+ /// <summary>Find all commands in the assembly.</summary>
+ private IEnumerable<ITrainerCommand> ScanForCommands()
{
- // 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())
- )
+ from type in this.GetType().Assembly.GetTypes()
+ where !type.IsAbstract && typeof(ITrainerCommand).IsAssignableFrom(type)
+ select (ITrainerCommand)Activator.CreateInstance(type)
);
}
-
- /****
- ** Logging
- ****/
- /// <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($"{error} Type 'help {command}' for usage.", LogLevel.Error);
- }
-
- /// <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.LogUsageError("The value must be a whole number.", command);
- }
-
- /// <summary>Log an error indicating a value is invalid.</summary>
- /// <param name="command">The name of the command.</param>
- private void LogArgumentsInvalid(string command)
- {
- this.LogUsageError("The arguments are invalid.", command);
- }
}
}
diff --git a/src/TrainerMod/TrainerMod.csproj b/src/TrainerMod/TrainerMod.csproj
index 46d8bef9..99a15c8f 100644
--- a/src/TrainerMod/TrainerMod.csproj
+++ b/src/TrainerMod/TrainerMod.csproj
@@ -51,11 +51,38 @@
<Compile Include="..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
- <Compile Include="ItemData\ISearchItem.cs" />
- <Compile Include="ItemData\ItemType.cs" />
- <Compile Include="ItemData\SearchableObject.cs" />
- <Compile Include="ItemData\SearchableRing.cs" />
- <Compile Include="ItemData\SearchableWeapon.cs" />
+ <Compile Include="Framework\Commands\ArgumentParser.cs" />
+ <Compile Include="Framework\Commands\Other\ShowDataFilesCommand.cs" />
+ <Compile Include="Framework\Commands\Other\ShowGameFilesCommand.cs" />
+ <Compile Include="Framework\Commands\Other\DebugCommand.cs" />
+ <Compile Include="Framework\Commands\Player\ListItemTypesCommand.cs" />
+ <Compile Include="Framework\Commands\Player\ListItemsCommand.cs" />
+ <Compile Include="Framework\Commands\Player\AddCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetStyleCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetColorCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetSpeedCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetLevelCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetMaxHealthCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetMaxStaminaCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetHealthCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetImmunityCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetStaminaCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetNameCommand.cs" />
+ <Compile Include="Framework\Commands\Player\SetMoneyCommand.cs" />
+ <Compile Include="Framework\Commands\Saves\LoadCommand.cs" />
+ <Compile Include="Framework\Commands\Saves\SaveCommand.cs" />
+ <Compile Include="Framework\Commands\TrainerCommand.cs" />
+ <Compile Include="Framework\Commands\World\SetMineLevelCommand.cs" />
+ <Compile Include="Framework\Commands\World\DownMineLevelCommand.cs" />
+ <Compile Include="Framework\Commands\World\SetYearCommand.cs" />
+ <Compile Include="Framework\Commands\World\SetSeasonCommand.cs" />
+ <Compile Include="Framework\Commands\World\SetDayCommand.cs" />
+ <Compile Include="Framework\Commands\World\SetTimeCommand.cs" />
+ <Compile Include="Framework\Commands\World\FreezeTimeCommand.cs" />
+ <Compile Include="Framework\ItemData\ItemType.cs" />
+ <Compile Include="Framework\Commands\ITrainerCommand.cs" />
+ <Compile Include="Framework\ItemData\SearchableItem.cs" />
+ <Compile Include="Framework\ItemRepository.cs" />
<Compile Include="TrainerMod.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
diff --git a/src/TrainerMod/manifest.json b/src/TrainerMod/manifest.json
index 40eb3237..f1665a45 100644
--- a/src/TrainerMod/manifest.json
+++ b/src/TrainerMod/manifest.json
@@ -3,8 +3,8 @@
"Author": "SMAPI",
"Version": {
"MajorVersion": 1,
- "MinorVersion": 14,
- "PatchVersion": 1,
+ "MinorVersion": 15,
+ "PatchVersion": 0,
"Build": null
},
"Description": "Adds SMAPI console commands that let you manipulate the game.",