diff --git a/MrBigsock/Assets/Code/Core/AttackStats.cs b/MrBigsock/Assets/Code/Core/AttackStats.cs index d2e844c4ef80f755d83b2078913b94de65059227..33259a089d4ef2cec1586263685d711f4234f02f 100644 --- a/MrBigsock/Assets/Code/Core/AttackStats.cs +++ b/MrBigsock/Assets/Code/Core/AttackStats.cs @@ -11,6 +11,8 @@ namespace BigSock { Represents the stats of an attack. */ public class AttackStats : IAttackStats { + public static readonly System.Random RND = new System.Random(); + /* The damage of the attack. */ @@ -36,6 +38,24 @@ namespace BigSock { */ public float AttackSpeed { get; set; } = 1f; + /* + The crit chance of the character. + */ + public float CritChance { get; set; } + + /* + The how much to modify damage by when critting. + */ + public float CritDamageModifier { get; set; } = 1; + + /* + How much the damage can vary in percent. + */ + public float DamageVariance { get; set; } = 0.2; + + + + /* The source of the attack. */ @@ -46,20 +66,35 @@ namespace BigSock { */ public Character Actor { get; set; } + + /* - The crit chance of the character. + Indicates if the attack stats have been calculated. */ - public float CritChance { get; set; } - + public bool IsCalculated { get; set; } + /* - The how much to modify damage by when critting. + Indicates if the attack was a critical hit. */ - public float CritDamageModifier { get; set; } = 1; - + public bool IsCrit { get; set; } + /* - How much the damage can vary in percent. + Calculates the final attack stats. + (Takes crit and damage spread and calculates the final values) */ - public float DamageVariance { get; set; } = 0.2; + public IAttackStats Calculate() { + IsCalculated = true; + + // Calculate damage variety. + var mod = (1-DamageVariance) + RND.NextDouble() * DamageVariance * 2; + Damage *= mod; + + // Check for crits. + if(RND.NextDouble() <= CritChance) { + Damage *= CritDamageModifier; + IsCrit = true; + } + } } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/IAttackStats.cs b/MrBigsock/Assets/Code/Core/IAttackStats.cs index 1105c0211c494f36b4ab02effd2e9096b3d32d39..7b074246aca354491a19a3a592c6761e96455b04 100644 --- a/MrBigsock/Assets/Code/Core/IAttackStats.cs +++ b/MrBigsock/Assets/Code/Core/IAttackStats.cs @@ -36,6 +36,23 @@ namespace BigSock { */ float AttackSpeed { get; } + /* + The crit chance of the character. + */ + float CritChance { get; } + + /* + The how much to modify damage by when critting. + */ + float CritDamageModifier { get; } + + /* + How much the damage can vary in percent. + */ + float DamageVariance { get; } + + + /* The source of the attack. */ @@ -46,20 +63,23 @@ namespace BigSock { */ Character Actor { get; } + + /* - The crit chance of the character. + Indicates if the attack stats have been calculated. */ - float CritChance { get; } - + bool IsCalculated { get; } + /* - The how much to modify damage by when critting. + Indicates if the attack was a critical hit. */ - float CritDamageModifier { get; } - + bool IsCrit { get; } + /* - How much the damage can vary in percent. + Calculates the final attack stats. + (Takes crit and damage spread and calculates the final values) */ - float DamageVariance { get; } + IAttackStats Calculate(); } @@ -79,11 +99,15 @@ namespace BigSock { Range = a.Range * b.Range, ProjectileSpeed = a.ProjectileSpeed, AttackSpeed = a.AttackSpeed * b.AttackSpeed, - Source = a.Source, - Actor = a.Actor, CritChance = a.CritChance * b.CritChance, CritDamageModifier = a.CritDamageModifier * b.CritDamageModifier, + + Source = a.Source, + Actor = a.Actor, + DamageVariance = a.DamageVariance, + IsCalculated = a.IsCalculated, + IsCrit = a.IsCrit, }; } }