update item spawning code, detect ring type automatically to support custom rings, minor refactor

This commit is contained in:
Jesse Plamondon-Willard 2019-12-22 12:04:40 -05:00
parent 05d237400c
commit 139e267aaa
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 129 additions and 131 deletions

View File

@ -8,6 +8,11 @@
* Updated for the 'Force Off' gamepad mode added in Stardew Valley 1.4.1. * 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 Mint 18 (thanks to techge!) and Arch Linux.
* Fixed compatibility with Linux systems which have libhybris-utils installed. * 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. * Internal optimizations.
* Updated translations. Thanks to PlussRolf (added Spanish)! * Updated translations. Thanks to PlussRolf (added Spanish)!

View File

@ -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 + 2, () => new Pan());
yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 3, () => new Wand()); 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 // wallpapers
for (int id = 0; id < 112; id++) for (int id = 0; id < 112; id++)
yield return this.TryCreate(ItemType.Wallpaper, id, () => new Wallpaper(id) { Category = SObject.furnitureCategory }); 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)); yield return this.TryCreate(ItemType.Boots, id, () => new Boots(id));
foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\hats").Keys) foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\hats").Keys)
yield return this.TryCreate(ItemType.Hat, id, () => new Hat(id)); 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 // weapons
foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\weapons").Keys) 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) foreach (int id in Game1.bigCraftablesInformation.Keys)
yield return this.TryCreate(ItemType.BigCraftable, id, () => new SObject(Vector2.Zero, id)); 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 // objects
foreach (int id in Game1.objectInformation.Keys) foreach (int id in Game1.objectInformation.Keys)
{ {
string[] fields = Game1.objectInformation[id]?.Split('/');
// secret notes
if (id == 79) 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 foreach (int secretNoteId in Game1.content.Load<Dictionary<int, string>>("Data\\SecretNotes").Keys)
? new ColoredObject(id, 1, Color.White)
: new SObject(id, 1)
);
yield return main;
item = main?.Item as SObject;
}
if (item == null)
continue;
// fruit products
if (item.Category == SObject.FruitsCategory)
{
// wine
yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + id, () =>
{ {
SObject wine = new SObject(348, 1) yield return this.TryCreate(ItemType.Object, this.CustomIDOffset + secretNoteId, () =>
{ {
Name = $"{item.Name} Wine", SObject note = new SObject(79, 1);
Price = item.Price * 3 note.name = $"{note.name} #{secretNoteId}";
}; return note;
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;
});
} }
// vegetable products // ring
else if (item.Category == SObject.VegetableCategory) 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));
// item
else
{ {
// juice // spawn main item
yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 4 + id, () => SObject item = null;
yield return this.TryCreate(ItemType.Object, id, () =>
{ {
SObject juice = new SObject(350, 1) return item = (id == 812 // roe
{ ? new ColoredObject(id, 1, Color.White)
Name = $"{item.Name} Juice", : new SObject(id, 1)
Price = (int)(item.Price * 2.25d) );
};
juice.preserve.Value = SObject.PreserveType.Juice;
juice.preservedParentSheetIndex.Value = item.ParentSheetIndex;
return juice;
}); });
if (item == null)
continue;
// pickled // flavored items
yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () => switch (item.Category)
{ {
SObject pickled = new SObject(342, 1) // fruit products
{ case SObject.FruitsCategory:
Name = $"Pickled {item.Name}", // wine
Price = 50 + item.Price * 2 yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + id, () => new SObject(348, 1)
};
pickled.preserve.Value = SObject.PreserveType.Pickle;
pickled.preservedParentSheetIndex.Value = item.ParentSheetIndex;
return pickled;
});
}
// flower honey
else if (item.Category == 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;
});
}
// roe and aged roe (derived from FishPond.GetFishProduce)
else if (id == 812)
{
foreach (var pair in Game1.objectInformation)
{
// 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)
{ {
name = $"Aged {input.Name} Roe", Name = $"{item.Name} Wine",
Category = -27, Price = item.Price * 3,
preserve = { Value = SObject.PreserveType.AgedRoe }, preserve = { SObject.PreserveType.Wine },
preservedParentSheetIndex = { Value = input.ParentSheetIndex }, preservedParentSheetIndex = { item.ParentSheetIndex }
Price = roe.Price * 2 });
};
yield return new SearchableItem(ItemType.Object, this.CustomIDOffset * 6 + 1, agedRoe); // 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)
{
// 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;
} }
} }
} }