diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-23 22:46:14 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-23 22:46:14 -0400 |
commit | 07197fac9dbea84565f6004029b15667c9c2b038 (patch) | |
tree | e5fc430d30e355c3e88a8aa20ade4aab1722a5eb | |
parent | c1926f263c21147047b23d91c11dac6478fa1211 (diff) | |
download | SMAPI-07197fac9dbea84565f6004029b15667c9c2b038.tar.gz SMAPI-07197fac9dbea84565f6004029b15667c9c2b038.tar.bz2 SMAPI-07197fac9dbea84565f6004029b15667c9c2b038.zip |
add support for non-melee weapons to TrainerMod (#259)
-rw-r--r-- | release-notes.md | 4 | ||||
-rw-r--r-- | src/TrainerMod/TrainerMod.cs | 56 |
2 files changed, 52 insertions, 8 deletions
diff --git a/release-notes.md b/release-notes.md index 1b44b57a..9227d4b3 100644 --- a/release-notes.md +++ b/release-notes.md @@ -16,9 +16,11 @@ See [log](https://github.com/Pathoschild/SMAPI/compare/1.9...1.10). For players: * Added support for Stardew Valley 1.2 beta. * Added logic to rewrite many mods for compatibility with game updates, though some mods may still need an update. -* Added `world_setyear` console command to TrainerMod. * Fixed some players getting `SEHException` errors. * Fixed rare issue where the installer would crash trying to delete a bundled mod from `%appdata%`. +* Improved TrainerMod commands: + * Added `world_setyear` to change the current year. + * Replaced `player_addmelee` with `player_addweapon` with support for non-melee weapons. For mod developers: * Mods are now initialised after the `Initialize`/`LoadContent` phase, which means the `GameEvents.Initialize` and `GameEvents.LoadContent` events are deprecated. You can move any logic in those methods to your mod's `Entry` method. diff --git a/src/TrainerMod/TrainerMod.cs b/src/TrainerMod/TrainerMod.cs index 465567f7..168b7e8e 100644 --- a/src/TrainerMod/TrainerMod.cs +++ b/src/TrainerMod/TrainerMod.cs @@ -97,7 +97,7 @@ namespace TrainerMod .Add("player_changestyle", "Sets the style of a player feature.\n\nUsage: player_changecolor <target> <value>.\n- target: what to change (one of 'hair', 'shirt', 'skin', 'acc', 'shoe', 'swim', or 'gender').\n- value: the integer style ID.", this.HandleCommand) .Add("player_additem", $"Gives the player an item.\n\nUsage: player_additem <item> [count] [quality]\n- item: the item ID (use the 'list_items' command to see a list).\n- count (optional): how many of the item to give.\n- quality (optional): one of {Object.lowQuality} (normal), {Object.medQuality} (silver), {Object.highQuality} (gold), or {Object.bestQuality} (iridium).", this.HandleCommand) - .Add("player_addmelee", "Gives the player a melee weapon.\n\nUsage: player_addmelee <item>\n- item: the melee weapon ID (use the 'list_items' command to see a list).", this.HandleCommand) + .Add("player_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) @@ -609,20 +609,62 @@ namespace TrainerMod this.LogArgumentsInvalid(command); break; - case "player_addmelee": + case "player_addweapon": if (args.Any()) { int weaponID; if (int.TryParse(args[0], out weaponID)) { - MeleeWeapon weapon = new MeleeWeapon(weaponID); - if (weapon.Name == null) + // 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); - else + return; + } + + // get raw weapon type + int type; { - Game1.player.addItemByMenuIfNecessary(weapon); - this.Monitor.Log($"OK, added {weapon.Name} to your inventory.", LogLevel.Info); + 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); |