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)); }
public bool RemoveModifier(CharacterStatModifer mod) { if (statModifiers.Remove(mod)) { isDirty = true; return(true); } return(false); }
protected int CompareModifierOrder(CharacterStatModifer a, CharacterStatModifer b) { if (a.Order < b.Order) { return(-1); } else if (a.Order > b.Order) { return(1); } return(0); }
public void AddModifier(CharacterStatModifer mod) { isDirty = true; statModifiers.Add(mod); statModifiers.Sort(CompareModifierOrder); }