public void Sell(ITradeableItem item, int desiredQuantity)
 {
     if (_inventoryModel is ITradeInventory)
     {
         tradeInterface.Sell((_inventoryModel as ITradeInventory), _buyerInventoryModel, item, desiredQuantity);
     }
 }
Ejemplo n.º 2
0
 public override void Sell(ITradeInventory seller, ITradeInventory buyer, ITradeableItem item, int desiredQuantity)
 {
     Trade(seller, buyer, item, desiredQuantity, item.CustomerSellPrice);
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 5
0
 protected abstract void Trade(ITradeInventory shop, ITradeInventory customer, ITradeableItem item, int desiredQuantity, float unitPrice);
Ejemplo n.º 6
0
 public abstract void Sell(ITradeInventory shop, ITradeInventory customer, ITradeableItem item, int desiredQuantity);