Merging Source v1.7.2: item changes
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.items;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
@@ -24,45 +26,73 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle
|
||||
|
||||
public abstract class EquipableItem extends Item {
|
||||
|
||||
public static final String AC_EQUIP = "EQUIP";
|
||||
public static final String AC_UNEQUIP = "UNEQUIP";
|
||||
|
||||
@Override
|
||||
public void execute( Hero hero, String action ) {
|
||||
if (action.equals( AC_EQUIP )) {
|
||||
doEquip( hero );
|
||||
} else if (action.equals( AC_UNEQUIP )) {
|
||||
doUnequip( hero, true );
|
||||
} else {
|
||||
super.execute( hero, action );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDrop( Hero hero ) {
|
||||
if (!isEquipped( hero ) || doUnequip( hero, false )) {
|
||||
super.doDrop( hero );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cast( final Hero user, int dst ) {
|
||||
|
||||
if (isEquipped( user )) {
|
||||
|
||||
if (quantity == 1 && !this.doUnequip( user, false )) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.cast( user, dst );
|
||||
}
|
||||
|
||||
protected static void equipCursed( Hero hero ) {
|
||||
hero.sprite.emitter().burst( ShadowParticle.CURSE, 6 );
|
||||
Sample.INSTANCE.play( Assets.SND_CURSED );
|
||||
}
|
||||
|
||||
public abstract boolean doEquip( Hero hero );
|
||||
public abstract boolean doUnequip( Hero hero, boolean collect );
|
||||
private static final String TXT_UNEQUIP_CURSED = "You can't remove cursed %s!";
|
||||
|
||||
public static final String AC_EQUIP = "EQUIP";
|
||||
public static final String AC_UNEQUIP = "UNEQUIP";
|
||||
|
||||
@Override
|
||||
public void execute( Hero hero, String action ) {
|
||||
if (action.equals( AC_EQUIP )) {
|
||||
doEquip( hero );
|
||||
} else if (action.equals( AC_UNEQUIP )) {
|
||||
doUnequip( hero, true );
|
||||
} else {
|
||||
super.execute( hero, action );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDrop( Hero hero ) {
|
||||
if (!isEquipped( hero ) || doUnequip( hero, false, false )) {
|
||||
super.doDrop( hero );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cast( final Hero user, int dst ) {
|
||||
|
||||
if (isEquipped( user )) {
|
||||
if (quantity == 1 && !this.doUnequip( user, false, false )) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.cast( user, dst );
|
||||
}
|
||||
|
||||
protected static void equipCursed( Hero hero ) {
|
||||
hero.sprite.emitter().burst( ShadowParticle.CURSE, 6 );
|
||||
Sample.INSTANCE.play( Assets.SND_CURSED );
|
||||
}
|
||||
|
||||
protected float time2equip( Hero hero ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public abstract boolean doEquip( Hero hero );
|
||||
|
||||
public boolean doUnequip( Hero hero, boolean collect, boolean single ) {
|
||||
|
||||
if (cursed) {
|
||||
GLog.w(TXT_UNEQUIP_CURSED, name());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (single) {
|
||||
hero.spendAndNext( time2equip( hero ) );
|
||||
} else {
|
||||
hero.spend( time2equip( hero ) );
|
||||
}
|
||||
|
||||
if (collect && !collect( hero.belongings.backpack )) {
|
||||
Dungeon.level.drop( this, hero.pos );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean doUnequip( Hero hero, boolean collect ) {
|
||||
return doUnequip( hero, collect, true );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user