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 {
// Start new IFrames
NextTimeCanTakeDamage = DateTime.Now + IFrameDuration;
// Trigger the event for taking damage.
OnTakeDamage?.Invoke(this, attack?.Actor, attack);
// Add damage
HP -= attack.Damage;
......@@ -273,6 +275,14 @@ namespace BigSock {
*/
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.
Params: actor, attack stats.
......
......@@ -36,5 +36,10 @@ namespace BigSock {
*/
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 {
*/
Vector2 Source { get; }
/*
The character that activated the attack.
*/
Character Actor { get; }
}
}
\ No newline at end of file
......@@ -95,16 +95,10 @@ namespace BigSock {
if(NextTimeCanAttack <= DateTime.Now) {
NextTimeCanAttack = DateTime.Now.AddSeconds(AttackCooldown);
Instantiate(attack, new Vector3(transform.position.x, transform.position.y, transform.position.z), attack.transform.rotation);
//if(movementInput.x < 0 ) {
// 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);
//}
}
var bullet = Instantiate(attack, new Vector3(transform.position.x, transform.position.y, transform.position.z), attack.transform.rotation);
bullet.GetComponent<AttackMovement>().Actor = this;
}
}
//!! Code for testing the new item stuff.
......
......@@ -21,6 +21,10 @@ namespace BigSock {
public float KnockbackForce => knockbackForce;
public float knockbackForce = 1;
/*
The character that activated the attack.
*/
public Character Actor { get; set; }
// Start is called before the first frame update
void Start()
......@@ -60,8 +64,16 @@ namespace BigSock {
//Range = 0,
//AttackSpeed = AttackSpeed,
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)) {
}
......
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