diff --git a/MrBigsock/Assets/Code/Core/AttackStats.cs b/MrBigsock/Assets/Code/Core/AttackStats.cs index 3d6a2db50e841e376898cf816a1a0614d18c8aa7..74fd330d62c9e734baa79132991dfdec1723657a 100644 --- a/MrBigsock/Assets/Code/Core/AttackStats.cs +++ b/MrBigsock/Assets/Code/Core/AttackStats.cs @@ -81,9 +81,19 @@ namespace BigSock { /* Calculates the final attack stats. (Takes crit and damage spread and calculates the final values) + Cannot calculate a calculated attack. */ - public IAttackStats Calculate() { - IsCalculated = true; + public IAttackStats Calculate(ICharacterStats char = null) { + // Check that this attack hasn't been calculated already. + if(IsCalculated) throw new InvalidOperationException("This attack has already been calculated!"); + + // Creates return object. + AttackStats res; + if(char != null) res = (AttackStats) this.Apply(char); + else res = Clone(); + + // Mark the calculated attack as calculated. + res.IsCalculated = true; // Calculate damage variety. var mod = (1-DamageVariance) + RND.NextDouble() * DamageVariance * 2; @@ -95,8 +105,30 @@ namespace BigSock { IsCrit = true; } - return this; + return res; } + + /* + Creates a clone of this object. + */ + public static AttackStats Clone() { + return new AttackStats{ + Damage = Damage, + Knockback = Knockback, + Range = Range, + ProjectileSpeed = ProjectileSpeed, + AttackSpeed = AttackSpeed, + CritChance = CritChance, + CritDamageModifier = CritDamageModifier, + + Source = Source, + Actor = Actor, + + DamageVariance = DamageVariance, + IsCalculated = IsCalculated, + IsCrit = IsCrit, + }; + } } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/IAttackStats.cs b/MrBigsock/Assets/Code/Core/IAttackStats.cs index 27936bc5eea426af00f3d41c370fb1a86b3b74bb..c35a50e6934f50ed21f2e8b61eb79c7dcc03ace9 100644 --- a/MrBigsock/Assets/Code/Core/IAttackStats.cs +++ b/MrBigsock/Assets/Code/Core/IAttackStats.cs @@ -79,7 +79,7 @@ namespace BigSock { Calculates the final attack stats. (Takes crit and damage spread and calculates the final values) */ - IAttackStats Calculate(); + IAttackStats Calculate(ICharacterStats char = null); }