Exemple #1
0
        public float CalculateFinalValue()
        {
            float finalValue         = baseValue;
            float sumPercentAdd      = 0;
            CharacterStatModifer mod = null;

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

                switch (mod.Type)
                {
                case StatModType.Flat:
                    finalValue += mod.Value;
                    break;

                case StatModType.PercentAdd:
                    sumPercentAdd += mod.Value;

                    if (i + 1 >= statModifiers.Count || statModifiers[i + 1].Type != StatModType.PercentAdd)
                    {
                        finalValue   *= 1 + sumPercentAdd;
                        sumPercentAdd = 0;
                    }
                    break;

                case StatModType.PercentMult:
                {
                    finalValue *= 1 + mod.Value;
                }
                break;
                }
            }
            return((float)Math.Round(finalValue, 4));
        }
Exemple #2
0
 public bool RemoveModifier(CharacterStatModifer mod)
 {
     if (statModifiers.Remove(mod))
     {
         isDirty = true;
         return(true);
     }
     return(false);
 }
Exemple #3
0
 protected int CompareModifierOrder(CharacterStatModifer a, CharacterStatModifer b)
 {
     if (a.Order < b.Order)
     {
         return(-1);
     }
     else if (a.Order > b.Order)
     {
         return(1);
     }
     return(0);
 }
Exemple #4
0
 public void AddModifier(CharacterStatModifer mod)
 {
     isDirty = true;
     statModifiers.Add(mod);
     statModifiers.Sort(CompareModifierOrder);
 }