v0.2.4c: fixed a crash with bombs choosing adjacent tiles

This commit is contained in:
Evan Debenham 2015-03-07 19:58:11 -05:00
parent 471aa3ca7d
commit ec1a4823b6

View File

@ -39,6 +39,8 @@ import com.watabou.utils.Bundle;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Bomb extends Item { public class Bomb extends Item {
@ -85,10 +87,11 @@ public class Bomb extends Item {
Actor.addDelayed(fuse = new Fuse().ignite(this), 2); Actor.addDelayed(fuse = new Fuse().ignite(this), 2);
} }
if (Actor.findChar( cell ) != null && !(Actor.findChar( cell ) instanceof Hero) ){ if (Actor.findChar( cell ) != null && !(Actor.findChar( cell ) instanceof Hero) ){
int newCell; ArrayList<Integer> candidates = new ArrayList<>();
do { for (int i : Level.NEIGHBOURS8)
newCell = cell + Level.NEIGHBOURS8[Random.Int( 8 )]; if (Level.passable[cell + i])
} while (!Level.passable[newCell]); candidates.add(cell + i);
int newCell = candidates.isEmpty() ? cell : Random.element(candidates);
Dungeon.level.drop( this, newCell ).sprite.drop( cell ); Dungeon.level.drop( this, newCell ).sprite.drop( cell );
} else } else
super.onThrow( cell ); super.onThrow( cell );