From 2cca108f47743e751d7480710fec2768909c2f67 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 7 Mar 2016 01:27:27 -0500 Subject: [PATCH] v0.3.5: some refactoring to equippable items --- .../actors/hero/Belongings.java | 9 +- .../items/EquipableItem.java | 3 + .../items/KindOfWeapon.java | 3 - .../items/KindofMisc.java | 86 +++++++++++++++++- .../items/artifacts/Artifact.java | 87 ++++--------------- .../items/rings/Ring.java | 68 +-------------- .../items/wands/CursedWand.java | 2 +- .../items/weapon/melee/MagesStaff.java | 11 +-- .../levels/traps/CursingTrap.java | 6 +- .../messages/items/items.properties | 9 +- 10 files changed, 124 insertions(+), 160 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index 2f797056c..5dd8acd0f 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -20,12 +20,10 @@ */ package com.shatteredpixel.shatteredpixeldungeon.actors.hero; -import java.util.Iterator; - import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag; @@ -37,6 +35,8 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.utils.Bundle; import com.watabou.utils.Random; +import java.util.Iterator; + public class Belongings implements Iterable { public static final int BACKPACK_SIZE = 19; @@ -96,6 +96,9 @@ public class Belongings implements Iterable { } armor = (Armor)bundle.get( ARMOR ); + if (armor != null){ + armor.activate( owner ); + } misc1 = (KindofMisc)bundle.get(MISC1); if (misc1 != null) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java index e9b50a51e..e0d9b2292 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java @@ -22,6 +22,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; @@ -120,4 +121,6 @@ public abstract class EquipableItem extends Item { final public boolean doUnequip( Hero hero, boolean collect ) { return doUnequip( hero, collect, true ); } + + public void activate( Char ch ){} } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java index ad0860735..64f817838 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java @@ -76,9 +76,6 @@ abstract public class KindOfWeapon extends EquipableItem { } } - - public void activate( Hero hero ) { - } abstract public int min(); abstract public int max(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java index dc7149100..8d7958657 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java @@ -20,11 +20,91 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items; -import com.shatteredpixel.shatteredpixeldungeon.actors.Char; -import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; +import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; +import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; public abstract class KindofMisc extends EquipableItem { - public abstract void activate(Char ch); + private static final float TIME_TO_EQUIP = 1f; + + @Override + public boolean doEquip(final Hero hero) { + + if (hero.belongings.misc1 != null && hero.belongings.misc2 != null) { + + final KindofMisc m1 = hero.belongings.misc1; + final KindofMisc m2 = hero.belongings.misc2; + final KindofMisc toEquip = this; + + GameScene.show( + new WndOptions(Messages.get(KindofMisc.class, "unequip_title"), + Messages.get(KindofMisc.class, "unequip_message"), + Messages.titleCase(m1.toString()), + Messages.titleCase(m2.toString())) { + + @Override + protected void onSelect(int index) { + + KindofMisc equipped = (index == 0 ? m1 : m2); + if (equipped.doUnequip(hero, true, false)) { + execute(hero, AC_EQUIP); + } + } + }); + + return false; + + } else { + + if (hero.belongings.misc1 == null) { + hero.belongings.misc1 = this; + } else { + hero.belongings.misc2 = this; + } + + detach( hero.belongings.backpack ); + + activate( hero ); + + cursedKnown = true; + if (cursed) { + equipCursed( hero ); + GLog.n( Messages.get(this, "cursed", this) ); + } + + hero.spendAndNext( TIME_TO_EQUIP ); + return true; + + } + + } + + @Override + public boolean doUnequip(Hero hero, boolean collect, boolean single) { + if (super.doUnequip(hero, collect, single)){ + + if (hero.belongings.misc1 == this) { + hero.belongings.misc1 = null; + } else { + hero.belongings.misc2 = null; + } + + return true; + + } else { + + return false; + + } + } + + @Override + public boolean isEquipped( Hero hero ) { + return hero.belongings.misc1 == this || hero.belongings.misc2 == this; + } + } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java index 0f3272b03..12947ea14 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; @@ -29,14 +28,11 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.watabou.utils.Bundle; import com.watabou.utils.Random; public class Artifact extends KindofMisc { - private static final float TIME_TO_EQUIP = 1f; - private static final String TXT_TO_STRING = "%s"; private static final String TXT_TO_STRING_CHARGE = "%s (%d/%d)"; private static final String TXT_TO_STRING_LVL = "%s%+d"; @@ -63,10 +59,6 @@ public class Artifact extends KindofMisc { //used by some artifacts to keep track of duration of effects or cooldowns to use. protected int cooldown = 0; - - public Artifact(){ - super(); - } @Override public boolean doEquip( final Hero hero ) { @@ -76,57 +68,19 @@ public class Artifact extends KindofMisc { GLog.w( Messages.get(Artifact.class, "cannot_wear_two") ); return false; - } else if (hero.belongings.misc1 != null && hero.belongings.misc2 != null) { - - final KindofMisc m1 = hero.belongings.misc1; - final KindofMisc m2 = hero.belongings.misc2; - final Artifact art = this; - - ShatteredPixelDungeon.scene().add( - new WndOptions(Messages.get(Artifact.class, "unequip_title"), - Messages.get(Artifact.class, "unequip_message"), - Messages.titleCase(m1.toString()), - Messages.titleCase(m2.toString())) { - - @Override - protected void onSelect(int index) { - - KindofMisc equipped = (index == 0 ? m1 : m2); - if (equipped.doUnequip(hero, true, false)) { - int slot = Dungeon.quickslot.getSlot( art ); - doEquip(hero); - if (slot != -1) { - Dungeon.quickslot.setSlot( slot, art ); - updateQuickslot(); - } - } - } - }); - - return false; - } else { - if (hero.belongings.misc1 == null) { - hero.belongings.misc1 = this; + if (super.doEquip( hero )){ + + identify(); + return true; + } else { - hero.belongings.misc2 = this; + + return false; + } - detach( hero.belongings.backpack ); - - activate( hero ); - - cursedKnown = true; - identify(); - if (cursed) { - equipCursed( hero ); - GLog.n( Messages.get(Artifact.class, "cursed_worn") ); - } - - hero.spendAndNext( TIME_TO_EQUIP ); - return true; - } } @@ -140,21 +94,15 @@ public class Artifact extends KindofMisc { public boolean doUnequip( Hero hero, boolean collect, boolean single ) { if (super.doUnequip( hero, collect, single )) { - if (hero.belongings.misc1 == this) { - hero.belongings.misc1 = null; - } else { - hero.belongings.misc2 = null; - } + passiveBuff.detach(); + passiveBuff = null; - passiveBuff.detach(); - passiveBuff = null; + if (activeBuff != null){ + activeBuff.detach(); + activeBuff = null; + } - if (activeBuff != null){ - activeBuff.detach(); - activeBuff = null; - } - - return true; + return true; } else { @@ -163,11 +111,6 @@ public class Artifact extends KindofMisc { } } - @Override - public boolean isEquipped( Hero hero ) { - return hero.belongings.misc1 == this || hero.belongings.misc2 == this; - } - @Override public boolean isUpgradable() { return false; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index 2ff49ad7b..c0d30e05b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -22,26 +22,22 @@ package com.shatteredpixel.shatteredpixeldungeon.items.rings; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; -import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.ItemStatusHandler; +import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.watabou.utils.Bundle; import com.watabou.utils.Random; public class Ring extends KindofMisc { private static final int TICKS_TO_KNOW = 200; - - private static final float TIME_TO_EQUIP = 1f; protected Buff buff; @@ -105,57 +101,6 @@ public class Ring extends KindofMisc { gem = handler.label( this ); } - @Override - public boolean doEquip( final Hero hero ) { - - if (hero.belongings.misc1 != null && hero.belongings.misc2 != null) { - - final KindofMisc m1 = hero.belongings.misc1; - final KindofMisc m2 = hero.belongings.misc2; - - ShatteredPixelDungeon.scene().add( - new WndOptions(Messages.get(Ring.class, "unequip_title"), - Messages.get(Ring.class, "unequip_message"), - Messages.titleCase(m1.toString()), - Messages.titleCase(m2.toString())) { - - @Override - protected void onSelect(int index) { - - KindofMisc equipped = (index == 0 ? m1 : m2); - if (equipped.doUnequip(hero, true, false)) { - doEquip(hero); - } - } - }); - - return false; - - } else { - - if (hero.belongings.misc1 == null) { - hero.belongings.misc1 = this; - } else { - hero.belongings.misc2 = this; - } - - detach( hero.belongings.backpack ); - - activate( hero ); - - cursedKnown = true; - if (cursed) { - equipCursed( hero ); - GLog.n( Messages.get(this, "cursed", this) ); - } - - hero.spendAndNext( TIME_TO_EQUIP ); - return true; - - } - - } - public void activate( Char ch ) { buff = buff(); buff.attachTo( ch ); @@ -165,12 +110,6 @@ public class Ring extends KindofMisc { public boolean doUnequip( Hero hero, boolean collect, boolean single ) { if (super.doUnequip( hero, collect, single )) { - if (hero.belongings.misc1 == this) { - hero.belongings.misc1 = null; - } else { - hero.belongings.misc2 = null; - } - hero.remove( buff ); buff = null; @@ -183,11 +122,6 @@ public class Ring extends KindofMisc { } } - @Override - public boolean isEquipped( Hero hero ) { - return hero.belongings.misc1 == this || hero.belongings.misc2 == this; - } - @Override public Item upgrade() { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java index 8c071a290..356d083b3 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java @@ -48,8 +48,8 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Bomb; import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Item; -import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; +import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MagesStaff.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MagesStaff.java index 1b7a5a57a..ceb5d7e9e 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MagesStaff.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MagesStaff.java @@ -29,7 +29,10 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade; -import com.shatteredpixel.shatteredpixeldungeon.items.wands.*; +import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand; +import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfCorruption; +import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfDisintegration; +import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfRegrowth; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; @@ -40,8 +43,6 @@ import com.watabou.noosa.audio.Sample; import com.watabou.noosa.particles.Emitter; import com.watabou.noosa.particles.PixelParticle; import com.watabou.utils.Bundle; -import com.watabou.utils.ColorMath; -import com.watabou.utils.PointF; import com.watabou.utils.Random; import java.util.ArrayList; @@ -98,8 +99,8 @@ public class MagesStaff extends MeleeWeapon { } @Override - public void activate( Hero hero ) { - if(wand != null) wand.charge( hero, STAFF_SCALE_FACTOR ); + public void activate( Char ch ) { + if(wand != null) wand.charge( ch, STAFF_SCALE_FACTOR ); } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/traps/CursingTrap.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/traps/CursingTrap.java index 6a02ed649..8a9871b2b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/traps/CursingTrap.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/traps/CursingTrap.java @@ -25,7 +25,11 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle; -import com.shatteredpixel.shatteredpixeldungeon.items.*; +import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; +import com.shatteredpixel.shatteredpixeldungeon.items.Heap; +import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; +import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties b/src/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties index 13d98d122..92b6445e2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties +++ b/src/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties @@ -87,10 +87,8 @@ items.artifacts.alchemiststoolkit.name=alchemists toolkit items.artifacts.alchemiststoolkit.ac_brew=BREW ##this one isn't dropped, so for now no i18n -items.artifacts.artifact.unequip_title=Unequip one item -items.artifacts.artifact.unequip_message=You can only wear two misc items at a time. items.artifacts.artifact.cannot_wear_two=You cannot wear two of the same artifact. -items.artifacts.artifact.cursed_worn=The artifact painfully binds itself to you. +items.artifacts.artifact.cursed=The artifact painfully binds itself to you. items.artifacts.artifact.curse_known=You can feel a malevolent magic lurking within the artifact. items.artifacts.artifact.need_to_equip=You need to equip your artifact to do that. @@ -467,8 +465,6 @@ items.rings.ring.identify=You are now familiar enough with your %s to identify i items.rings.ring.on_finger=The %s is on your finger. items.rings.ring.cursed_worn=Because this ring is cursed, you are powerless to remove it. items.rings.ring.curse_known=You can feel a malevolent magic lurking within the %s. -items.rings.ring.unequip_title=Unequip one item -items.rings.ring.unequip_message=You can only wear two misc items at a time. items.rings.ringofaccuracy.name=ring of accuracy items.rings.ringofaccuracy.desc=This ring increases your focus, reducing your enemy's ability to dodge your attacks. A degraded ring will instead make you easier to evade. @@ -837,6 +833,9 @@ items.item.ac_drop=DROP items.item.ac_throw=THROW items.item.rankings_desc=Killed by: %s +items.kindofmisc.unequip_title=Unequip one item +items.kindofmisc.unequip_message=You can only wear two misc items at a time. + items.kindofweapon.cursed=you wince as your grip involuntarily tightens around your %s items.merchantsbeacon.name=merchant's beacon