diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index f756423909c97f32fa3399166673f93690bde49f..5614e91c694883c86c10ca6f5bcd4ba4c4d7f48c 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -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. diff --git a/MrBigsock/Assets/Code/Core/AttackStats.cs b/MrBigsock/Assets/Code/Core/AttackStats.cs index 3c46627a71368455c784a50f9a24ed0caf448213..6eac3a66344a0e6096c2d907d505c9bbc5cc2327 100644 --- a/MrBigsock/Assets/Code/Core/AttackStats.cs +++ b/MrBigsock/Assets/Code/Core/AttackStats.cs @@ -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 diff --git a/MrBigsock/Assets/Code/Core/IAttackStats.cs b/MrBigsock/Assets/Code/Core/IAttackStats.cs index a097916ab08bd53f6477036cabc074f97803110c..ea103727f1cb17a22798b4392db54908a0772484 100644 --- a/MrBigsock/Assets/Code/Core/IAttackStats.cs +++ b/MrBigsock/Assets/Code/Core/IAttackStats.cs @@ -36,5 +36,9 @@ namespace BigSock { */ Vector2 Source { get; } + /* + The character that activated the attack. + */ + Character Actor { get; } } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index 95ef3e8cadcf3956e2d0c0694f65dafe6da27d8f..7fcca51046af8da6f0d22f6e53aca3f351b52a9e 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -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. diff --git a/MrBigsock/Assets/Code/attack/AttackMovement.cs b/MrBigsock/Assets/Code/attack/AttackMovement.cs index 4768aed3df61a8e6f88499b42378da4fd421d130..30c7f101c5b40cc29bdb5881373121ac299b35ed 100644 --- a/MrBigsock/Assets/Code/attack/AttackMovement.cs +++ b/MrBigsock/Assets/Code/attack/AttackMovement.cs @@ -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)) { }