v0.8.2c: added crash safety checks to tengu and WndBlacksmith

This commit is contained in:
Evan Debenham 2020-08-26 19:12:38 -04:00
parent 8e5648bbe4
commit 17ac29b190
2 changed files with 10 additions and 6 deletions

View File

@ -266,17 +266,21 @@ public class NewTengu extends Mob {
//otherwise, jump in a larger possible area, as the room is bigger //otherwise, jump in a larger possible area, as the room is bigger
} else { } else {
int tries = 100;
do { do {
newPos = Random.Int(level.length()); newPos = Random.Int(level.length());
} while ( tries--;
level.solid[newPos] || } while ( tries > 0 &&
(level.solid[newPos] ||
level.distance(newPos, enemy.pos) < 5 || level.distance(newPos, enemy.pos) < 5 ||
level.distance(newPos, enemy.pos) > 7 || level.distance(newPos, enemy.pos) > 7 ||
level.distance(newPos, Dungeon.hero.pos) < 5 || level.distance(newPos, Dungeon.hero.pos) < 5 ||
level.distance(newPos, Dungeon.hero.pos) > 7 || level.distance(newPos, Dungeon.hero.pos) > 7 ||
level.distance(newPos, pos) < 5 || level.distance(newPos, pos) < 5 ||
Actor.findChar(newPos) != null || Actor.findChar(newPos) != null ||
Dungeon.level.heaps.get(newPos) != null); Dungeon.level.heaps.get(newPos) != null));
if (tries <= 0) newPos = pos;
if (level.heroFOV[pos]) CellEmitter.get( pos ).burst( Speck.factory( Speck.WOOL ), 6 ); if (level.heroFOV[pos]) CellEmitter.get( pos ).burst( Speck.factory( Speck.WOOL ), 6 );

View File

@ -103,7 +103,7 @@ public class WndBlacksmith extends Window {
protected WndBag.Listener itemSelector = new WndBag.Listener() { protected WndBag.Listener itemSelector = new WndBag.Listener() {
@Override @Override
public void onSelect( Item item ) { public void onSelect( Item item ) {
if (item != null) { if (item != null && btnPressed.parent != null) {
btnPressed.item( item ); btnPressed.item( item );
if (btnItem1.item != null && btnItem2.item != null) { if (btnItem1.item != null && btnItem2.item != null) {