public bool SetValue(int newTypedValue, int coinItemType)
        {
            if (newTypedValue < 0 || newTypedValue >= 100)
            {
                return(false);
            }

            long value = this.OfferTotal;

            switch (coinItemType)
            {
            case ItemID.PlatinumCoin:
                value %= 1000000L;
                value += (long)newTypedValue * 1000000L;
                break;

            case ItemID.GoldCoin:
                long plats = this.OfferTotal / 1000000L;
                value %= 10000;
                value += (long)newTypedValue * 10000;
                value += plats * 1000000L;
                break;

            case ItemID.SilverCoin:
                long golds = this.OfferTotal / 10000L;
                value %= 100;
                value += (long)newTypedValue * 100L;
                value += golds * 10000L;
                break;

            case ItemID.CopperCoin:
                long silvs = this.OfferTotal / 100L;
                value += (long)newTypedValue;
                value += silvs * 100L;
                break;

            default:
                return(false);
            }

            long max = PlayerItemHelpers.CountMoney(Main.LocalPlayer, false);

            if (value > max)
            {
                return(false);
            }

            this.OfferTotal = value;

            return(true);
        }
        ////////////////

        public override void Update(GameTime gameTime)
        {
            if (!this.IsOpen)
            {
                return;
            }

            base.Update(gameTime);

            long money = PlayerItemHelpers.CountMoney(Main.LocalPlayer, false);

            if (this.OfferTotal > money)
            {
                this.Reset();
                Main.NewText("Don't be tryin t' pull a fast one, matey!", Color.Yellow);
            }
        }
示例#3
0
        public void Update(Player player)
        {
            if (!this.IsReady(player))
            {
                CapitalismLogic.IsDay = Main.dayTime;
                return;
            }

            var mymod = CapitalismMod.Instance;

            if (player.talkNPC != -1)
            {
                long money = PlayerItemHelpers.CountMoney(player, false);
                long spent = this.LastMoney - money;

                this.LastMoney = money;

                if (spent > 0)
                {
                    this.LastBuyItem = this.AccountForPurchase(player, spent, this.LastBuyItem);
                }
                else if (spent < 0)
                {
                    this.AccountForSale(player, -spent);
                }
                else
                {
                    this.LastBuyItem = null;
                }

                // Snapshot current inventory
                int len = player.inventory.Length;
                for (int i = 0; i < len; i++)
                {
                    Item item = player.inventory[i];
                    if (item != null)
                    {
                        this.PrevInventoryInfos[i] = new KeyValuePair <int, int>(item.type, item.stack);
                    }
                    else
                    {
                        this.PrevInventoryInfos[i] = new KeyValuePair <int, int>(0, 0);
                    }
                }

                if (Main.mouseItem != null)
                {
                    this.PrevMouseInfo = new KeyValuePair <int, int>(Main.mouseItem.type, Main.mouseItem.stack);
                }
                else
                {
                    this.PrevMouseInfo = new KeyValuePair <int, int>(0, 0);
                }
            }

            // Advance day
            if (CapitalismLogic.IsDay != Main.dayTime)
            {
                CapitalismLogic.IsDay = Main.dayTime;

                this.DecayAllVendorPrices(player);
            }
        }