From 9c1617c9ee51a0f6b93242fe8fc789336957460c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 11 Apr 2018 21:15:16 -0400 Subject: drop support for Stardew Valley 1.2 (#453) --- .../Framework/Commands/Player/AddCommand.cs | 4 -- .../Framework/Commands/Player/SetColorCommand.cs | 8 ---- .../Framework/Commands/Player/SetNameCommand.cs | 4 -- .../Commands/World/DownMineLevelCommand.cs | 4 -- .../Commands/World/SetMineLevelCommand.cs | 4 -- .../Framework/ItemRepository.cs | 56 +--------------------- 6 files changed, 1 insertion(+), 79 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index a6f42b98..ff11da1e 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -54,11 +54,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player // apply quality if (match.Item is Object obj) -#if STARDEW_VALLEY_1_3 obj.Quality = quality; -#else - obj.quality = quality; -#endif else if (match.Item is Tool tool) tool.UpgradeLevel = quality; diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetColorCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetColorCommand.cs index aa4fd105..f0815ef6 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetColorCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetColorCommand.cs @@ -36,11 +36,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player switch (target) { case "hair": -#if STARDEW_VALLEY_1_3 Game1.player.hairstyleColor.Value = color; -#else - Game1.player.hairstyleColor = color; -#endif monitor.Log("OK, your hair color is updated.", LogLevel.Info); break; @@ -50,11 +46,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player break; case "pants": -#if STARDEW_VALLEY_1_3 Game1.player.pantsColor.Value = color; -#else - Game1.player.pantsColor = color; -#endif monitor.Log("OK, your pants color is updated.", LogLevel.Info); break; } diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetNameCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetNameCommand.cs index 71e17f71..e8cb0584 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetNameCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetNameCommand.cs @@ -39,11 +39,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player case "farm": if (!string.IsNullOrWhiteSpace(name)) { -#if STARDEW_VALLEY_1_3 Game1.player.farmName.Value = args[1]; -#else - Game1.player.farmName = args[1]; -#endif monitor.Log($"OK, your farm's name is now {Game1.player.farmName}.", LogLevel.Info); } else diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/DownMineLevelCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/DownMineLevelCommand.cs index c83c3b07..2cec0fd3 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/DownMineLevelCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/DownMineLevelCommand.cs @@ -21,11 +21,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World { int level = (Game1.currentLocation as MineShaft)?.mineLevel ?? 0; monitor.Log($"OK, warping you to mine level {level + 1}.", LogLevel.Info); -#if STARDEW_VALLEY_1_3 Game1.enterMine(level + 1); -#else - Game1.enterMine(false, level + 1, ""); -#endif } } } diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetMineLevelCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetMineLevelCommand.cs index 5947af1a..b4f6d5b3 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetMineLevelCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetMineLevelCommand.cs @@ -26,11 +26,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World // handle level = Math.Max(1, level); monitor.Log($"OK, warping you to mine level {level}.", LogLevel.Info); -#if STARDEW_VALLEY_1_3 Game1.enterMine(level); -#else - Game1.enterMine(true, level, ""); -#endif } } } diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index 9c0981c4..833fddde 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -96,28 +96,16 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework if (item.category == SObject.FruitsCategory) { // wine -#if STARDEW_VALLEY_1_3 - SObject wine = - new SObject(348, 1) + SObject wine = new SObject(348, 1) { Name = $"{item.Name} Wine", Price = item.price * 3 }; wine.preserve.Value = SObject.PreserveType.Wine; wine.preservedParentSheetIndex.Value = item.parentSheetIndex; -#else - SObject wine = new SObject(348, 1) - { - name = $"{item.Name} Wine", - price = item.price * 3, - preserve = SObject.PreserveType.Wine, - preservedParentSheetIndex = item.parentSheetIndex - }; -#endif yield return new SearchableItem(ItemType.Object, this.CustomIDOffset + id, wine); // jelly -#if STARDEW_VALLEY_1_3 SObject jelly = new SObject(344, 1) { Name = $"{item.Name} Jelly", @@ -125,15 +113,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }; jelly.preserve.Value = SObject.PreserveType.Jelly; jelly.preservedParentSheetIndex.Value = item.parentSheetIndex; -#else - SObject jelly = new SObject(344, 1) - { - name = $"{item.Name} Jelly", - price = 50 + item.Price * 2, - preserve = SObject.PreserveType.Jelly, - preservedParentSheetIndex = item.parentSheetIndex - }; -#endif yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 2 + id, jelly); } @@ -141,7 +120,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework else if (item.category == SObject.VegetableCategory) { // juice -#if STARDEW_VALLEY_1_3 SObject juice = new SObject(350, 1) { Name = $"{item.Name} Juice", @@ -149,19 +127,9 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }; juice.preserve.Value = SObject.PreserveType.Juice; juice.preservedParentSheetIndex.Value = item.parentSheetIndex; -#else - SObject juice = new SObject(350, 1) - { - name = $"{item.Name} Juice", - price = (int)(item.price * 2.25d), - preserve = SObject.PreserveType.Juice, - preservedParentSheetIndex = item.parentSheetIndex - }; -#endif yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 3 + id, juice); // pickled -#if STARDEW_VALLEY_1_3 SObject pickled = new SObject(342, 1) { Name = $"Pickled {item.Name}", @@ -169,15 +137,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }; pickled.preserve.Value = SObject.PreserveType.Pickle; pickled.preservedParentSheetIndex.Value = item.parentSheetIndex; -#else - SObject pickled = new SObject(342, 1) - { - name = $"Pickled {item.Name}", - price = 50 + item.Price * 2, - preserve = SObject.PreserveType.Pickle, - preservedParentSheetIndex = item.parentSheetIndex - }; -#endif yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 4 + id, pickled); } @@ -211,7 +170,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // yield honey if (type != null) { -#if STARDEW_VALLEY_1_3 SObject honey = new SObject(Vector2.Zero, 340, item.Name + " Honey", false, true, false, false) { Name = "Wild Honey" @@ -223,18 +181,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework honey.Name = $"{item.Name} Honey"; honey.Price += item.Price * 2; } -#else - 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; - } -#endif yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 5 + id, honey); } } -- cgit From 6616c87c1806159ce6e751d4ccd54b5500d8b903 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 14 Apr 2018 00:24:24 -0400 Subject: fix world_settime command sometimes breaking NPC schedules --- docs/release-notes.md | 1 + .../Framework/Commands/World/SetTimeCommand.cs | 34 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index f3e9af6f..e524ea65 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -6,6 +6,7 @@ * Added `Context.IsMultiplayer` and `Context.IsMainPlayer` flags. * Fixed SMAPI update checks not showing newer beta versions when using a beta version. * Fixed console color scheme on Mac or PowerShell, and added override option to `StardewModdingAPI.config.json`. + * Fixed `world_settime` console command sometimes breaking NPC schedules (e.g. so they stay in bed). * For modders: * Added code analysis to mod build config package to flag common issues as warnings. diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs index d6c71387..7644ee46 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using StardewValley; namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World @@ -31,9 +32,38 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World return; // handle - Game1.timeOfDay = time; + this.SafelySetTime(time); FreezeTimeCommand.FrozenTime = Game1.timeOfDay; monitor.Log($"OK, the time is now {Game1.timeOfDay.ToString().PadLeft(4, '0')}.", LogLevel.Info); } + + + /********* + ** Private methods + *********/ + /// Safely transition to the given time, allowing NPCs to update their schedule. + /// The time of day. + private void SafelySetTime(int time) + { + // define conversion between game time and TimeSpan + TimeSpan ToTimeSpan(int value) => new TimeSpan(0, value / 100, value % 100, 0); + int FromTimeSpan(TimeSpan span) => (int)((span.Hours * 100) + span.Minutes); + + // transition to new time + int intervals = (int)((ToTimeSpan(time) - ToTimeSpan(Game1.timeOfDay)).TotalMinutes / 10); + if (intervals > 0) + { + for (int i = 0; i < intervals; i++) + Game1.performTenMinuteClockUpdate(); + } + else if (intervals < 0) + { + for (int i = 0; i > intervals; i--) + { + Game1.timeOfDay = FromTimeSpan(ToTimeSpan(Game1.timeOfDay).Subtract(TimeSpan.FromMinutes(20))); // offset 20 mins so game updates to next interval + Game1.performTenMinuteClockUpdate(); + } + } + } } } -- cgit From 7f4941167e58f27f43b073db2e37d14b7fee2543 Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Sun, 15 Apr 2018 22:13:26 -0500 Subject: initial player_add changes --- .../Framework/Commands/Player/AddCommand.cs | 96 ++++++++++++++++++---- 1 file changed, 81 insertions(+), 15 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index ff11da1e..09b9585c 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData; using StardewValley; @@ -30,24 +31,25 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player /// The command arguments. 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)) + SearchableItem match; + int optionalArgStartIndex; + + if (!args.TryGet(0, "item type or name", out string typeOrName, required: true)) 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); + // read arguments + if (Enum.GetNames(typeof(ItemType)).Contains(typeOrName, StringComparer.InvariantCultureIgnoreCase)) + this.FindItemByTypeAndId(monitor, args, typeOrName, out optionalArgStartIndex, out match); + else + this.FindItemByName(monitor, args, typeOrName, out optionalArgStartIndex, out match); + if (match == null) - { - monitor.Log($"There's no {type} item with ID {id}.", LogLevel.Error); return; - } + + if (!args.TryGetInt(optionalArgStartIndex, "count", out int count, min: 1, required: false)) + count = 1; + if (!args.TryGetInt(optionalArgStartIndex + 1, "quality", out int quality, min: Object.lowQuality, max: Object.bestQuality, required: false)) + quality = Object.lowQuality; // apply count match.Item.Stack = count; @@ -63,6 +65,69 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player monitor.Log($"OK, added {match.Name} ({match.Type} #{match.ID}) to your inventory.", LogLevel.Info); } + /// + /// Finds a matching item by item type and id. + /// + /// Writes messages to the console and log file. + /// The command arguments. + /// The raw item type. + /// The index of subsequent arguments. + /// The matching item. + private void FindItemByTypeAndId(IMonitor monitor, ArgumentParser args, string rawType, out int nextArgIndex, out SearchableItem match) + { + match = null; + nextArgIndex = 2; + + // read arguments + if (!args.TryGetInt(1, "item ID", out int id, min: 0)) + return; + + ItemType type = (ItemType)Enum.Parse(typeof(ItemType), rawType, ignoreCase: true); + + // find matching item + 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); + } + } + + /// + /// Finds a matching item by name. + /// + /// Writes messages to the console and log file. + /// The command arguments. + /// The item name. + /// The index of subsequent arguments. + /// The matching item. + private void FindItemByName(IMonitor monitor, ArgumentParser args, string name, out int nextArgIndex, out SearchableItem match) + { + match = null; + nextArgIndex = 1; + + // interpret names with underscores as spaces + name = name.Replace('_', ' '); + + // find matching items + IEnumerable matching = this.Items.GetAll().Where(p => p.DisplayName.Equals(name, StringComparison.CurrentCultureIgnoreCase)); + int numberOfMatches = matching.Count(); + + // handle unique requirement + if (numberOfMatches == 0) + { + monitor.Log($"There's no item with name {name}.", LogLevel.Error); + } + else if (numberOfMatches == 1) + { + match = matching.ElementAt(0); + } + else + { + monitor.Log($"There are {numberOfMatches} items with name {name}. Try specifying a type and id instead.", LogLevel.Error); + } + } + /********* ** Private methods *********/ @@ -71,9 +136,10 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player string[] typeValues = Enum.GetNames(typeof(ItemType)); return "Gives the player an item.\n" + "\n" - + "Usage: player_add [count] [quality]\n" + + "Usage: player_add ( |) [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" + + "- name: the display name of the item (only if there is exactly one such item).\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" -- cgit From a6e1ea0a4f87c621edc74d789eb76ce70893b5d1 Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Mon, 16 Apr 2018 00:42:57 -0500 Subject: fix private method comment location --- .../Framework/Commands/Player/AddCommand.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 09b9585c..6c48d8df 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -65,6 +65,10 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player monitor.Log($"OK, added {match.Name} ({match.Type} #{match.ID}) to your inventory.", LogLevel.Info); } + /********* + ** Private methods + *********/ + /// /// Finds a matching item by item type and id. /// @@ -128,9 +132,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player } } - /********* - ** Private methods - *********/ private static string GetDescription() { string[] typeValues = Enum.GetNames(typeof(ItemType)); -- cgit From d362843706c012867324dc9723e7c7a49a7a2621 Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Mon, 16 Apr 2018 03:15:25 -0500 Subject: add Name as new type, show more helpful info on multiple matches --- .../Framework/Commands/Player/AddCommand.cs | 43 +++++++++++----------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 6c48d8df..47ba9e8d 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -16,6 +16,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player /// Provides methods for searching and constructing items. private readonly ItemRepository Items = new ItemRepository(); + private readonly string[] ItemTypeAndName = Enum.GetNames(typeof(ItemType)).Union(new string[] { "Name" }).ToArray(); /********* ** Public methods @@ -32,23 +33,21 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player public override void Handle(IMonitor monitor, string command, ArgumentParser args) { SearchableItem match; - int optionalArgStartIndex; - if (!args.TryGet(0, "item type or name", out string typeOrName, required: true)) + //read arguments + if (!args.TryGet(0, "item type", out string typeOrName, oneOf: this.ItemTypeAndName)) return; - - // read arguments if (Enum.GetNames(typeof(ItemType)).Contains(typeOrName, StringComparer.InvariantCultureIgnoreCase)) - this.FindItemByTypeAndId(monitor, args, typeOrName, out optionalArgStartIndex, out match); + this.FindItemByTypeAndId(monitor, args, typeOrName, out match); else - this.FindItemByName(monitor, args, typeOrName, out optionalArgStartIndex, out match); - + this.FindItemByName(monitor, args, out match); + if (match == null) return; - if (!args.TryGetInt(optionalArgStartIndex, "count", out int count, min: 1, required: false)) + if (!args.TryGetInt(2, "count", out int count, min: 1, required: false)) count = 1; - if (!args.TryGetInt(optionalArgStartIndex + 1, "quality", out int quality, min: Object.lowQuality, max: Object.bestQuality, required: false)) + if (!args.TryGetInt(3, "quality", out int quality, min: Object.lowQuality, max: Object.bestQuality, required: false)) quality = Object.lowQuality; // apply count @@ -75,12 +74,10 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player /// Writes messages to the console and log file. /// The command arguments. /// The raw item type. - /// The index of subsequent arguments. /// The matching item. - private void FindItemByTypeAndId(IMonitor monitor, ArgumentParser args, string rawType, out int nextArgIndex, out SearchableItem match) + private void FindItemByTypeAndId(IMonitor monitor, ArgumentParser args, string rawType, out SearchableItem match) { match = null; - nextArgIndex = 2; // read arguments if (!args.TryGetInt(1, "item ID", out int id, min: 0)) @@ -103,18 +100,17 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player /// Writes messages to the console and log file. /// The command arguments. /// The item name. - /// The index of subsequent arguments. /// The matching item. - private void FindItemByName(IMonitor monitor, ArgumentParser args, string name, out int nextArgIndex, out SearchableItem match) + private void FindItemByName(IMonitor monitor, ArgumentParser args, out SearchableItem match) { match = null; - nextArgIndex = 1; - // interpret names with underscores as spaces - name = name.Replace('_', ' '); + // read arguments + if (!args.TryGet(1, "item name", out string name)) + return; // find matching items - IEnumerable matching = this.Items.GetAll().Where(p => p.DisplayName.Equals(name, StringComparison.CurrentCultureIgnoreCase)); + IEnumerable matching = this.Items.GetAll().Where(p => p.DisplayName.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) != -1); int numberOfMatches = matching.Count(); // handle unique requirement @@ -128,7 +124,10 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player } else { - monitor.Log($"There are {numberOfMatches} items with name {name}. Try specifying a type and id instead.", LogLevel.Error); + string options = this.GetTableString(matching, new string[] { "type", "name", "command" }, item => new string[] { item.Type.ToString(), item.DisplayName, $"player_add {item.Type} {item.ID}" }); + + monitor.Log($"Found multiple item names containing '{name}'. Type one of these commands for the one you want:", LogLevel.Error); + monitor.Log($"\n{options}", LogLevel.Info); } } @@ -137,10 +136,10 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player string[] typeValues = Enum.GetNames(typeof(ItemType)); return "Gives the player an item.\n" + "\n" - + "Usage: player_add ( |) [count] [quality]\n" - + $"- type: the item type (one of {string.Join(", ", typeValues)}).\n" + + "Usage: player_add (|) [count] [quality]\n" + + $"- type: the item type (either Name or one of {string.Join(", ", typeValues)}).\n" + "- item: the item ID (use the 'list_items' command to see a list).\n" - + "- name: the display name of the item (only if there is exactly one such item).\n" + + "- name: the display name of the item (when using type Name).\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" -- cgit From 96753c35fd3d6baed73a933c552e5f0a5a8fa02c Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Mon, 16 Apr 2018 03:39:08 -0500 Subject: add world ready check and more helpful error messages --- .../Framework/Commands/Player/AddCommand.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 47ba9e8d..3d55b425 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -32,6 +32,13 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player /// The command arguments. 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; + } + SearchableItem match; //read arguments @@ -111,16 +118,22 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player // find matching items IEnumerable matching = this.Items.GetAll().Where(p => p.DisplayName.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) != -1); + SearchableItem exactMatch = matching.FirstOrDefault(item => item.DisplayName.Equals(name, StringComparison.InvariantCultureIgnoreCase)); + int numberOfMatches = matching.Count(); // handle unique requirement - if (numberOfMatches == 0) + if (exactMatch != null) { - monitor.Log($"There's no item with name {name}.", LogLevel.Error); + match = matching.ElementAt(0); + } + else if (numberOfMatches == 0) + { + monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error); } else if (numberOfMatches == 1) { - match = matching.ElementAt(0); + monitor.Log($"There's no item with name '{name}'. Did you mean '{matching.ElementAt(0).DisplayName}'? If so, type 'player_add name {matching.ElementAt(0).DisplayName}'.", LogLevel.Error); } else { -- cgit From 43487a40e391978221df00ba86f2b7628ed8d343 Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Tue, 17 Apr 2018 15:35:22 -0500 Subject: refactor finding items by name slightly --- .../Framework/Commands/Player/AddCommand.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 3d55b425..453b8e32 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -118,16 +118,17 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player // find matching items IEnumerable matching = this.Items.GetAll().Where(p => p.DisplayName.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) != -1); - SearchableItem exactMatch = matching.FirstOrDefault(item => item.DisplayName.Equals(name, StringComparison.InvariantCultureIgnoreCase)); - - int numberOfMatches = matching.Count(); + match = matching.FirstOrDefault(item => item.DisplayName.Equals(name, StringComparison.InvariantCultureIgnoreCase)); // handle unique requirement - if (exactMatch != null) + if (match != null) { - match = matching.ElementAt(0); + return; } - else if (numberOfMatches == 0) + + int numberOfMatches = matching.Count(); + + if (numberOfMatches == 0) { monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error); } -- cgit From f451e172e2d2cf1959c86fdb24c708ca5b1924f7 Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Thu, 19 Apr 2018 01:35:15 -0500 Subject: update documentation format and document field --- .../Framework/Commands/Player/AddCommand.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 453b8e32..803ae7f6 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -16,6 +16,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player /// Provides methods for searching and constructing items. private readonly ItemRepository Items = new ItemRepository(); + /// All possible item types along with Name. private readonly string[] ItemTypeAndName = Enum.GetNames(typeof(ItemType)).Union(new string[] { "Name" }).ToArray(); /********* @@ -75,9 +76,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player ** Private methods *********/ - /// - /// Finds a matching item by item type and id. - /// + /// Finds a matching item by item type and id. /// Writes messages to the console and log file. /// The command arguments. /// The raw item type. @@ -101,9 +100,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player } } - /// - /// Finds a matching item by name. - /// + /// Finds a matching item by name. /// Writes messages to the console and log file. /// The command arguments. /// The item name. -- cgit From 0134f0b28d355766a17b1c9da89b8173f978d195 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 25 Apr 2018 13:16:25 -0400 Subject: update release notes, refactor a bit (#474) --- docs/release-notes.md | 1 + .../Framework/Commands/Player/AddCommand.cs | 123 +++++++++------------ .../Framework/ItemData/SearchableItem.cs | 21 +++- src/SMAPI/Framework/CommandManager.cs | 21 ++-- 4 files changed, 85 insertions(+), 81 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index 308007bb..6842c941 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -11,6 +11,7 @@ * For modders: * Added code analysis to mod build config package to flag common issues as warnings. * Added `Context.IsMultiplayer` and `Context.IsMainPlayer` flags. + * Added `player_add name` console command, which lets you add items to your inventory by name instead of ID. * Fixed assets loaded by temporary content managers not being editable. * Fixed issue where assets didn't reload correctly when the player switches language. * Fixed user command input not saved to log file. diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 803ae7f6..71c3ff98 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData; using StardewValley; @@ -16,16 +15,16 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player /// Provides methods for searching and constructing items. private readonly ItemRepository Items = new ItemRepository(); - /// All possible item types along with Name. - private readonly string[] ItemTypeAndName = Enum.GetNames(typeof(ItemType)).Union(new string[] { "Name" }).ToArray(); + /// The type names recognised by this command. + private readonly string[] ValidTypes = Enum.GetNames(typeof(ItemType)).Concat(new[] { "Name" }).ToArray(); + /********* ** Public methods *********/ /// Construct an instance. public AddCommand() - : base("player_add", AddCommand.GetDescription()) - { } + : base("player_add", AddCommand.GetDescription()) { } /// Handle the command. /// Writes messages to the console and log file. @@ -40,24 +39,21 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player return; } - SearchableItem match; - - //read arguments - if (!args.TryGet(0, "item type", out string typeOrName, oneOf: this.ItemTypeAndName)) - return; - if (Enum.GetNames(typeof(ItemType)).Contains(typeOrName, StringComparer.InvariantCultureIgnoreCase)) - this.FindItemByTypeAndId(monitor, args, typeOrName, out match); - else - this.FindItemByName(monitor, args, out match); - - if (match == null) + // read arguments + if (!args.TryGet(0, "item type", out string type, oneOf: this.ValidTypes)) 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; + // find matching item + SearchableItem match = Enum.TryParse(type, true, out ItemType itemType) + ? this.FindItemByID(monitor, args, itemType) + : this.FindItemByName(monitor, args); + if (match == null) + return; + // apply count match.Item.Stack = count; @@ -72,90 +68,81 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player monitor.Log($"OK, added {match.Name} ({match.Type} #{match.ID}) to your inventory.", LogLevel.Info); } + /********* ** Private methods *********/ - - /// Finds a matching item by item type and id. + /// Get a matching item by its ID. /// Writes messages to the console and log file. /// The command arguments. - /// The raw item type. - /// The matching item. - private void FindItemByTypeAndId(IMonitor monitor, ArgumentParser args, string rawType, out SearchableItem match) + /// The item type. + private SearchableItem FindItemByID(IMonitor monitor, ArgumentParser args, ItemType type) { - match = null; - // read arguments if (!args.TryGetInt(1, "item ID", out int id, min: 0)) - return; - - ItemType type = (ItemType)Enum.Parse(typeof(ItemType), rawType, ignoreCase: true); + return null; // find matching item - match = this.Items.GetAll().FirstOrDefault(p => p.Type == type && p.ID == id); - - if (match == null) - { + SearchableItem item = this.Items.GetAll().FirstOrDefault(p => p.Type == type && p.ID == id); + if (item == null) monitor.Log($"There's no {type} item with ID {id}.", LogLevel.Error); - } + return item; } - /// Finds a matching item by name. + /// Get a matching item by its name. /// Writes messages to the console and log file. /// The command arguments. - /// The item name. - /// The matching item. - private void FindItemByName(IMonitor monitor, ArgumentParser args, out SearchableItem match) + private SearchableItem FindItemByName(IMonitor monitor, ArgumentParser args) { - match = null; - // read arguments if (!args.TryGet(1, "item name", out string name)) - return; + return null; // find matching items - IEnumerable matching = this.Items.GetAll().Where(p => p.DisplayName.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) != -1); - match = matching.FirstOrDefault(item => item.DisplayName.Equals(name, StringComparison.InvariantCultureIgnoreCase)); - - // handle unique requirement - if (match != null) - { - return; - } - - int numberOfMatches = matching.Count(); - - if (numberOfMatches == 0) - { - monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error); - } - else if (numberOfMatches == 1) + SearchableItem[] matches = this.Items.GetAll().Where(p => p.NameContains(name)).ToArray(); + switch (matches.Length) { - monitor.Log($"There's no item with name '{name}'. Did you mean '{matching.ElementAt(0).DisplayName}'? If so, type 'player_add name {matching.ElementAt(0).DisplayName}'.", LogLevel.Error); - } - else - { - string options = this.GetTableString(matching, new string[] { "type", "name", "command" }, item => new string[] { item.Type.ToString(), item.DisplayName, $"player_add {item.Type} {item.ID}" }); - - monitor.Log($"Found multiple item names containing '{name}'. Type one of these commands for the one you want:", LogLevel.Error); - monitor.Log($"\n{options}", LogLevel.Info); + // none found + case 0: + monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error); + return null; + + // exact match + case 1 when matches[0].NameEquivalentTo(name): + return matches[0]; + + // list matches + default: + string options = this.GetTableString( + data: matches, + header: new[] { "type", "name", "command" }, + getRow: item => new[] { item.Type.ToString(), item.DisplayName, $"player_add {item.Type} {item.ID}" } + ); + monitor.Log($"There's no item with name '{name}'. Do you mean one of these?\n\n{options}", LogLevel.Info); + return null; } } + /// Get the command description. private static string GetDescription() { string[] typeValues = Enum.GetNames(typeof(ItemType)); return "Gives the player an item.\n" + "\n" - + "Usage: player_add (|) [count] [quality]\n" - + $"- type: the item type (either Name or one of {string.Join(", ", typeValues)}).\n" + + "Usage: player_add [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" - + "- name: the display name of the item (when using type Name).\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"; + + "Usage: player_add name \"\" [count] [quality]\n" + + "- name: the item name to search (use the 'list_items' command to see a list). This will add the item immediately if it's an exact match, else show a table of matching items.\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" + + "These examples both add the galaxy sword to your inventory:\n" + + " player_add weapon 4\n" + + " player_add name \"Galaxy Sword\""; } } } diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs index 3eede413..b618a308 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs @@ -1,4 +1,5 @@ -using StardewValley; +using System; +using StardewValley; namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData { @@ -37,5 +38,23 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData this.ID = id; this.Item = item; } + + /// Get whether the item name contains a case-insensitive substring. + /// The substring to find. + public bool NameContains(string substring) + { + return + this.Name.IndexOf(substring, StringComparison.InvariantCultureIgnoreCase) != -1 + || this.DisplayName.IndexOf(substring, StringComparison.InvariantCultureIgnoreCase) != -1; + } + + /// Get whether the item name is exactly equal to a case-insensitive string. + /// The substring to find. + public bool NameEquivalentTo(string name) + { + return + this.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) + || this.DisplayName.Equals(name, StringComparison.InvariantCultureIgnoreCase); + } } } diff --git a/src/SMAPI/Framework/CommandManager.cs b/src/SMAPI/Framework/CommandManager.cs index 0c48d8ec..f9651ed9 100644 --- a/src/SMAPI/Framework/CommandManager.cs +++ b/src/SMAPI/Framework/CommandManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace StardewModdingAPI.Framework { @@ -103,31 +104,27 @@ namespace StardewModdingAPI.Framework /********* ** Private methods *********/ - /// - /// Parses a string into an array of arguments. - /// + /// Parse a string into command arguments. /// The string to parse. private string[] ParseArgs(string input) { bool inQuotes = false; IList args = new List(); - IList currentArg = new List(); - foreach (char c in input) + StringBuilder currentArg = new StringBuilder(); + foreach (char ch in input) { - if (c == '"') - { + if (ch == '"') inQuotes = !inQuotes; - } - else if (!inQuotes && char.IsWhiteSpace(c)) + else if (!inQuotes && char.IsWhiteSpace(ch)) { - args.Add(string.Concat(currentArg)); + args.Add(currentArg.ToString()); currentArg.Clear(); } else - currentArg.Add(c); + currentArg.Append(ch); } - args.Add(string.Concat(currentArg)); + args.Add(currentArg.ToString()); return args.Where(item => !string.IsNullOrWhiteSpace(item)).ToArray(); } -- cgit From beb2f9c1484626e03acfecffd0f90cd2cddb8cc6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 27 Apr 2018 19:59:41 -0400 Subject: remove alias no longer needed in SDV 1.3 (#453) --- .../NetFieldAnalyzerTests.cs | 3 +-- .../Framework/Commands/Player/SetLevelCommand.cs | 15 +++++++-------- src/SMAPI/Framework/SGame.cs | 11 +++++------ src/SMAPI/Framework/StateTracking/PlayerTracker.cs | 5 ++--- 4 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/NetFieldAnalyzerTests.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/NetFieldAnalyzerTests.cs index 7b410085..ab3f2c5e 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/NetFieldAnalyzerTests.cs +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/NetFieldAnalyzerTests.cs @@ -19,7 +19,6 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests using StardewValley; using Netcode; using SObject = StardewValley.Object; - using SFarmer = StardewValley.Farmer; namespace SampleMod { @@ -34,7 +33,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests "; /// The line number where the unit tested code is injected into . - private const int SampleCodeLine = 14; + private const int SampleCodeLine = 13; /// The column number where the unit tested code is injected into . private const int SampleCodeColumn = 25; diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetLevelCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetLevelCommand.cs index 68891267..97a36066 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetLevelCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetLevelCommand.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using StardewValley; -using SFarmer = StardewValley.Farmer; namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player { @@ -11,7 +10,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player ** Properties *********/ /// The experience points needed to reach each level. - /// Derived from . + /// Derived from . private readonly IDictionary LevelExp = new Dictionary { [0] = 0, @@ -52,37 +51,37 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player { case "luck": Game1.player.LuckLevel = level; - Game1.player.experiencePoints[SFarmer.luckSkill] = this.LevelExp[level]; + Game1.player.experiencePoints[Farmer.luckSkill] = this.LevelExp[level]; monitor.Log($"OK, your luck skill is now {Game1.player.LuckLevel}.", LogLevel.Info); break; case "mining": Game1.player.MiningLevel = level; - Game1.player.experiencePoints[SFarmer.miningSkill] = this.LevelExp[level]; + Game1.player.experiencePoints[Farmer.miningSkill] = this.LevelExp[level]; monitor.Log($"OK, your mining skill is now {Game1.player.MiningLevel}.", LogLevel.Info); break; case "combat": Game1.player.CombatLevel = level; - Game1.player.experiencePoints[SFarmer.combatSkill] = this.LevelExp[level]; + Game1.player.experiencePoints[Farmer.combatSkill] = this.LevelExp[level]; monitor.Log($"OK, your combat skill is now {Game1.player.CombatLevel}.", LogLevel.Info); break; case "farming": Game1.player.FarmingLevel = level; - Game1.player.experiencePoints[SFarmer.farmingSkill] = this.LevelExp[level]; + Game1.player.experiencePoints[Farmer.farmingSkill] = this.LevelExp[level]; monitor.Log($"OK, your farming skill is now {Game1.player.FarmingLevel}.", LogLevel.Info); break; case "fishing": Game1.player.FishingLevel = level; - Game1.player.experiencePoints[SFarmer.fishingSkill] = this.LevelExp[level]; + Game1.player.experiencePoints[Farmer.fishingSkill] = this.LevelExp[level]; monitor.Log($"OK, your fishing skill is now {Game1.player.FishingLevel}.", LogLevel.Info); break; case "foraging": Game1.player.ForagingLevel = level; - Game1.player.experiencePoints[SFarmer.foragingSkill] = this.LevelExp[level]; + Game1.player.experiencePoints[Farmer.foragingSkill] = this.LevelExp[level]; monitor.Log($"OK, your foraging skill is now {Game1.player.ForagingLevel}.", LogLevel.Info); break; } diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 89bf18ef..7578473b 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -23,7 +23,6 @@ using StardewValley.Menus; using StardewValley.Tools; using xTile.Dimensions; using xTile.Layers; -using SFarmer = StardewValley.Farmer; using SObject = StardewValley.Object; namespace StardewModdingAPI.Framework @@ -872,10 +871,10 @@ namespace StardewModdingAPI.Framework Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch); Game1.currentLocation.Map.GetLayer("Back").Draw(Game1.mapDisplayDevice, Game1.viewport, Location.Origin, false, 4); Game1.currentLocation.drawWater(Game1.spriteBatch); - IEnumerable source = Game1.currentLocation.farmers; + IEnumerable source = Game1.currentLocation.farmers; if (Game1.currentLocation.currentEvent != null && !Game1.currentLocation.currentEvent.isFestival && Game1.currentLocation.currentEvent.farmerActors.Count > 0) - source = (IEnumerable)Game1.currentLocation.currentEvent.farmerActors; - IEnumerable farmers = source.Where((Func)(farmer => + source = (IEnumerable)Game1.currentLocation.currentEvent.farmerActors; + IEnumerable farmers = source.Where((Func)(farmer => { if (!farmer.IsLocalPlayer) return !(bool)((NetFieldBase)farmer.hidden); @@ -899,7 +898,7 @@ namespace StardewModdingAPI.Framework Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, actor.Position + new Vector2((float)(actor.Sprite.SpriteWidth * 4) / 2f, (float)(actor.GetBoundingBox().Height + (actor.IsMonster ? 0 : (actor.Sprite.SpriteHeight <= 16 ? -4 : 12))))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)actor.yJumpOffset / 40.0) * (float)((NetFieldBase)actor.scale), SpriteEffects.None, Math.Max(0.0f, (float)actor.getStandingY() / 10000f) - 1E-06f); } } - foreach (SFarmer farmer in farmers) + foreach (Farmer farmer in farmers) { if (!(bool)((NetFieldBase)farmer.swimming) && !farmer.isRidingHorse() && (Game1.currentLocation == null || !Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(farmer.getTileLocation()))) { @@ -943,7 +942,7 @@ namespace StardewModdingAPI.Framework Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, actor.Position + new Vector2((float)(actor.Sprite.SpriteWidth * 4) / 2f, (float)(actor.GetBoundingBox().Height + (actor.IsMonster ? 0 : 12)))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)actor.yJumpOffset / 40.0) * (float)((NetFieldBase)actor.scale), SpriteEffects.None, Math.Max(0.0f, (float)actor.getStandingY() / 10000f) - 1E-06f); } } - foreach (SFarmer farmer in farmers) + foreach (Farmer farmer in farmers) { if (!(bool)((NetFieldBase)farmer.swimming) && !farmer.isRidingHorse() && (Game1.currentLocation != null && Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(farmer.getTileLocation()))) { diff --git a/src/SMAPI/Framework/StateTracking/PlayerTracker.cs b/src/SMAPI/Framework/StateTracking/PlayerTracker.cs index f6bfc98e..032705b7 100644 --- a/src/SMAPI/Framework/StateTracking/PlayerTracker.cs +++ b/src/SMAPI/Framework/StateTracking/PlayerTracker.cs @@ -6,7 +6,6 @@ using StardewModdingAPI.Events; using StardewModdingAPI.Framework.StateTracking.FieldWatchers; using StardewValley; using StardewValley.Locations; -using SFarmer = StardewValley.Farmer; using SObject = StardewValley.Object; namespace StardewModdingAPI.Framework.StateTracking @@ -34,7 +33,7 @@ namespace StardewModdingAPI.Framework.StateTracking ** Accessors *********/ /// The player being tracked. - public SFarmer Player { get; } + public Farmer Player { get; } /// The player's current location. public IValueWatcher LocationWatcher { get; } @@ -54,7 +53,7 @@ namespace StardewModdingAPI.Framework.StateTracking *********/ /// Construct an instance. /// The player to track. - public PlayerTracker(SFarmer player) + public PlayerTracker(Farmer player) { // init player data this.Player = player; -- cgit From ccd09eb9143bee60bfdc4182c3a7505fabddbe48 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 12 May 2018 16:04:18 -0400 Subject: fix world_setseason command not running season change logic --- docs/release-notes.md | 1 + .../Framework/Commands/World/SetSeasonCommand.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index cf531c57..ff9fcdac 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -10,6 +10,7 @@ * Fixed detection of GOG Galaxy install path in rare cases. * Fixed install error on Linux/Mac in some cases. * Fixed `smapi.io/install` not linking to a useful page. + * Fixed `world_setseason` command not running season-change logic. * Renamed `install.exe` to `install on Windows.exe` to avoid confusion. * For modders: diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetSeasonCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetSeasonCommand.cs index 897d052f..3d6d4b3d 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetSeasonCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetSeasonCommand.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using StardewValley; namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World @@ -39,6 +39,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World // handle Game1.currentSeason = season; + Game1.setGraphicsForSeason(); monitor.Log($"OK, the date is now {Game1.currentSeason} {Game1.dayOfMonth}.", LogLevel.Info); } } -- cgit From df1d856cb00e8dbc6a6ef7a03990d943a7f3f4de Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 16 May 2018 00:48:13 -0400 Subject: fix typo in command help --- .../Framework/Commands/Player/SetStyleCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetStyleCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetStyleCommand.cs index b59be2e5..31f4107d 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetStyleCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetStyleCommand.cs @@ -1,4 +1,4 @@ -using StardewValley; +using StardewValley; namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player { @@ -10,7 +10,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player *********/ /// Construct an instance. public SetStyleCommand() - : base("player_changestyle", "Sets the style of a player feature.\n\nUsage: player_changecolor .\n- target: what to change (one of 'hair', 'shirt', 'skin', 'acc', 'shoe', 'swim', or 'gender').\n- value: the integer style ID.") { } + : base("player_changestyle", "Sets the style of a player feature.\n\nUsage: player_changestyle .\n- target: what to change (one of 'hair', 'shirt', 'skin', 'acc', 'shoe', 'swim', or 'gender').\n- value: the integer style ID.") { } /// Handle the command. /// Writes messages to the console and log file. -- cgit From 317a33764621f7d0ff9af0239a5fcfea6662a7ed Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 9 Jun 2018 14:31:47 -0400 Subject: fix world_setseason command not normalising season --- docs/release-notes.md | 1 + .../Framework/Commands/World/SetSeasonCommand.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index 6e16032d..e7c946a3 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -55,6 +55,7 @@ * In console commands: * Added `player_add name`, which lets you add items to your inventory by name instead of ID. * Fixed `world_settime` sometimes breaking NPC schedules (e.g. so they stay in bed). + * Fixed `world_setseason` not normalising the season value. * For the log parser: * Redesigned upload page to make it more intuitive for new players. diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetSeasonCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetSeasonCommand.cs index 3d6d4b3d..b5db9c0d 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetSeasonCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetSeasonCommand.cs @@ -38,7 +38,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World return; // handle - Game1.currentSeason = season; + Game1.currentSeason = season.ToLower(); Game1.setGraphicsForSeason(); monitor.Log($"OK, the date is now {Game1.currentSeason} {Game1.dayOfMonth}.", LogLevel.Info); } -- cgit From bd0800f2609c14e30e8822e48323d4eb92c67bb4 Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Sun, 10 Jun 2018 12:13:47 -0700 Subject: find item if there is exactly one exact name match --- .../Framework/Commands/Player/AddCommand.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 71c3ff98..f1b573cd 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData; using StardewValley; @@ -100,6 +101,12 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player // find matching items SearchableItem[] matches = this.Items.GetAll().Where(p => p.NameContains(name)).ToArray(); + + // if exactly one item with the exact same name, use that item + SearchableItem[] exactNameMatches = matches.Where(p => p.NameEquivalentTo(name)).ToArray(); + if (exactNameMatches.Length == 1) + return exactNameMatches[0]; + switch (matches.Length) { // none found @@ -107,10 +114,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error); return null; - // exact match - case 1 when matches[0].NameEquivalentTo(name): - return matches[0]; - // list matches default: string options = this.GetTableString( -- cgit From 580fd687b0f676b9ddac3ee7938b4e0ac5a987c3 Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Sun, 10 Jun 2018 12:21:04 -0700 Subject: remove unused import --- src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index f1b573cd..5bc97225 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData; using StardewValley; -- cgit From 645a64cd24146edba44b89f7493ba5ea9950c3c8 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 19 Jun 2018 19:09:00 -0400 Subject: refactor player_add command a bit (#542) --- .../Framework/Commands/Player/AddCommand.cs | 38 ++++++++++------------ 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 5bc97225..37f4719e 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -100,29 +100,25 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player // find matching items SearchableItem[] matches = this.Items.GetAll().Where(p => p.NameContains(name)).ToArray(); - - // if exactly one item with the exact same name, use that item - SearchableItem[] exactNameMatches = matches.Where(p => p.NameEquivalentTo(name)).ToArray(); - if (exactNameMatches.Length == 1) - return exactNameMatches[0]; - - switch (matches.Length) + if (!matches.Any()) { - // none found - case 0: - monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error); - return null; - - // list matches - default: - string options = this.GetTableString( - data: matches, - header: new[] { "type", "name", "command" }, - getRow: item => new[] { item.Type.ToString(), item.DisplayName, $"player_add {item.Type} {item.ID}" } - ); - monitor.Log($"There's no item with name '{name}'. Do you mean one of these?\n\n{options}", LogLevel.Info); - return null; + monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error); + return null; } + + // handle single exact match + SearchableItem[] exactMatches = matches.Where(p => p.NameEquivalentTo(name)).ToArray(); + if (exactMatches.Length == 1) + return exactMatches[0]; + + // handle ambiguous results + string options = this.GetTableString( + data: matches, + header: new[] { "type", "name", "command" }, + getRow: item => new[] { item.Type.ToString(), item.DisplayName, $"player_add {item.Type} {item.ID}" } + ); + monitor.Log($"There's no item with name '{name}'. Do you mean one of these?\n\n{options}", LogLevel.Info); + return null; } /// Get the command description. -- cgit From 997c65b6f46f74469fb41af81a69e07d788a1e6e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 20 Jun 2018 23:51:00 -0400 Subject: fix list_items and player_add commands not handling secret notes --- .../Framework/ItemRepository.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index 833fddde..e678d057 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -83,9 +83,19 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework foreach (int id in Game1.bigCraftablesInformation.Keys) yield return new SearchableItem(ItemType.BigCraftable, id, new SObject(Vector2.Zero, id)); + // secret notes + foreach (int id in Game1.content.Load>("Data\\SecretNotes").Keys) + { + SObject note = new SObject(79, 1); + note.name = $"{note.name} #{id}"; + yield return new SearchableItem(ItemType.Object, this.CustomIDOffset + id, note); + } + // objects foreach (int id in Game1.objectInformation.Keys) { + if (id == 79) + continue; // secret note handled above if (id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange) continue; // handled separated @@ -103,7 +113,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }; wine.preserve.Value = SObject.PreserveType.Wine; wine.preservedParentSheetIndex.Value = item.parentSheetIndex; - yield return new SearchableItem(ItemType.Object, this.CustomIDOffset + id, wine); + yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 2 + id, wine); // jelly SObject jelly = new SObject(344, 1) @@ -113,7 +123,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }; jelly.preserve.Value = SObject.PreserveType.Jelly; jelly.preservedParentSheetIndex.Value = item.parentSheetIndex; - yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 2 + id, jelly); + yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 3 + id, jelly); } // vegetable products @@ -127,7 +137,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }; juice.preserve.Value = SObject.PreserveType.Juice; juice.preservedParentSheetIndex.Value = item.parentSheetIndex; - yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 3 + id, juice); + yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 4 + id, juice); // pickled SObject pickled = new SObject(342, 1) @@ -137,7 +147,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }; pickled.preserve.Value = SObject.PreserveType.Pickle; pickled.preservedParentSheetIndex.Value = item.parentSheetIndex; - yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 4 + id, pickled); + yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 5 + id, pickled); } // flower honey -- cgit From 599f5851928c82dba118e1d302da731a4ed4f91d Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 30 Jun 2018 17:09:29 -0400 Subject: remove player_setlevel and player_setspeed commands (#415) --- docs/release-notes.md | 1 + .../Framework/Commands/Player/SetLevelCommand.cs | 90 ---------------------- .../Framework/Commands/Player/SetSpeedCommand.cs | 30 -------- .../StardewModdingAPI.Mods.ConsoleCommands.csproj | 2 - 4 files changed, 1 insertion(+), 122 deletions(-) delete mode 100644 src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetLevelCommand.cs delete mode 100644 src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetSpeedCommand.cs (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index ae7f766d..adf161b4 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -28,6 +28,7 @@ * Fixed issue where a mod crashing in `CanEdit` or `CanLoad` could cause an abort-retry loop. * Fixed many mods not working if the player name is blank. * Renamed `install.exe` to `install on Windows.exe` to avoid confusion. + * Removed the `player_setspeed` and `player_setlevel` commands, which weren't implemented in a useful way. Use a mod like CJB Cheats Menu if you need those. * Updated compatibility list. * For modders: diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetLevelCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetLevelCommand.cs deleted file mode 100644 index 97a36066..00000000 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetLevelCommand.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System.Collections.Generic; -using StardewValley; - -namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player -{ - /// A command which edits the player's current level for a skill. - internal class SetLevelCommand : TrainerCommand - { - /********* - ** Properties - *********/ - /// The experience points needed to reach each level. - /// Derived from . - private readonly IDictionary LevelExp = new Dictionary - { - [0] = 0, - [1] = 100, - [2] = 380, - [3] = 770, - [4] = 1300, - [5] = 2150, - [6] = 3300, - [7] = 4800, - [8] = 6900, - [9] = 10000, - [10] = 15000 - }; - - - /********* - ** Public methods - *********/ - /// Construct an instance. - public SetLevelCommand() - : base("player_setlevel", "Sets the player's specified skill to the specified value.\n\nUsage: player_setlevel \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).") { } - - /// Handle the command. - /// Writes messages to the console and log file. - /// The command name. - /// The command arguments. - 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; - Game1.player.experiencePoints[Farmer.luckSkill] = this.LevelExp[level]; - monitor.Log($"OK, your luck skill is now {Game1.player.LuckLevel}.", LogLevel.Info); - break; - - case "mining": - Game1.player.MiningLevel = level; - Game1.player.experiencePoints[Farmer.miningSkill] = this.LevelExp[level]; - monitor.Log($"OK, your mining skill is now {Game1.player.MiningLevel}.", LogLevel.Info); - break; - - case "combat": - Game1.player.CombatLevel = level; - Game1.player.experiencePoints[Farmer.combatSkill] = this.LevelExp[level]; - monitor.Log($"OK, your combat skill is now {Game1.player.CombatLevel}.", LogLevel.Info); - break; - - case "farming": - Game1.player.FarmingLevel = level; - Game1.player.experiencePoints[Farmer.farmingSkill] = this.LevelExp[level]; - monitor.Log($"OK, your farming skill is now {Game1.player.FarmingLevel}.", LogLevel.Info); - break; - - case "fishing": - Game1.player.FishingLevel = level; - Game1.player.experiencePoints[Farmer.fishingSkill] = this.LevelExp[level]; - monitor.Log($"OK, your fishing skill is now {Game1.player.FishingLevel}.", LogLevel.Info); - break; - - case "foraging": - Game1.player.ForagingLevel = level; - Game1.player.experiencePoints[Farmer.foragingSkill] = this.LevelExp[level]; - monitor.Log($"OK, your foraging skill is now {Game1.player.ForagingLevel}.", LogLevel.Info); - break; - } - } - } -} diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetSpeedCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetSpeedCommand.cs deleted file mode 100644 index e9693540..00000000 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetSpeedCommand.cs +++ /dev/null @@ -1,30 +0,0 @@ -using StardewValley; - -namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player -{ - /// A command which edits the player's current added speed. - internal class SetSpeedCommand : TrainerCommand - { - /********* - ** Public methods - *********/ - /// Construct an instance. - public SetSpeedCommand() - : base("player_setspeed", "Sets the player's added speed to the specified value.\n\nUsage: player_setspeed \n- value: an integer amount (0 is normal).") { } - - /// Handle the command. - /// Writes messages to the console and log file. - /// The command name. - /// The command arguments. - 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/SMAPI.Mods.ConsoleCommands/StardewModdingAPI.Mods.ConsoleCommands.csproj b/src/SMAPI.Mods.ConsoleCommands/StardewModdingAPI.Mods.ConsoleCommands.csproj index 357f34d7..50b7b87f 100644 --- a/src/SMAPI.Mods.ConsoleCommands/StardewModdingAPI.Mods.ConsoleCommands.csproj +++ b/src/SMAPI.Mods.ConsoleCommands/StardewModdingAPI.Mods.ConsoleCommands.csproj @@ -56,8 +56,6 @@ - - -- cgit