v0.9.4: adjusted AI behaviour, only allies ignore invuln targets

This commit is contained in:
Evan Debenham 2021-06-29 21:33:40 -04:00
parent 0d0f33d845
commit f547b8a0b0

View File

@ -229,25 +229,30 @@ public abstract class Mob extends Char {
//we have no enemy, or the current one is dead/missing
if ( enemy == null || !enemy.isAlive() || !Actor.chars().contains(enemy) || state == WANDERING) {
newEnemy = true;
//We are an ally, and current enemy is another ally.
} else if (alignment == Alignment.ALLY && enemy.alignment == Alignment.ALLY) {
newEnemy = true;
//We are amoked and current enemy is the hero
} else if (buff( Amok.class ) != null && enemy == Dungeon.hero) {
newEnemy = true;
//We are charmed and current enemy is what charmed us
} else if (buff(Charm.class) != null && buff(Charm.class).object == enemy.id()) {
newEnemy = true;
//we aren't amoked, current enemy is invulnerable to us, and that enemy isn't affect by aggression
} else if (buff( Amok.class ) == null && enemy.isInvulnerable(getClass()) && enemy.buff(StoneOfAggression.Aggression.class) == null) {
newEnemy = true;
}
//additionally, if we are an ally, find a new enemy if...
if (!newEnemy && alignment == Alignment.ALLY){
//current enemy is also an ally
if (enemy.alignment == Alignment.ALLY){
newEnemy = true;
//current enemy is invulnerable
} else if (enemy.isInvulnerable(getClass())){
newEnemy = true;
}
}
if ( newEnemy ) {
HashSet<Char> enemies = new HashSet<>();
//if the mob is amoked...
//if we are amoked...
if ( buff(Amok.class) != null) {
//try to find an enemy mob to attack first.
for (Mob mob : Dungeon.level.mobs)
@ -272,7 +277,7 @@ public abstract class Mob extends Char {
}
}
//if the mob is an ally...
//if we are an ally...
} else if ( alignment == Alignment.ALLY ) {
//look for hostile mobs to attack
for (Mob mob : Dungeon.level.mobs)
@ -284,20 +289,21 @@ public abstract class Mob extends Char {
enemies.add(mob);
}
//if the mob is an enemy...
//if we are an enemy...
} else if (alignment == Alignment.ENEMY) {
//look for ally mobs to attack
for (Mob mob : Dungeon.level.mobs)
if (mob.alignment == Alignment.ALLY && fieldOfView[mob.pos] && mob.invisible <= 0 && !mob.isInvulnerable(getClass()))
if (mob.alignment == Alignment.ALLY && fieldOfView[mob.pos] && mob.invisible <= 0)
enemies.add(mob);
//and look for the hero
if (fieldOfView[Dungeon.hero.pos] && Dungeon.hero.invisible <= 0 && !Dungeon.hero.isInvulnerable(getClass())) {
if (fieldOfView[Dungeon.hero.pos] && Dungeon.hero.invisible <= 0) {
enemies.add(Dungeon.hero);
}
}
//do not target anything that's charming us
Charm charm = buff( Charm.class );
if (charm != null){
Char source = (Char)Actor.findById( charm.object );