FishShots.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 net.sf.l2j.gameserver.handler.itemhandlers;
  16. import net.sf.l2j.gameserver.handler.IItemHandler;
  17. import net.sf.l2j.gameserver.model.L2ItemInstance;
  18. import net.sf.l2j.gameserver.model.L2Object;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  21. import net.sf.l2j.gameserver.network.SystemMessageId;
  22. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  23. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  24. import net.sf.l2j.gameserver.templates.L2Item;
  25. import net.sf.l2j.gameserver.templates.L2Weapon;
  26. import net.sf.l2j.gameserver.templates.L2WeaponType;
  27. import net.sf.l2j.gameserver.util.Broadcast;
  28. /**
  29. * @author -Nemesiss-
  30. *
  31. */
  32. public class FishShots implements IItemHandler
  33. {
  34. // All the item IDs that this handler knows.
  35. private static final int[] ITEM_IDS =
  36. {
  37. 6535, 6536, 6537, 6538, 6539, 6540
  38. };
  39. private static final int[] SKILL_IDS =
  40. {
  41. 2181, 2182, 2183, 2184, 2185, 2186
  42. };
  43. /**
  44. *
  45. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  46. */
  47. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  48. {
  49. if (!(playable instanceof L2PcInstance))
  50. return;
  51. L2PcInstance activeChar = (L2PcInstance) playable;
  52. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  53. L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  54. if (weaponInst == null || weaponItem.getItemType() != L2WeaponType.ROD)
  55. {
  56. return;
  57. }
  58. if (weaponInst.getChargedFishshot())
  59. {
  60. // spirit shot is already active
  61. return;
  62. }
  63. int FishshotId = item.getItemId();
  64. int grade = weaponItem.getCrystalType();
  65. int count = item.getCount();
  66. 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)
  67. || (grade == L2Item.CRYSTAL_A && FishshotId != 6539) || (grade == L2Item.CRYSTAL_S && FishshotId != 6540) || (grade == L2Item.CRYSTAL_S80 && FishshotId != 6540))
  68. {
  69. //1479 - This fishing shot is not fit for the fishing pole crystal.
  70. activeChar.sendPacket(new SystemMessage(SystemMessageId.WRONG_FISHINGSHOT_GRADE));
  71. return;
  72. }
  73. if (count < 1)
  74. {
  75. return;
  76. }
  77. weaponInst.setChargedFishshot(true);
  78. activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), 1, null, false);
  79. L2Object oldTarget = activeChar.getTarget();
  80. activeChar.setTarget(activeChar);
  81. MagicSkillUse MSU = new MagicSkillUse(activeChar, SKILL_IDS[grade], 1, 0, 0);
  82. Broadcast.toSelfAndKnownPlayers(activeChar, MSU);
  83. activeChar.setTarget(oldTarget);
  84. }
  85. /**
  86. *
  87. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  88. */
  89. public int[] getItemIds()
  90. {
  91. return ITEM_IDS;
  92. }
  93. }