v0.7.0: improved potion quickslot behaviour

This commit is contained in:
Evan Debenham 2018-07-06 23:18:31 -04:00
parent 52f5bceb1e
commit 05c4c39fb5
3 changed files with 44 additions and 17 deletions

View File

@ -60,6 +60,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndItem;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
@ -72,6 +73,9 @@ import java.util.HashSet;
public class Potion extends Item { public class Potion extends Item {
public static final String AC_DRINK = "DRINK"; 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; private static final float TIME_TO_DRINK = 1f;
@ -109,6 +113,20 @@ public class Potion extends Item {
} }
}; };
private static final HashSet<Class<?extends Potion>> mustThrowPots = new HashSet<>();
static{
mustThrowPots.add(PotionOfToxicGas.class);
mustThrowPots.add(PotionOfLiquidFlame.class);
mustThrowPots.add(PotionOfParalyticGas.class);
mustThrowPots.add(PotionOfFrost.class);
}
private static final HashSet<Class<?extends Potion>> canThrowPots = new HashSet<>();
static{
canThrowPots.add(PotionOfPurity.class);
canThrowPots.add(PotionOfLevitation.class);
}
private static ItemStatusHandler<Potion> handler; private static ItemStatusHandler<Potion> handler;
private String color; private String color;
@ -150,7 +168,14 @@ public class Potion extends Item {
image = handler.image(this); image = handler.image(this);
color = handler.label(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 @Override
public ArrayList<String> actions( Hero hero ) { public ArrayList<String> actions( Hero hero ) {
@ -163,13 +188,14 @@ public class Potion extends Item {
public void execute( final Hero hero, String action ) { public void execute( final Hero hero, String action ) {
super.execute( hero, action ); super.execute( hero, action );
if (action.equals( AC_DRINK )) { if (action.equals( AC_CHOOSE )){
if (isKnown() && ( GameScene.show(new WndItem(null, this, true) );
this instanceof PotionOfLiquidFlame ||
this instanceof PotionOfToxicGas || } else if (action.equals( AC_DRINK )) {
this instanceof PotionOfParalyticGas)) {
if (isKnown() && mustThrowPots.contains(getClass())) {
GameScene.show( GameScene.show(
new WndOptions( Messages.get(Potion.class, "harmful"), new WndOptions( Messages.get(Potion.class, "harmful"),
@ -194,13 +220,9 @@ public class Potion extends Item {
@Override @Override
public void doThrow( final Hero hero ) { public void doThrow( final Hero hero ) {
if (isKnown() && ( if (isKnown()
this instanceof PotionOfExperience || && !mustThrowPots.contains(this.getClass())
this instanceof PotionOfHealing || && !canThrowPots.contains(this.getClass())) {
this instanceof PotionOfMindVision ||
this instanceof PotionOfStrength ||
this instanceof PotionOfInvisibility ||
this instanceof PotionOfMight)) {
GameScene.show( GameScene.show(
new WndOptions( Messages.get(Potion.class, "beneficial"), new WndOptions( Messages.get(Potion.class, "beneficial"),
@ -265,7 +287,7 @@ public class Potion extends Item {
} }
public boolean isKnown() { public boolean isKnown() {
return handler.isKnown( this ); return handler != null && handler.isKnown( this );
} }
public void setKnown() { public void setKnown() {
@ -273,6 +295,11 @@ public class Potion extends Item {
if (!isKnown()) { if (!isKnown()) {
handler.know(this); handler.know(this);
updateQuickslot(); updateQuickslot();
if (mustThrowPots.contains(this.getClass())){
defaultAction = AC_THROW;
} else if (canThrowPots.contains(this.getClass())){
defaultAction = AC_CHOOSE;
}
} }
if (Dungeon.hero.isAlive()) { if (Dungeon.hero.isAlive()) {

View File

@ -136,7 +136,7 @@ public class Ring extends KindofMisc {
} }
public boolean isKnown() { public boolean isKnown() {
return handler.isKnown( this ); return handler != null && handler.isKnown( this );
} }
protected void setKnown() { protected void setKnown() {

View File

@ -177,7 +177,7 @@ public abstract class Scroll extends Item {
} }
public boolean isKnown() { public boolean isKnown() {
return handler.isKnown( this ); return handler != null && handler.isKnown( this );
} }
public void setKnown() { public void setKnown() {