diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java index db39ef5b5..9b73e7e74 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java @@ -60,6 +60,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; @@ -72,6 +73,9 @@ import java.util.HashSet; public class Potion extends Item { public static final String AC_DRINK = "DRINK"; + + //used internally for potions that can be drunk or thrown + public static final String AC_CHOOSE = "CHOOSE"; private static final float TIME_TO_DRINK = 1f; @@ -109,6 +113,20 @@ public class Potion extends Item { } }; + private static final HashSet> mustThrowPots = new HashSet<>(); + static{ + mustThrowPots.add(PotionOfToxicGas.class); + mustThrowPots.add(PotionOfLiquidFlame.class); + mustThrowPots.add(PotionOfParalyticGas.class); + mustThrowPots.add(PotionOfFrost.class); + } + + private static final HashSet> canThrowPots = new HashSet<>(); + static{ + canThrowPots.add(PotionOfPurity.class); + canThrowPots.add(PotionOfLevitation.class); + } + private static ItemStatusHandler handler; private String color; @@ -150,7 +168,14 @@ public class Potion extends Item { image = handler.image(this); color = handler.label(this); } - }; + if (isKnown()){ + if (mustThrowPots.contains(this.getClass())) { + defaultAction = AC_THROW; + } else if (canThrowPots.contains(this.getClass())){ + defaultAction = AC_CHOOSE; + } + } + } @Override public ArrayList actions( Hero hero ) { @@ -163,13 +188,14 @@ public class Potion extends Item { public void execute( final Hero hero, String action ) { super.execute( hero, action ); - - if (action.equals( AC_DRINK )) { + + if (action.equals( AC_CHOOSE )){ - if (isKnown() && ( - this instanceof PotionOfLiquidFlame || - this instanceof PotionOfToxicGas || - this instanceof PotionOfParalyticGas)) { + GameScene.show(new WndItem(null, this, true) ); + + } else if (action.equals( AC_DRINK )) { + + if (isKnown() && mustThrowPots.contains(getClass())) { GameScene.show( new WndOptions( Messages.get(Potion.class, "harmful"), @@ -194,13 +220,9 @@ public class Potion extends Item { @Override public void doThrow( final Hero hero ) { - if (isKnown() && ( - this instanceof PotionOfExperience || - this instanceof PotionOfHealing || - this instanceof PotionOfMindVision || - this instanceof PotionOfStrength || - this instanceof PotionOfInvisibility || - this instanceof PotionOfMight)) { + if (isKnown() + && !mustThrowPots.contains(this.getClass()) + && !canThrowPots.contains(this.getClass())) { GameScene.show( new WndOptions( Messages.get(Potion.class, "beneficial"), @@ -265,7 +287,7 @@ public class Potion extends Item { } public boolean isKnown() { - return handler.isKnown( this ); + return handler != null && handler.isKnown( this ); } public void setKnown() { @@ -273,6 +295,11 @@ public class Potion extends Item { if (!isKnown()) { handler.know(this); updateQuickslot(); + if (mustThrowPots.contains(this.getClass())){ + defaultAction = AC_THROW; + } else if (canThrowPots.contains(this.getClass())){ + defaultAction = AC_CHOOSE; + } } if (Dungeon.hero.isAlive()) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index e77b10372..81b4b0097 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -136,7 +136,7 @@ public class Ring extends KindofMisc { } public boolean isKnown() { - return handler.isKnown( this ); + return handler != null && handler.isKnown( this ); } protected void setKnown() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java index 2f750cfbc..87d0e0663 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java @@ -177,7 +177,7 @@ public abstract class Scroll extends Item { } public boolean isKnown() { - return handler.isKnown( this ); + return handler != null && handler.isKnown( this ); } public void setKnown() {