Unstuck.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2004-2015 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.usercommandhandlers;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.GameTimeController;
  22. import com.l2jserver.gameserver.ThreadPoolManager;
  23. import com.l2jserver.gameserver.ai.CtrlIntention;
  24. import com.l2jserver.gameserver.datatables.SkillData;
  25. import com.l2jserver.gameserver.handler.IUserCommandHandler;
  26. import com.l2jserver.gameserver.model.TeleportWhereType;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.entity.TvTEvent;
  29. import com.l2jserver.gameserver.model.skills.Skill;
  30. import com.l2jserver.gameserver.network.SystemMessageId;
  31. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  32. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  33. import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
  34. import com.l2jserver.gameserver.util.Broadcast;
  35. /**
  36. * Unstuck user command.
  37. */
  38. public class Unstuck implements IUserCommandHandler
  39. {
  40. private static final int[] COMMAND_IDS =
  41. {
  42. 52
  43. };
  44. @Override
  45. public boolean useUserCommand(int id, L2PcInstance activeChar)
  46. {
  47. // Thanks nbd
  48. if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
  49. {
  50. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  51. return false;
  52. }
  53. else if (activeChar.isJailed())
  54. {
  55. activeChar.sendMessage("You cannot use this function while you are jailed.");
  56. return false;
  57. }
  58. int unstuckTimer = (activeChar.getAccessLevel().isGm() ? 1000 : Config.UNSTUCK_INTERVAL * 1000);
  59. if (activeChar.isInOlympiadMode())
  60. {
  61. activeChar.sendPacket(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  62. return false;
  63. }
  64. if (activeChar.isCastingNow() || activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead() || activeChar.inObserverMode() || activeChar.isCombatFlagEquipped())
  65. {
  66. return false;
  67. }
  68. activeChar.forceIsCasting(GameTimeController.getInstance().getGameTicks() + (unstuckTimer / GameTimeController.MILLIS_IN_TICK));
  69. Skill escape = SkillData.getInstance().getSkill(2099, 1); // 5 minutes escape
  70. Skill GM_escape = SkillData.getInstance().getSkill(2100, 1); // 1 second escape
  71. if (activeChar.getAccessLevel().isGm())
  72. {
  73. if (GM_escape != null)
  74. {
  75. activeChar.doCast(GM_escape);
  76. return true;
  77. }
  78. activeChar.sendMessage("You use Escape: 1 second.");
  79. }
  80. else if ((Config.UNSTUCK_INTERVAL == 300) && (escape != null))
  81. {
  82. activeChar.doCast(escape);
  83. return true;
  84. }
  85. else
  86. {
  87. if (Config.UNSTUCK_INTERVAL > 100)
  88. {
  89. activeChar.sendMessage("You use Escape: " + (unstuckTimer / 60000) + " minutes.");
  90. }
  91. else
  92. {
  93. activeChar.sendMessage("You use Escape: " + (unstuckTimer / 1000) + " seconds.");
  94. }
  95. }
  96. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  97. // SoE Animation section
  98. activeChar.setTarget(activeChar);
  99. activeChar.disableAllSkills();
  100. MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, unstuckTimer, 0);
  101. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 900);
  102. SetupGauge sg = new SetupGauge(0, unstuckTimer);
  103. activeChar.sendPacket(sg);
  104. // End SoE Animation section
  105. // continue execution later
  106. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(new EscapeFinalizer(activeChar), unstuckTimer));
  107. return true;
  108. }
  109. private static class EscapeFinalizer implements Runnable
  110. {
  111. private final L2PcInstance _activeChar;
  112. protected EscapeFinalizer(L2PcInstance activeChar)
  113. {
  114. _activeChar = activeChar;
  115. }
  116. @Override
  117. public void run()
  118. {
  119. if (_activeChar.isDead())
  120. {
  121. return;
  122. }
  123. _activeChar.setIsIn7sDungeon(false);
  124. _activeChar.enableAllSkills();
  125. _activeChar.setIsCastingNow(false);
  126. _activeChar.setInstanceId(0);
  127. _activeChar.teleToLocation(TeleportWhereType.TOWN);
  128. }
  129. }
  130. @Override
  131. public int[] getUserCommandList()
  132. {
  133. return COMMAND_IDS;
  134. }
  135. }