public int Calculate() { float defaultValue = 1f; additiveMultipliers = additiveMultipliers != null ? additiveMultipliers : new float[0]; multiplicativeMultipliers = multiplicativeMultipliers != null ? multiplicativeMultipliers : new float[0]; // Apply elemental multiplier Array.Resize(ref multiplicativeMultipliers, multiplicativeMultipliers.Length + 1); multiplicativeMultipliers[multiplicativeMultipliers.Length - 1] = element.Against(receiver.Element); float add = additiveMultipliers.DefaultIfEmpty(defaultValue).Sum(); float mult = multiplicativeMultipliers.DefaultIfEmpty(defaultValue).Aggregate((i, j) => i * j); float final = add * mult; int damage = Mathf.CeilToInt(baseDamage * final); // Debug.Log($"Additive Multipliers: {{ {string.Join(", ", _additiveMultipliers)} }}"); // Debug.Log($"Multiplicative Multipliers: {{ {string.Join(", ", _multiplicativeMultipliers)} }}"); // Debug.Log($"Calculated Damage Results = Add: {add} | Mult: {mult} | Final: {final} | Base: {damageDealer.Damage.Value} | Damage: {damage}"); return(damage); }
public CombatCalculator(IDamageDealer _applier, IDamageable _receiver, IElement _element, ICriticalModifier _critModifier, int _base, float _variance, float[] _additiveMultipliers = null, float[] _multiplicativeMultipliers = null) { this.applier = _applier; this.receiver = _receiver; this.element = _element; this.baseDamage = _base; this.variance = _variance; this.additiveMultipliers = _additiveMultipliers != null ? _additiveMultipliers : new float[0]; this.multiplicativeMultipliers = _multiplicativeMultipliers != null ? _multiplicativeMultipliers : new float[0]; // Apply elemental multiplier Array.Resize(ref this.multiplicativeMultipliers, this.multiplicativeMultipliers.Length + 1); this.multiplicativeMultipliers[this.multiplicativeMultipliers.Length - 1] = element.Against(receiver.Element); CriticalHitModifier = _critModifier; CriticalHitModifier.OnCriticalHit += applier.OnCriticalHitCallback; }