Пример #1
0
        protected virtual float CalculateFinalValue()
        {
            float finalValue    = BaseValue;
            float sumPercentAdd = 0;

            for (int i = 0; i < towerModifiers.Count; i++)
            {
                TowerModifier mod = towerModifiers[i];

                if (mod.Type == StatModType.Flat)
                {
                    finalValue += mod.Value;
                }
                else if (mod.Type == StatModType.PercentAdd)
                {
                    sumPercentAdd += mod.Value;
                    if (i + 1 >= towerModifiers.Count || towerModifiers[i + 1].Type != StatModType.PercentAdd)
                    {
                        finalValue   *= 1 + sumPercentAdd;
                        sumPercentAdd = 0;
                    }
                }
                else if (mod.Type == StatModType.PercentMult)
                {
                    finalValue *= 1 + mod.Value;
                }
            }
            return((float)Math.Round(finalValue, 4)); //4 significant digits
        }
Пример #2
0
 public virtual bool RemoveModifier(TowerModifier mod)
 {
     if (towerModifiers.Remove(mod))
     {
         isDirty = true;
         return(isDirty);
     }
     return(false);
 }
Пример #3
0
 protected virtual int CompareModifierOrder(TowerModifier a, TowerModifier b)
 {
     if (a.Order < b.Order)
     {
         return(-1);
     }
     else if (a.Order > b.Order)
     {
         return(1);
     }
     return(0); // if (a.Order == b.Order)
 }
Пример #4
0
 public virtual void AddModifier(TowerModifier mod)
 {
     isDirty = true;
     towerModifiers.Add(mod);
     towerModifiers.Sort(CompareModifierOrder);
 }