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

@ -47,6 +47,15 @@ public class AIEntity : Entity
return false; 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{ abstract class BaseStateAI : BaseState{
protected AIEntity entity; protected AIEntity entity;
@ -163,7 +172,7 @@ public class AIEntity : Entity
private BaseState? Attack(){ private BaseState? Attack(){
Entity targetEntity = entity.GetTarget().GetComponent<Entity>(); Entity targetEntity = entity.GetTarget().GetComponent<Entity>();
if(targetEntity != null){ if(targetEntity != null){
targetEntity.TakeDamage(entity.attackDmg); targetEntity.TakeDamage(entity.attackDmg, entity);
bool isTargetAlive = targetEntity.IsAlive(); bool isTargetAlive = targetEntity.IsAlive();
if(!isTargetAlive){ if(!isTargetAlive){
return new FindTargetState(entity); 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 //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; Health -= amount;
healthBar.SetHealthFraction(Health / initialHealth); healthBar.SetHealthFraction(Health / initialHealth);

View File

@ -59,7 +59,7 @@ public class MinionThrower : MonoBehaviour {
if(minionHealthCost >= vampireEntity.Health) { if(minionHealthCost >= vampireEntity.Health) {
return; return;
} }
vampireEntity.TakeDamage(minionHealthCost); vampireEntity.TakeDamage(minionHealthCost, vampireEntity);
currentInitialCooldown = 2f; // TODO currentInitialCooldown = 2f; // TODO
currentCooldownTimer = currentInitialCooldown; currentCooldownTimer = currentInitialCooldown;

View File

@ -21,7 +21,7 @@ public class VampireEntity : Entity {
if (gameFlowManager.Paused) if (gameFlowManager.Paused)
return; return;
TakeDamage(playerStats.bloodLossRate * Time.deltaTime); TakeDamage(playerStats.bloodLossRate * Time.deltaTime, this);
} }
// public override void TakeDamage(float amount) { // public override void TakeDamage(float amount) {