public static GuardianShop CreateShop(int OwnerID, string OwnerModID) { GuardianShop shop = new GuardianShop { OwnerID = OwnerID, OwnerModID = OwnerModID }; Shops.Add(shop); return(shop); }
public static void SaveShops(Terraria.ModLoader.IO.TagCompound tag) { tag.Add("Shop_Count", Shops.Count); for (int s = 0; s < Shops.Count; s++) { string ShopTag = "Shop_s" + s + ">"; GuardianShop shop = Shops[s]; tag.Add(ShopTag + "OwnerID", shop.OwnerID); tag.Add(ShopTag + "OwnerModID", shop.OwnerModID); tag.Add(ShopTag + "ItemCount", shop.Items.Count); for (int i = 0; i < shop.Items.Count; i++) { string ItemTag = ShopTag + "i" + i + ">"; GuardianShopItem item = shop.Items[i]; bool HasItem = item.ItemID != 0; tag.Add(ItemTag + "hasitem", HasItem); if (HasItem) { Item dummyItem = new Item(); dummyItem.SetDefaults(item.ItemID, true); bool IsModItem = dummyItem.modItem != null; tag.Add(ItemTag + "ismoditem", IsModItem); if (IsModItem) { tag.Add(ItemTag + "itemname", dummyItem.modItem.Name); tag.Add(ItemTag + "itemmodname", dummyItem.modItem.mod.Name); } else { tag.Add(ItemTag + "itemid", item.ItemID); } tag.Add(ItemTag + "saletime", item.SaleTime); tag.Add(ItemTag + "timedsaletime", item.TimedSaleTime); tag.Add(ItemTag + "stack", item.Stack); } } } }
public static void LoadShops(Terraria.ModLoader.IO.TagCompound tag, int ModVersion) { int ShopCount = tag.GetInt("Shop_Count"); for (int s = 0; s < ShopCount; s++) { string ShopTag = "Shop_s" + s + ">"; int OwnerID = tag.GetInt(ShopTag + "OwnerID"); string OwnerModID = tag.GetString(ShopTag + "OwnerModID"); GuardianBase gb = GuardianBase.GetGuardianBase(OwnerID, OwnerModID); GuardianShop shop = GetShop(OwnerID, OwnerModID); if (shop == null) { gb.SetupShop(OwnerID, OwnerModID); shop = GetShop(OwnerID, OwnerModID); } if (shop != null) { int ItemCount = tag.GetInt(ShopTag + "ItemCount"); for (int i = 0; i < ItemCount; i++) { string ItemTag = ShopTag + "i" + i + ">"; if (tag.GetBool(ItemTag + "hasitem")) { bool IsModItem = tag.GetBool(ItemTag + "ismoditem"); string ItemInternalName = null, ItemModInternalName = null; int ItemID = 0; if (IsModItem) { ItemInternalName = tag.GetString(ItemTag + "itemname"); ItemModInternalName = tag.GetString(ItemTag + "itemmodname"); } else { ItemID = tag.GetInt(ItemTag + "itemid"); } foreach (GuardianShopItem item in shop.Items) { if (item.ItemID == 0) { continue; } if (ItemInternalName != null) { Item anotheritem = new Item(); anotheritem.SetDefaults(item.ItemID, true); if (anotheritem.modItem == null || anotheritem.modItem.Name != ItemInternalName || anotheritem.modItem.mod.Name != ItemModInternalName) { continue; } } else if (ItemID != item.ItemID) { continue; } item.SaleTime = tag.GetInt(ItemTag + "saletime"); item.TimedSaleTime = tag.GetInt(ItemTag + "timedsaletime"); item.Stack = tag.GetInt(ItemTag + "stack"); break; } } } } } }