/* * Pixel Dungeon * Copyright (C) 2012-2014 Oleg Dolya * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see */ package com.shatteredpixel.shatteredpixeldungeon.items; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; 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 ); }