Escape.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.usercommandhandlers;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.GameTimeController;
  18. import net.sf.l2j.gameserver.ThreadPoolManager;
  19. import net.sf.l2j.gameserver.ai.CtrlIntention;
  20. import net.sf.l2j.gameserver.datatables.MapRegionTable;
  21. import net.sf.l2j.gameserver.handler.IUserCommandHandler;
  22. import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  24. import net.sf.l2j.gameserver.model.entity.TvTEvent;
  25. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  26. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  27. import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
  28. import net.sf.l2j.gameserver.util.Broadcast;
  29. /**
  30. *
  31. *
  32. */
  33. public class Escape implements IUserCommandHandler
  34. {
  35. private static final int[] COMMAND_IDS =
  36. {
  37. 52
  38. };
  39. /**
  40. *
  41. * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#useUserCommand(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
  42. */
  43. public boolean useUserCommand(int id, L2PcInstance activeChar)
  44. {
  45. // Thanks nbd
  46. if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
  47. {
  48. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  49. return false;
  50. }
  51. if (activeChar.isCastingNow() || activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead() || activeChar.isInOlympiadMode())
  52. return false;
  53. int unstuckTimer = (activeChar.getAccessLevel().isGm() ? 5000 : Config.UNSTUCK_INTERVAL * 1000);
  54. // Check to see if the player is in a festival.
  55. if (activeChar.isFestivalParticipant())
  56. {
  57. activeChar.sendMessage("You may not use an escape command in a festival.");
  58. return false;
  59. }
  60. // Check to see if player is in jail
  61. if (activeChar.isInJail())
  62. {
  63. activeChar.sendMessage("You can not escape from jail.");
  64. return false;
  65. }
  66. if (GrandBossManager.getInstance().getZone(activeChar) != null && !activeChar.isGM())
  67. {
  68. activeChar.sendMessage("You may not use an escape command in a Boss Zone.");
  69. return false;
  70. }
  71. if (activeChar.getAccessLevel().isGm())
  72. {
  73. activeChar.sendMessage("You use Fast Escape: 5 seconds.");
  74. }
  75. else if (Config.UNSTUCK_INTERVAL > 100)
  76. {
  77. activeChar.sendMessage("You use Escape: " + unstuckTimer / 60000 + " minutes.");
  78. }
  79. else
  80. activeChar.sendMessage("You use Escape: " + unstuckTimer / 1000 + " seconds.");
  81. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  82. //SoE Animation section
  83. activeChar.setTarget(activeChar);
  84. activeChar.disableAllSkills();
  85. MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, unstuckTimer, 0);
  86. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 810000/*900*/);
  87. SetupGauge sg = new SetupGauge(0, unstuckTimer);
  88. activeChar.sendPacket(sg);
  89. //End SoE Animation section
  90. EscapeFinalizer ef = new EscapeFinalizer(activeChar);
  91. // continue execution later
  92. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(ef, unstuckTimer));
  93. activeChar.setSkillCastEndTime(10 + GameTimeController.getGameTicks() + unstuckTimer / GameTimeController.MILLIS_IN_TICK);
  94. return true;
  95. }
  96. static class EscapeFinalizer implements Runnable
  97. {
  98. private L2PcInstance _activeChar;
  99. EscapeFinalizer(L2PcInstance activeChar)
  100. {
  101. _activeChar = activeChar;
  102. }
  103. public void run()
  104. {
  105. if (_activeChar.isDead())
  106. return;
  107. _activeChar.setIsIn7sDungeon(false);
  108. _activeChar.enableAllSkills();
  109. try
  110. {
  111. _activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  112. }
  113. catch (Throwable e)
  114. {
  115. if (Config.DEBUG)
  116. e.printStackTrace();
  117. }
  118. }
  119. }
  120. /**
  121. *
  122. * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()
  123. */
  124. public int[] getUserCommandList()
  125. {
  126. return COMMAND_IDS;
  127. }
  128. }