diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java index 7c5dd1736..5b1d8861e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -185,6 +185,11 @@ public abstract class Actor implements Bundlable { for (Mob mob : Dungeon.level.mobs) { add( mob ); } + + //mobs need to remember their targets after every actor is added + for (Mob mob : Dungeon.level.mobs) { + mob.restoreEnemy(); + } for (Blob blob : Dungeon.level.blobs.values()) { add( blob ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GreatCrab.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GreatCrab.java index dc7473d13..3e4702156 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GreatCrab.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GreatCrab.java @@ -70,7 +70,6 @@ public class GreatCrab extends Crab { @Override public void damage( int dmg, Object src ){ - if (enemy == null) enemy = chooseEnemy(); //crab blocks all wand damage from the hero if it sees them. //Direct damage is negated, but add-on effects and environmental effects go through as normal. if (enemySeen @@ -89,7 +88,6 @@ public class GreatCrab extends Crab { @Override public int defenseSkill( Char enemy ) { - if (this.enemy == null) this.enemy = chooseEnemy(); //crab blocks all melee attacks from its current target if (enemySeen && state != SLEEPING diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index 8e740a51e..43f83c48f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -109,6 +109,7 @@ public abstract class Mob extends Char { public int maxLvl = Hero.MAX_LEVEL; protected Char enemy; + protected int enemyID = -1; //used for save/restore protected boolean enemySeen; protected boolean alerted = false; @@ -118,6 +119,8 @@ public abstract class Mob extends Char { private static final String SEEN = "seen"; private static final String TARGET = "target"; private static final String MAX_LVL = "max_lvl"; + + private static final String ENEMY_ID = "enemy_id"; @Override public void storeInBundle( Bundle bundle ) { @@ -138,6 +141,10 @@ public abstract class Mob extends Char { bundle.put( SEEN, enemySeen ); bundle.put( TARGET, target ); bundle.put( MAX_LVL, maxLvl ); + + if (enemy != null) { + bundle.put(ENEMY_ID, enemy.id() ); + } } @Override @@ -163,6 +170,15 @@ public abstract class Mob extends Char { target = bundle.getInt( TARGET ); if (bundle.contains(MAX_LVL)) maxLvl = bundle.getInt(MAX_LVL); + + if (bundle.contains(ENEMY_ID)) { + enemyID = bundle.getInt(ENEMY_ID); + } + } + + //mobs need to remember their targets after every actor is added + public void restoreEnemy(){ + if (enemyID != -1 && enemy == null) enemy = (Char)Actor.findById(enemyID); } public CharSprite sprite() {