Escape.java 5.0 KB

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