PaganKeys.java 4.0 KB

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