v1.3.0: all mobs now remember their enemy through save/load
This commit is contained in:
@@ -186,6 +186,11 @@ public abstract class Actor implements Bundlable {
|
|||||||
add( mob );
|
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()) {
|
for (Blob blob : Dungeon.level.blobs.values()) {
|
||||||
add( blob );
|
add( blob );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ public class GreatCrab extends Crab {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ){
|
public void damage( int dmg, Object src ){
|
||||||
if (enemy == null) enemy = chooseEnemy();
|
|
||||||
//crab blocks all wand damage from the hero if it sees them.
|
//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.
|
//Direct damage is negated, but add-on effects and environmental effects go through as normal.
|
||||||
if (enemySeen
|
if (enemySeen
|
||||||
@@ -89,7 +88,6 @@ public class GreatCrab extends Crab {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int defenseSkill( Char enemy ) {
|
public int defenseSkill( Char enemy ) {
|
||||||
if (this.enemy == null) this.enemy = chooseEnemy();
|
|
||||||
//crab blocks all melee attacks from its current target
|
//crab blocks all melee attacks from its current target
|
||||||
if (enemySeen
|
if (enemySeen
|
||||||
&& state != SLEEPING
|
&& state != SLEEPING
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ public abstract class Mob extends Char {
|
|||||||
public int maxLvl = Hero.MAX_LEVEL;
|
public int maxLvl = Hero.MAX_LEVEL;
|
||||||
|
|
||||||
protected Char enemy;
|
protected Char enemy;
|
||||||
|
protected int enemyID = -1; //used for save/restore
|
||||||
protected boolean enemySeen;
|
protected boolean enemySeen;
|
||||||
protected boolean alerted = false;
|
protected boolean alerted = false;
|
||||||
|
|
||||||
@@ -119,6 +120,8 @@ public abstract class Mob extends Char {
|
|||||||
private static final String TARGET = "target";
|
private static final String TARGET = "target";
|
||||||
private static final String MAX_LVL = "max_lvl";
|
private static final String MAX_LVL = "max_lvl";
|
||||||
|
|
||||||
|
private static final String ENEMY_ID = "enemy_id";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeInBundle( Bundle bundle ) {
|
public void storeInBundle( Bundle bundle ) {
|
||||||
|
|
||||||
@@ -138,6 +141,10 @@ public abstract class Mob extends Char {
|
|||||||
bundle.put( SEEN, enemySeen );
|
bundle.put( SEEN, enemySeen );
|
||||||
bundle.put( TARGET, target );
|
bundle.put( TARGET, target );
|
||||||
bundle.put( MAX_LVL, maxLvl );
|
bundle.put( MAX_LVL, maxLvl );
|
||||||
|
|
||||||
|
if (enemy != null) {
|
||||||
|
bundle.put(ENEMY_ID, enemy.id() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,6 +170,15 @@ public abstract class Mob extends Char {
|
|||||||
target = bundle.getInt( TARGET );
|
target = bundle.getInt( TARGET );
|
||||||
|
|
||||||
if (bundle.contains(MAX_LVL)) maxLvl = bundle.getInt(MAX_LVL);
|
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() {
|
public CharSprite sprite() {
|
||||||
|
|||||||
Reference in New Issue
Block a user