From ab847c9e1b70c39c387473d169c46b00503b8d90 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 17 Sep 2017 17:18:40 -0400 Subject: [PATCH] v0.6.2: improved ai logic for piranhas and guards --- .../actors/mobs/Guard.java | 46 +++++++++---------- .../actors/mobs/Piranha.java | 39 ++++++++-------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Guard.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Guard.java index f6969284a..6731a4afb 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Guard.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Guard.java @@ -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 ); + } + + } + } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Piranha.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Piranha.java index efd0a5b58..4d9c42548 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Piranha.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Piranha.java @@ -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> 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; + } + } }