diff options
Diffstat (limited to 'src/TrainerMod')
-rw-r--r-- | src/TrainerMod/Framework/Extensions.cs | 3 | ||||
-rw-r--r-- | src/TrainerMod/TrainerMod.cs | 615 |
2 files changed, 316 insertions, 302 deletions
diff --git a/src/TrainerMod/Framework/Extensions.cs b/src/TrainerMod/Framework/Extensions.cs index 30019748..705d09b7 100644 --- a/src/TrainerMod/Framework/Extensions.cs +++ b/src/TrainerMod/Framework/Extensions.cs @@ -3,6 +3,9 @@ /// <summary>Provides extension methods on primitive types.</summary> public static class Extensions { + /********* + ** Public methods + *********/ /// <summary>Get whether an object is a number.</summary> /// <param name="value">The object value.</param> public static bool IsInt(this object value) diff --git a/src/TrainerMod/TrainerMod.cs b/src/TrainerMod/TrainerMod.cs index 3c40a941..1c1c3711 100644 --- a/src/TrainerMod/TrainerMod.cs +++ b/src/TrainerMod/TrainerMod.cs @@ -13,113 +13,154 @@ using Object = StardewValley.Object; namespace TrainerMod { + /// <summary>The main entry point for the mod.</summary> public class TrainerMod : Mod { - public static int frozenTime; - public static bool infHealth, infStamina, infMoney, freezeTime; + /********* + ** Properties + *********/ + /// <summary>The time of day at which to freeze time.</summary> + public static int FrozenTime; + /// <summary>Whether to keep the player's health at its maximum.</summary> + public static bool InfiniteHealth; + + /// <summary>Whether to keep the player's stamina at its maximum.</summary> + public static bool InfiniteStamina; + + /// <summary>Whether to keep the player's money at a set value.</summary> + public static bool InfiniteMoney; + + /// <summary>Whether to freeze time.</summary> + public static bool FreezeTime; + + + /********* + ** Public methods + *********/ /// <summary>The entry point for your mod. It will always be called once when the mod loads.</summary> /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param> public override void Entry(ModHelper helper) { - RegisterCommands(); - GameEvents.UpdateTick += Events_UpdateTick; + TrainerMod.RegisterCommands(); + GameEvents.UpdateTick += TrainerMod.ReceiveUpdateTick; } - private static void Events_UpdateTick(object sender, EventArgs e) + + /********* + ** 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 static void ReceiveUpdateTick(object sender, EventArgs e) { if (Game1.player == null) return; - if (infHealth) - { + if (TrainerMod.InfiniteHealth) Game1.player.health = Game1.player.maxHealth; - } - if (infStamina) - { + if (TrainerMod.InfiniteStamina) Game1.player.stamina = Game1.player.MaxStamina; - } - if (infMoney) - { + if (TrainerMod.InfiniteMoney) Game1.player.money = 999999; - } - if (freezeTime) - { - Game1.timeOfDay = frozenTime; - } + if (TrainerMod.FreezeTime) + Game1.timeOfDay = TrainerMod.FrozenTime; } + /// <summary>Register all trainer commands.</summary> public static void RegisterCommands() { - Command.RegisterCommand("types", "Lists all value types | types").CommandFired += types_CommandFired; + Command.RegisterCommand("types", "Lists all value types | types").CommandFired += TrainerMod.HandleTypes; - Command.RegisterCommand("save", "Saves the game? Doesn't seem to work. | save").CommandFired += save_CommandFired; - Command.RegisterCommand("load", "Shows the load screen | load").CommandFired += load_CommandFired; + Command.RegisterCommand("save", "Saves the game? Doesn't seem to work. | save").CommandFired += TrainerMod.HandleSave; + Command.RegisterCommand("load", "Shows the load screen | load").CommandFired += TrainerMod.HandleLoad; - Command.RegisterCommand("exit", "Closes the game | exit").CommandFired += exit_CommandFired; - Command.RegisterCommand("stop", "Closes the game | stop").CommandFired += exit_CommandFired; + Command.RegisterCommand("exit", "Closes the game | exit").CommandFired += TrainerMod.HandleExit; + Command.RegisterCommand("stop", "Closes the game | stop").CommandFired += TrainerMod.HandleExit; - Command.RegisterCommand("player_setname", "Sets the player's name | player_setname <object> <value>", new[] {"(player, pet, farm)<object> (String)<value> The target name"}).CommandFired += player_setName; - Command.RegisterCommand("player_setmoney", "Sets the player's money | player_setmoney <value>|inf", new[] {"(Int32)<value> The target money"}).CommandFired += player_setMoney; - Command.RegisterCommand("player_setstamina", "Sets the player's stamina | player_setstamina <value>|inf", new[] {"(Int32)<value> The target stamina"}).CommandFired += player_setStamina; - Command.RegisterCommand("player_setmaxstamina", "Sets the player's max stamina | player_setmaxstamina <value>", new[] {"(Int32)<value> The target max stamina"}).CommandFired += player_setMaxStamina; - Command.RegisterCommand("player_sethealth", "Sets the player's health | player_sethealth <value>|inf", new[] {"(Int32)<value> The target health"}).CommandFired += player_setHealth; - Command.RegisterCommand("player_setmaxhealth", "Sets the player's max health | player_setmaxhealth <value>", new[] {"(Int32)<value> The target max health"}).CommandFired += player_setMaxHealth; - Command.RegisterCommand("player_setimmunity", "Sets the player's immunity | player_setimmunity <value>", new[] {"(Int32)<value> The target immunity"}).CommandFired += player_setImmunity; + Command.RegisterCommand("player_setname", "Sets the player's name | player_setname <object> <value>", new[] { "(player, pet, farm)<object> (String)<value> The target name" }).CommandFired += TrainerMod.HandlePlayerSetName; + Command.RegisterCommand("player_setmoney", "Sets the player's money | player_setmoney <value>|inf", new[] { "(Int32)<value> The target money" }).CommandFired += TrainerMod.HandlePlayerSetMoney; + Command.RegisterCommand("player_setstamina", "Sets the player's stamina | player_setstamina <value>|inf", new[] { "(Int32)<value> The target stamina" }).CommandFired += TrainerMod.HandlePlayerSetStamina; + Command.RegisterCommand("player_setmaxstamina", "Sets the player's max stamina | player_setmaxstamina <value>", new[] { "(Int32)<value> The target max stamina" }).CommandFired += TrainerMod.HandlePlayerSetMaxStamina; + Command.RegisterCommand("player_sethealth", "Sets the player's health | player_sethealth <value>|inf", new[] { "(Int32)<value> The target health" }).CommandFired += TrainerMod.HandlePlayerSetHealth; + Command.RegisterCommand("player_setmaxhealth", "Sets the player's max health | player_setmaxhealth <value>", new[] { "(Int32)<value> The target max health" }).CommandFired += TrainerMod.HandlePlayerSetMaxHealth; + Command.RegisterCommand("player_setimmunity", "Sets the player's immunity | player_setimmunity <value>", new[] { "(Int32)<value> The target immunity" }).CommandFired += TrainerMod.HandlePlayerSetImmunity; - Command.RegisterCommand("player_setlevel", "Sets the player's specified skill to the specified value | player_setlevel <skill> <value>", new[] {"(luck, mining, combat, farming, fishing, foraging)<skill> (1-10)<value> The target level"}).CommandFired += player_setLevel; - Command.RegisterCommand("player_setspeed", "Sets the player's speed to the specified value?", new[] {"(Int32)<value> The target speed [0 is normal]"}).CommandFired += player_setSpeed; - Command.RegisterCommand("player_changecolour", "Sets the player's colour of the specified object | player_changecolor <object> <colour>", new[] {"(hair, eyes, pants)<object> (r,g,b)<colour>"}).CommandFired += player_changeColour; - Command.RegisterCommand("player_changestyle", "Sets the player's style of the specified object | player_changecolor <object> <value>", new[] {"(hair, shirt, skin, acc, shoe, swim, gender)<object> (Int32)<value>"}).CommandFired += player_changeStyle; + Command.RegisterCommand("player_setlevel", "Sets the player's specified skill to the specified value | player_setlevel <skill> <value>", new[] { "(luck, mining, combat, farming, fishing, foraging)<skill> (1-10)<value> The target level" }).CommandFired += TrainerMod.HandlePlayerSetLevel; + Command.RegisterCommand("player_setspeed", "Sets the player's speed to the specified value?", new[] { "(Int32)<value> The target speed [0 is normal]" }).CommandFired += TrainerMod.HandlePlayerSetSpeed; + Command.RegisterCommand("player_changecolour", "Sets the player's colour of the specified object | player_changecolor <object> <colour>", new[] { "(hair, eyes, pants)<object> (r,g,b)<colour>" }).CommandFired += TrainerMod.HandlePlayerChangeColor; + Command.RegisterCommand("player_changestyle", "Sets the player's style of the specified object | player_changecolor <object> <value>", new[] { "(hair, shirt, skin, acc, shoe, swim, gender)<object> (Int32)<value>" }).CommandFired += TrainerMod.HandlePlayerChangeStyle; - Command.RegisterCommand("player_additem", "Gives the player an item | player_additem <item> [count] [quality]", new[] {"(Int32)<id> (Int32)[count] (Int32)[quality]"}).CommandFired += player_addItem; - Command.RegisterCommand("player_addmelee", "Gives the player a melee item | player_addmelee <item>", new[] {"?<item>"}).CommandFired += player_addMelee; - Command.RegisterCommand("player_addring", "Gives the player a ring | player_addring <item>", new[] {"?<item>"}).CommandFired += player_addRing; + Command.RegisterCommand("player_additem", "Gives the player an item | player_additem <item> [count] [quality]", new[] { "(Int32)<id> (Int32)[count] (Int32)[quality]" }).CommandFired += TrainerMod.HandlePlayerAddItem; + Command.RegisterCommand("player_addmelee", "Gives the player a melee item | player_addmelee <item>", new[] { "?<item>" }).CommandFired += TrainerMod.HandlePlayerAddMelee; + Command.RegisterCommand("player_addring", "Gives the player a ring | player_addring <item>", new[] { "?<item>" }).CommandFired += TrainerMod.HandlePlayerAddRing; - Command.RegisterCommand("out_items", "Outputs a list of items | out_items", new[] {""}).CommandFired += out_items; - Command.RegisterCommand("out_melee", "Outputs a list of melee weapons | out_melee", new[] {""}).CommandFired += out_melee; - Command.RegisterCommand("out_rings", "Outputs a list of rings | out_rings", new[] {""}).CommandFired += out_rings; - Command.RegisterCommand("newitem", "not to be used | newitem", new[] {""}).CommandFired += RegisterNewItem; + Command.RegisterCommand("out_items", "Outputs a list of items | out_items", new[] { "" }).CommandFired += TrainerMod.HandleOutItems; + Command.RegisterCommand("out_melee", "Outputs a list of melee weapons | out_melee", new[] { "" }).CommandFired += TrainerMod.HandleOutMelee; + Command.RegisterCommand("out_rings", "Outputs a list of rings | out_rings", new[] { "" }).CommandFired += TrainerMod.HandleOutRings; + Command.RegisterCommand("newitem", "not to be used | newitem", new[] { "" }).CommandFired += TrainerMod.HandleNewItem; - Command.RegisterCommand("world_settime", "Sets the time to the specified value | world_settime <value>", new[] {"(Int32)<value> The target time [06:00 AM is 600]"}).CommandFired += world_setTime; - Command.RegisterCommand("world_freezetime", "Freezes or thaws time | world_freezetime <value>", new[] {"(0 - 1)<value> Whether or not to freeze time. 0 is thawed, 1 is frozen"}).CommandFired += world_freezeTime; - Command.RegisterCommand("world_setday", "Sets the day to the specified value | world_setday <value>", new[] {"(Int32)<value> The target day [1-28]"}).CommandFired += world_setDay; - Command.RegisterCommand("world_setseason", "Sets the season to the specified value | world_setseason <value>", new[] {"(winter, spring, summer, fall)<value> The target season"}).CommandFired += world_setSeason; - Command.RegisterCommand("world_downminelevel", "Goes down one mine level? | world_downminelevel", new[] {""}).CommandFired += world_downMineLevel; - Command.RegisterCommand("world_setminelevel", "Sets mine level? | world_setminelevel", new[] {"(Int32)<value> The target level"}).CommandFired += world_setMineLevel; + Command.RegisterCommand("world_settime", "Sets the time to the specified value | world_settime <value>", new[] { "(Int32)<value> The target time [06:00 AM is 600]" }).CommandFired += TrainerMod.HandleWorldSetTime; + Command.RegisterCommand("world_freezetime", "Freezes or thaws time | world_freezetime <value>", new[] { "(0 - 1)<value> Whether or not to freeze time. 0 is thawed, 1 is frozen" }).CommandFired += TrainerMod.HandleWorldFreezeTime; + Command.RegisterCommand("world_setday", "Sets the day to the specified value | world_setday <value>", new[] { "(Int32)<value> The target day [1-28]" }).CommandFired += TrainerMod.world_setDay; + Command.RegisterCommand("world_setseason", "Sets the season to the specified value | world_setseason <value>", new[] { "(winter, spring, summer, fall)<value> The target season" }).CommandFired += TrainerMod.HandleWorldSetSeason; + Command.RegisterCommand("world_downminelevel", "Goes down one mine level? | world_downminelevel", new[] { "" }).CommandFired += TrainerMod.HandleWorldDownMineLevel; + Command.RegisterCommand("world_setminelevel", "Sets mine level? | world_setminelevel", new[] { "(Int32)<value> The target level" }).CommandFired += TrainerMod.HandleWorldSetMineLevel; } - private static void types_CommandFired(object sender, EventArgsCommand e) + /**** + ** Command handlers + ****/ + /// <summary>The event raised when the 'types' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleTypes(object sender, EventArgsCommand e) { Log.AsyncY($"[Int32: {int.MinValue} - {int.MaxValue}], [Int64: {long.MinValue} - {long.MaxValue}], [String: \"raw text\"], [Colour: r,g,b (EG: 128, 32, 255)]"); } - private static void save_CommandFired(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'save' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleSave(object sender, EventArgsCommand e) { SaveGame.Save(); } - private static void load_CommandFired(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'load' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleLoad(object sender, EventArgsCommand e) { Game1.hasLoadedGame = false; Game1.activeClickableMenu = new LoadGameMenu(); } - private static void exit_CommandFired(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'exit' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleExit(object sender, EventArgsCommand e) { Program.gamePtr.Exit(); Environment.Exit(0); } - private static void player_setName(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setName' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetName(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 1) { - var obj = e.Command.CalledArgs[0]; - var objs = "player,pet,farm".Split(','); - if (objs.Contains(obj)) + string target = e.Command.CalledArgs[0]; + string[] validTargets = { "player", "pet", "farm" }; + if (validTargets.Contains(target)) { - switch (obj) + switch (target) { case "player": Game1.player.Name = e.Command.CalledArgs[1]; @@ -133,245 +174,233 @@ namespace TrainerMod } } else - { TrainerMod.LogObjectInvalid(); - } } else - { TrainerMod.LogObjectValueNotSpecified(); - } } - private static void player_setMoney(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setMoney' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetMoney(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0] == "inf") - { - infMoney = true; - } + string amountStr = e.Command.CalledArgs[0]; + if (amountStr == "inf") + TrainerMod.InfiniteMoney = true; else { - infMoney = false; - var ou = 0; - if (int.TryParse(e.Command.CalledArgs[0], out ou)) + TrainerMod.InfiniteMoney = false; + int amount; + if (int.TryParse(amountStr, out amount)) { - Game1.player.Money = ou; + Game1.player.Money = amount; Log.Async($"Set {Game1.player.Name}'s money to {Game1.player.Money}"); } else - { TrainerMod.LogValueNotInt32(); - } } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void player_setStamina(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setStamina' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetStamina(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0] == "inf") - { - infStamina = true; - } + string amountStr = e.Command.CalledArgs[0]; + if (amountStr == "inf") + TrainerMod.InfiniteStamina = true; else { - infStamina = false; - var ou = 0; - if (int.TryParse(e.Command.CalledArgs[0], out ou)) + TrainerMod.InfiniteStamina = false; + int amount; + if (int.TryParse(amountStr, out amount)) { - Game1.player.Stamina = ou; + Game1.player.Stamina = amount; Log.Async($"Set {Game1.player.Name}'s stamina to {Game1.player.Stamina}"); } else - { TrainerMod.LogValueNotInt32(); - } } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void player_setMaxStamina(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setMaxStamina' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetMaxStamina(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - var ou = 0; - if (int.TryParse(e.Command.CalledArgs[0], out ou)) + int amount; + if (int.TryParse(e.Command.CalledArgs[0], out amount)) { - Game1.player.MaxStamina = ou; + Game1.player.MaxStamina = amount; Log.Async($"Set {Game1.player.Name}'s max stamina to {Game1.player.MaxStamina}"); } else - { TrainerMod.LogValueNotInt32(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void player_setLevel(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setLevel' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetLevel(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 1) { - var skill = e.Command.CalledArgs[0]; - var skills = "luck,mining,combat,farming,fishing,foraging".Split(','); + string skill = e.Command.CalledArgs[0]; + string[] skills = { "luck", "mining", "combat", "farming", "fishing", "foraging" }; if (skills.Contains(skill)) { - var ou = 0; - if (int.TryParse(e.Command.CalledArgs[1], out ou)) + int level; + if (int.TryParse(e.Command.CalledArgs[1], out level)) { switch (skill) { case "luck": - Game1.player.LuckLevel = ou; + Game1.player.LuckLevel = level; break; case "mining": - Game1.player.MiningLevel = ou; + Game1.player.MiningLevel = level; break; case "combat": - Game1.player.CombatLevel = ou; + Game1.player.CombatLevel = level; break; case "farming": - Game1.player.FarmingLevel = ou; + Game1.player.FarmingLevel = level; break; case "fishing": - Game1.player.FishingLevel = ou; + Game1.player.FishingLevel = level; break; case "foraging": - Game1.player.ForagingLevel = ou; + Game1.player.ForagingLevel = level; break; } } else - { TrainerMod.LogValueNotInt32(); - } } else - { Log.AsyncR("<skill> is invalid"); - } } else - { Log.AsyncR("<skill> and <value> must be specified"); - } } - private static void player_setSpeed(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setSpeed' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetSpeed(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0].IsInt()) + string amountStr = e.Command.CalledArgs[0]; + if (amountStr.IsInt()) { - Game1.player.addedSpeed = e.Command.CalledArgs[0].ToInt(); + Game1.player.addedSpeed = amountStr.ToInt(); Log.Async($"Set {Game1.player.Name}'s added speed to {Game1.player.addedSpeed}"); } else - { TrainerMod.LogValueNotInt32(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void player_changeColour(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_changeColour' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerChangeColor(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 1) { - var obj = e.Command.CalledArgs[0]; - var objs = "hair,eyes,pants".Split(','); - if (objs.Contains(obj)) + string target = e.Command.CalledArgs[0]; + string[] validTargets = { "hair", "eyes", "pants" }; + if (validTargets.Contains(target)) { - var cs = e.Command.CalledArgs[1].Split(new[] {','}, 3); - if (cs[0].IsInt() && cs[1].IsInt() && cs[2].IsInt()) + string[] colorHexes = e.Command.CalledArgs[1].Split(new[] { ',' }, 3); + if (colorHexes[0].IsInt() && colorHexes[1].IsInt() && colorHexes[2].IsInt()) { - var c = new Color(cs[0].ToInt(), cs[1].ToInt(), cs[2].ToInt()); - switch (obj) + var color = new Color(colorHexes[0].ToInt(), colorHexes[1].ToInt(), colorHexes[2].ToInt()); + switch (target) { case "hair": - Game1.player.hairstyleColor = c; + Game1.player.hairstyleColor = color; break; case "eyes": - Game1.player.changeEyeColor(c); + Game1.player.changeEyeColor(color); break; case "pants": - Game1.player.pantsColor = c; + Game1.player.pantsColor = color; break; } } else - { Log.AsyncR("<colour> is invalid"); - } } else - { TrainerMod.LogObjectInvalid(); - } } else - { Log.AsyncR("<object> and <colour> must be specified"); - } } - private static void player_changeStyle(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_changeStyle' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerChangeStyle(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 1) { - var obj = e.Command.CalledArgs[0]; - var objs = "hair,shirt,skin,acc,shoe,swim,gender".Split(','); - if (objs.Contains(obj)) + string target = e.Command.CalledArgs[0]; + string[] validTargets = { "hair", "shirt", "skin", "acc", "shoe", "swim", "gender" }; + if (validTargets.Contains(target)) { if (e.Command.CalledArgs[1].IsInt()) { - var i = e.Command.CalledArgs[1].ToInt(); - switch (obj) + var styleID = e.Command.CalledArgs[1].ToInt(); + switch (target) { case "hair": - Game1.player.changeHairStyle(i); + Game1.player.changeHairStyle(styleID); break; case "shirt": - Game1.player.changeShirt(i); + Game1.player.changeShirt(styleID); break; case "acc": - Game1.player.changeAccessory(i); + Game1.player.changeAccessory(styleID); break; case "skin": - Game1.player.changeSkinColor(i); + Game1.player.changeSkinColor(styleID); break; case "shoe": - Game1.player.changeShoeColor(i); + Game1.player.changeShoeColor(styleID); break; case "swim": - if (i == 0) + if (styleID == 0) Game1.player.changeOutOfSwimSuit(); - else if (i == 1) + else if (styleID == 1) Game1.player.changeIntoSwimsuit(); else Log.AsyncR("<value> must be 0 or 1 for this <object>"); break; case "gender": - if (i == 0) + if (styleID == 0) Game1.player.changeGender(true); - else if (i == 1) + else if (styleID == 1) Game1.player.changeGender(false); else Log.AsyncR("<value> must be 0 or 1 for this <object>"); @@ -379,204 +408,187 @@ namespace TrainerMod } } else - { TrainerMod.LogValueInvalid(); - } } else - { TrainerMod.LogObjectInvalid(); - } } else - { TrainerMod.LogObjectValueNotSpecified(); - } } - private static void world_freezeTime(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'world_freezeTime' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleWorldFreezeTime(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0].IsInt()) + string valueStr = e.Command.CalledArgs[0]; + if (valueStr.IsInt()) { - if (e.Command.CalledArgs[0].ToInt() == 0 || e.Command.CalledArgs[0].ToInt() == 1) + int value = valueStr.ToInt(); + if (value == 0 || value == 1) { - freezeTime = e.Command.CalledArgs[0].ToInt() == 1; - frozenTime = freezeTime ? Game1.timeOfDay : 0; - Log.AsyncY("Time is now " + (freezeTime ? "frozen" : "thawed")); + TrainerMod.FreezeTime = value == 1; + TrainerMod.FrozenTime = TrainerMod.FreezeTime ? Game1.timeOfDay : 0; + Log.AsyncY("Time is now " + (TrainerMod.FreezeTime ? "frozen" : "thawed")); } else - { Log.AsyncR("<value> should be 0 or 1"); - } } else - { TrainerMod.LogValueNotInt32(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void world_setTime(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'world_setTime' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleWorldSetTime(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0].IsInt()) + string timeStr = e.Command.CalledArgs[0]; + if (timeStr.IsInt()) { - if (e.Command.CalledArgs[0].ToInt() <= 2600 && e.Command.CalledArgs[0].ToInt() >= 600) + int time = timeStr.ToInt(); + + if (time <= 2600 && time >= 600) { Game1.timeOfDay = e.Command.CalledArgs[0].ToInt(); - frozenTime = freezeTime ? Game1.timeOfDay : 0; - Log.AsyncY("Time set to: " + Game1.timeOfDay); + TrainerMod.FrozenTime = TrainerMod.FreezeTime ? Game1.timeOfDay : 0; + Log.AsyncY($"Time set to: {Game1.timeOfDay}"); } else - { Log.AsyncR("<value> should be between 600 and 2600 (06:00 AM - 02:00 AM [NEXT DAY])"); - } } else - { TrainerMod.LogValueNotInt32(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } + /// <summary>The event raised when the 'world_setDay' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> private static void world_setDay(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0].IsInt()) + string dayStr = e.Command.CalledArgs[0]; + + if (dayStr.IsInt()) { - if (e.Command.CalledArgs[0].ToInt() <= 28 && e.Command.CalledArgs[0].ToInt() > 0) - { - Game1.dayOfMonth = e.Command.CalledArgs[0].ToInt(); - } + int day = dayStr.ToInt(); + if (day <= 28 && day > 0) + Game1.dayOfMonth = day; else - { Log.AsyncY("<value> must be between 1 and 28"); - } } else - { TrainerMod.LogValueNotInt32(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void world_setSeason(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'world_setSeason' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleWorldSetSeason(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - var obj = e.Command.CalledArgs[0]; - var objs = "winter,spring,summer,fall".Split(','); - if (objs.Contains(obj)) - { - Game1.currentSeason = obj; - } + string season = e.Command.CalledArgs[0]; + string[] validSeasons = { "winter", "spring", "summer", "fall" }; + if (validSeasons.Contains(season)) + Game1.currentSeason = season; else - { TrainerMod.LogValueInvalid(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void player_setHealth(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setHealth' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetHealth(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0] == "inf") - { - infHealth = true; - } + string amountStr = e.Command.CalledArgs[0]; + + if (amountStr == "inf") + TrainerMod.InfiniteHealth = true; else { - infHealth = false; - if (e.Command.CalledArgs[0].IsInt()) - { - Game1.player.health = e.Command.CalledArgs[0].ToInt(); - } + TrainerMod.InfiniteHealth = false; + if (amountStr.IsInt()) + Game1.player.health = amountStr.ToInt(); else - { TrainerMod.LogValueNotInt32(); - } } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void player_setMaxHealth(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setMaxHealth' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetMaxHealth(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0].IsInt()) - { - Game1.player.maxHealth = e.Command.CalledArgs[0].ToInt(); - } + string amountStr = e.Command.CalledArgs[0]; + if (amountStr.IsInt()) + Game1.player.maxHealth = amountStr.ToInt(); else - { TrainerMod.LogValueNotInt32(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void player_setImmunity(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_setImmunity' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerSetImmunity(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0].IsInt()) - { - Game1.player.immunity = e.Command.CalledArgs[0].ToInt(); - } + string amountStr = e.Command.CalledArgs[0]; + if (amountStr.IsInt()) + Game1.player.immunity = amountStr.ToInt(); else - { TrainerMod.LogValueNotInt32(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void player_addItem(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_addItem' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerAddItem(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { - if (e.Command.CalledArgs[0].IsInt()) + string itemIdStr = e.Command.CalledArgs[0]; + if (itemIdStr.IsInt()) { - var count = 1; - var quality = 0; + int itemID = itemIdStr.ToInt(); + int count = 1; + int quality = 0; if (e.Command.CalledArgs.Length > 1) { - Console.WriteLine(e.Command.CalledArgs[1]); if (e.Command.CalledArgs[1].IsInt()) - { count = e.Command.CalledArgs[1].ToInt(); - } else { Log.AsyncR("[count] is invalid"); @@ -586,9 +598,7 @@ namespace TrainerMod if (e.Command.CalledArgs.Length > 2) { if (e.Command.CalledArgs[2].IsInt()) - { quality = e.Command.CalledArgs[2].ToInt(); - } else { Log.AsyncR("[quality] is invalid"); @@ -597,158 +607,159 @@ namespace TrainerMod } } - var o = new Object(e.Command.CalledArgs[0].ToInt(), count) {quality = quality}; + var item = new Object(itemID, count) { quality = quality }; - Game1.player.addItemByMenuIfNecessary(o); + Game1.player.addItemByMenuIfNecessary(item); } else - { Log.AsyncR("<item> is invalid"); - } } else - { TrainerMod.LogObjectValueNotSpecified(); - } } - private static void player_addMelee(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_addMelee' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerAddMelee(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { if (e.Command.CalledArgs[0].IsInt()) { - var toAdd = new MeleeWeapon(e.Command.CalledArgs[0].ToInt()); - Game1.player.addItemByMenuIfNecessary(toAdd); - Log.Async($"Given {toAdd.Name} to {Game1.player.Name}"); + MeleeWeapon weapon = new MeleeWeapon(e.Command.CalledArgs[0].ToInt()); + Game1.player.addItemByMenuIfNecessary(weapon); + Log.Async($"Given {weapon.Name} to {Game1.player.Name}"); } else - { Log.AsyncR("<item> is invalid"); - } } else - { TrainerMod.LogObjectValueNotSpecified(); - } } - private static void player_addRing(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'player_addRing' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandlePlayerAddRing(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { if (e.Command.CalledArgs[0].IsInt()) { - var toAdd = new Ring(e.Command.CalledArgs[0].ToInt()); - Game1.player.addItemByMenuIfNecessary(toAdd); - Log.Async($"Given {toAdd.Name} to {Game1.player.Name}"); + Ring ring = new Ring(e.Command.CalledArgs[0].ToInt()); + Game1.player.addItemByMenuIfNecessary(ring); + Log.Async($"Given {ring.Name} to {Game1.player.Name}"); } else - { Log.AsyncR("<item> is invalid"); - } } else - { TrainerMod.LogObjectValueNotSpecified(); - } } - private static void out_items(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'out_items' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleOutItems(object sender, EventArgsCommand e) { - for (var i = 0; i < 1000; i++) + for (var itemID = 0; itemID < 1000; itemID++) { try { - Item it = new Object(i, 1); - if (it.Name != "Error Item") - Console.WriteLine(i + "| " + it.Name); - } - catch - { + Item itemName = new Object(itemID, 1); + if (itemName.Name != "Error Item") + Console.WriteLine($"{itemID} | {itemName.Name}"); } + catch { } } } - private static void out_melee(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'out_melee' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleOutMelee(object sender, EventArgsCommand e) { - var d = Game1.content.Load<Dictionary<int, string>>("Data\\weapons"); + var data = Game1.content.Load<Dictionary<int, string>>("Data\\weapons"); Console.Write("DATA\\WEAPONS: "); - foreach (var v in d) - { - Console.WriteLine(v.Key + " | " + v.Value); - } + foreach (var pair in data) + Console.WriteLine($"{pair.Key} | {pair.Value}"); } - private static void out_rings(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'out_rings' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleOutRings(object sender, EventArgsCommand e) { - for (var i = 0; i < 100; i++) + for (var ringID = 0; ringID < 100; ringID++) { try { - Item it = new Ring(i); - if (it.Name != "Error Item") - Console.WriteLine(i + "| " + it.Name); - } - catch - { + Item item = new Ring(ringID); + if (item.Name != "Error Item") + Console.WriteLine($"{ringID} | {item.Name}"); } + catch { } } } - private static void world_downMineLevel(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'world_downMineLevel' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleWorldDownMineLevel(object sender, EventArgsCommand e) { Game1.nextMineLevel(); } - private static void world_setMineLevel(object sender, EventArgsCommand e) + /// <summary>The event raised when the 'world_setMineLevel' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleWorldSetMineLevel(object sender, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) { if (e.Command.CalledArgs[0].IsInt()) - { Game1.enterMine(true, e.Command.CalledArgs[0].ToInt(), ""); - } else - { TrainerMod.LogValueNotInt32(); - } } else - { TrainerMod.LogValueNotSpecified(); - } } - private static void blank_command(object sender, EventArgsCommand e) - { - } - - private static void RegisterNewItem(object sender, EventArgsCommand e) - { - } + /// <summary>The event raised when the 'newIteem' command is triggered.</summary> + /// <param name="sender">The event sender.</param> + /// <param name="e">The event arguments.</param> + private static void HandleNewItem(object sender, EventArgsCommand e) { } - /// <summary>Log an error indicating the </summary> + /**** + ** Logging + ****/ + /// <summary>Log an error indicating a value must be specified.</summary> public static void LogValueNotSpecified() { Log.AsyncR("<value> must be specified"); } + /// <summary>Log an error indicating a target and value must be specified.</summary> public static void LogObjectValueNotSpecified() { Log.AsyncR("<object> and <value> must be specified"); } + /// <summary>Log an error indicating a value is invalid.</summary> public static void LogValueInvalid() { Log.AsyncR("<value> is invalid"); } + /// <summary>Log an error indicating a target is invalid.</summary> public static void LogObjectInvalid() { Log.AsyncR("<object> is invalid"); } + /// <summary>Log an error indicating a value must be an integer.</summary> public static void LogValueNotInt32() { Log.AsyncR("<value> must be a whole number (Int32)"); |