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

Healing & item event triggers.

- Added method for healing characters.
- Added calls to trigger some item events.
parent 7e2946b2
No related branches found
No related tags found
1 merge request!24PrefabService & abilities
......@@ -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.
......
......@@ -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
......@@ -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)) {
......
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