/* * Pixel Dungeon * Copyright (C) 2012-2015 Oleg Dolya * * Shattered Pixel Dungeon * Copyright (C) 2014-2015 Evan Debenham * * 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.weapon.missiles; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.MissileSprite; import java.util.ArrayList; public class Boomerang extends MissileWeapon { { image = ItemSpriteSheet.BOOMERANG; STR = 10; stackable = false; unique = true; bones = false; } @Override public ArrayList actions(Hero hero) { ArrayList actions = super.actions( hero ); if (!isEquipped(hero)) actions.add(AC_EQUIP); return actions; } @Override public int min() { return 1 + level(); } @Override public int max() { return 5 + 2 * level(); } @Override public boolean isUpgradable() { return true; } @Override public Item upgrade() { return upgrade( false ); } @Override public Item upgrade( boolean enchant ) { super.upgrade( enchant ); updateQuickslot(); return this; } @Override public Item degrade() { return super.degrade(); } @Override public void proc( Char attacker, Char defender, int damage ) { super.proc( attacker, defender, damage ); if (attacker instanceof Hero && ((Hero)attacker).rangedWeapon == this) { circleBack( defender.pos, (Hero)attacker ); } } @Override protected void miss( int cell ) { circleBack( cell, curUser ); } private void circleBack( int from, Hero owner ) { ((MissileSprite)curUser.sprite.parent.recycle( MissileSprite.class )). reset( from, curUser.pos, curItem, null ); if (throwEquiped) { owner.belongings.weapon = this; owner.spend( -TIME_TO_EQUIP ); Dungeon.quickslot.replaceSimilar(this); updateQuickslot(); } else if (!collect( curUser.belongings.backpack )) { Dungeon.level.drop( this, owner.pos ).sprite.drop(); } } private boolean throwEquiped; @Override public void cast( Hero user, int dst ) { throwEquiped = isEquipped( user ); super.cast( user, dst ); } @Override public String desc() { String info = super.desc(); switch (imbue) { case LIGHT: info += "\n\n" + Messages.get(Weapon.class, "lighter"); break; case HEAVY: info += "\n\n" + Messages.get(Weapon.class, "heavier"); break; case NONE: } return info; } }