Harvester.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.datatables.SkillTable;
  17. import net.sf.l2j.gameserver.handler.IItemHandler;
  18. import net.sf.l2j.gameserver.instancemanager.CastleManorManager;
  19. import net.sf.l2j.gameserver.model.L2ItemInstance;
  20. import net.sf.l2j.gameserver.model.L2Skill;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  24. import net.sf.l2j.gameserver.network.SystemMessageId;
  25. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  26. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  27. /**
  28. * @author l3x
  29. */
  30. public class Harvester implements IItemHandler
  31. {
  32. private static final int[] ITEM_IDS =
  33. {
  34. /* Harvester */
  35. 5125
  36. };
  37. L2PcInstance _activeChar;
  38. L2MonsterInstance _target;
  39. /**
  40. *
  41. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  42. */
  43. public void useItem(L2PlayableInstance playable, L2ItemInstance _item)
  44. {
  45. if (!(playable instanceof L2PcInstance))
  46. return;
  47. if (CastleManorManager.getInstance().isDisabled())
  48. return;
  49. _activeChar = (L2PcInstance) playable;
  50. if (!(_activeChar.getTarget() instanceof L2MonsterInstance))
  51. {
  52. _activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  53. _activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  54. return;
  55. }
  56. _target = (L2MonsterInstance) _activeChar.getTarget();
  57. if (_target == null || !_target.isDead())
  58. {
  59. _activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  60. return;
  61. }
  62. L2Skill skill = SkillTable.getInstance().getInfo(2098, 1); //harvesting skill
  63. _activeChar.useMagic(skill, false, false);
  64. }
  65. /**
  66. *
  67. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  68. */
  69. public int[] getItemIds()
  70. {
  71. return ITEM_IDS;
  72. }
  73. }