Class ShopManager
Provides access to all shops in the game and convenience methods for shop integration.
public static class ShopManager
- Inheritance
-
ShopManager
- Inherited Members
Methods
AddToCompatibleShops(ItemDefinition, float?)
Adds an item to all shops that sell items in the same category. This is a convenience method for making custom items available wherever similar items are sold.
public static int AddToCompatibleShops(ItemDefinition item, float? customPrice = null)
Parameters
itemItemDefinitionThe item to add to compatible shops.
customPricefloat?Optional custom price override.
Returns
- int
The number of shops the item was added to.
Examples
var metalRack = ItemManager.GetItemDefinition("metalstoragerack");
int shopsUpdated = ShopManager.AddToCompatibleShops(metalRack);
Logger.Msg($"Added metal rack to {shopsUpdated} shops");
AddToShops(ItemDefinition, float?, params string[])
Adds an item to specific shops by name with a custom price.
public static int AddToShops(ItemDefinition item, float? customPrice, params string[] shopNames)
Parameters
itemItemDefinitionThe item to add.
customPricefloat?Optional custom price override.
shopNamesstring[]Names of shops to add the item to.
Returns
- int
The number of shops the item was added to.
AddToShops(ItemDefinition, params string[])
Adds an item to specific shops by name.
public static int AddToShops(ItemDefinition item, params string[] shopNames)
Parameters
itemItemDefinitionThe item to add.
shopNamesstring[]Names of shops to add the item to.
Returns
- int
The number of shops the item was added to.
Examples
ShopManager.AddToShops(myItem, "Hardware Store", "General Store");
FindShopsByCategory(ItemCategory)
Finds all shops that sell items in the specified category.
public static Shop[] FindShopsByCategory(ItemCategory category)
Parameters
categoryItemCategoryThe item category to search for.
Returns
- Shop[]
Array of shops that sell items in this category.
Examples
// Find all shops that sell tools
var toolShops = ShopManager.FindShopsByCategory(ItemCategory.Tools);
FindShopsByItem(string)
Finds all shops that sell a specific item.
public static Shop[] FindShopsByItem(string itemId)
Parameters
itemIdstringThe ID of the item to search for.
Returns
- Shop[]
Array of shops that sell this item.
GetAllShops()
Gets all shops currently loaded in the game. Results are cached until the scene changes.
public static Shop[] GetAllShops()
Returns
- Shop[]
Array of all available shops.
GetShopByName(string)
Gets a shop by its display name (case-insensitive).
public static Shop GetShopByName(string shopName)
Parameters
shopNamestringThe name of the shop to find.
Returns
- Shop
The shop if found, null otherwise.
Examples
var hardwareStore = ShopManager.GetShopByName("Hardware Store");
if (hardwareStore != null)
{
hardwareStore.AddItem(myCustomItem);
}
RefreshItemIcon(ItemDefinition)
Refreshes the icon displayed in shop listings for the specified item. This is useful when an item's icon is generated or updated after it has been added to shops.
public static int RefreshItemIcon(ItemDefinition item)
Parameters
itemItemDefinitionThe item whose icon should be refreshed in shop listings.
Returns
- int
The number of shop listings that were updated.
Examples
// After generating a custom icon for an item
myItem.Icon = generatedSprite;
int updated = ShopManager.RefreshItemIcon(myItem);
Logger.Msg($"Updated icon in {updated} shop listing(s)");
RefreshItemIcon(string)
Refreshes the icon displayed in shop listings for the specified item by ID. This is useful when an item's icon is generated or updated after it has been added to shops.
public static int RefreshItemIcon(string itemId)
Parameters
itemIdstringThe ID of the item whose icon should be refreshed.
Returns
- int
The number of shop listings that were updated.