PaganKeys.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.itemhandlers;
  20. import com.l2jserver.gameserver.datatables.DoorTable;
  21. import com.l2jserver.gameserver.handler.IItemHandler;
  22. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.actor.L2Playable;
  25. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  30. /**
  31. * @author chris
  32. */
  33. public class PaganKeys implements IItemHandler
  34. {
  35. public static final int INTERACTION_DISTANCE = 100;
  36. @Override
  37. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  38. {
  39. if (!playable.isPlayer())
  40. {
  41. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  42. return false;
  43. }
  44. final int itemId = item.getItemId();
  45. final L2PcInstance activeChar = (L2PcInstance) playable;
  46. final L2Object target = activeChar.getTarget();
  47. if (!(target instanceof L2DoorInstance))
  48. {
  49. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  50. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  51. return false;
  52. }
  53. L2DoorInstance door = (L2DoorInstance) target;
  54. if (!(activeChar.isInsideRadius(door, INTERACTION_DISTANCE, false, false)))
  55. {
  56. activeChar.sendMessage("Too far.");
  57. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  58. return false;
  59. }
  60. if ((activeChar.getAbnormalEffect() > 0) || activeChar.isInCombat())
  61. {
  62. activeChar.sendMessage("You cannot use the key now.");
  63. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  64. return false;
  65. }
  66. if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
  67. {
  68. return false;
  69. }
  70. // TODO: Unhardcode these!
  71. switch (itemId)
  72. {
  73. case 9698:
  74. if (door.getDoorId() == 24220020)
  75. {
  76. if (activeChar.getInstanceId() != door.getInstanceId())
  77. {
  78. final L2DoorInstance instanceDoor = InstanceManager.getInstance().getInstance(activeChar.getInstanceId()).getDoor(door.getDoorId());
  79. if (instanceDoor != null)
  80. {
  81. instanceDoor.openMe();
  82. }
  83. }
  84. else
  85. {
  86. door.openMe();
  87. }
  88. }
  89. else
  90. {
  91. activeChar.sendMessage("Incorrect Door.");
  92. }
  93. break;
  94. case 9699:
  95. if (door.getDoorId() == 24220022)
  96. {
  97. if (activeChar.getInstanceId() != door.getInstanceId())
  98. {
  99. final L2DoorInstance instanceDoor = InstanceManager.getInstance().getInstance(activeChar.getInstanceId()).getDoor(door.getDoorId());
  100. if (instanceDoor != null)
  101. {
  102. instanceDoor.openMe();
  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. }