Unstuck.java 4.3 KB

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