v0.3.5: some refactoring to equippable items

This commit is contained in:
Evan Debenham 2016-03-07 01:27:27 -05:00
parent f8efaa6d5d
commit 2cca108f47
10 changed files with 124 additions and 160 deletions

View File

@ -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<Item> {
public static final int BACKPACK_SIZE = 19;
@ -96,6 +96,9 @@ public class Belongings implements Iterable<Item> {
}
armor = (Armor)bundle.get( ARMOR );
if (armor != null){
armor.activate( owner );
}
misc1 = (KindofMisc)bundle.get(MISC1);
if (misc1 != null) {

View File

@ -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 ){}
}

View File

@ -76,9 +76,6 @@ abstract public class KindOfWeapon extends EquipableItem {
}
}
public void activate( Hero hero ) {
}
abstract public int min();
abstract public int max();

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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() {

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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