Gladiators stop targeting vampire if monster hit

This commit is contained in:
Soulaha Balde 2022-04-02 16:41:34 -04:00
parent c74dbe3aef
commit bac85ff90f
4 changed files with 13 additions and 4 deletions

View File

@ -48,6 +48,15 @@ public class AIEntity : Entity
return false;
}
override public bool TakeDamage(float amount, Entity other){
Entity currTargetEntity = GetTarget().GetComponent<Entity>();
if(!(currTargetEntity is null)){
if(currTargetEntity.entityName == "Vampire")
SetTarget(other.transform);
}
return base.TakeDamage(amount, other);
}
abstract class BaseStateAI : BaseState{
protected AIEntity entity;
public BaseStateAI(AIEntity entity){
@ -163,7 +172,7 @@ public class AIEntity : Entity
private BaseState? Attack(){
Entity targetEntity = entity.GetTarget().GetComponent<Entity>();
if(targetEntity != null){
targetEntity.TakeDamage(entity.attackDmg);
targetEntity.TakeDamage(entity.attackDmg, entity);
bool isTargetAlive = targetEntity.IsAlive();
if(!isTargetAlive){
return new FindTargetState(entity);

View File

@ -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);

View File

@ -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;

View File

@ -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) {