diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-12-22 12:04:40 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-12-22 12:04:40 -0500 |
commit | 139e267aaaeca9ad84e2a46b1068967b5599f1b6 (patch) | |
tree | 124d24e5a6f2bf068ba6839d6bfafd7359ee7837 | |
parent | 05d237400c518d7ed288ddf2f5031913a9ca4af4 (diff) | |
download | SMAPI-139e267aaaeca9ad84e2a46b1068967b5599f1b6.tar.gz SMAPI-139e267aaaeca9ad84e2a46b1068967b5599f1b6.tar.bz2 SMAPI-139e267aaaeca9ad84e2a46b1068967b5599f1b6.zip |
update item spawning code, detect ring type automatically to support custom rings, minor refactor
-rw-r--r-- | docs/release-notes.md | 5 | ||||
-rw-r--r-- | src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs | 253 |
2 files changed, 128 insertions, 130 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index bae1cb98..a9df73f4 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -8,6 +8,11 @@ * Updated for the 'Force Off' gamepad mode added in Stardew Valley 1.4.1. * Fixed compatibility with Linux Mint 18 (thanks to techge!) and Arch Linux. * Fixed compatibility with Linux systems which have libhybris-utils installed. + * Fixes for the bundled Console Commands mod: + * added new clothing items; + * fixed spawning new flooring and rings (thanks to Mizzion!); + * fixed spawning custom rings added by mods; + * Fixed errors when some item data is invalid. * Internal optimizations. * Updated translations. Thanks to PlussRolf (added Spanish)! diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index 1371d3a5..08dd8eed 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -46,6 +46,10 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 2, () => new Pan()); yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 3, () => new Wand()); + // clothing + foreach (int id in Game1.clothingInformation.Keys) + yield return this.TryCreate(ItemType.Clothing, id, () => new Clothing(id)); + // wallpapers for (int id = 0; id < 112; id++) yield return this.TryCreate(ItemType.Wallpaper, id, () => new Wallpaper(id) { Category = SObject.furnitureCategory }); @@ -59,11 +63,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework yield return this.TryCreate(ItemType.Boots, id, () => new Boots(id)); foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\hats").Keys) yield return this.TryCreate(ItemType.Hat, id, () => new Hat(id)); - foreach (int id in Game1.objectInformation.Keys) - { - if ((id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange) || (id >= 810 && id <= 811)) - yield return this.TryCreate(ItemType.Ring, id, () => new Ring(id)); - } // weapons foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\weapons").Keys) @@ -87,147 +86,141 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework foreach (int id in Game1.bigCraftablesInformation.Keys) yield return this.TryCreate(ItemType.BigCraftable, id, () => new SObject(Vector2.Zero, id)); - // secret notes - foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\SecretNotes").Keys) - { - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset + id, () => - { - SObject note = new SObject(79, 1); - note.name = $"{note.name} #{id}"; - return note; - }); - } - // objects foreach (int id in Game1.objectInformation.Keys) { - if (id == 79) - continue; // secret note handled above - if ((id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange) || (id >= 810 && id <= 811)) - continue; // handled separated - - // spawn main item - SObject item; - { - SearchableItem main = this.TryCreate(ItemType.Object, id, () => id == 812 - ? new ColoredObject(id, 1, Color.White) - : new SObject(id, 1) - ); - yield return main; - item = main?.Item as SObject; - } - if (item == null) - continue; + string[] fields = Game1.objectInformation[id]?.Split('/'); - // fruit products - if (item.Category == SObject.FruitsCategory) + // secret notes + if (id == 79) { - // wine - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + id, () => + foreach (int secretNoteId in Game1.content.Load<Dictionary<int, string>>("Data\\SecretNotes").Keys) { - SObject wine = new SObject(348, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset + secretNoteId, () => { - Name = $"{item.Name} Wine", - Price = item.Price * 3 - }; - wine.preserve.Value = SObject.PreserveType.Wine; - wine.preservedParentSheetIndex.Value = item.ParentSheetIndex; - return wine; - }); - - // jelly - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 3 + id, () => - { - SObject jelly = new SObject(344, 1) - { - Name = $"{item.Name} Jelly", - Price = 50 + item.Price * 2 - }; - jelly.preserve.Value = SObject.PreserveType.Jelly; - jelly.preservedParentSheetIndex.Value = item.ParentSheetIndex; - return jelly; - }); + SObject note = new SObject(79, 1); + note.name = $"{note.name} #{secretNoteId}"; + return note; + }); + } } - // vegetable products - else if (item.Category == SObject.VegetableCategory) - { - // juice - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 4 + id, () => - { - SObject juice = new SObject(350, 1) - { - Name = $"{item.Name} Juice", - Price = (int)(item.Price * 2.25d) - }; - juice.preserve.Value = SObject.PreserveType.Juice; - juice.preservedParentSheetIndex.Value = item.ParentSheetIndex; - return juice; - }); - - // pickled - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () => - { - SObject pickled = new SObject(342, 1) - { - Name = $"Pickled {item.Name}", - Price = 50 + item.Price * 2 - }; - pickled.preserve.Value = SObject.PreserveType.Pickle; - pickled.preservedParentSheetIndex.Value = item.ParentSheetIndex; - return pickled; - }); - } + // ring + else if (id != 801 && fields?.Length >= 4 && fields[3] == "Ring") // 801 = wedding ring, which isn't an equippable ring + yield return this.TryCreate(ItemType.Ring, id, () => new Ring(id)); - // flower honey - else if (item.Category == SObject.flowersCategory) + // item + else { - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () => + // spawn main item + SObject item = null; + yield return this.TryCreate(ItemType.Object, id, () => { - SObject honey = new SObject(Vector2.Zero, 340, $"{item.Name} Honey", false, true, false, false) - { - Name = $"{item.Name} Honey", - preservedParentSheetIndex = { item.ParentSheetIndex } - }; - honey.Price += item.Price * 2; - return honey; + return item = (id == 812 // roe + ? new ColoredObject(id, 1, Color.White) + : new SObject(id, 1) + ); }); - } + if (item == null) + continue; - // roe and aged roe (derived from FishPond.GetFishProduce) - else if (id == 812) - { - foreach (var pair in Game1.objectInformation) + // flavored items + switch (item.Category) { - // get input - SObject input = new SObject(pair.Key, 1); - if (input.Category != SObject.FishCategory) - continue; - Color color = TailoringMenu.GetDyeColor(input) ?? Color.Orange; - - // yield roe - SObject roe = new ColoredObject(812, 1, color) - { - name = $"{input.Name} Roe", - preserve = { Value = SObject.PreserveType.Roe }, - preservedParentSheetIndex = { Value = input.ParentSheetIndex } - }; - roe.Price += input.Price / 2; - yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 6 + 1, roe); - - // aged roe - if (pair.Key != 698) // aged sturgeon roe is caviar, which is a separate item - { - ColoredObject agedRoe = new ColoredObject(447, 1, color) + // fruit products + case SObject.FruitsCategory: + // wine + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + id, () => new SObject(348, 1) + { + Name = $"{item.Name} Wine", + Price = item.Price * 3, + preserve = { SObject.PreserveType.Wine }, + preservedParentSheetIndex = { item.ParentSheetIndex } + }); + + // jelly + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 3 + id, () => new SObject(344, 1) + { + Name = $"{item.Name} Jelly", + Price = 50 + item.Price * 2, + preserve = { SObject.PreserveType.Jelly }, + preservedParentSheetIndex = { item.ParentSheetIndex } + }); + break; + + // vegetable products + case SObject.VegetableCategory: + // juice + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 4 + id, () => new SObject(350, 1) + { + Name = $"{item.Name} Juice", + Price = (int)(item.Price * 2.25d), + preserve = { SObject.PreserveType.Juice }, + preservedParentSheetIndex = { item.ParentSheetIndex } + }); + + // pickled + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () => new SObject(342, 1) + { + Name = $"Pickled {item.Name}", + Price = 50 + item.Price * 2, + preserve = { SObject.PreserveType.Pickle }, + preservedParentSheetIndex = { item.ParentSheetIndex } + }); + break; + + // flower honey + case SObject.flowersCategory: + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () => + { + SObject honey = new SObject(Vector2.Zero, 340, $"{item.Name} Honey", false, true, false, false) + { + Name = $"{item.Name} Honey", + preservedParentSheetIndex = { item.ParentSheetIndex } + }; + honey.Price += item.Price * 2; + return honey; + }); + break; + + // roe and aged roe (derived from FishPond.GetFishProduce) + case SObject.sellAtFishShopCategory when id == 812: + foreach (var pair in Game1.objectInformation) { - name = $"Aged {input.Name} Roe", - Category = -27, - preserve = { Value = SObject.PreserveType.AgedRoe }, - preservedParentSheetIndex = { Value = input.ParentSheetIndex }, - Price = roe.Price * 2 - }; - yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 6 + 1, agedRoe); - } + // get input + SObject input = this.TryCreate(ItemType.Object, -1, () => new SObject(pair.Key, 1))?.Item as SObject; + if (input == null || input.Category != SObject.FishCategory) + continue; + Color color = TailoringMenu.GetDyeColor(input) ?? Color.Orange; + + // yield roe + SObject roe = null; + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + id, () => + { + roe = new ColoredObject(812, 1, color) + { + name = $"{input.Name} Roe", + preserve = { Value = SObject.PreserveType.Roe }, + preservedParentSheetIndex = { Value = input.ParentSheetIndex } + }; + roe.Price += input.Price / 2; + return roe; + }); + + // aged roe + if (roe != null && pair.Key != 698) // aged sturgeon roe is caviar, which is a separate item + { + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + id, () => new ColoredObject(447, 1, color) + { + name = $"Aged {input.Name} Roe", + Category = -27, + preserve = { Value = SObject.PreserveType.AgedRoe }, + preservedParentSheetIndex = { Value = input.ParentSheetIndex }, + Price = roe.Price * 2 + }); + } + } + break; } } } |