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

OnHit & OnTakeDamage.

- Added code to trigger the events.
- Added Actor prop to AttackStats so we can see where the damage came from.
parent da2eebd6
No related branches found
No related tags found
1 merge request!22Implemented initial version of conditional items.
...@@ -160,6 +160,8 @@ namespace BigSock { ...@@ -160,6 +160,8 @@ namespace BigSock {
// Start new IFrames // Start new IFrames
NextTimeCanTakeDamage = DateTime.Now + IFrameDuration; NextTimeCanTakeDamage = DateTime.Now + IFrameDuration;
// Trigger the event for taking damage.
OnTakeDamage?.Invoke(this, attack?.Actor, attack);
// Add damage // Add damage
HP -= attack.Damage; HP -= attack.Damage;
...@@ -273,6 +275,14 @@ namespace BigSock { ...@@ -273,6 +275,14 @@ namespace BigSock {
*/ */
public partial class Character { public partial class Character {
/*
Trigers the OnHit event.
*/
public void TargetHit(Character target, AttackStats attack) {
OnHit?.Invoke(this, target, attack);
}
/* /*
Triggers when character uses an attack. Triggers when character uses an attack.
Params: actor, attack stats. Params: actor, attack stats.
......
...@@ -36,5 +36,10 @@ namespace BigSock { ...@@ -36,5 +36,10 @@ namespace BigSock {
*/ */
public Vector2 Source { get; set; } public Vector2 Source { get; set; }
/*
The character that activated the attack.
*/
public Character Actor { get; set; }
} }
} }
\ No newline at end of file
...@@ -36,5 +36,9 @@ namespace BigSock { ...@@ -36,5 +36,9 @@ namespace BigSock {
*/ */
Vector2 Source { get; } Vector2 Source { get; }
/*
The character that activated the attack.
*/
Character Actor { get; }
} }
} }
\ No newline at end of file
...@@ -95,16 +95,10 @@ namespace BigSock { ...@@ -95,16 +95,10 @@ namespace BigSock {
if(NextTimeCanAttack <= DateTime.Now) { if(NextTimeCanAttack <= DateTime.Now) {
NextTimeCanAttack = DateTime.Now.AddSeconds(AttackCooldown); NextTimeCanAttack = DateTime.Now.AddSeconds(AttackCooldown);
Instantiate(attack, new Vector3(transform.position.x, transform.position.y, transform.position.z), attack.transform.rotation); var bullet = Instantiate(attack, new Vector3(transform.position.x, transform.position.y, transform.position.z), attack.transform.rotation);
//if(movementInput.x < 0 ) { bullet.GetComponent<AttackMovement>().Actor = this;
// Instantiate(attack, new Vector3(transform.position.x - 1.0f, transform.position.y, transform.position.z), attack.transform.rotation);
//} else if(movementInput.x >= 0) {
// Instantiate(attack, new Vector3(transform.position.x + 1.0f, transform.position.y, transform.position.z), attack.transform.rotation);
//}
}
}
} }
//!! Code for testing the new item stuff. //!! Code for testing the new item stuff.
......
...@@ -21,6 +21,10 @@ namespace BigSock { ...@@ -21,6 +21,10 @@ namespace BigSock {
public float KnockbackForce => knockbackForce; public float KnockbackForce => knockbackForce;
public float knockbackForce = 1; public float knockbackForce = 1;
/*
The character that activated the attack.
*/
public Character Actor { get; set; }
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
...@@ -60,8 +64,16 @@ namespace BigSock { ...@@ -60,8 +64,16 @@ namespace BigSock {
//Range = 0, //Range = 0,
//AttackSpeed = AttackSpeed, //AttackSpeed = AttackSpeed,
Source = transform.position, Source = transform.position,
Actor = Actor,
}; };
// If we have an actor: Apply their stat mods & trigger their OnHit.
if(Actor != null) {
attack.Damage *= Actor.Damage;
attack.Knockback *= Actor.KnockbackForce;
Actor.TargetHit(target, attack);
}
if(target.TakeDamage(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