FishShots.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.ShotType;
  20. import com.l2jserver.gameserver.model.actor.L2Playable;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.holders.SkillHolder;
  23. import com.l2jserver.gameserver.model.items.L2Weapon;
  24. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  25. import com.l2jserver.gameserver.model.items.type.L2ActionType;
  26. import com.l2jserver.gameserver.model.items.type.L2WeaponType;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  29. import com.l2jserver.gameserver.util.Broadcast;
  30. /**
  31. * @author -Nemesiss-
  32. */
  33. public class FishShots implements IItemHandler
  34. {
  35. @Override
  36. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  37. {
  38. if (!playable.isPlayer())
  39. {
  40. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  41. return false;
  42. }
  43. final L2PcInstance activeChar = playable.getActingPlayer();
  44. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  45. final L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  46. if ((weaponInst == null) || (weaponItem.getItemType() != L2WeaponType.FISHINGROD))
  47. {
  48. return false;
  49. }
  50. if (activeChar.isChargedShot(ShotType.FISH_SOULSHOTS))
  51. {
  52. return false;
  53. }
  54. final long count = item.getCount();
  55. final SkillHolder[] skills = item.getItem().getSkills();
  56. if (skills == null)
  57. {
  58. _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
  59. return false;
  60. }
  61. boolean gradeCheck = item.isEtcItem() && (item.getEtcItem().getDefaultAction() == L2ActionType.fishingshot) && (weaponInst.getItem().getItemGradeSPlus() == item.getItem().getItemGradeSPlus());
  62. if (!gradeCheck)
  63. {
  64. activeChar.sendPacket(SystemMessageId.WRONG_FISHINGSHOT_GRADE);
  65. return false;
  66. }
  67. if (count < 1)
  68. {
  69. return false;
  70. }
  71. activeChar.setChargedShot(ShotType.FISH_SOULSHOTS, true);
  72. activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), 1, null, false);
  73. L2Object oldTarget = activeChar.getTarget();
  74. activeChar.setTarget(activeChar);
  75. Broadcast.toSelfAndKnownPlayers(activeChar, new MagicSkillUse(activeChar, skills[0].getSkillId(), skills[0].getSkillLvl(), 0, 0));
  76. activeChar.setTarget(oldTarget);
  77. return true;
  78. }
  79. }