Skip to content
Snippets Groups Projects
Commit 86ead76a authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

Added method for calculating final attack values.

- Checks crit and damage variance.
parent 59b3492a
No related branches found
No related tags found
1 merge request!30Improvements to attacks.
......@@ -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
......@@ -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,
};
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment