Unstuck.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.instancemanager.MapRegionManager;
  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. int unstuckTimer = (activeChar.getAccessLevel().isGm() ? 1000 : Config.UNSTUCK_INTERVAL * 1000);
  53. if (activeChar.isCastingNow() || activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead() || activeChar.isInOlympiadMode() || activeChar.inObserverMode() || activeChar.isCombatFlagEquipped())
  54. {
  55. return false;
  56. }
  57. activeChar.forceIsCasting(GameTimeController.getInstance().getGameTicks() + (unstuckTimer / GameTimeController.MILLIS_IN_TICK));
  58. L2Skill escape = SkillTable.getInstance().getInfo(2099, 1); // 5 minutes escape
  59. L2Skill GM_escape = SkillTable.getInstance().getInfo(2100, 1); // 1 second escape
  60. if (activeChar.getAccessLevel().isGm())
  61. {
  62. if (GM_escape != null)
  63. {
  64. activeChar.doCast(GM_escape);
  65. return true;
  66. }
  67. activeChar.sendMessage("You use Escape: 1 second.");
  68. }
  69. else if ((Config.UNSTUCK_INTERVAL == 300) && (escape != null))
  70. {
  71. activeChar.doCast(escape);
  72. return true;
  73. }
  74. else
  75. {
  76. if (Config.UNSTUCK_INTERVAL > 100)
  77. {
  78. activeChar.sendMessage("You use Escape: " + (unstuckTimer / 60000) + " minutes.");
  79. }
  80. else
  81. {
  82. activeChar.sendMessage("You use Escape: " + (unstuckTimer / 1000) + " seconds.");
  83. }
  84. }
  85. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  86. // SoE Animation section
  87. activeChar.setTarget(activeChar);
  88. activeChar.disableAllSkills();
  89. MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, unstuckTimer, 0);
  90. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 900);
  91. SetupGauge sg = new SetupGauge(0, unstuckTimer);
  92. activeChar.sendPacket(sg);
  93. // End SoE Animation section
  94. // continue execution later
  95. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(new EscapeFinalizer(activeChar), unstuckTimer));
  96. return true;
  97. }
  98. private static class EscapeFinalizer implements Runnable
  99. {
  100. private final L2PcInstance _activeChar;
  101. protected EscapeFinalizer(L2PcInstance activeChar)
  102. {
  103. _activeChar = activeChar;
  104. }
  105. @Override
  106. public void run()
  107. {
  108. if (_activeChar.isDead())
  109. {
  110. return;
  111. }
  112. _activeChar.setIsIn7sDungeon(false);
  113. _activeChar.enableAllSkills();
  114. _activeChar.setIsCastingNow(false);
  115. _activeChar.setInstanceId(0);
  116. _activeChar.teleToLocation(MapRegionManager.TeleportWhereType.Town);
  117. }
  118. }
  119. @Override
  120. public int[] getUserCommandList()
  121. {
  122. return COMMAND_IDS;
  123. }
  124. }