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