FishShots.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.itemhandlers;
  16. import java.util.logging.Level;
  17. import com.l2jserver.gameserver.handler.IItemHandler;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.actor.L2Playable;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.holders.SkillHolder;
  22. import com.l2jserver.gameserver.model.items.L2Weapon;
  23. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  24. import com.l2jserver.gameserver.model.items.type.L2ActionType;
  25. import com.l2jserver.gameserver.model.items.type.L2WeaponType;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  28. import com.l2jserver.gameserver.util.Broadcast;
  29. /**
  30. * @author -Nemesiss-
  31. */
  32. public class FishShots implements IItemHandler
  33. {
  34. @Override
  35. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  36. {
  37. if (!playable.isPlayer())
  38. {
  39. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  40. return false;
  41. }
  42. final L2PcInstance activeChar = playable.getActingPlayer();
  43. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  44. final L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  45. if (weaponInst == null || weaponItem.getItemType() != L2WeaponType.FISHINGROD)
  46. return false;
  47. if (weaponInst.getChargedFishshot()) // spirit shot is already active
  48. return false;
  49. final long count = item.getCount();
  50. final SkillHolder[] skills = item.getItem().getSkills();
  51. if (skills == null)
  52. {
  53. _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
  54. return false;
  55. }
  56. boolean gradeCheck = item.isEtcItem() && item.getEtcItem().getDefaultAction() == L2ActionType.fishingshot && weaponInst.getItem().getItemGradeSPlus() == item.getItem().getItemGradeSPlus();
  57. if (!gradeCheck)
  58. {
  59. activeChar.sendPacket(SystemMessageId.WRONG_FISHINGSHOT_GRADE);
  60. return false;
  61. }
  62. if (count < 1)
  63. return false;
  64. weaponInst.setChargedFishshot(true);
  65. activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), 1, null, false);
  66. L2Object oldTarget = activeChar.getTarget();
  67. activeChar.setTarget(activeChar);
  68. Broadcast.toSelfAndKnownPlayers(activeChar, new MagicSkillUse(activeChar, skills[0].getSkillId(), skills[0].getSkillLvl(), 0, 0));
  69. activeChar.setTarget(oldTarget);
  70. return true;
  71. }
  72. }