ChristianSDM

escape

Nov 22nd, 2020 (edited)
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. /*
  2. * L2jFrozen Project - www.l2jfrozen.com
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  17. * 02111-1307, USA.
  18. *
  19. * http://www.gnu.org/copyleft/gpl.html
  20. */
  21. package com.l2jfrozen.gameserver.handler.usercommandhandlers;
  22.  
  23. import com.l2jfrozen.Config;
  24. import com.l2jfrozen.gameserver.ai.CtrlIntention;
  25. import com.l2jfrozen.gameserver.controllers.GameTimeController;
  26. import com.l2jfrozen.gameserver.datatables.xml.MapRegionTable;
  27. import com.l2jfrozen.gameserver.handler.IUserCommandHandler;
  28. import com.l2jfrozen.gameserver.managers.GrandBossManager;
  29. import com.l2jfrozen.gameserver.model.L2Character;
  30. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jfrozen.gameserver.model.entity.event.CTF;
  32. import com.l2jfrozen.gameserver.model.entity.event.DM;
  33. import com.l2jfrozen.gameserver.model.entity.event.TvT;
  34. import com.l2jfrozen.gameserver.model.entity.event.VIP;
  35. import com.l2jfrozen.gameserver.network.serverpackets.MagicSkillUser;
  36. import com.l2jfrozen.gameserver.network.serverpackets.SetupGauge;
  37. import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
  38. import com.l2jfrozen.gameserver.util.Broadcast;
  39.  
  40. /**
  41. *
  42. *
  43. */
  44. public class Escape implements IUserCommandHandler
  45. {
  46. private static final int[] COMMAND_IDS =
  47. {
  48. 52
  49. };
  50.  
  51. /*
  52. * (non-Javadoc)
  53. * @see com.l2jfrozen.gameserver.handler.IUserCommandHandler#useUserCommand(int, com.l2jfrozen.gameserver.model.L2PcInstance)
  54. */
  55. @Override
  56. public boolean useUserCommand(final int id, final L2PcInstance activeChar)
  57. {
  58.  
  59. final int unstuckTimer = activeChar.getAccessLevel().isGm() ? 1000 : Config.UNSTUCK_INTERVAL * 1000;
  60.  
  61. // Check to see if the current player is in Festival.
  62. if (activeChar.isFestivalParticipant())
  63. {
  64. activeChar.sendMessage("You may not use an escape command in a festival.");
  65. return false;
  66. }
  67. if (activeChar.isArenaProtection() || activeChar.isInsideZone(L2Character.TOURNAMENT))
  68. {
  69. activeChar.sendMessage("You cannot use this skill in Tournament Event/Zone.");
  70. return false;
  71. }
  72. // Check to see if the current player is in TVT Event.
  73. if (activeChar._inEventTvT && TvT.is_started())
  74. {
  75. activeChar.sendMessage("You may not use an escape skill in TvT.");
  76. return false;
  77. }
  78.  
  79. // Check to see if the current player is in CTF Event.
  80. if (activeChar._inEventCTF && CTF.is_started())
  81. {
  82. activeChar.sendMessage("You may not use an escape skill in CTF.");
  83. return false;
  84. }
  85.  
  86. // Check to see if the current player is in DM Event.
  87. if (activeChar._inEventDM && DM.is_started())
  88. {
  89. activeChar.sendMessage("You may not use an escape skill in DM.");
  90. return false;
  91. }
  92.  
  93. // Check to see if the current player is in Vip Event.
  94. if (activeChar._inEventVIP && VIP._started)
  95. {
  96. activeChar.sendMessage("You may not use an escape skill in VIP.");
  97. return false;
  98. }
  99.  
  100. // Check to see if the current player is in Grandboss zone.
  101. if (GrandBossManager.getInstance().getZone(activeChar) != null && !activeChar.isGM())
  102. {
  103. activeChar.sendMessage("You may not use an escape command in Grand boss zone.");
  104. return false;
  105. }
  106.  
  107. // Check to see if the current player is in jail.
  108. if (activeChar.isInJail())
  109. {
  110. activeChar.sendMessage("You can not escape from jail.");
  111. return false;
  112. }
  113.  
  114. // Check to see if the current player is in fun event.
  115. if (activeChar.isInFunEvent())
  116. {
  117. activeChar.sendMessage("You may not escape from an Event.");
  118. return false;
  119. }
  120.  
  121. // Check to see if the current player is in Observer Mode.
  122. if (activeChar.inObserverMode())
  123. {
  124. activeChar.sendMessage("You may not escape during Observer mode.");
  125. return false;
  126. }
  127.  
  128. // Check to see if the current player is sitting.
  129. if (activeChar.isSitting())
  130. {
  131. activeChar.sendMessage("You may not escape when you sitting.");
  132. return false;
  133. }
  134.  
  135. // Check player status.
  136. if (activeChar.isCastingNow() || activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead() || activeChar.isInOlympiadMode() || activeChar.isAwaying())
  137. return false;
  138.  
  139. if (unstuckTimer < 60000)
  140. activeChar.sendMessage("After " + unstuckTimer / 60000 + " min. you be returned to near village.");
  141. else
  142. activeChar.sendMessage("After " + unstuckTimer / 60000 + " min. you be returned to near village.");
  143.  
  144. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  145. // SoE Animation section
  146. activeChar.setTarget(activeChar);
  147. activeChar.disableAllSkills();
  148.  
  149. MagicSkillUser msk = new MagicSkillUser(activeChar, Config.UNSTUCK_ANIMATION_ID, 1, unstuckTimer, 0);
  150. activeChar.setTarget(null); // Like retail we haven't self target
  151. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 810000/* 900 */);
  152. SetupGauge sg = new SetupGauge(0, unstuckTimer);
  153. activeChar.sendPacket(sg);
  154. msk = null;
  155. sg = null;
  156. // End SoE Animation section
  157. EscapeFinalizer ef = new EscapeFinalizer(activeChar);
  158. // continue execution later
  159. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(ef, unstuckTimer));
  160. activeChar.setSkillCastEndTime(10 + GameTimeController.getGameTicks() + unstuckTimer / GameTimeController.MILLIS_IN_TICK);
  161.  
  162. ef = null;
  163.  
  164. return true;
  165. }
  166.  
  167. static class EscapeFinalizer implements Runnable
  168. {
  169. private final L2PcInstance _activeChar;
  170.  
  171. EscapeFinalizer(final L2PcInstance activeChar)
  172. {
  173. _activeChar = activeChar;
  174. }
  175.  
  176. @Override
  177. public void run()
  178. {
  179. if (_activeChar.isDead())
  180. return;
  181.  
  182. _activeChar.setIsIn7sDungeon(false);
  183. _activeChar.enableAllSkills();
  184.  
  185. try
  186. {
  187. if (_activeChar.getKarma() > 0 && Config.ALT_KARMA_TELEPORT_TO_FLORAN)
  188. {
  189. _activeChar.teleToLocation(17836, 170178, -3507, true); // Floran
  190. return;
  191. }
  192.  
  193. if (Config.CUSTOMESCAPE_ENABLE)
  194. {
  195. _activeChar.teleToLocation(Config.ESCAPE_X, Config.ESCAPE_Y, Config.ESCAPE_Z);
  196. }
  197. else if (!Config.CUSTOMESCAPE_ENABLE)
  198. {
  199. _activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  200. }
  201. }
  202. catch (final Throwable e)
  203. {
  204. if (Config.ENABLE_ALL_EXCEPTIONS)
  205. e.printStackTrace();
  206. }
  207. }
  208. }
  209.  
  210. /*
  211. * (non-Javadoc)
  212. * @see com.l2jfrozen.gameserver.handler.IUserCommandHandler#getUserCommandList()
  213. */
  214. @Override
  215. public int[] getUserCommandList()
  216. {
  217. return COMMAND_IDS;
  218. }
  219. }
  220.  
Add Comment
Please, Sign In to add comment