From bc757ed57b64511d4a9c6d738589d03a0747ff0b Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 30 Jun 2020 20:18:55 -0400 Subject: [PATCH] v0.8.1a: fixed a variety of rare crashes caused by: - shields rarely failing to apply (having no target) - ghouls dieing while over pits - Tengu having nowhere to jump in rare cases - multiplicity when the attacker is the hero - talisman buffs not always respecting floor differences - null pointers in reflection --- .../src/main/java/com/watabou/utils/Reflection.java | 4 ++-- .../shatteredpixel/shatteredpixeldungeon/Dungeon.java | 2 ++ .../shatteredpixeldungeon/actors/buffs/ShieldBuff.java | 8 ++++---- .../shatteredpixeldungeon/actors/mobs/Ghoul.java | 2 +- .../shatteredpixeldungeon/actors/mobs/Mob.java | 9 +++------ .../shatteredpixeldungeon/actors/mobs/NewTengu.java | 4 ++-- .../shatteredpixeldungeon/actors/mobs/Warlock.java | 2 +- .../items/armor/curses/Multiplicity.java | 3 ++- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/utils/Reflection.java b/SPD-classes/src/main/java/com/watabou/utils/Reflection.java index 09ace4049..c22ac5603 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/Reflection.java +++ b/SPD-classes/src/main/java/com/watabou/utils/Reflection.java @@ -39,7 +39,7 @@ public class Reflection { public static T newInstance( Class cls ){ try { return ClassReflection.newInstance(cls); - } catch (ReflectionException e) { + } catch (Exception e) { Game.reportException(e); return null; } @@ -52,7 +52,7 @@ public class Reflection { public static Class forName( String name ){ try { return ClassReflection.forName( name ); - } catch (ReflectionException e) { + } catch (Exception e) { Game.reportException(e); return null; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 781fef8ae..5c54fdcde 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -801,6 +801,7 @@ public class Dungeon { } for (TalismanOfForesight.CharAwareness c : hero.buffs(TalismanOfForesight.CharAwareness.class)){ + if (Dungeon.depth != c.depth) continue; Char ch = (Char) Actor.findById(c.charID); if (ch == null) continue; BArray.or( level.visited, level.heroFOV, ch.pos - 1 - level.width(), 3, level.visited ); @@ -810,6 +811,7 @@ public class Dungeon { } for (TalismanOfForesight.HeapAwareness h : hero.buffs(TalismanOfForesight.HeapAwareness.class)){ + if (Dungeon.depth != h.depth) continue; BArray.or( level.visited, level.heroFOV, h.pos - 1 - level.width(), 3, level.visited ); BArray.or( level.visited, level.heroFOV, h.pos - 1, 3, level.visited ); BArray.or( level.visited, level.heroFOV, h.pos - 1 + level.width(), 3, level.visited ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/ShieldBuff.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/ShieldBuff.java index 558c569fd..0d2933b19 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/ShieldBuff.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/ShieldBuff.java @@ -50,7 +50,7 @@ public abstract class ShieldBuff extends Buff { public void setShield( int shield ) { this.shielding = shield; - target.needsShieldUpdate = true; + if (target != null) target.needsShieldUpdate = true; } public void incShield(){ @@ -59,7 +59,7 @@ public abstract class ShieldBuff extends Buff { public void incShield( int amt ){ shielding += amt; - target.needsShieldUpdate = true; + if (target != null) target.needsShieldUpdate = true; } public void decShield(){ @@ -68,7 +68,7 @@ public abstract class ShieldBuff extends Buff { public void decShield( int amt ){ shielding -= amt; - target.needsShieldUpdate = true; + if (target != null) target.needsShieldUpdate = true; } //returns the amount of damage leftover @@ -83,7 +83,7 @@ public abstract class ShieldBuff extends Buff { if (shielding == 0){ detach(); } - target.needsShieldUpdate = true; + if (target != null) target.needsShieldUpdate = true; return dmg; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Ghoul.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Ghoul.java index e26279315..5aeb89630 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Ghoul.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Ghoul.java @@ -138,7 +138,7 @@ public class Ghoul extends Mob { @Override public void die(Object cause) { - if (cause != Chasm.class && cause != GhoulLifeLink.class){ + if (cause != Chasm.class && cause != GhoulLifeLink.class && !Dungeon.level.pit[pos]){ Ghoul nearby = GhoulLifeLink.searchForHost(this); if (nearby != null){ beingLifeLinked = true; 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 c0abf6bcd..baaee80f5 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 @@ -868,13 +868,10 @@ public abstract class Mob extends Char { } else { //if moving towards an enemy isn't possible, try to switch targets to another enemy that is closer - Char oldEnemy = enemy; - enemy = null; - enemy = chooseEnemy(); - if (enemy != null && enemy != oldEnemy){ + Char newEnemy = chooseEnemy(); + if (newEnemy != null && enemy != newEnemy){ + enemy = newEnemy; return act(enemyInFOV, justAlerted); - } else { - enemy = oldEnemy; } spend( TICK ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/NewTengu.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/NewTengu.java index 58e3b6ad3..06834ae1c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/NewTengu.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/NewTengu.java @@ -244,8 +244,8 @@ public class NewTengu extends Mob { do { newPos = ((NewPrisonBossLevel)Dungeon.level).randomTenguCellPos(); - } while ( level.trueDistance(newPos, enemy.pos) <= 4 - || level.trueDistance(newPos, Dungeon.hero.pos) <= 4 + } while ( level.trueDistance(newPos, enemy.pos) <= 3.5f + || level.trueDistance(newPos, Dungeon.hero.pos) <= 3.5f || Actor.findChar(newPos) != null); if (level.heroFOV[pos]) CellEmitter.get( pos ).burst( Speck.factory( Speck.WOOL ), 6 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Warlock.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Warlock.java index af9320e0a..1940bb143 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Warlock.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Warlock.java @@ -114,7 +114,7 @@ public class Warlock extends Mob implements Callback { int dmg = Random.NormalIntRange( 12, 18 ); enemy.damage( dmg, new DarkBolt() ); - if (!enemy.isAlive() && enemy == Dungeon.hero) { + if (enemy == Dungeon.hero && !enemy.isAlive()) { Dungeon.fail( getClass() ); GLog.n( Messages.get(this, "bolt_kill") ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java index bfefa3271..7447cf562 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java @@ -68,7 +68,8 @@ public class Multiplicity extends Armor.Glyph { } else { //FIXME should probably have a mob property for this - if (attacker.properties().contains(Char.Property.BOSS) || attacker.properties().contains(Char.Property.MINIBOSS) + if (!(attacker instanceof Mob) + || attacker.properties().contains(Char.Property.BOSS) || attacker.properties().contains(Char.Property.MINIBOSS) || attacker instanceof Mimic || attacker instanceof Statue){ m = Dungeon.level.createMob(); } else {