v1.3.0: all mobs now remember their enemy through save/load

This commit is contained in:
Evan Debenham
2022-05-25 12:52:31 -04:00
parent ba504f75de
commit d2c8bc89dc
3 changed files with 21 additions and 2 deletions

View File

@@ -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 );

View File

@@ -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

View File

@@ -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() {