Beispiel #1
0
        public ShopInterface(Vector2 positionAbsolute, ITradeInventory shop, ITradeInventory player)
        {
            _shopInventory    = shop;
            _playerInventory  = player;
            isActive          = true;
            _positionAbsolute = positionAbsolute;


            _buyTab = new TextElement("Buy")
            {
                IsActive = true,
                Position = new Vector2(this.Position.X, this.Position.Y)
            };
            _buyTab.OnClickEvent += SwitchToBuyMenu;

            _sellTab = new TextElement("Sell")
            {
                IsActive = true,
                Position = new Vector2(_buyTab.Position.X + _buyTab.BoundingBox.Width + 20, _buyTab.Position.Y)
            };
            _sellTab.OnClickEvent += SwitchToSellMenu;

            Vector2 listsPosition = new Vector2(_positionAbsolute.X, _positionAbsolute.Y + _buyTab.BoundingBox.Height + 20);

            _tradeViews.Add(TradeType.Buy, new ShopInventroyListView(shop, player, listsPosition, TradeType.Buy));
            _tradeViews.Add(TradeType.Sell, new ShopInventroyListView(player, shop, listsPosition, TradeType.Sell));
        }
        public ShopInventroyListView(ITradeInventory sellerInventoryModel, ITradeInventory buyerInventoryModel, Vector2 positionAbsolute, TradeType tradeType)
            : base(sellerInventoryModel, positionAbsolute)
        {
            _buyerInventoryModel = buyerInventoryModel;

            tradeInterface = new ShopTradeInterface();

            _tradeType = tradeType;

            OnInventoryModelUpdate();
        }
        public void Update(GameTime theTime, GameState state, ITradeInventory buyerInventory)
        {
            Update(theTime, state);

            if (_totalPrice > buyerInventory.Currency)
            {
                priceColor = Color.Red;
            }
            else
            {
                priceColor = Color.White;
            }
        }
Beispiel #4
0
        protected override void Trade(ITradeInventory shop, ITradeInventory customer, ITradeableItem item, int desiredQuantity, float unitPrice)
        {
            int availableQuantity = 0;

            if (shop.Items.Contains(item.InventoryItem))//Only do the trade if the item is in the shop's inventory
            {
                //1. Get the actual available qunatity
                if (item.InventoryItem.Stock >= desiredQuantity)
                {
                    availableQuantity = desiredQuantity;
                }
                else
                {
                    availableQuantity = item.InventoryItem.Stock;
                }
                //2. From the qunatity available, get the amount the buyer can carry
                int quantityBuyerCanCarry = customer.QuantityCanAdd(item.InventoryItem, availableQuantity);

                float totalBuyPrice = unitPrice * quantityBuyerCanCarry;

                int quantityBuyerCanAfford = 0;
                //3. From the amount the buyer can carry, get the amount the buyer can afford
                if (customer.Currency >= totalBuyPrice)
                {
                    quantityBuyerCanAfford = quantityBuyerCanCarry;
                }
                else
                {
                    quantityBuyerCanAfford = (int)(customer.Currency / unitPrice);
                    if (customer.Currency <= 0)
                    {
                        quantityBuyerCanAfford = 0;
                    }
                }

                float actualBuyPrice = unitPrice * quantityBuyerCanAfford;

                if (customer.Currency >= actualBuyPrice && quantityBuyerCanCarry > 0)
                {
                    customer.Currency -= actualBuyPrice;
                    shop.Currency     += actualBuyPrice;
                    InventoryItem buyerItem = item.InventoryItem.SplitStack(quantityBuyerCanAfford);
                    customer.AddItem(buyerItem);
                }
            }
        }
Beispiel #5
0
 public override void Sell(ITradeInventory seller, ITradeInventory buyer, ITradeableItem item, int desiredQuantity)
 {
     Trade(seller, buyer, item, desiredQuantity, item.CustomerSellPrice);
 }
Beispiel #6
0
 public override void Buy(ITradeInventory seller, ITradeInventory buyer, ITradeableItem item, int desiredQuantity)
 {
     //Note: Buy and Sell will both call Trade with different parameters
     //i.e:
     Trade(seller, buyer, item, desiredQuantity, item.CustomerBuyPrice);
 }
Beispiel #7
0
 protected abstract void Trade(ITradeInventory shop, ITradeInventory customer, ITradeableItem item, int desiredQuantity, float unitPrice);
Beispiel #8
0
 public abstract void Sell(ITradeInventory shop, ITradeInventory customer, ITradeableItem item, int desiredQuantity);