diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 4fcb42cabba858172e22000dfd039ea6fe600404..50524d5e2a4be94e819abcb169ec63f0ff58857d 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -152,7 +152,7 @@ namespace BigSock { } /* - Adds damage to the player if they don't have IFrames. + Adds damage to the character if they don't have IFrames. */ public virtual bool TakeDamage(AttackStats attack) { // Check if player has IFrames @@ -163,25 +163,39 @@ namespace BigSock { NextTimeCanTakeDamage = DateTime.Now + IFrameDuration; // Trigger the event for taking damage. - OnTakeDamage?.Invoke(this, attack?.Actor, attack); + OnTakeDamage?.Invoke(this, attack.Actor, attack); + + // Inform the attacker they hit us. + if(attack.Actor != null) attack.Actor.TargetHit(this, attack); + // Add damage HP -= attack.Damage; AfterDamage(attack); - TryKill(); + TryKill(attack); return true; } /* - Try to kill the player. + Try to kill the character. */ - public bool TryKill() { + public bool TryKill(AttackStats attack) { if(Alive && HP <= 0) { + + + // Trigger the event for us dying. + OnDeath?.Invoke(this, attack.Actor, attack); + + //== PUT CODE HERE TO HANDLE IF WE DODGED DEATH (In case we had an item to revieve or cheat death) + Alive = false; + // Inform the attacker killed us. + if(attack.Actor != null) attack.Actor.TargetKilled(this, attack); + AfterDeath(); return true; @@ -190,11 +204,31 @@ namespace BigSock { } + /* + Method for healing the character. + */ + public bool TryHeal(float amount) { + // Can't heal if full. + if(HP >= MaxHP) { + print($"[Character.TryHeal()] Already Full! ({HP:N1} >= {MaxHP:N1})"); + return false; + } + + print($"[Character.TryHeal()] {HP:N1} + {amount:N1} = {HP + amount:N1}"); + OnHeal?.Invoke(this, amount); + + // Heal the character. + var res = HP + amount; + if(res > MaxHP) res = MaxHP; + HP = res; + return true; + } + /* Method for what to do when the character takes damage. */ protected virtual void AfterDamage(IAttackStats attack) { - print($"[Character.AfterDamage()] {HP} - {attack.Damage}"); + print($"[Character.AfterDamage()] {HP + attack.Damage:N1} - {attack.Damage:N1} = {HP:N1}"); KnockBack(attack); } @@ -288,6 +322,12 @@ namespace BigSock { OnHit?.Invoke(this, target, attack); } + /* + Trigers the OnKill event. + */ + public void TargetKilled(Character target, AttackStats attack) { + OnKill?.Invoke(this, target, attack); + } /* Triggers when character uses an attack. @@ -321,7 +361,7 @@ namespace BigSock { Params: actor, amount. (Add heal source later on) */ - public event Action<Character, int> OnHeal; + public event Action<Character, float> OnHeal; /* Triggers when character has taken fatal damage. diff --git a/MrBigsock/Assets/Code/Item/Base/Conditional/OnHealItemBase.cs b/MrBigsock/Assets/Code/Item/Base/Conditional/OnHealItemBase.cs index 4a27777331f36ee29e41c331ce777d8627f8b943..8322d480a07cac05942a5223603346930b6f30d2 100644 --- a/MrBigsock/Assets/Code/Item/Base/Conditional/OnHealItemBase.cs +++ b/MrBigsock/Assets/Code/Item/Base/Conditional/OnHealItemBase.cs @@ -19,7 +19,7 @@ namespace BigSock.Item { /* The handler to activate when the condition is triggered. */ - public abstract void Handler(Character source, int amount); + public abstract void Handler(Character source, float amount); } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/attack/AttackMovement.cs b/MrBigsock/Assets/Code/attack/AttackMovement.cs index 5ed4cc03c3546ebd8334d702e8d2cbb57d10f985..37b53fa9705d5bfb24c47e4824e351bdf21de880 100644 --- a/MrBigsock/Assets/Code/attack/AttackMovement.cs +++ b/MrBigsock/Assets/Code/attack/AttackMovement.cs @@ -71,7 +71,7 @@ namespace BigSock { if(Actor != null) { attack.Damage *= Actor.Damage; attack.Knockback *= Actor.KnockbackForce; - Actor.TargetHit(target, attack); + //Actor.TargetHit(target, attack); } if(target.TakeDamage(attack)) {