コード例 #1
0
        ////////////////

        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;
            }
        }
コード例 #2
0
        ////////////////

        public static VendorLogic Create(int npcType)
        {
            Chest shop = NPCTownHelpers.GetShop(npcType);

            if (shop == null)
            {
                return(null);
            }

            return(new VendorLogic(npcType));
        }
コード例 #3
0
        ////////////////

        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;
            }
        }