diff --git a/Assets/Scripts/AIEntity.cs b/Assets/Scripts/AIEntity.cs index dc29f9f..fd8fd6b 100644 --- a/Assets/Scripts/AIEntity.cs +++ b/Assets/Scripts/AIEntity.cs @@ -47,6 +47,15 @@ public class AIEntity : Entity return false; } + + override public bool TakeDamage(float amount, Entity other){ + Entity currTargetEntity = GetTarget().GetComponent(); + if(!(currTargetEntity is null)){ + if(currTargetEntity.entityName == "Vampire") + SetTarget(other.transform); + } + return base.TakeDamage(amount, other); + } abstract class BaseStateAI : BaseState{ protected AIEntity entity; @@ -163,7 +172,7 @@ public class AIEntity : Entity private BaseState? Attack(){ Entity targetEntity = entity.GetTarget().GetComponent(); if(targetEntity != null){ - targetEntity.TakeDamage(entity.attackDmg); + targetEntity.TakeDamage(entity.attackDmg, entity); bool isTargetAlive = targetEntity.IsAlive(); if(!isTargetAlive){ return new FindTargetState(entity); diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 964a492..538caad 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -80,7 +80,7 @@ public class Entity : MonoBehaviour { } //Apply damage to the entity, returns true if it is still alive - public virtual bool TakeDamage(float amount) { + public virtual bool TakeDamage(float amount, Entity other) { Health -= amount; healthBar.SetHealthFraction(Health / initialHealth); diff --git a/Assets/Scripts/MinionThrower.cs b/Assets/Scripts/MinionThrower.cs index 759ce59..c9d3f90 100644 --- a/Assets/Scripts/MinionThrower.cs +++ b/Assets/Scripts/MinionThrower.cs @@ -59,7 +59,7 @@ public class MinionThrower : MonoBehaviour { if(minionHealthCost >= vampireEntity.Health) { return; } - vampireEntity.TakeDamage(minionHealthCost); + vampireEntity.TakeDamage(minionHealthCost, vampireEntity); currentInitialCooldown = 2f; // TODO currentCooldownTimer = currentInitialCooldown; diff --git a/Assets/Scripts/VampireEntity.cs b/Assets/Scripts/VampireEntity.cs index 85afed0..c426a6a 100644 --- a/Assets/Scripts/VampireEntity.cs +++ b/Assets/Scripts/VampireEntity.cs @@ -21,7 +21,7 @@ public class VampireEntity : Entity { if (gameFlowManager.Paused) return; - TakeDamage(playerStats.bloodLossRate * Time.deltaTime); + TakeDamage(playerStats.bloodLossRate * Time.deltaTime, this); } // public override void TakeDamage(float amount) {