From 9bab7dfd5e34442cb7a3286061ab7b8eb64a3b97 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 7 Jun 2019 00:18:19 -0400 Subject: [PATCH] v0.7.4: piranha now act as if they can't see enemies they can't reach --- .../actors/mobs/Piranha.java | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) 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 7482176fb..5452ea1cc 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 @@ -28,10 +28,8 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Vertigo; 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.PathFinder; import com.watabou.utils.Random; public class Piranha extends Mob { @@ -46,8 +44,12 @@ public class Piranha extends Mob { loot = MysteryMeat.class; lootChance = 1f; + SLEEPING = new Sleeping(); + WANDERING = new Wandering(); HUNTING = new Hunting(); + state = SLEEPING; + properties.add(Property.BLOB_IMMUNE); } @@ -134,19 +136,41 @@ public class Piranha extends Mob { immunities.add( Vertigo.class ); } + //if there is not a path to the enemy, piranhas act as if they can't see them + private class Sleeping extends Mob.Sleeping{ + @Override + public boolean act(boolean enemyInFOV, boolean justAlerted) { + if (enemyInFOV) { + PathFinder.buildDistanceMap(enemy.pos, Dungeon.level.water, viewDistance); + enemyInFOV = PathFinder.distance[pos] != Integer.MAX_VALUE; + } + + return super.act(enemyInFOV, justAlerted); + } + } + + private class Wandering extends Mob.Wandering{ + @Override + public boolean act(boolean enemyInFOV, boolean justAlerted) { + if (enemyInFOV) { + PathFinder.buildDistanceMap(enemy.pos, Dungeon.level.water, viewDistance); + enemyInFOV = PathFinder.distance[pos] != Integer.MAX_VALUE; + } + + return super.act(enemyInFOV, justAlerted); + } + } + 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)); - } + if (enemyInFOV) { + PathFinder.buildDistanceMap(enemy.pos, Dungeon.level.water, viewDistance); + enemyInFOV = PathFinder.distance[pos] != Integer.MAX_VALUE; } - return result; + + return super.act(enemyInFOV, justAlerted); } } }