コード例 #1
0
ファイル: QI_Vendor.cs プロジェクト: burningman2k20/SpaceRPG
 /// <summary>
 /// Adds currency to a stash.
 /// </summary>
 /// <param name="name">The name of the currency.</param>
 /// <param name="amount">The amount to add.</param>
 public void AddCurrency(string name, float amount)
 {
     if (Currencies.ContainsKey(name))
     {
         QI_CurrencyStash stash = Currencies[name];
         stash.Amount    += amount;
         Currencies[name] = stash;
     }
 }
コード例 #2
0
ファイル: QI_Vendor.cs プロジェクト: burningman2k20/SpaceRPG
 /// <summary>
 /// Removes currency from a stash.
 /// </summary>
 /// <param name="name">The name of the currency.</param>
 /// <param name="amount">The amount to remove.</param>
 public void RemoveCurrency(string name, float amount)
 {
     if (Currencies.ContainsKey(name))
     {
         QI_CurrencyStash stash = Currencies[name];
         stash.Amount     = Mathf.Clamp(stash.Amount - amount, 0, stash.Amount + amount);
         Currencies[name] = stash;
     }
 }
コード例 #3
0
ファイル: QI_Vendor.cs プロジェクト: burningman2k20/SpaceRPG
        /// <summary>
        /// Adds currency to a stash, adding a new stash if it doesn't exist.
        /// </summary>
        /// <param name="currency">The currency to add.</param>
        /// <param name="amount">The amount to add.</param>
        public void AddCurrency(QI_Currency currency, float amount)
        {
            if (!Currencies.ContainsKey(currency.Name))
            {
                Currencies.Add(currency.Name, new QI_CurrencyStash {
                    Currency = currency, Amount = 0
                });
            }

            QI_CurrencyStash stash = Currencies[currency.Name];

            stash.Amount += amount;
            Currencies[currency.Name] = stash;
        }
コード例 #4
0
ファイル: QI_Vendor.cs プロジェクト: burningman2k20/SpaceRPG
        /// <summary>
        /// Returns if the vendor buying something was successful.
        /// </summary>
        /// <param name="item">The item to buy.</param>
        /// <param name="currencyName">The name of the currency needed.</param>
        /// <param name="amount">The amount to buy.</param>
        /// <returns></returns>
        public bool Buy(QI_ItemData item, string currencyName, int amount)
        {
            if (!CanBuy(currencyName, item.Price, amount))
            {
                return(false);
            }

            QI_CurrencyStash currency = Currencies[currencyName];

            currency.Amount         -= item.Price * amount;
            Currencies[currencyName] = currency;
            Inventory.AddItem(item, amount);

            return(true);
        }
コード例 #5
0
ファイル: QI_Vendor.cs プロジェクト: burningman2k20/SpaceRPG
        /// <summary>
        /// Returns if the vendor selling something was successful.
        /// </summary>
        /// <param name="item">The item to buy.</param>
        /// <param name="currencyName">The name of the currency gained.</param>
        /// <param name="amount">The amount to sell.</param>
        /// <returns></returns>
        public bool Sell(QI_ItemData item, string currencyName, int amount)
        {
            if (!CanSell(item.Name, amount))
            {
                return(false);
            }

            if (Currencies.ContainsKey(currencyName))
            {
                QI_CurrencyStash currency = Currencies[currencyName];
                currency.Amount         += item.Price * amount;
                Currencies[currencyName] = currency;
            }

            Inventory.RemoveItem(item.Name, amount);

            return(true);
        }