Unstuck.java 4.5 KB

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