123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- /*
- * Copyright (C) 2004-2015 L2J DataPack
- *
- * This file is part of L2J DataPack.
- *
- * L2J DataPack is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J DataPack is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package handlers.usercommandhandlers;
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.GameTimeController;
- import com.l2jserver.gameserver.ThreadPoolManager;
- import com.l2jserver.gameserver.ai.CtrlIntention;
- import com.l2jserver.gameserver.datatables.SkillData;
- import com.l2jserver.gameserver.handler.IUserCommandHandler;
- import com.l2jserver.gameserver.model.TeleportWhereType;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.entity.TvTEvent;
- import com.l2jserver.gameserver.model.skills.Skill;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
- import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
- import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
- import com.l2jserver.gameserver.util.Broadcast;
- /**
- * Unstuck user command.
- */
- public class Unstuck implements IUserCommandHandler
- {
- private static final int[] COMMAND_IDS =
- {
- 52
- };
-
- @Override
- public boolean useUserCommand(int id, L2PcInstance activeChar)
- {
- // Thanks nbd
- if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
- {
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- else if (activeChar.isJailed())
- {
- activeChar.sendMessage("You cannot use this function while you are jailed.");
- return false;
- }
-
- int unstuckTimer = (activeChar.getAccessLevel().isGm() ? 1000 : Config.UNSTUCK_INTERVAL * 1000);
-
- if (activeChar.isInOlympiadMode())
- {
- activeChar.sendPacket(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
- return false;
- }
-
- if (activeChar.isCastingNow() || activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead() || activeChar.inObserverMode() || activeChar.isCombatFlagEquipped())
- {
- return false;
- }
-
- activeChar.forceIsCasting(GameTimeController.getInstance().getGameTicks() + (unstuckTimer / GameTimeController.MILLIS_IN_TICK));
-
- Skill escape = SkillData.getInstance().getSkill(2099, 1); // 5 minutes escape
- Skill GM_escape = SkillData.getInstance().getSkill(2100, 1); // 1 second escape
- if (activeChar.getAccessLevel().isGm())
- {
- if (GM_escape != null)
- {
- activeChar.doCast(GM_escape);
- return true;
- }
- activeChar.sendMessage("You use Escape: 1 second.");
- }
- else if ((Config.UNSTUCK_INTERVAL == 300) && (escape != null))
- {
- activeChar.doCast(escape);
- return true;
- }
- else
- {
- if (Config.UNSTUCK_INTERVAL > 100)
- {
- activeChar.sendMessage("You use Escape: " + (unstuckTimer / 60000) + " minutes.");
- }
- else
- {
- activeChar.sendMessage("You use Escape: " + (unstuckTimer / 1000) + " seconds.");
- }
- }
- activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- // SoE Animation section
- activeChar.setTarget(activeChar);
- activeChar.disableAllSkills();
-
- MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, unstuckTimer, 0);
- Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 900);
- SetupGauge sg = new SetupGauge(0, unstuckTimer);
- activeChar.sendPacket(sg);
- // End SoE Animation section
-
- // continue execution later
- activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(new EscapeFinalizer(activeChar), unstuckTimer));
-
- return true;
- }
-
- private static class EscapeFinalizer implements Runnable
- {
- private final L2PcInstance _activeChar;
-
- protected EscapeFinalizer(L2PcInstance activeChar)
- {
- _activeChar = activeChar;
- }
-
- @Override
- public void run()
- {
- if (_activeChar.isDead())
- {
- return;
- }
-
- _activeChar.setIsIn7sDungeon(false);
- _activeChar.enableAllSkills();
- _activeChar.setIsCastingNow(false);
- _activeChar.setInstanceId(0);
- _activeChar.teleToLocation(TeleportWhereType.TOWN);
- }
- }
-
- @Override
- public int[] getUserCommandList()
- {
- return COMMAND_IDS;
- }
- }
|