v0.6.2: improved ai logic for piranhas and guards

This commit is contained in:
Evan Debenham 2017-09-17 17:18:40 -04:00
parent 933b2b5b89
commit ab847c9e1b
2 changed files with 44 additions and 41 deletions

View File

@ -57,6 +57,8 @@ public class Guard extends Mob {
lootChance = 0.25f;
properties.add(Property.DEMONIC);
HUNTING = new Hunting();
}
@Override
@ -64,29 +66,6 @@ public class Guard extends Mob {
return Random.NormalIntRange(4, 12);
}
@Override
protected boolean act() {
//FIXME should handle chaining in an extended hunting aistate
/*Dungeon.level.updateFieldOfView( this, fieldOfView );
if (state == HUNTING &&
paralysed <= 0 &&
enemy != null &&
enemy.invisible == 0 &&
Level.fieldOfView[enemy.pos] &&
Dungeon.level.distance( pos, enemy.pos ) < 5 &&
!Dungeon.level.adjacent( pos, enemy.pos ) &&
Random.Int(3) == 0 &&
chain(enemy.pos)) {
return false;
} else {*/
return super.act();
//}
}
private boolean chain(int target){
if (chainsUsed || enemy.properties().contains(Property.IMMOVABLE))
return false;
@ -180,4 +159,25 @@ public class Guard extends Mob {
super.restoreFromBundle(bundle);
chainsUsed = bundle.getBoolean(CHAINSUSED);
}
private class Hunting extends Mob.Hunting{
@Override
public boolean act( boolean enemyInFOV, boolean justAlerted ) {
enemySeen = enemyInFOV;
if (!chainsUsed
&& enemyInFOV
&& !isCharmedBy( enemy )
&& !canAttack( enemy )
&& Dungeon.level.distance( pos, enemy.pos ) < 5
&& Random.Int(3) == 0
&& chain(enemy.pos)){
return false;
} else {
return super.act( enemyInFOV, justAlerted );
}
}
}
}

View File

@ -32,6 +32,9 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Roots;
import com.shatteredpixel.shatteredpixeldungeon.items.food.MysteryMeat;
import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PoolRoom;
import com.shatteredpixel.shatteredpixeldungeon.sprites.PiranhaSprite;
import com.watabou.utils.Random;
@ -45,6 +48,8 @@ public class Piranha extends Mob {
baseSpeed = 2f;
EXP = 0;
HUNTING = new Hunting();
}
public Piranha() {
@ -62,24 +67,6 @@ public class Piranha extends Mob {
sprite.killAndErase();
return true;
} else {
//FIXME should handle this is an extended hunting
//this causes pirahna to move away when a door is closed on them.
/*Dungeon.level.updateFieldOfView( this, Level.fieldOfView );
enemy = chooseEnemy();
if (state == this.HUNTING &&
!(enemy != null && enemy.isAlive() && Level.fieldOfView[enemy.pos] && enemy.invisible <= 0)){
state = this.WANDERING;
int oldPos = pos;
int i = 0;
do {
i++;
target = Dungeon.level.randomDestination();
if (i == 100) return true;
} while (!getCloser(target));
moveSprite( oldPos, pos );
return true;
}*/
return super.act();
}
}
@ -158,4 +145,20 @@ public class Piranha extends Mob {
public HashSet<Class<?>> immunities() {
return IMMUNITIES;
}
private class Hunting extends Mob.Hunting{
@Override
public boolean act(boolean enemyInFOV, boolean justAlerted) {
boolean result = super.act(enemyInFOV, justAlerted);
//this causes piranha to move away when a door is closed on them in a pool room.
if (state == WANDERING && Dungeon.level instanceof RegularLevel){
Room curRoom = ((RegularLevel)Dungeon.level).room(pos);
if (curRoom instanceof PoolRoom) {
target = Dungeon.level.pointToCell(curRoom.random(1));
}
}
return result;
}
}
}