Skip to content

Instantly share code, notes, and snippets.

@Kryzarel
Created November 30, 2017 20:31
Show Gist options
  • Save Kryzarel/5f3a6e0b4ce934fdf09d652b36d46357 to your computer and use it in GitHub Desktop.
Save Kryzarel/5f3a6e0b4ce934fdf09d652b36d46357 to your computer and use it in GitHub Desktop.
Changed CalculateFinalValue() to deal with Flat and Percent modifiers
private float CalculateFinalValue()
{
float finalValue = BaseValue;
for (int i = 0; i < statModifiers.Count; i++)
{
StatModifier mod = statModifiers[i];
if (mod.Type == StatModType.Flat)
{
finalValue += mod.Value;
}
else if (mod.Type == StatModType.Percent)
{
finalValue *= 1 + mod.Value;
}
}
// Rounding gets around float calculation errors (like getting 12.0001f, instead of 12f)
// 4 digits is usually precise enough, but feel free to change this to fit your needs
return (float)Math.Round(finalValue, 4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment