示例#1
0
        public bool HasSufficientFunds()
        {
            if (!isBuyingMode)
            {
                return(true);
            }
            Purse purse = currentShopper.GetComponent <Purse>();

            if (purse == null)
            {
                return(false);
            }

            return(purse.GetBalance() >= TransactionTotal());
        }
示例#2
0
        private void BuyItem(Inventory shopperInventory, Purse shopperPurse, InventoryItem item, float price)
        {
            if (shopperPurse.GetBalance() < price)
            {
                return;
            }

            bool success = shopperInventory.AddToFirstEmptySlot(item, 1);

            if (success)
            {
                AddToTransaction(item, -1);
                if (!stockSold.ContainsKey(item))
                {
                    stockSold[item] = 0;
                }
                stockSold[item]++;
                shopperPurse.UpdateBalance(-price);
            }
        }
示例#3
0
        public void ConfirmTransaction()
        {
            Inventory shopperInventory = currentShopper.GetComponent <Inventory>();
            Purse     shopperPurse     = currentShopper.GetComponent <Purse>();

            if (shopperInventory == null || shopperPurse == null)
            {
                return;
            }

            // Transfer to or from the inventory
            foreach (ShopItem shopItem in GetAllItems())
            {
                InventoryItem item     = shopItem.GetInventoryItem();
                int           quantity = shopItem.GetQuantityInTransaction();
                float         price    = shopItem.GetPrice();
                for (int i = 0; i < quantity; i++)
                {
                    if (shopperPurse.GetBalance() < price)
                    {
                        break;
                    }

                    bool success = shopperInventory.AddToFirstEmptySlot(item, 1);
                    if (success)
                    {
                        AddToTransaction(item, -1);
                        stock[item]--;
                        shopperPurse.UpdateBalance(-price);
                    }
                }
            }
            // Removal from transaction
            // Debting or Crediting of funds

            if (onChange != null)
            {
                onChange();
            }
        }
示例#4
0
文件: PurseUI.cs 项目: ssshammi/RPG
 private void RefreshUI()
 {
     balanceField.text = $"${playerPurse.GetBalance():N2}";
 }