Last active
November 30, 2017 19:31
-
-
Save Kryzarel/6f0446f73066503661cdb52d1fc45636 to your computer and use it in GitHub Desktop.
Added: Add(), Remove() and CalculateFinalValue()
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
public float Value { get { return CalculateFinalValue(); } } | |
public void AddModifier(StatModifier mod) | |
{ | |
statModifiers.Add(mod); | |
} | |
public bool RemoveModifier(StatModifier mod) | |
{ | |
return statModifiers.Remove(mod); | |
} | |
private float CalculateFinalValue() | |
{ | |
float finalValue = BaseValue; | |
for (int i = 0; i < statModifiers.Count; i++) | |
{ | |
finalValue += statModifiers[i].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); | |
} |
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
// We also need to add this outside the class curly braces | |
// to be able to use the Math.Round method | |
using System; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment