2
0

Escape.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 = { 52 };
  36. /* (non-Javadoc)
  37. * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#useUserCommand(int, net.sf.l2j.gameserver.model.L2PcInstance)
  38. */
  39. public boolean useUserCommand(int id, L2PcInstance activeChar)
  40. {
  41. // Thanks nbd
  42. if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
  43. {
  44. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  45. return false;
  46. }
  47. if (activeChar.isCastingNow() || activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead() ||
  48. activeChar.isInOlympiadMode())
  49. return false;
  50. int unstuckTimer = (activeChar.getAccessLevel().isGm()? 5000 : 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.getAccessLevel().isGm())
  69. {
  70. activeChar.sendMessage("You use Fast Escape: 5 seconds.");
  71. }
  72. else if(Config.UNSTUCK_INTERVAL > 100)
  73. {
  74. activeChar.sendMessage("You use Escape: " + unstuckTimer/60000 + " minutes.");
  75. }
  76. else activeChar.sendMessage("You use Escape: " + unstuckTimer/1000 + " seconds.");
  77. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  78. //SoE Animation section
  79. activeChar.setTarget(activeChar);
  80. activeChar.disableAllSkills();
  81. MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, unstuckTimer, 0);
  82. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 810000/*900*/);
  83. SetupGauge sg = new SetupGauge(0, unstuckTimer);
  84. activeChar.sendPacket(sg);
  85. //End SoE Animation section
  86. EscapeFinalizer ef = new EscapeFinalizer(activeChar);
  87. // continue execution later
  88. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(ef, unstuckTimer));
  89. activeChar.setSkillCastEndTime(10+GameTimeController.getGameTicks()+unstuckTimer/GameTimeController.MILLIS_IN_TICK);
  90. return true;
  91. }
  92. static class EscapeFinalizer implements Runnable
  93. {
  94. private L2PcInstance _activeChar;
  95. EscapeFinalizer(L2PcInstance activeChar)
  96. {
  97. _activeChar = activeChar;
  98. }
  99. public void run()
  100. {
  101. if (_activeChar.isDead())
  102. return;
  103. _activeChar.setIsIn7sDungeon(false);
  104. _activeChar.enableAllSkills();
  105. try
  106. {
  107. _activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  108. } catch (Throwable e) { if (Config.DEBUG) e.printStackTrace(); }
  109. }
  110. }
  111. /* (non-Javadoc)
  112. * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()
  113. */
  114. public int[] getUserCommandList()
  115. {
  116. return COMMAND_IDS;
  117. }
  118. }