v0.7.0: added safety checks when items are dropped or thrown

This commit is contained in:
Evan Debenham 2018-09-17 14:11:31 -04:00
parent 8663623d19
commit 2ede820dab
2 changed files with 10 additions and 4 deletions

View File

@ -113,8 +113,10 @@ public class Item implements Bundlable {
}
public void doDrop( Hero hero ) {
hero.spendAndNext( TIME_TO_DROP );
Dungeon.level.drop( detachAll( hero.belongings.backpack ), hero.pos ).sprite.drop( hero.pos );
if (hero.belongings.backpack.contains(this)) {
hero.spendAndNext(TIME_TO_DROP);
Dungeon.level.drop(detachAll(hero.belongings.backpack), hero.pos).sprite.drop(hero.pos);
}
}
//resets an item's properties, to ensure consistency between runs
@ -124,7 +126,9 @@ public class Item implements Bundlable {
}
public void doThrow( Hero hero ) {
GameScene.selectCell( thrower );
if (hero.belongings.backpack.contains(this)) {
GameScene.selectCell(thrower);
}
}
public void execute( Hero hero, String action ) {

View File

@ -45,7 +45,9 @@ public abstract class Brew extends Potion {
@Override
public void doThrow(Hero hero) {
//identical to Item.doThrow
GameScene.selectCell( thrower );
if (hero.belongings.backpack.contains(this)) {
GameScene.selectCell(thrower);
}
}
@Override