FishShots.java 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 com.l2jserver.gameserver.handler.IItemHandler;
  17. import com.l2jserver.gameserver.model.L2Object;
  18. import com.l2jserver.gameserver.model.actor.L2Playable;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.items.L2Item;
  21. import com.l2jserver.gameserver.model.items.L2Weapon;
  22. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  23. import com.l2jserver.gameserver.model.items.type.L2WeaponType;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  26. import com.l2jserver.gameserver.util.Broadcast;
  27. /**
  28. * @author -Nemesiss-
  29. */
  30. public class FishShots implements IItemHandler
  31. {
  32. private static final int[] SKILL_IDS =
  33. {
  34. 2181, 2182, 2183, 2184, 2185, 2186
  35. };
  36. @Override
  37. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  38. {
  39. if (!(playable instanceof L2PcInstance))
  40. return false;
  41. L2PcInstance activeChar = (L2PcInstance) playable;
  42. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  43. L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  44. if (weaponInst == null || weaponItem.getItemType() != L2WeaponType.FISHINGROD)
  45. return false;
  46. if (weaponInst.getChargedFishshot())
  47. // spirit shot is already active
  48. return false;
  49. int FishshotId = item.getItemId();
  50. int grade = weaponItem.getCrystalType();
  51. long count = item.getCount();
  52. if ((grade == L2Item.CRYSTAL_NONE && FishshotId != 6535) || (grade == L2Item.CRYSTAL_D && FishshotId != 6536) || (grade == L2Item.CRYSTAL_C && FishshotId != 6537) || (grade == L2Item.CRYSTAL_B && FishshotId != 6538)
  53. || (grade == L2Item.CRYSTAL_A && FishshotId != 6539) || (FishshotId != 6540 && grade == L2Item.CRYSTAL_S ))
  54. {
  55. //1479 - This fishing shot is not fit for the fishing pole crystal.
  56. activeChar.sendPacket(SystemMessageId.WRONG_FISHINGSHOT_GRADE);
  57. return false;
  58. }
  59. if (count < 1)
  60. return false;
  61. weaponInst.setChargedFishshot(true);
  62. activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), 1, null, false);
  63. L2Object oldTarget = activeChar.getTarget();
  64. activeChar.setTarget(activeChar);
  65. Broadcast.toSelfAndKnownPlayers(activeChar, new MagicSkillUse(activeChar, SKILL_IDS[grade], 1, 0, 0));
  66. activeChar.setTarget(oldTarget);
  67. return true;
  68. }
  69. }