Created
November 30, 2017 20:31
-
-
Save Kryzarel/5f3a6e0b4ce934fdf09d652b36d46357 to your computer and use it in GitHub Desktop.
Changed CalculateFinalValue() to deal with Flat and Percent modifiers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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