v2.2.0: overhauled logic for item consumption when use has multi steps

This commit is contained in:
Evan Debenham
2023-07-21 12:37:41 -04:00
parent f495b85df7
commit 2879e9ae54
31 changed files with 99 additions and 55 deletions
@@ -153,6 +153,7 @@ public class UnstableSpellbook extends Artifact {
handler.detach(); handler.detach();
if (index == 1){ if (index == 1){
Scroll scroll = Reflection.newInstance(ExoticScroll.regToExo.get(fScroll.getClass())); Scroll scroll = Reflection.newInstance(ExoticScroll.regToExo.get(fScroll.getClass()));
curItem = scroll;
charge--; charge--;
scroll.anonymize(); scroll.anonymize();
scroll.doRead(); scroll.doRead();
@@ -44,11 +44,19 @@ public class PotionOfDivineInspiration extends ExoticPotion {
icon = ItemSpriteSheet.Icons.POTION_DIVINE; icon = ItemSpriteSheet.Icons.POTION_DIVINE;
} }
protected static boolean identifiedByUse = false;
@Override @Override
//need to override drink so that time isn't spent right away //need to override drink so that time isn't spent right away
protected void drink(final Hero hero) { protected void drink(final Hero hero) {
curUser = hero;
curItem = this; if (!isKnown()) {
identify();
curItem = detach( hero.belongings.backpack );
identifiedByUse = true;
} else {
identifiedByUse = false;
}
boolean[] enabled = new boolean[5]; boolean[] enabled = new boolean[5];
enabled[1] = enabled[2] = enabled[3] = enabled[4] = true; enabled[1] = enabled[2] = enabled[3] = enabled[4] = true;
@@ -71,10 +79,6 @@ public class PotionOfDivineInspiration extends ExoticPotion {
} }
} }
if (!isIdentified()) {
curItem.detach(curUser.belongings.backpack);
}
GameScene.show(new WndOptions( GameScene.show(new WndOptions(
new ItemSprite(this), new ItemSprite(this),
Messages.titleCase(trueName()), Messages.titleCase(trueName()),
@@ -96,11 +100,11 @@ public class PotionOfDivineInspiration extends ExoticPotion {
if (index != -1){ if (index != -1){
Buff.affect(curUser, DivineInspirationTracker.class).setBoosted(index+1); Buff.affect(curUser, DivineInspirationTracker.class).setBoosted(index+1);
if (isIdentified()) { if (!identifiedByUse) {
curItem.detach(curUser.belongings.backpack); curItem.detach(curUser.belongings.backpack);
} }
identifiedByUse = false;
identify();
curUser.busy(); curUser.busy();
curUser.sprite.operate(curUser.pos); curUser.sprite.operate(curUser.pos);
@@ -132,7 +136,7 @@ public class PotionOfDivineInspiration extends ExoticPotion {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
//window can be closed if potion is already IDed //window can be closed if potion is already IDed
if (isIdentified()){ if (!identifiedByUse){
super.onBackPressed(); super.onBackPressed();
} }
} }
@@ -60,11 +60,10 @@ public class PotionOfDragonsBreath extends ExoticPotion {
@Override @Override
//need to override drink so that time isn't spent right away //need to override drink so that time isn't spent right away
protected void drink(final Hero hero) { protected void drink(final Hero hero) {
curUser = hero;
curItem = detach( hero.belongings.backpack );
if (!isKnown()) { if (!isKnown()) {
identify(); identify();
curItem = detach( hero.belongings.backpack );
identifiedByUse = true; identifiedByUse = true;
} else { } else {
identifiedByUse = false; identifiedByUse = false;
@@ -116,9 +115,10 @@ public class PotionOfDragonsBreath extends ExoticPotion {
} ); } );
} }
}); });
} else if (cell == null && !anonymous){
curItem.collect( curUser.belongings.backpack );
} else if (cell != null) { } else if (cell != null) {
if (!identifiedByUse) {
curItem.detach(curUser.belongings.backpack);
}
potionAlreadyUsed = true; potionAlreadyUsed = true;
identifiedByUse = false; identifiedByUse = false;
curUser.busy(); curUser.busy();
@@ -127,8 +127,6 @@ public class PotionOfDragonsBreath extends ExoticPotion {
@Override @Override
public void call() { public void call() {
curItem.detach(curUser.belongings.backpack);
curUser.sprite.idle(); curUser.sprite.idle();
curUser.sprite.zap(cell); curUser.sprite.zap(cell);
Sample.INSTANCE.play( Assets.Sounds.BURNING ); Sample.INSTANCE.play( Assets.Sounds.BURNING );
@@ -49,11 +49,10 @@ public class PotionOfMastery extends ExoticPotion {
@Override @Override
//need to override drink so that time isn't spent right away //need to override drink so that time isn't spent right away
protected void drink(final Hero hero) { protected void drink(final Hero hero) {
curUser = hero;
curItem = detach( hero.belongings.backpack );
if (!isKnown()) { if (!isKnown()) {
identify(); identify();
curItem = detach( hero.belongings.backpack );
identifiedByUse = true; identifiedByUse = true;
} else { } else {
identifiedByUse = false; identifiedByUse = false;
@@ -99,8 +98,6 @@ public class PotionOfMastery extends ExoticPotion {
} }
public void onBackPressed() {} public void onBackPressed() {}
} ); } );
} else if (item == null && !anonymous){
curItem.collect( curUser.belongings.backpack );
} else if (item != null) { } else if (item != null) {
if (item instanceof Weapon) { if (item instanceof Weapon) {
@@ -114,7 +111,11 @@ public class PotionOfMastery extends ExoticPotion {
Sample.INSTANCE.play( Assets.Sounds.DRINK ); Sample.INSTANCE.play( Assets.Sounds.DRINK );
curUser.sprite.operate(curUser.pos); curUser.sprite.operate(curUser.pos);
curItem.detach(curUser.belongings.backpack);
if (!identifiedByUse) {
curItem.detach(curUser.belongings.backpack);
}
identifiedByUse = false;
} }
@@ -40,6 +40,7 @@ public abstract class InventoryScroll extends Scroll {
if (!isKnown()) { if (!isKnown()) {
identify(); identify();
curItem = detach( curUser.belongings.backpack );
identifiedByUse = true; identifiedByUse = true;
} else { } else {
identifiedByUse = false; identifiedByUse = false;
@@ -109,7 +110,10 @@ public abstract class InventoryScroll extends Scroll {
} }
if (item != null) { if (item != null) {
if (!identifiedByUse) {
curItem = detach(curUser.belongings.backpack);
}
((InventoryScroll)curItem).onItemSelected( item ); ((InventoryScroll)curItem).onItemSelected( item );
((InventoryScroll)curItem).readAnimation(); ((InventoryScroll)curItem).readAnimation();
@@ -119,10 +123,6 @@ public abstract class InventoryScroll extends Scroll {
((InventoryScroll)curItem).confirmCancelation(); ((InventoryScroll)curItem).confirmCancelation();
} else if (!((Scroll)curItem).anonymous) {
curItem.collect( curUser.belongings.backpack );
} else { } else {
curUser.spendAndNext( TIME_TO_READ ); curUser.spendAndNext( TIME_TO_READ );
@@ -171,8 +171,6 @@ public abstract class Scroll extends Item {
&& !(this instanceof ScrollOfRemoveCurse || this instanceof ScrollOfAntiMagic)){ && !(this instanceof ScrollOfRemoveCurse || this instanceof ScrollOfAntiMagic)){
GLog.n( Messages.get(this, "cursed") ); GLog.n( Messages.get(this, "cursed") );
} else { } else {
curUser = hero;
curItem = detach( hero.belongings.backpack );
doRead(); doRead();
} }
@@ -40,7 +40,8 @@ public class ScrollOfLullaby extends Scroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
curUser.sprite.centerEmitter().start( Speck.factory( Speck.NOTE ), 0.3f, 5 ); curUser.sprite.centerEmitter().start( Speck.factory( Speck.NOTE ), 0.3f, 5 );
Sample.INSTANCE.play( Assets.Sounds.LULLABY ); Sample.INSTANCE.play( Assets.Sounds.LULLABY );
@@ -41,7 +41,8 @@ public class ScrollOfMagicMapping extends Scroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
int length = Dungeon.level.length(); int length = Dungeon.level.length();
int[] map = Dungeon.level.map; int[] map = Dungeon.level.map;
boolean[] mapped = Dungeon.level.mapped; boolean[] mapped = Dungeon.level.mapped;
@@ -46,6 +46,7 @@ public class ScrollOfMirrorImage extends Scroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
if ( spawnImages(curUser, NIMAGES) > 0){ if ( spawnImages(curUser, NIMAGES) > 0){
GLog.i(Messages.get(this, "copies")); GLog.i(Messages.get(this, "copies"));
} else { } else {
@@ -42,6 +42,7 @@ public class ScrollOfRage extends Scroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) { for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
mob.beckon( curUser.pos ); mob.beckon( curUser.pos );
if (mob.alignment != Char.Alignment.ALLY && Dungeon.level.heroFOV[mob.pos]) { if (mob.alignment != Char.Alignment.ALLY && Dungeon.level.heroFOV[mob.pos]) {
@@ -42,6 +42,7 @@ public class ScrollOfRecharging extends Scroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
Buff.affect(curUser, Recharging.class, Recharging.DURATION); Buff.affect(curUser, Recharging.class, Recharging.DURATION);
charge(curUser); charge(curUser);
@@ -50,6 +50,8 @@ public class ScrollOfRemoveCurse extends InventoryScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
TormentedSpirit spirit = null; TormentedSpirit spirit = null;
for (int i : PathFinder.NEIGHBOURS8){ for (int i : PathFinder.NEIGHBOURS8){
if (Actor.findChar(curUser.pos+i) instanceof TormentedSpirit){ if (Actor.findChar(curUser.pos+i) instanceof TormentedSpirit){
@@ -41,7 +41,8 @@ public class ScrollOfRetribution extends Scroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
GameScene.flash( 0x80FFFFFF ); GameScene.flash( 0x80FFFFFF );
//scales from 0x to 1x power, maxing at ~10% HP //scales from 0x to 1x power, maxing at ~10% HP
@@ -57,6 +57,7 @@ public class ScrollOfTeleportation extends Scroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
Sample.INSTANCE.play( Assets.Sounds.READ ); Sample.INSTANCE.play( Assets.Sounds.READ );
if (teleportPreferringUnseen( curUser )){ if (teleportPreferringUnseen( curUser )){
@@ -41,7 +41,8 @@ public class ScrollOfTerror extends Scroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
new Flare( 5, 32 ).color( 0xFF0000, true ).show( curUser.sprite, 2f ); new Flare( 5, 32 ).color( 0xFF0000, true ).show( curUser.sprite, 2f );
Sample.INSTANCE.play( Assets.Sounds.READ ); Sample.INSTANCE.play( Assets.Sounds.READ );
@@ -34,7 +34,8 @@ public class ScrollOfAntiMagic extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
Buff.affect( curUser, MagicImmune.class, MagicImmune.DURATION ); Buff.affect( curUser, MagicImmune.class, MagicImmune.DURATION );
new Flare( 5, 32 ).color( 0x00FF00, true ).show( curUser.sprite, 2f ); new Flare( 5, 32 ).color( 0x00FF00, true ).show( curUser.sprite, 2f );
@@ -50,6 +50,8 @@ public class ScrollOfChallenge extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) { for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
mob.beckon( curUser.pos ); mob.beckon( curUser.pos );
} }
@@ -51,7 +51,8 @@ public class ScrollOfDivination extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
curUser.sprite.parent.add( new Identification( curUser.sprite.center().offset( 0, -16 ) ) ); curUser.sprite.parent.add( new Identification( curUser.sprite.center().offset( 0, -16 ) ) );
Sample.INSTANCE.play( Assets.Sounds.READ ); Sample.INSTANCE.play( Assets.Sounds.READ );
@@ -40,6 +40,8 @@ public class ScrollOfDread extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
new Flare( 5, 32 ).color( 0xFF0000, true ).show( curUser.sprite, 2f ); new Flare( 5, 32 ).color( 0xFF0000, true ).show( curUser.sprite, 2f );
Sample.INSTANCE.play( Assets.Sounds.READ ); Sample.INSTANCE.play( Assets.Sounds.READ );
@@ -59,6 +59,7 @@ public class ScrollOfEnchantment extends ExoticScroll {
public void doRead() { public void doRead() {
if (!isKnown()) { if (!isKnown()) {
identify(); identify();
curItem = detach(curUser.belongings.backpack);
identifiedByUse = true; identifiedByUse = true;
} else { } else {
identifiedByUse = false; identifiedByUse = false;
@@ -113,6 +114,10 @@ public class ScrollOfEnchantment extends ExoticScroll {
public void onSelect(final Item item) { public void onSelect(final Item item) {
if (item instanceof Weapon){ if (item instanceof Weapon){
if (!identifiedByUse) {
curItem.detach(curUser.belongings.backpack);
}
identifiedByUse = false;
final Weapon.Enchantment enchants[] = new Weapon.Enchantment[3]; final Weapon.Enchantment enchants[] = new Weapon.Enchantment[3];
@@ -124,6 +129,10 @@ public class ScrollOfEnchantment extends ExoticScroll {
GameScene.show(new WndEnchantSelect((Weapon) item, enchants[0], enchants[1], enchants[2])); GameScene.show(new WndEnchantSelect((Weapon) item, enchants[0], enchants[1], enchants[2]));
} else if (item instanceof Armor) { } else if (item instanceof Armor) {
if (!identifiedByUse) {
curItem.detach(curUser.belongings.backpack);
}
identifiedByUse = false;
final Armor.Glyph glyphs[] = new Armor.Glyph[3]; final Armor.Glyph glyphs[] = new Armor.Glyph[3];
@@ -133,12 +142,8 @@ public class ScrollOfEnchantment extends ExoticScroll {
glyphs[2] = Armor.Glyph.random( existing, glyphs[0].getClass(), glyphs[1].getClass()); glyphs[2] = Armor.Glyph.random( existing, glyphs[0].getClass(), glyphs[1].getClass());
GameScene.show(new WndGlyphSelect((Armor) item, glyphs[0], glyphs[1], glyphs[2])); GameScene.show(new WndGlyphSelect((Armor) item, glyphs[0], glyphs[1], glyphs[2]));
} else { } else if (identifiedByUse){
if (!identifiedByUse){ ((ScrollOfEnchantment)curItem).confirmCancelation();
curItem.collect();
} else {
((ScrollOfEnchantment)curItem).confirmCancelation();
}
} }
} }
}; };
@@ -35,6 +35,8 @@ public class ScrollOfForesight extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
Sample.INSTANCE.play( Assets.Sounds.READ ); Sample.INSTANCE.play( Assets.Sounds.READ );
Buff.affect(curUser, Foresight.class, Foresight.DURATION); Buff.affect(curUser, Foresight.class, Foresight.DURATION);
@@ -58,6 +58,7 @@ public class ScrollOfMetamorphosis extends ExoticScroll {
public void doRead() { public void doRead() {
if (!isKnown()) { if (!isKnown()) {
identify(); identify();
curItem = detach(curUser.belongings.backpack);
identifiedByUse = true; identifiedByUse = true;
} else { } else {
identifiedByUse = false; identifiedByUse = false;
@@ -156,7 +157,6 @@ public class ScrollOfMetamorphosis extends ExoticScroll {
((ScrollOfMetamorphosis)curItem).confirmCancelation(this); ((ScrollOfMetamorphosis)curItem).confirmCancelation(this);
} else { } else {
super.onBackPressed(); super.onBackPressed();
curItem.collect();
} }
} }
@@ -193,6 +193,11 @@ public class ScrollOfMetamorphosis extends ExoticScroll {
public WndMetamorphReplace(Talent replacing, int tier){ public WndMetamorphReplace(Talent replacing, int tier){
super(); super();
if (!identifiedByUse) {
curItem.detach(curUser.belongings.backpack);
}
identifiedByUse = false;
INSTANCE = this; INSTANCE = this;
this.replacing = replacing; this.replacing = replacing;
@@ -37,7 +37,8 @@ public class ScrollOfMysticalEnergy extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
//append buff //append buff
Buff.affect(curUser, ArtifactRecharge.class).set( 30 ).ignoreHornOfPlenty = false; Buff.affect(curUser, ArtifactRecharge.class).set( 30 ).ignoreHornOfPlenty = false;
@@ -39,6 +39,7 @@ public class ScrollOfPassage extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
identify(); identify();
readAnimation(); readAnimation();
@@ -39,7 +39,8 @@ public class ScrollOfPrismaticImage extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
boolean found = false; boolean found = false;
for (Mob m : Dungeon.level.mobs.toArray(new Mob[0])){ for (Mob m : Dungeon.level.mobs.toArray(new Mob[0])){
if (m instanceof PrismaticImage){ if (m instanceof PrismaticImage){
@@ -43,7 +43,8 @@ public class ScrollOfPsionicBlast extends ExoticScroll {
@Override @Override
public void doRead() { public void doRead() {
detach(curUser.belongings.backpack);
GameScene.flash( 0x80FFFFFF ); GameScene.flash( 0x80FFFFFF );
Sample.INSTANCE.play( Assets.Sounds.BLAST ); Sample.INSTANCE.play( Assets.Sounds.BLAST );
@@ -44,10 +44,18 @@ public class ScrollOfSirensSong extends ExoticScroll {
{ {
icon = ItemSpriteSheet.Icons.SCROLL_SIREN; icon = ItemSpriteSheet.Icons.SCROLL_SIREN;
} }
protected static boolean identifiedByUse = false;
@Override @Override
public void doRead() { public void doRead() {
if (!anonymous) curItem.collect(); //we detach it later if (!isKnown()) {
identify();
curItem = detach(curUser.belongings.backpack);
identifiedByUse = true;
} else {
identifiedByUse = false;
}
GameScene.selectCell(targeter); GameScene.selectCell(targeter);
} }
@@ -67,14 +75,12 @@ public class ScrollOfSirensSong extends ExoticScroll {
} }
} }
if (target == null && isKnown() && !anonymous){ if (target == null && !anonymous && !identifiedByUse){
GLog.w(Messages.get(ScrollOfSirensSong.class, "cancel")); GLog.w(Messages.get(ScrollOfSirensSong.class, "cancel"));
return; return;
} else { } else {
detach(curUser.belongings.backpack);
curUser.sprite.centerEmitter().start( Speck.factory( Speck.HEART ), 0.2f, 5 ); curUser.sprite.centerEmitter().start( Speck.factory( Speck.HEART ), 0.2f, 5 );
Sample.INSTANCE.play( Assets.Sounds.CHARMS ); Sample.INSTANCE.play( Assets.Sounds.CHARMS );
Sample.INSTANCE.playDelayed( Assets.Sounds.LULLABY, 0.1f ); Sample.INSTANCE.playDelayed( Assets.Sounds.LULLABY, 0.1f );
@@ -99,7 +105,10 @@ public class ScrollOfSirensSong extends ExoticScroll {
GLog.w(Messages.get(ScrollOfSirensSong.class, "no_target")); GLog.w(Messages.get(ScrollOfSirensSong.class, "no_target"));
} }
identify(); if (!identifiedByUse) {
curItem.detach(curUser.belongings.backpack);
}
identifiedByUse = false;
readAnimation(); readAnimation();
@@ -52,7 +52,6 @@ public abstract class InventoryStone extends Runestone {
public void execute(Hero hero, String action) { public void execute(Hero hero, String action) {
super.execute(hero, action); super.execute(hero, action);
if (action.equals(AC_USE)){ if (action.equals(AC_USE)){
curItem = detach( hero.belongings.backpack );
activate(curUser.pos); activate(curUser.pos);
} }
} }
@@ -66,7 +65,7 @@ public abstract class InventoryStone extends Runestone {
curUser.spend( 1f ); curUser.spend( 1f );
curUser.busy(); curUser.busy();
curUser.sprite.operate(curUser.pos); curUser.sprite.operate(curUser.pos);
Sample.INSTANCE.play( Assets.Sounds.READ ); Sample.INSTANCE.play( Assets.Sounds.READ );
Invisibility.dispel(); Invisibility.dispel();
} }
@@ -110,11 +109,9 @@ public abstract class InventoryStone extends Runestone {
} }
if (item != null) { if (item != null) {
((InventoryStone)curItem).onItemSelected( item ); ((InventoryStone)curItem).onItemSelected( item );
} else{
curItem.collect( curUser.belongings.backpack );
} }
} }
}; };
@@ -60,6 +60,7 @@ public class StoneOfAugmentation extends InventoryStone {
weapon.augment = augment; weapon.augment = augment;
useAnimation(); useAnimation();
ScrollOfUpgrade.upgrade(curUser); ScrollOfUpgrade.upgrade(curUser);
curItem.detach( curUser.belongings.backpack );
} }
@@ -68,6 +69,7 @@ public class StoneOfAugmentation extends InventoryStone {
armor.augment = augment; armor.augment = augment;
useAnimation(); useAnimation();
ScrollOfUpgrade.upgrade(curUser); ScrollOfUpgrade.upgrade(curUser);
curItem.detach( curUser.belongings.backpack );
} }
@Override @Override
@@ -48,6 +48,7 @@ public class StoneOfEnchantment extends InventoryStone {
@Override @Override
protected void onItemSelected(Item item) { protected void onItemSelected(Item item) {
curItem.detach( curUser.belongings.backpack );
if (item instanceof Weapon) { if (item instanceof Weapon) {
@@ -66,7 +66,7 @@ public class StoneOfIntuition extends InventoryStone {
@Override @Override
protected void onItemSelected(Item item) { protected void onItemSelected(Item item) {
GameScene.show( new WndGuess(item)); GameScene.show( new WndGuess(item));
} }
@@ -110,12 +110,13 @@ public class StoneOfIntuition extends InventoryStone {
if (curUser.buff(IntuitionUseTracker.class) == null){ if (curUser.buff(IntuitionUseTracker.class) == null){
GLog.h( Messages.get(WndGuess.class, "preserved") ); GLog.h( Messages.get(WndGuess.class, "preserved") );
new StoneOfIntuition().collect();
Buff.affect(curUser, IntuitionUseTracker.class); Buff.affect(curUser, IntuitionUseTracker.class);
} else { } else {
curItem.detach( curUser.belongings.backpack );
curUser.buff(IntuitionUseTracker.class).detach(); curUser.buff(IntuitionUseTracker.class).detach();
} }
} else { } else {
curItem.detach( curUser.belongings.backpack );
if (curUser.buff(IntuitionUseTracker.class) != null) { if (curUser.buff(IntuitionUseTracker.class) != null) {
curUser.buff(IntuitionUseTracker.class).detach(); curUser.buff(IntuitionUseTracker.class).detach();
} }