/// <summary> /// Adds a stat modifier /// </summary> /// <param name="statModType">The type of stat modifier to add</param> /// <param name="amount">The flat Amount the stat is modified by</param> /// <param name="percentage">The amount in percentage the stat should be modified by</param> public void AddModifier(StatModTypes statModType, int amount, float percentage) { if (StatsModified.ContainsKey(statModType)) { StatsModified[statModType].Add(new StatMod(amount, percentage)); } else { StatsModified.Add(statModType, new List <StatMod>() { new StatMod(amount, percentage) }); } TotalStats[statModType].Amount += amount; TotalStats[statModType].Percentage += percentage; }
/// <summary> /// Returns the sum of all percent modifiers affecting a particular stat /// </summary> /// <param name="statModType">The type of stat modifier to retrieve the percentage for</param> /// <returns>The total value of the percent modifiers affecting the stat. The base value is 1</returns> public float SumPercentModifier(StatModTypes statModType) { float percentage = 1f; if (StatsModified.ContainsKey(statModType)) { List <StatMod> modifiers = StatsModified[statModType]; for (int i = 0; i < modifiers.Count; i++) { //Percentages are stacked additively percentage += modifiers[i].Percentage; } } return(percentage); }
/// <summary> /// Returns the sum of all flat Amount modifiers affecting a particular stat /// </summary> /// <param name="statModType">The type of stat modifier to retrieve the Amount for</param> /// <returns>The total value of the Amount modifiers affecting the stat. The base value is 0</returns> public int SumAmountModifier(StatModTypes statModType) { int amount = 0; //Check if the key exists if (StatsModified.ContainsKey(statModType)) { List <StatMod> modifiers = StatsModified[statModType]; //Simply add all the values together for (int i = 0; i < modifiers.Count; i++) { amount += modifiers[i].Amount; } } return(amount); }
/// <summary> /// Removes a modifier with a designated percentage /// </summary> /// <param name="statModType">The type of the StatModifier</param> /// <param name="amount">The percentage corresponding to a particular StatMod</param> /// <returns>Whether the modifier was successfully found and removed or not</returns> public bool RemoveModifierWithPercentage(StatModTypes statModType, float percentage) { if (StatsModified.ContainsKey(statModType)) { List <StatMod> statMods = StatsModified[statModType]; for (int i = 0; i < statMods.Count; i++) { if (statMods[i].Percentage == percentage) { TotalStats[statModType].Percentage -= percentage; TotalStats[statModType].Amount -= statMods[i].Amount; statMods.RemoveAt(i); //Debug.Log($"Removed StatMod of type {statModType} with Percentage {percentage}!"); return(true); } } } Debug.Log($"Cannot find StatMod of type {statModType} with Percentage {percentage}"); return(false); }
/// <summary> /// Gets the value of all percent modifiers affecting a particular stat. This method is in O(1) time /// </summary> /// <param name="statModType">The type of stat modifier to retrieve the percentage for</param> /// <returns>The total value of the percent modifiers affecting the stat. The base value is 1</returns> public float GetModifierPercent(StatModTypes statModType) { return(TotalStats[statModType].Percentage); }
/// <summary> /// Gets the value of all flat Amount modifiers affecting a particular stat. This method is in O(1) time /// </summary> /// <param name="statModType">The type of stat modifier to retrieve the Amount for</param> /// <returns>The total value of the amount modifiers affecting the stat. The base value is 0</returns> public int GetModifierAmount(StatModTypes statModType) { return(TotalStats[statModType].Amount); }