Ejemplo n.º 1
0
        public static bool CanRemoveCurrency(CurrencyDefinition currency, float amount, bool allowCurrencyConversion)
        {
            if (amount <= 0f)
            {
                return(true);
            }

            return(CanRemoveCurrency(currency.ID, amount, allowCurrencyConversion));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert this currency to the amount given ID.
        /// </summary>
        /// <param name="currencyID"></param>
        /// <returns></returns>
        public float ConvertTo(float amount, CurrencyDefinition currency)
        {
            foreach (var conversion in currencyConversions)
            {
                if (conversion.currency == currency)
                {
                    return(amount * conversion.factor);
                }
            }

            Debug.LogWarning("Conversion not possible no conversion found with: " + currency);
            return(0.0f);
        }
 public CurrencyDecorator(CurrencyDefinition currency, float startAmount)
 {
     this.currency = currency;
     _amount       = startAmount;
 }
 public CurrencyDecorator(CurrencyDefinition currency)
     : this(currency, 0)
 {
 }
        /// <summary>
        /// Grab the total factor of converting from a currency to another.
        /// For example copper to silver = 0.01 > silver to gold = 0.01 * 0.01 = 0.0001
        /// </summary>
        /// <returns></returns>
        private float _GetConversionFactor(Dictionary <CurrencyDefinition, float> dict, CurrencyDefinition fromCurrency, float factor)
        {
            foreach (var lookup in parentGroup.lookups)
            {
                // Find currency that converts to our current currency.
                var convertToCurrent = lookup.currency.currencyConversions.FirstOrDefault(o => o.currency == fromCurrency && o.useInAutoConversion);
                if (convertToCurrent != null)
                {
                    if (dict.ContainsKey(lookup.currency))
                    {
                        //Debug.Log("need update?  factor: " + factor + " convertToCurrent factor: " + convertToCurrent.factor + " at " + lookup.currency.pluralName);
                    }
                    else
                    {
                        // One conversion higher
                        factor /= convertToCurrent.factor; // Division because we're going the other way...

                        dict.Add(lookup.currency, factor);
                        return(_GetConversionFactor(dict, lookup.currency, factor));
                    }
                }
            }


            return(factor);
        }
Ejemplo n.º 6
0
 public static bool AddCurrency(CurrencyDefinition currency, float amount)
 {
     return(AddCurrency(currency.ID, amount));
 }
 public CurrencyDecoratorSerializationModel(CurrencyDefinition currency, float amount)
     : this(currency.ID, amount)
 {
 }
 public CurrencyDecorator GetCurrency(CurrencyDefinition currency)
 {
     return(lookups.FirstOrDefault(o => o.currency == currency));
 }