//////////////// private VendorLogic(int npcType) { this.NpcType = npcType; this.TotalPurchases = new Dictionary <int, float>(); this.TotalSpendings = new Dictionary <int, float>(); this.BasePrices = new Dictionary <int, long>(); Chest shop = NPCTownHelpers.GetShop(this.NpcType); ISet <int> foundTypes = new HashSet <int>(); for (int i = 0; i < shop.item.Length; i++) { Item item = shop.item[i]; if (item == null || item.type == 0) { break; } if (foundTypes.Contains(item.type)) { continue; } foundTypes.Add(item.type); item.SetDefaults(item.type); this.BasePrices[item.type] = item.value; this.TotalPurchases[item.type] = 0; this.TotalSpendings[item.type] = 0; } }
//////////////// public static VendorLogic Create(int npcType) { Chest shop = NPCTownHelpers.GetShop(npcType); if (shop == null) { return(null); } return(new VendorLogic(npcType)); }
//////////////// public void UpdateShop(Chest shop = null) { if (shop == null) { shop = NPCTownHelpers.GetShop(this.NpcType); if (shop == null) { return; } } ISet <int> foundTypes = new HashSet <int>(); for (int i = 0; i < shop.item.Length; i++) { Item item = shop.item[i]; if (item == null || item.type <= 0 || item.stack <= 0) { break; } // Update only the first instance of an item if (foundTypes.Contains(item.type)) { continue; } foundTypes.Add(item.type); int value = this.UpdateShopItem(item, shop); double basePrice = (double)this.BasePrices[item.type]; double markup = ((double)value - basePrice) / basePrice; item.value = value; var itemInfo = item.GetGlobalItem <CapitalismItemInfo>(); itemInfo.MarkupPercentPlus = markup; } }