PaganKeys.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. if (!playable.isPlayer())
  36. {
  37. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  38. return false;
  39. }
  40. final int itemId = item.getItemId();
  41. final L2PcInstance activeChar = (L2PcInstance) playable;
  42. final L2Object target = activeChar.getTarget();
  43. if (!(target instanceof L2DoorInstance))
  44. {
  45. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  46. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  47. return false;
  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 false;
  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 false;
  61. }
  62. if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
  63. return false;
  64. // TODO: Unhardcode these!
  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. {
  74. if (instanceDoor.getDoorId() == door.getDoorId())
  75. {
  76. instanceDoor.openMe();
  77. break;
  78. }
  79. }
  80. }
  81. else
  82. {
  83. door.openMe();
  84. }
  85. }
  86. else
  87. {
  88. activeChar.sendMessage("Incorrect Door.");
  89. }
  90. break;
  91. case 9699:
  92. if (door.getDoorId() == 24220022)
  93. {
  94. if (activeChar.getInstanceId() != door.getInstanceId())
  95. {
  96. for (L2DoorInstance instanceDoor : InstanceManager.getInstance().getInstance(activeChar.getInstanceId()).getDoors())
  97. {
  98. if (instanceDoor.getDoorId() == door.getDoorId())
  99. {
  100. instanceDoor.openMe();
  101. break;
  102. }
  103. }
  104. }
  105. else
  106. {
  107. door.openMe();
  108. }
  109. }
  110. else
  111. {
  112. activeChar.sendMessage("Incorrect Door.");
  113. }
  114. break;
  115. case 8056:
  116. if (door.getDoorId() == 23150004 || door.getDoorId() == 23150003)
  117. {
  118. DoorTable.getInstance().getDoor(23150003).openMe();
  119. DoorTable.getInstance().getDoor(23150004).openMe();
  120. }
  121. else
  122. {
  123. activeChar.sendMessage("Incorrect Door.");
  124. }
  125. break;
  126. }
  127. return true;
  128. }
  129. }