PaganKeys.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 net.sf.l2j.gameserver.handler.itemhandlers;
  16. import net.sf.l2j.gameserver.handler.IItemHandler;
  17. import net.sf.l2j.gameserver.model.L2ItemInstance;
  18. import net.sf.l2j.gameserver.model.L2Object;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  22. import net.sf.l2j.gameserver.network.SystemMessageId;
  23. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  24. import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
  25. import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  26. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  27. import net.sf.l2j.util.Rnd;
  28. /**
  29. * @author chris
  30. */
  31. public class PaganKeys implements IItemHandler
  32. {
  33. private static final int[] ITEM_IDS =
  34. {
  35. 8273, 8274, 8275
  36. };
  37. public static final int INTERACTION_DISTANCE = 100;
  38. /**
  39. *
  40. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  41. */
  42. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  43. {
  44. int itemId = item.getItemId();
  45. if (!(playable instanceof L2PcInstance))
  46. return;
  47. L2PcInstance activeChar = (L2PcInstance) playable;
  48. L2Object target = activeChar.getTarget();
  49. if (!(target instanceof L2DoorInstance))
  50. {
  51. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  52. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  53. return;
  54. }
  55. L2DoorInstance door = (L2DoorInstance) target;
  56. if (!(activeChar.isInsideRadius(door, INTERACTION_DISTANCE, false, false)))
  57. {
  58. activeChar.sendMessage("Too far.");
  59. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  60. return;
  61. }
  62. if (activeChar.getAbnormalEffect() > 0 || activeChar.isInCombat())
  63. {
  64. activeChar.sendMessage("You cannot use the key now.");
  65. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  66. return;
  67. }
  68. int openChance = 35;
  69. if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
  70. return;
  71. switch (itemId)
  72. {
  73. case 8273: //AnteroomKey
  74. if (door.getDoorName().startsWith("Anteroom"))
  75. {
  76. if (Rnd.get(100) < openChance)
  77. {
  78. activeChar.sendMessage("You opened Anterooms Door.");
  79. door.openMe();
  80. door.onOpen(); // Closes the door after 60sec
  81. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 3));
  82. }
  83. else
  84. {
  85. //test with: activeChar.sendPacket(new SystemMessage(SystemMessage.FAILED_TO_UNLOCK_DOOR));
  86. activeChar.sendMessage("You failed to open Anterooms Door.");
  87. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 13));
  88. PlaySound playSound = new PlaySound("interfacesound.system_close_01");
  89. activeChar.sendPacket(playSound);
  90. }
  91. }
  92. else
  93. {
  94. activeChar.sendMessage("Incorrect Door.");
  95. }
  96. break;
  97. case 8274: //Chapel key, Chapel Door has a Gatekeeper?? I use this key for Altar Entrance
  98. if (door.getDoorName().startsWith("Altar_Entrance"))
  99. {
  100. if (Rnd.get(100) < openChance)
  101. {
  102. activeChar.sendMessage("You opened Altar Entrance.");
  103. door.openMe();
  104. door.onOpen();
  105. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 3));
  106. }
  107. else
  108. {
  109. activeChar.sendMessage("You failed to open Altar Entrance.");
  110. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 13));
  111. PlaySound playSound = new PlaySound("interfacesound.system_close_01");
  112. activeChar.sendPacket(playSound);
  113. }
  114. }
  115. else
  116. {
  117. activeChar.sendMessage("Incorrect Door.");
  118. }
  119. break;
  120. case 8275: //Key of Darkness
  121. if (door.getDoorName().startsWith("Door_of_Darkness"))
  122. {
  123. if (Rnd.get(100) < openChance)
  124. {
  125. activeChar.sendMessage("You opened Door of Darkness.");
  126. door.openMe();
  127. door.onOpen();
  128. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 3));
  129. }
  130. else
  131. {
  132. activeChar.sendMessage("You failed to open Door of Darkness.");
  133. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 13));
  134. PlaySound playSound = new PlaySound("interfacesound.system_close_01");
  135. activeChar.sendPacket(playSound);
  136. }
  137. }
  138. else
  139. {
  140. activeChar.sendMessage("Incorrect Door.");
  141. }
  142. break;
  143. }
  144. }
  145. /**
  146. *
  147. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  148. */
  149. public int[] getItemIds()
  150. {
  151. return ITEM_IDS;
  152. }
  153. }