Пример #1
0
 /// <summary>
 /// Search by currency type a currency stored in the backpack.
 /// </summary>
 /// <param name="type">The type of currency that will be searched within the backapck.</param>
 /// <returns>Returns the currency if found, null if not.</returns>
 public StackableItem GetCurrency(Currency.Type currencyType)
 {
     foreach (StackableItem stackedItem in items)
     {
         if (stackedItem.item.GetType() == typeof(Currency))
         {
             Currency c = (Currency)stackedItem.item;
             if (c.type == currencyType)
             {
                 return(stackedItem);
             }
         }
     }
     return(null);
 }
Пример #2
0
        /// <summary>
        /// Gets the amount of the specified currency stored in the backpack.
        /// </summary>
        /// <param name="currencyType">The type of currency that will be searched within the backpack.</param>
        /// <returns>Returns the amount if the item was found, 0 if not.</returns>
        public float GetCurrencyAmount(Currency.Type currencyType)
        {
            float amount = 0;

            foreach (StackableItem stackedItem in items)
            {
                if (stackedItem.item.GetType() == typeof(Currency))
                {
                    Currency c = (Currency)stackedItem.item;
                    if (c.type == currencyType)
                    {
                        amount += stackedItem.amount;
                    }
                }
            }
            return(amount);
        }
Пример #3
0
        public static void Spend(SDV.Farmer farmer, int amount, Currency.Type currency)
        {
            switch (currency)
            {
            case Currency.Type.Money:
                farmer.Money = Math.Max(0, farmer.Money - amount);
                break;

            case Currency.Type.FestivalScore:
                farmer.festivalScore = Math.Max(0, farmer.festivalScore - amount);
                break;

            case Currency.Type.ClubCoins:
                farmer.clubCoins = Math.Max(0, farmer.clubCoins - amount);
                break;
            }
        }
Пример #4
0
        public static bool CanAfford(SDV.Farmer farmer, int amount, Currency.Type currency = Currency.Type.Money)
        {
            switch (currency)
            {
            case Currency.Type.Money:
                return(farmer.Money >= amount);

            case Currency.Type.FestivalScore:
                return(farmer.festivalScore >= amount);

            case Currency.Type.ClubCoins:
                return(farmer.clubCoins >= amount);

            default:
                return(false);
            }
        }