diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java index 4a5a7a3c1..06c28443c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java @@ -315,7 +315,7 @@ public abstract class Char extends Actor { if (this instanceof Hero){ Hero h = (Hero)this; - if (h.belongings.weapon instanceof MissileWeapon + if (h.belongings.weapon() instanceof MissileWeapon && h.subClass == HeroSubClass.SNIPER && !Dungeon.level.adjacent(h.pos, enemy.pos)){ dr = 0; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java index 3ab050b01..bb428dfde 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java @@ -168,8 +168,8 @@ public class Combo extends Buff implements ActionIndicator.Action { @Override public Image getIcon() { Image icon; - if (((Hero)target).belongings.weapon != null){ - icon = new ItemSprite(((Hero)target).belongings.weapon.image, null); + if (((Hero)target).belongings.weapon() != null){ + icon = new ItemSprite(((Hero)target).belongings.weapon().image, null); } else { icon = new ItemSprite(new Item(){ {image = ItemSpriteSheet.WEAPON_HOLDER; }}); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index 510e0a3f3..11432f796 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -44,18 +44,6 @@ import java.util.Iterator; public class Belongings implements Iterable { private Hero owner; - - public Bag backpack; - - //FIXME these need accessor methods so they can work in conjunction with the lost inventory debuff =I - public KindOfWeapon weapon = null; - public Armor armor = null; - public Artifact artifact = null; - public KindofMisc misc = null; - public Ring ring = null; - - //used when thrown weapons temporary occupy the weapon slot - public KindOfWeapon stashedWeapon = null; public static class Backpack extends Bag { public int capacity(){ @@ -68,6 +56,8 @@ public class Belongings implements Iterable { return cap; } } + + public Backpack backpack; public Belongings( Hero owner ) { this.owner = owner; @@ -75,6 +65,69 @@ public class Belongings implements Iterable { backpack = new Backpack(); backpack.owner = owner; } + + public KindOfWeapon weapon = null; + public Armor armor = null; + public Artifact artifact = null; + public KindofMisc misc = null; + public Ring ring = null; + + //used when thrown weapons temporary become the current weapon + public KindOfWeapon thrownWeapon = null; + + //*** these accessor methods are so that worn items can be affected by various effects/debuffs + // we still want to access the raw equipped items in cases where effects should be ignored though, + // such as when equipping something, showing an interface, or dealing with items from a dead hero + + public KindOfWeapon weapon(){ + //no point in lost invent check, if it's assigned it must be usable + if (thrownWeapon != null) return thrownWeapon; + + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + if (!lostInvent || (weapon != null && weapon.keptThoughLostInvent)){ + return weapon; + } else { + return null; + } + } + + public Armor armor(){ + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + if (!lostInvent || (armor != null && armor.keptThoughLostInvent)){ + return armor; + } else { + return null; + } + } + + public Artifact artifact(){ + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + if (!lostInvent || (artifact != null && artifact.keptThoughLostInvent)){ + return artifact; + } else { + return null; + } + } + + public KindofMisc misc(){ + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + if (!lostInvent || (misc != null && misc.keptThoughLostInvent)){ + return misc; + } else { + return null; + } + } + + public Ring ring(){ + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + if (!lostInvent || (ring != null && ring.keptThoughLostInvent)){ + return ring; + } else { + return null; + } + } + + // *** private static final String WEAPON = "weapon"; private static final String ARMOR = "armor"; @@ -172,11 +225,13 @@ public class Belongings implements Iterable { @SuppressWarnings("unchecked") public T getItem( Class itemClass ) { - if (owner != null && owner.buff(LostInventory.class) != null) return null; + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; for (Item item : this) { if (itemClass.isInstance( item )) { - return (T)item; + if (!lostInvent || item.keptThoughLostInvent) { + return (T) item; + } } } @@ -186,11 +241,13 @@ public class Belongings implements Iterable { public ArrayList getAllItems( Class itemClass ) { ArrayList result = new ArrayList<>(); - if (owner != null && owner.buff(LostInventory.class) != null) return result; + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; for (Item item : this) { if (itemClass.isInstance( item )) { - result.add((T) item); + if (!lostInvent || item.keptThoughLostInvent) { + result.add((T) item); + } } } @@ -199,11 +256,13 @@ public class Belongings implements Iterable { public boolean contains( Item contains ){ - if (owner != null && owner.buff(LostInventory.class) != null) return false; + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; for (Item item : this) { - if (contains == item ) { - return true; + if (contains == item) { + if (!lostInvent || item.keptThoughLostInvent) { + return true; + } } } @@ -212,11 +271,13 @@ public class Belongings implements Iterable { public Item getSimilar( Item similar ){ - if (owner != null && owner.buff(LostInventory.class) != null) return null; + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; for (Item item : this) { if (similar != item && similar.isSimilar(item)) { - return item; + if (!lostInvent || item.keptThoughLostInvent) { + return item; + } } } @@ -226,11 +287,13 @@ public class Belongings implements Iterable { public ArrayList getAllSimilar( Item similar ){ ArrayList result = new ArrayList<>(); - if (owner != null && owner.buff(LostInventory.class) != null) return result; + boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; for (Item item : this) { if (item != similar && similar.isSimilar(item)) { - result.add(item); + if (!lostInvent || item.keptThoughLostInvent) { + result.add(item); + } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 414d58cfa..8c97197e7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -359,8 +359,8 @@ public class Hero extends Char { @Override public void hitSound(float pitch) { - if ( belongings.weapon != null ){ - belongings.weapon.hitSound(pitch); + if ( belongings.weapon() != null ){ + belongings.weapon().hitSound(pitch); } else if (RingOfForce.getBuffedBonus(this, RingOfForce.Force.class) > 0) { //pitch deepens by 2.5% (additive) per point of strength, down to 75% super.hitSound( pitch * GameMath.gate( 0.75f, 1.25f - 0.025f*STR(), 1f) ); @@ -371,7 +371,7 @@ public class Hero extends Char { @Override public boolean blockSound(float pitch) { - if ( belongings.weapon != null && belongings.weapon.defenseFactor(this) >= 4 ){ + if ( belongings.weapon() != null && belongings.weapon().defenseFactor(this) >= 4 ){ Sample.INSTANCE.play( Assets.Sounds.HIT_PARRY, 1, pitch); return true; } @@ -387,10 +387,10 @@ public class Hero extends Char { } public int tier() { - if (belongings.armor instanceof ClassArmor){ + if (belongings.armor() instanceof ClassArmor){ return 6; - } else if (belongings.armor != null){ - return belongings.armor.tier; + } else if (belongings.armor() != null){ + return belongings.armor().tier; } else { return 0; } @@ -401,12 +401,11 @@ public class Hero extends Char { this.enemy = enemy; //temporarily set the hero's weapon to the missile weapon being used - belongings.stashedWeapon = belongings.weapon; - belongings.weapon = wep; + //TODO improve this! + belongings.thrownWeapon = wep; boolean hit = attack( enemy ); Invisibility.dispel(); - belongings.weapon = belongings.stashedWeapon; - belongings.stashedWeapon = null; + belongings.thrownWeapon = null; if (hit && subClass == HeroSubClass.GLADIATOR){ Buff.affect( this, Combo.class ).hit( enemy ); @@ -417,7 +416,7 @@ public class Hero extends Char { @Override public int attackSkill( Char target ) { - KindOfWeapon wep = belongings.weapon; + KindOfWeapon wep = belongings.weapon(); float accuracy = 1; accuracy *= RingOfAccuracy.accuracyMultiplier( this ); @@ -455,8 +454,8 @@ public class Hero extends Char { evasion /= 2; } - if (belongings.armor != null) { - evasion = belongings.armor.evasionFactor(this, evasion); + if (belongings.armor() != null) { + evasion = belongings.armor().evasionFactor(this, evasion); } return Math.round(evasion); @@ -480,17 +479,17 @@ public class Hero extends Char { public int drRoll() { int dr = 0; - if (belongings.armor != null) { - int armDr = Random.NormalIntRange( belongings.armor.DRMin(), belongings.armor.DRMax()); - if (STR() < belongings.armor.STRReq()){ - armDr -= 2*(belongings.armor.STRReq() - STR()); + if (belongings.armor() != null) { + int armDr = Random.NormalIntRange( belongings.armor().DRMin(), belongings.armor().DRMax()); + if (STR() < belongings.armor().STRReq()){ + armDr -= 2*(belongings.armor().STRReq() - STR()); } if (armDr > 0) dr += armDr; } - if (belongings.weapon != null) { - int wepDr = Random.NormalIntRange( 0 , belongings.weapon.defenseFactor( this ) ); - if (STR() < ((Weapon)belongings.weapon).STRReq()){ - wepDr -= 2*(((Weapon)belongings.weapon).STRReq() - STR()); + if (belongings.weapon() != null) { + int wepDr = Random.NormalIntRange( 0 , belongings.weapon().defenseFactor( this ) ); + if (STR() < ((Weapon)belongings.weapon()).STRReq()){ + wepDr -= 2*(((Weapon)belongings.weapon()).STRReq() - STR()); } if (wepDr > 0) dr += wepDr; } @@ -504,7 +503,7 @@ public class Hero extends Char { @Override public int damageRoll() { - KindOfWeapon wep = belongings.weapon; + KindOfWeapon wep = belongings.weapon(); int dmg; if (wep != null) { @@ -525,8 +524,8 @@ public class Hero extends Char { speed *= RingOfHaste.speedMultiplier(this); - if (belongings.armor != null) { - speed = belongings.armor.speedFactor(this, speed); + if (belongings.armor() != null) { + speed = belongings.armor().speedFactor(this, speed); } Momentum momentum = buff(Momentum.class); @@ -547,9 +546,9 @@ public class Hero extends Char { } public boolean canSurpriseAttack(){ - if (belongings.weapon == null || !(belongings.weapon instanceof Weapon)) return true; - if (STR() < ((Weapon)belongings.weapon).STRReq()) return false; - if (belongings.weapon instanceof Flail) return false; + if (belongings.weapon() == null || !(belongings.weapon() instanceof Weapon)) return true; + if (STR() < ((Weapon)belongings.weapon()).STRReq()) return false; + if (belongings.weapon() instanceof Flail) return false; return true; } @@ -564,7 +563,7 @@ public class Hero extends Char { return true; } - KindOfWeapon wep = Dungeon.hero.belongings.weapon; + KindOfWeapon wep = Dungeon.hero.belongings.weapon(); if (wep != null){ return wep.canReach(this, enemy.pos); @@ -579,9 +578,9 @@ public class Hero extends Char { return 0; } - if (belongings.weapon != null) { + if (belongings.weapon() != null) { - return belongings.weapon.delayFactor( this ); + return belongings.weapon().delayFactor( this ); } else { //Normally putting furor speed on unarmed attacks would be unnecessary @@ -1110,7 +1109,7 @@ public class Hero extends Char { public int attackProc( final Char enemy, int damage ) { damage = super.attackProc( enemy, damage ); - KindOfWeapon wep = belongings.weapon; + KindOfWeapon wep = belongings.weapon(); if (wep != null) damage = wep.proc( this, enemy, damage ); @@ -1158,8 +1157,8 @@ public class Hero extends Char { berserk.damage(damage); } - if (belongings.armor != null) { - damage = belongings.armor.proc( enemy, this, damage ); + if (belongings.armor() != null) { + damage = belongings.armor().proc( enemy, this, damage ); } Earthroot.Armor armor = buff( Earthroot.Armor.class ); @@ -1198,9 +1197,9 @@ public class Hero extends Char { dmg = (int)Math.ceil(dmg * RingOfTenacity.damageMultiplier( this )); //TODO improve this when I have proper damage source logic - if (belongings.armor != null && belongings.armor.hasGlyph(AntiMagic.class, this) + if (belongings.armor() != null && belongings.armor().hasGlyph(AntiMagic.class, this) && AntiMagic.RESISTS.contains(src.getClass())){ - dmg -= AntiMagic.drRoll(belongings.armor.buffedLvl()); + dmg -= AntiMagic.drRoll(belongings.armor().buffedLvl()); } if (buff(Talent.WarriorFoodImmunity.class) != null){ @@ -1586,8 +1585,8 @@ public class Hero extends Char { public float stealth() { float stealth = super.stealth(); - if (belongings.armor != null){ - stealth = belongings.armor.stealthFactor(this, stealth); + if (belongings.armor() != null){ + stealth = belongings.armor().stealthFactor(this, stealth); } return stealth; @@ -1834,8 +1833,8 @@ public class Hero extends Char { @Override public boolean isImmune(Class effect) { if (effect == Burning.class - && belongings.armor != null - && belongings.armor.hasGlyph(Brimstone.class, this)){ + && belongings.armor() != null + && belongings.armor().hasGlyph(Brimstone.class, this)){ return true; } return super.isImmune(effect); @@ -1982,6 +1981,13 @@ public class Hero extends Char { Buff.affect(this, LostInventory.class); Buff.affect(this, Invisibility.class, 3f); //lost inventory is dropped in interlevelscene + + //activate items that persist after lost inventory + if (belongings.weapon() != null) belongings.weapon().activate(this); + if (belongings.armor() != null) belongings.armor().activate(this); + if (belongings.artifact() != null) belongings.artifact().activate(this); + if (belongings.misc() != null) belongings.misc().activate(this); + if (belongings.ring() != null) belongings.ring().activate(this); } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java index 7e24c2d63..c4256ebb2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java @@ -239,8 +239,8 @@ public enum Talent { } if (talent == ARMSMASTERS_INTUITION && hero.pointsInTalent(ARMSMASTERS_INTUITION) == 2){ - if (hero.belongings.weapon != null) hero.belongings.weapon.identify(); - if (hero.belongings.armor != null) hero.belongings.armor.identify(); + if (hero.belongings.weapon() != null) hero.belongings.weapon().identify(); + if (hero.belongings.armor() != null) hero.belongings.armor.identify(); } if (talent == THIEFS_INTUITION && hero.pointsInTalent(THIEFS_INTUITION) == 2){ if (hero.belongings.ring instanceof Ring) hero.belongings.ring.identify(); @@ -446,7 +446,7 @@ public enum Talent { } if (hero.hasTalent(Talent.FOLLOWUP_STRIKE)) { - if (hero.belongings.weapon instanceof MissileWeapon) { + if (hero.belongings.weapon() instanceof MissileWeapon) { Buff.affect(enemy, FollowupStrikeTracker.class); } else if (enemy.buff(FollowupStrikeTracker.class) != null){ dmg += 1 + hero.pointsInTalent(FOLLOWUP_STRIKE); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/rogue/ShadowClone.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/rogue/ShadowClone.java index 122ecd136..15d374dd6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/rogue/ShadowClone.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/rogue/ShadowClone.java @@ -203,8 +203,8 @@ public class ShadowClone extends ArmorAbility { public int attackProc( Char enemy, int damage ) { damage = super.attackProc( enemy, damage ); if (Random.Int(4) < Dungeon.hero.pointsInTalent(Talent.SHADOW_BLADE) - && Dungeon.hero.belongings.weapon != null){ - return Dungeon.hero.belongings.weapon.proc( this, enemy, damage ); + && Dungeon.hero.belongings.weapon() != null){ + return Dungeon.hero.belongings.weapon().proc( this, enemy, damage ); } else { return damage; } @@ -225,8 +225,8 @@ public class ShadowClone extends ArmorAbility { public int defenseProc(Char enemy, int damage) { damage = super.defenseProc(enemy, damage); if (Random.Int(4) < Dungeon.hero.pointsInTalent(Talent.CLONED_ARMOR) - && Dungeon.hero.belongings.armor != null){ - return Dungeon.hero.belongings.armor.proc( enemy, this, damage ); + && Dungeon.hero.belongings.armor() != null){ + return Dungeon.hero.belongings.armor().proc( enemy, this, damage ); } else { return damage; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index 2339ce553..7ac2f99cb 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -568,7 +568,7 @@ public abstract class Mob extends Char { public int defenseProc( Char enemy, int damage ) { if (enemy instanceof Hero - && ((Hero) enemy).belongings.weapon instanceof MissileWeapon + && ((Hero) enemy).belongings.weapon() instanceof MissileWeapon && !hitWithRanged){ hitWithRanged = true; Statistics.thrownAssists++; @@ -580,8 +580,8 @@ public abstract class Mob extends Char { Badges.validateRogueUnlock(); //TODO this is somewhat messy, it would be nicer to not have to manually handle delays here // playing the strong hit sound might work best as another property of weapon? - if (Dungeon.hero.belongings.weapon instanceof SpiritBow.SpiritArrow - || Dungeon.hero.belongings.weapon instanceof Dart){ + if (Dungeon.hero.belongings.weapon() instanceof SpiritBow.SpiritArrow + || Dungeon.hero.belongings.weapon() instanceof Dart){ Sample.INSTANCE.playDelayed(Assets.Sounds.HIT_STRONG, 0.125f); } else { Sample.INSTANCE.play(Assets.Sounds.HIT_STRONG); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/MirrorImage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/MirrorImage.java index 92773bf09..e25c543d5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/MirrorImage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/MirrorImage.java @@ -102,8 +102,8 @@ public class MirrorImage extends NPC { @Override public int damageRoll() { int damage; - if (hero.belongings.weapon != null){ - damage = hero.belongings.weapon.damageRoll(this); + if (hero.belongings.weapon() != null){ + damage = hero.belongings.weapon().damageRoll(this); } else { damage = hero.damageRoll(); //handles ring of force } @@ -135,13 +135,13 @@ public class MirrorImage extends NPC { @Override protected boolean canAttack(Char enemy) { - return super.canAttack(enemy) || (hero.belongings.weapon != null && hero.belongings.weapon.canReach(this, enemy.pos)); + return super.canAttack(enemy) || (hero.belongings.weapon() != null && hero.belongings.weapon().canReach(this, enemy.pos)); } @Override public int drRoll() { - if (hero != null && hero.belongings.weapon != null){ - return Random.NormalIntRange(0, hero.belongings.weapon.defenseFactor(this)/2); + if (hero != null && hero.belongings.weapon() != null){ + return Random.NormalIntRange(0, hero.belongings.weapon().defenseFactor(this)/2); } else { return 0; } @@ -159,8 +159,8 @@ public class MirrorImage extends NPC { if (enemy instanceof Mob) { ((Mob)enemy).aggro( this ); } - if (hero.belongings.weapon != null){ - damage = hero.belongings.weapon.proc( this, enemy, damage ); + if (hero.belongings.weapon() != null){ + damage = hero.belongings.weapon().proc( this, enemy, damage ); if (!enemy.isAlive() && enemy == Dungeon.hero){ Dungeon.fail(getClass()); GLog.n( Messages.capitalize(Messages.get(Char.class, "kill", name())) ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/PrismaticImage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/PrismaticImage.java index 8e88862a2..e3098226d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/PrismaticImage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/PrismaticImage.java @@ -185,8 +185,8 @@ public class PrismaticImage extends NPC { @Override public int defenseProc(Char enemy, int damage) { damage = super.defenseProc(enemy, damage); - if (hero != null && hero.belongings.armor != null){ - return hero.belongings.armor.proc( enemy, this, damage ); + if (hero != null && hero.belongings.armor() != null){ + return hero.belongings.armor().proc( enemy, this, damage ); } else { return damage; } @@ -196,9 +196,9 @@ public class PrismaticImage extends NPC { public void damage(int dmg, Object src) { //TODO improve this when I have proper damage source logic - if (hero != null && hero.belongings.armor != null && hero.belongings.armor.hasGlyph(AntiMagic.class, this) + if (hero != null && hero.belongings.armor() != null && hero.belongings.armor().hasGlyph(AntiMagic.class, this) && AntiMagic.RESISTS.contains(src.getClass())){ - dmg -= AntiMagic.drRoll(hero.belongings.armor.buffedLvl()); + dmg -= AntiMagic.drRoll(hero.belongings.armor().buffedLvl()); } super.damage(dmg, src); @@ -206,8 +206,8 @@ public class PrismaticImage extends NPC { @Override public float speed() { - if (hero != null && hero.belongings.armor != null){ - return hero.belongings.armor.speedFactor(this, super.speed()); + if (hero != null && hero.belongings.armor() != null){ + return hero.belongings.armor().speedFactor(this, super.speed()); } return super.speed(); } @@ -238,8 +238,8 @@ public class PrismaticImage extends NPC { public boolean isImmune(Class effect) { if (effect == Burning.class && hero != null - && hero.belongings.armor != null - && hero.belongings.armor.hasGlyph(Brimstone.class, this)){ + && hero.belongings.armor() != null + && hero.belongings.armor().hasGlyph(Brimstone.class, this)){ return true; } return super.isImmune(effect); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java index b9b2975a7..51e08a037 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java @@ -117,7 +117,7 @@ public class RatKing extends NPC { yell( Messages.get(this, "not_sleeping") ); state = WANDERING; } else if (crown != null){ - if (Dungeon.hero.belongings.armor == null){ + if (Dungeon.hero.belongings.armor() == null){ yell( Messages.get(RatKing.class, "crown_clothes") ); } else { Badges.validateRatmogrify(); @@ -135,7 +135,7 @@ public class RatKing extends NPC { @Override protected void onSelect(int index) { if (index == 0){ - crown.upgradeArmor(Dungeon.hero, Dungeon.hero.belongings.armor, new Ratmogrify()); + crown.upgradeArmor(Dungeon.hero, Dungeon.hero.belongings.armor(), new Ratmogrify()); ((RatKingSprite)sprite).resetAnims(); yell(Messages.get(RatKing.class, "crown_thankyou")); } else if (index == 1) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java index e3a7fca4d..ce74b1dd5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java @@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Degrade; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; @@ -87,6 +88,9 @@ public class Item implements Bundlable { // Unique items persist through revival public boolean unique = false; + // These items are preserved even if the hero's inventory is lost via unblessed ankh + public boolean keptThoughLostInvent = false; + // whether an item can be included in heroes remains public boolean bones = false; @@ -484,6 +488,7 @@ public class Item implements Bundlable { private static final String CURSED = "cursed"; private static final String CURSED_KNOWN = "cursedKnown"; private static final String QUICKSLOT = "quickslotpos"; + private static final String KEPT_LOST = "kept_lost"; @Override public void storeInBundle( Bundle bundle ) { @@ -495,6 +500,7 @@ public class Item implements Bundlable { if (Dungeon.quickslot.contains(this)) { bundle.put( QUICKSLOT, Dungeon.quickslot.getSlot(this) ); } + bundle.put( KEPT_LOST, keptThoughLostInvent ); } @Override @@ -518,6 +524,8 @@ public class Item implements Bundlable { Dungeon.quickslot.setSlot(bundle.getInt(QUICKSLOT), this); } } + + keptThoughLostInvent = bundle.getBoolean( KEPT_LOST ); } public int targetingPos( Hero user, int dst ){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java index 7028a2a44..5f1975c09 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java @@ -44,7 +44,7 @@ abstract public class KindOfWeapon extends EquipableItem { @Override public boolean isEquipped( Hero hero ) { - return hero.belongings.weapon == this || hero.belongings.stashedWeapon == this; + return hero.belongings.weapon() == this; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java index 89c28e3dd..87bf1b0c6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java @@ -174,9 +174,9 @@ public abstract class KindofMisc extends EquipableItem { @Override public boolean isEquipped( Hero hero ) { - return hero.belongings.artifact == this - || hero.belongings.misc == this - || hero.belongings.ring == this; + return hero.belongings.artifact() == this + || hero.belongings.misc() == this + || hero.belongings.ring() == this; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KingsCrown.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KingsCrown.java index 4dbebb74a..ea7d1ebb9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KingsCrown.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/KingsCrown.java @@ -67,8 +67,8 @@ public class KingsCrown extends Item { if (action.equals(AC_WEAR)) { curUser = hero; - if (hero.belongings.armor != null){ - GameScene.show( new WndChooseAbility(this, hero.belongings.armor, hero)); + if (hero.belongings.armor() != null){ + GameScene.show( new WndChooseAbility(this, hero.belongings.armor(), hero)); } else { GLog.w( Messages.get(this, "naked")); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/LostBackpack.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/LostBackpack.java index b4195d083..081475855 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/LostBackpack.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/LostBackpack.java @@ -1,6 +1,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; @@ -20,6 +21,17 @@ public class LostBackpack extends Item { if (hero.buff(LostInventory.class) != null){ hero.buff(LostInventory.class).detach(); } + + for (Item i : hero.belongings){ + if (i.keptThoughLostInvent){ + i.keptThoughLostInvent = false; + } else { + if (i instanceof EquipableItem && i.isEquipped(hero)){ + ((EquipableItem) i).activate(hero); + } + } + } + Item.updateQuickslot(); Sample.INSTANCE.play( Assets.Sounds.DEWDROP ); hero.spendAndNext(TIME_TO_PICK_UP); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java index 03b0b8bcc..4a59ea60b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java @@ -276,7 +276,7 @@ public class Armor extends EquipableItem { @Override public boolean isEquipped( Hero hero ) { - return hero.belongings.armor == this; + return hero.belongings.armor() == this; } public final int DRMax(){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Viscosity.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Viscosity.java index 0f45310bd..5fe6af47b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Viscosity.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Viscosity.java @@ -57,7 +57,7 @@ public class Viscosity extends Glyph { //account for huntress armor piercing if (attacker instanceof Hero - && ((Hero) attacker).belongings.weapon instanceof MissileWeapon + && ((Hero) attacker).belongings.weapon() instanceof MissileWeapon && ((Hero) attacker).subClass == HeroSubClass.SNIPER && !Dungeon.level.adjacent(attacker.pos, defender.pos)){ realDamage = damage; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/bags/Bag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/bags/Bag.java index 5a34fdddd..c9d6d11b4 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/bags/Bag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/bags/Bag.java @@ -167,7 +167,8 @@ public class Bag extends Item implements Iterable { } public boolean canHold( Item item ){ - if (!loading && owner != null && owner.buff(LostInventory.class) != null){ + if (!loading && owner != null && owner.buff(LostInventory.class) != null + && !item.keptThoughLostInvent){ return false; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/Dart.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/Dart.java index 8d8053fb2..cf8f31309 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/Dart.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/Dart.java @@ -98,8 +98,8 @@ public class Dart extends MissileWeapon { private static Crossbow bow; private void updateCrossbow(){ - if (Dungeon.hero.belongings.weapon instanceof Crossbow){ - bow = (Crossbow) Dungeon.hero.belongings.weapon; + if (Dungeon.hero.belongings.weapon() instanceof Crossbow){ + bow = (Crossbow) Dungeon.hero.belongings.weapon(); } else { bow = null; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/HighGrass.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/HighGrass.java index 2d463ab15..73b47bb3a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/HighGrass.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/HighGrass.java @@ -126,7 +126,7 @@ public class HighGrass { //Camouflage //FIXME doesn't work with sad ghost - if (hero.belongings.armor != null && hero.belongings.armor.hasGlyph(Camouflage.class, hero)) { + if (hero.belongings.armor() != null && hero.belongings.armor().hasGlyph(Camouflage.class, hero)) { Buff.prolong(hero, Invisibility.class, 3 + hero.belongings.armor.buffedLvl()/2); Sample.INSTANCE.play( Assets.Sounds.MELD ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/CursingTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/CursingTrap.java index 9fdc199f6..83330d6d9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/CursingTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/CursingTrap.java @@ -74,7 +74,7 @@ public class CursingTrap extends Trap { //items the trap can curse if nothing else is available. ArrayList canCurse = new ArrayList<>(); - KindOfWeapon weapon = hero.belongings.weapon; + KindOfWeapon weapon = hero.belongings.weapon(); if (weapon instanceof Weapon && !(weapon instanceof MagesStaff)){ if (((Weapon) weapon).enchantment == null) priorityCurse.add(weapon); @@ -82,7 +82,7 @@ public class CursingTrap extends Trap { canCurse.add(weapon); } - Armor armor = hero.belongings.armor; + Armor armor = hero.belongings.armor(); if (armor != null){ if (armor.glyph == null) priorityCurse.add(armor); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MissileSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MissileSprite.java index 3d76ae02e..243c39702 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MissileSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MissileSprite.java @@ -149,7 +149,7 @@ public class MissileSprite extends ItemSprite implements Tweener.Listener { } float speed = SPEED; - if (item instanceof Dart && Dungeon.hero.belongings.weapon instanceof Crossbow){ + if (item instanceof Dart && Dungeon.hero.belongings.weapon() instanceof Crossbow){ speed *= 3f; } else if (item instanceof SpiritBow.SpiritArrow diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java index f5c42d60b..8a70876fe 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java @@ -216,7 +216,9 @@ public class QuickSlotButton extends Button { } private void enableSlot() { - slot.enable(Dungeon.quickslot.isNonePlaceholder( slotNum ) && Dungeon.hero.buff(LostInventory.class) == null); + //TODO check if item persists! + slot.enable(Dungeon.quickslot.isNonePlaceholder( slotNum ) + && (Dungeon.hero.buff(LostInventory.class) == null || Dungeon.quickslot.getItem(slotNum).keptThoughLostInvent)); } public static void useTargeting(int idx){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index f10d65aa5..cdeeb0e19 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -388,7 +388,8 @@ public class WndBag extends WndTabbed { enable( false ); } else if (selector != null && !selector.itemSelectable(item)) { enable(false); - } else if (Dungeon.hero.buff(LostInventory.class) != null){ + } else if (Dungeon.hero.buff(LostInventory.class) != null + && !item.keptThoughLostInvent){ enable(false); } } else { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndCombo.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndCombo.java index 74837dedd..b3de25e2b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndCombo.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndCombo.java @@ -55,8 +55,8 @@ public class WndCombo extends Window { pos = title.bottom() + 3*MARGIN; Image icon; - if (Dungeon.hero.belongings.weapon != null){ - icon = new ItemSprite(Dungeon.hero.belongings.weapon.image, null); + if (Dungeon.hero.belongings.weapon() != null){ + icon = new ItemSprite(Dungeon.hero.belongings.weapon().image, null); } else { icon = new ItemSprite(new Item(){ {image = ItemSpriteSheet.WEAPON_HOLDER; }}); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java index acbfa8f72..da0190e6f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java @@ -198,8 +198,9 @@ public class WndQuickBag extends Window { } } - if (Dungeon.hero.buff(LostInventory.class) != null){ - enable(false); //TODO enable when hero has selected this item to keep + if (Dungeon.hero.buff(LostInventory.class) != null + && !item.keptThoughLostInvent){ + enable(false); } } else { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndResurrect.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndResurrect.java index 427fa1495..e3eff6d18 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndResurrect.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndResurrect.java @@ -69,6 +69,14 @@ public class WndResurrect extends Window { hide(); Statistics.ankhsUsed++; + + //TODO let the player choose their items, instead of rigid weapon or armor + if (Dungeon.hero.belongings.weapon() != null){ + Dungeon.hero.belongings.weapon().keptThoughLostInvent = true; + } + if (Dungeon.hero.belongings.armor() != null){ + Dungeon.hero.belongings.armor().keptThoughLostInvent = true; + } InterlevelScene.mode = InterlevelScene.Mode.RESURRECT; Game.switchScene( InterlevelScene.class );