2
0

Key.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.model.L2ItemInstance;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2Skill;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2ChestInstance;
  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. public class Key implements IItemHandler
  28. {
  29. public static final int INTERACTION_DISTANCE = 100;
  30. private static final int[] ITEM_IDS =
  31. {
  32. 6665, 6666, 6667, 6668, 6669,
  33. 6670, 6671, 6672, 8060
  34. };
  35. /**
  36. *
  37. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  38. */
  39. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  40. {
  41. if (!(playable instanceof L2PcInstance))
  42. return;
  43. L2PcInstance activeChar = (L2PcInstance) playable;
  44. int itemId = item.getItemId();
  45. switch (itemId)
  46. {
  47. case 6665:
  48. case 6666:
  49. case 6667:
  50. case 6668:
  51. case 6669:
  52. case 6670:
  53. case 6671:
  54. case 6672:
  55. {
  56. L2Skill skill = SkillTable.getInstance().getInfo(2229, itemId - 6664); // box key skill
  57. L2Object target = activeChar.getTarget();
  58. if (!(target instanceof L2ChestInstance))
  59. {
  60. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  61. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  62. }
  63. else
  64. {
  65. L2ChestInstance chest = (L2ChestInstance) target;
  66. if (chest.isDead() || chest.isInteracted())
  67. {
  68. activeChar.sendMessage("The chest Is empty.");
  69. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  70. return;
  71. }
  72. activeChar.useMagic(skill, false, false);
  73. }
  74. break;
  75. }
  76. case 8060:
  77. {
  78. L2Skill skill = SkillTable.getInstance().getInfo(2260, 1);
  79. activeChar.doCast(skill);
  80. break;
  81. }
  82. }
  83. }
  84. /**
  85. *
  86. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  87. */
  88. public int[] getItemIds()
  89. {
  90. return ITEM_IDS;
  91. }
  92. }