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

Misc fixes

parent 49e28f58
No related branches found
No related tags found
1 merge request!30Improvements to attacks.
...@@ -166,6 +166,9 @@ namespace BigSock { ...@@ -166,6 +166,9 @@ namespace BigSock {
Adds damage to the character if they don't have IFrames. Adds damage to the character if they don't have IFrames.
*/ */
public virtual bool TakeDamage(AttackStats attack) { public virtual bool TakeDamage(AttackStats attack) {
if(attack == null) throw new ArgumentNullException(nameof(attack));
if(!attack.IsCalculated) throw new ArgumentException("Attack needs to be calculated.", nameof(attack));
// Check if player has IFrames // Check if player has IFrames
if(NextTimeCanTakeDamage > DateTime.Now) if(NextTimeCanTakeDamage > DateTime.Now)
return false; return false;
...@@ -243,7 +246,7 @@ namespace BigSock { ...@@ -243,7 +246,7 @@ namespace BigSock {
Method for what to do when the character takes damage. Method for what to do when the character takes damage.
*/ */
protected virtual void AfterDamage(IAttackStats attack) { protected virtual void AfterDamage(IAttackStats attack) {
print($"[Character.AfterDamage()] {HP + attack.Damage:N1} - {attack.Damage:N1} = {HP:N1}"); print($"[Character.AfterDamage()] {HP + attack.Damage:N1} - {attack.Damage:N1} = {HP:N1} {(attack.IsCrit ? "[CRIT]":"")}");
KnockBack(attack); KnockBack(attack);
} }
......
...@@ -51,7 +51,7 @@ namespace BigSock { ...@@ -51,7 +51,7 @@ namespace BigSock {
/* /*
How much the damage can vary in percent. How much the damage can vary in percent.
*/ */
public float DamageVariance { get; set; } = 0.2; public float DamageVariance { get; set; } = 0.2f;
...@@ -83,21 +83,21 @@ namespace BigSock { ...@@ -83,21 +83,21 @@ namespace BigSock {
(Takes crit and damage spread and calculates the final values) (Takes crit and damage spread and calculates the final values)
Cannot calculate a calculated attack. Cannot calculate a calculated attack.
*/ */
public IAttackStats Calculate(ICharacterStats char = null) { public IAttackStats Calculate(ICharacterStats charStats = null) {
// Check that this attack hasn't been calculated already. // Check that this attack hasn't been calculated already.
if(IsCalculated) throw new InvalidOperationException("This attack has already been calculated!"); if(IsCalculated) throw new InvalidOperationException("This attack has already been calculated!");
// Creates return object. // Creates return object.
AttackStats res; AttackStats res;
if(char != null) res = (AttackStats) this.Apply(char); if(charStats != null) res = (AttackStats) this.Apply(charStats);
else res = Clone(); else res = Clone();
// Mark the calculated attack as calculated. // Mark the calculated attack as calculated.
res.IsCalculated = true; res.IsCalculated = true;
// Calculate damage variety. // Calculate damage variety.
var mod = (1-DamageVariance) + RND.NextDouble() * DamageVariance * 2; var mod = (1-DamageVariance) + RND.NextDouble() * DamageVariance * 2;
Damage *= mod; Damage *= (float) mod;
// Check for crits. // Check for crits.
if(RND.NextDouble() <= CritChance) { if(RND.NextDouble() <= CritChance) {
...@@ -112,7 +112,7 @@ namespace BigSock { ...@@ -112,7 +112,7 @@ namespace BigSock {
/* /*
Creates a clone of this object. Creates a clone of this object.
*/ */
public static AttackStats Clone() { public AttackStats Clone() {
return new AttackStats{ return new AttackStats{
Damage = Damage, Damage = Damage,
Knockback = Knockback, Knockback = Knockback,
......
...@@ -79,7 +79,7 @@ namespace BigSock { ...@@ -79,7 +79,7 @@ namespace BigSock {
Calculates the final attack stats. Calculates the final attack stats.
(Takes crit and damage spread and calculates the final values) (Takes crit and damage spread and calculates the final values)
*/ */
IAttackStats Calculate(ICharacterStats char = null); IAttackStats Calculate(ICharacterStats charStats = null);
} }
......
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