PaganKeys.java 3.9 KB

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