diff options
Diffstat (limited to 'src/TrainerMod/Framework/Commands/World')
7 files changed, 325 insertions, 0 deletions
diff --git a/src/TrainerMod/Framework/Commands/World/DownMineLevelCommand.cs b/src/TrainerMod/Framework/Commands/World/DownMineLevelCommand.cs new file mode 100644 index 00000000..2700a0dc --- /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, string[] 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..89cd68cb --- /dev/null +++ b/src/TrainerMod/Framework/Commands/World/FreezeTimeCommand.cs @@ -0,0 +1,72 @@ +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, string[] args) + { + if (args.Any()) + { + if (int.TryParse(args[0], out int value)) + { + if (value == 0 || value == 1) + { + this.FreezeTime = value == 1; + FreezeTimeCommand.FrozenTime = Game1.timeOfDay; + monitor.Log($"OK, time is now {(this.FreezeTime ? "frozen" : "resumed")}.", LogLevel.Info); + } + else + this.LogUsageError(monitor, "The value should be 0 (not frozen), 1 (frozen), or empty (toggle).", command); + } + else + this.LogArgumentNotInt(monitor, command); + } + 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..e47b76a7 --- /dev/null +++ b/src/TrainerMod/Framework/Commands/World/SetDayCommand.cs @@ -0,0 +1,45 @@ +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, string[] args) + { + // validate + if (!args.Any()) + { + monitor.Log($"The current date is {Game1.currentSeason} {Game1.dayOfMonth}. Specify a value to change the day.", LogLevel.Info); + return; + } + if (!int.TryParse(args[0], out int day)) + { + this.LogArgumentNotInt(monitor, command); + return; + } + if (day > 28 || day <= 0) + { + this.LogUsageError(monitor, "That isn't a valid day.", command); + 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..bfcc566f --- /dev/null +++ b/src/TrainerMod/Framework/Commands/World/SetMineLevelCommand.cs @@ -0,0 +1,42 @@ +using System; +using System.Linq; +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, string[] args) + { + // validate + if (!args.Any()) + { + this.LogArgumentsInvalid(monitor, command); + return; + } + if (!int.TryParse(args[0], out int level)) + { + this.LogArgumentNotInt(monitor, command); + 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..d60f8601 --- /dev/null +++ b/src/TrainerMod/Framework/Commands/World/SetSeasonCommand.cs @@ -0,0 +1,47 @@ +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, string[] args) + { + // validate + if (!args.Any()) + { + monitor.Log($"The current season is {Game1.currentSeason}. Specify a value to change it.", LogLevel.Info); + return; + } + if (!this.ValidSeasons.Contains(args[0])) + { + this.LogUsageError(monitor, "That isn't a valid season name.", command); + return; + } + + // handle + Game1.currentSeason = args[0]; + 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..4ecff485 --- /dev/null +++ b/src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs @@ -0,0 +1,46 @@ +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, string[] args) + { + // validate + if (!args.Any()) + { + monitor.Log($"The current time is {Game1.timeOfDay}. Specify a value to change it.", LogLevel.Info); + return; + } + if (!int.TryParse(args[0], out int time)) + { + this.LogArgumentNotInt(monitor, command); + return; + } + if (time > 2600 || time < 600) + { + this.LogUsageError(monitor, "That isn't a valid time.", command); + 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..6b2b0d93 --- /dev/null +++ b/src/TrainerMod/Framework/Commands/World/SetYearCommand.cs @@ -0,0 +1,45 @@ +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, string[] args) + { + // validate + if (!args.Any()) + { + monitor.Log($"The current year is {Game1.year}. Specify a value to change the year.", LogLevel.Info); + return; + } + if (!int.TryParse(args[0], out int year)) + { + this.LogArgumentNotInt(monitor, command); + return; + } + if (year < 1) + { + this.LogUsageError(monitor, "That isn't a valid year.", command); + return; + } + + // handle + Game1.year = year; + monitor.Log($"OK, the year is now {Game1.year}.", LogLevel.Info); + } + } +} |