PaganKeys.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.datatables.DoorTable;
  17. import com.l2jserver.gameserver.handler.IItemHandler;
  18. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.actor.L2Playable;
  21. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  26. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  27. /**
  28. * @author chris
  29. */
  30. public class PaganKeys implements IItemHandler
  31. {
  32. public static final int INTERACTION_DISTANCE = 100;
  33. /**
  34. *
  35. * @see com.l2jserver.gameserver.handler.IItemHandler#useItem(com.l2jserver.gameserver.model.actor.L2Playable, com.l2jserver.gameserver.model.L2ItemInstance, boolean)
  36. */
  37. public void useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  38. {
  39. int itemId = item.getItemId();
  40. if (!(playable instanceof L2PcInstance))
  41. return;
  42. L2PcInstance activeChar = (L2PcInstance) playable;
  43. L2Object target = activeChar.getTarget();
  44. if (!(target instanceof L2DoorInstance))
  45. {
  46. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  47. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  48. return;
  49. }
  50. L2DoorInstance door = (L2DoorInstance) target;
  51. if (!(activeChar.isInsideRadius(door, INTERACTION_DISTANCE, false, false)))
  52. {
  53. activeChar.sendMessage("Too far.");
  54. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  55. return;
  56. }
  57. if (activeChar.getAbnormalEffect() > 0 || activeChar.isInCombat())
  58. {
  59. activeChar.sendMessage("You cannot use the key now.");
  60. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  61. return;
  62. }
  63. if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
  64. return;
  65. switch (itemId)
  66. {
  67. case 9698:
  68. if (door.getDoorId() == 24220020)
  69. {
  70. if (activeChar.getInstanceId() != door.getInstanceId())
  71. {
  72. for (L2DoorInstance instanceDoor : InstanceManager.getInstance().getInstance(activeChar.getInstanceId()).getDoors())
  73. if (instanceDoor.getDoorId() == door.getDoorId())
  74. {
  75. instanceDoor.openMe();
  76. }
  77. }
  78. else
  79. {
  80. door.openMe();
  81. }
  82. }
  83. else
  84. {
  85. activeChar.sendMessage("Incorrect Door.");
  86. }
  87. break;
  88. case 9699:
  89. if (door.getDoorId() == 24220022)
  90. {
  91. if (activeChar.getInstanceId() != door.getInstanceId())
  92. {
  93. for (L2DoorInstance instanceDoor : InstanceManager.getInstance().getInstance(activeChar.getInstanceId()).getDoors())
  94. if (instanceDoor.getDoorId() == door.getDoorId())
  95. {
  96. instanceDoor.openMe();
  97. }
  98. }
  99. else
  100. {
  101. door.openMe();
  102. }
  103. }
  104. else
  105. {
  106. activeChar.sendMessage("Incorrect Door.");
  107. }
  108. break;
  109. case 8056:
  110. if (door.getDoorId() == 23150004||door.getDoorId() == 23150003)
  111. {
  112. DoorTable.getInstance().getDoor(23150003).openMe();
  113. DoorTable.getInstance().getDoor(23150003).onOpen();
  114. DoorTable.getInstance().getDoor(23150004).openMe();
  115. DoorTable.getInstance().getDoor(23150004).onOpen();
  116. }
  117. else
  118. {
  119. activeChar.sendMessage("Incorrect Door.");
  120. }
  121. break;
  122. }
  123. }
  124. }