From 54a85767decf45a29180889e43b70939b2b0271f Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 19 Feb 2021 23:06:53 -0500 Subject: [PATCH] v0.9.2: fixed cloak unequiping and save/load errors --- .../items/artifacts/CloakOfShadows.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java index 41ff1b43e..4e954d173 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java @@ -64,15 +64,13 @@ public class CloakOfShadows extends Artifact { bones = false; } - private boolean stealthed = false; - public static final String AC_STEALTH = "STEALTH"; @Override public ArrayList actions( Hero hero ) { ArrayList actions = super.actions( hero ); if ((isEquipped( hero ) || hero.hasTalent(Talent.LIGHT_CLOAK)) - && !cursed && (charge > 0 || stealthed)) { + && !cursed && (charge > 0 || activeBuff != null)) { actions.add(AC_STEALTH); } return actions; @@ -85,12 +83,11 @@ public class CloakOfShadows extends Artifact { if (action.equals( AC_STEALTH )) { - if (!stealthed){ + if (activeBuff == null){ if (!isEquipped(hero) && !hero.hasTalent(Talent.LIGHT_CLOAK)) GLog.i( Messages.get(Artifact.class, "need_to_equip") ); else if (cursed) GLog.i( Messages.get(this, "cursed") ); else if (charge <= 0) GLog.i( Messages.get(this, "no_charge") ); else { - stealthed = true; hero.spend( 1f ); hero.busy(); Sample.INSTANCE.play(Assets.Sounds.MELD); @@ -105,7 +102,6 @@ public class CloakOfShadows extends Artifact { hero.sprite.operate(hero.pos); } } else { - stealthed = false; activeBuff.detach(); activeBuff = null; hero.spend( 1f ); @@ -118,8 +114,7 @@ public class CloakOfShadows extends Artifact { @Override public void activate(Char ch){ super.activate(ch); - if (stealthed){ - activeBuff = activeBuff(); + if (activeBuff != null){ activeBuff.attachTo(ch); } } @@ -127,7 +122,6 @@ public class CloakOfShadows extends Artifact { @Override public boolean doUnequip(Hero hero, boolean collect, boolean single) { if (super.doUnequip(hero, collect, single)){ - stealthed = false; if (hero.hasTalent(Talent.LIGHT_CLOAK)){ activate(hero); } @@ -141,6 +135,7 @@ public class CloakOfShadows extends Artifact { public boolean collect( Bag container ) { if (super.collect(container)){ if (container.owner instanceof Hero + && passiveBuff == null && ((Hero) container.owner).hasTalent(Talent.LIGHT_CLOAK)){ activate((Hero) container.owner); } @@ -167,7 +162,6 @@ public class CloakOfShadows extends Artifact { return new cloakRecharge(); } - //FIXME errors with this! @Override protected ArtifactBuff activeBuff( ) { return new cloakStealth(); @@ -197,17 +191,21 @@ public class CloakOfShadows extends Artifact { } private static final String STEALTHED = "stealthed"; + private static final String BUFF = "buff"; @Override public void storeInBundle( Bundle bundle ) { super.storeInBundle(bundle); - bundle.put( STEALTHED, stealthed ); + if (activeBuff != null) bundle.put(BUFF, activeBuff); } @Override public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle(bundle); - stealthed = bundle.getBoolean( STEALTHED ); + if (bundle.contains(BUFF)){ + activeBuff = new cloakStealth(); + activeBuff.restoreFromBundle(bundle.getBundle(BUFF)); + } } @Override @@ -220,7 +218,7 @@ public class CloakOfShadows extends Artifact { public boolean act() { if (charge < chargeCap) { LockedFloor lock = target.buff(LockedFloor.class); - if (!stealthed && (lock == null || lock.regenOn())) { + if (activeBuff == null && (lock == null || lock.regenOn())) { float missing = (chargeCap - charge); if (level() > 7) missing += 5*(level() - 7)/3f; float turnsToCharge = (45 - missing); @@ -363,9 +361,7 @@ public class CloakOfShadows extends Artifact { @Override public void detach() { - if (target.invisible > 0) - target.invisible--; - stealthed = false; + if (target.invisible > 0) target.invisible--; updateQuickslot(); super.detach();