вот весь код
package net.sf.l2j.gameserver.handler.items;
import java.util.Random;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.GameTimeController;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.ai.CtrlIntention;
import net.sf.l2j.gameserver.data.MapRegionTable;
import net.sf.l2j.gameserver.data.other.SkillTable;
import net.sf.l2j.gameserver.handler.IItemHandler;
import net.sf.l2j.gameserver.instancemanager.CastleManager;
import net.sf.l2j.gameserver.instancemanager.ClanHallManager;
import net.sf.l2j.gameserver.instancemanager.FortManager;
import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
import net.sf.l2j.gameserver.model.L2ItemInstance;
import net.sf.l2j.gameserver.model.L2Skill;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
import net.sf.l2j.gameserver.model.base.Race;
import net.sf.l2j.gameserver.model.entity.TvTEvent;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
/**
* This class ...
*
* @version $Revision: 1.2.2.3.2.5 $ $Date: 2005/03/27 15:30:07 $
*/
public class ScrollOfEscape implements IItemHandler
{
// all the items ids that this handler knowns
private static final int[] ITEM_IDS =
{
20000, 20001, 20002,
};
/* (non-Javadoc)
* @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.L2PcInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
*/
public void useItem(L2PlayableInstance playable, L2ItemInstance item)
{
if (!(playable instanceof L2PcInstance))
{
return;
}
L2PcInstance activeChar = (L2PcInstance) playable;
// Thanks nbd
if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
{
activeChar.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead() || activeChar.isAllSkillsDisabled()) {
return;
}
if (activeChar.isSitting()) {
activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_MOVE_SITTING));
return;
}
if (GrandBossManager.getInstance().getZone(activeChar) != null && !activeChar.isGM()) {
activeChar.sendPacket(ActionFailed.STATIC_PACKET);
//activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SCROLL_OF_ESCAPE_INSIDE_BOSS_ZONE));
// SystemMessage doesn't exist ??!
activeChar.sendMessage("Cant summon target inside boss zone.");
return;
}
if (activeChar.isInOlympiadMode()) {
activeChar.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
return;
}
// Check to see if the player is in a festival.
if (activeChar.isFestivalParticipant()) {
activeChar.sendMessage("You may not use an escape skill in a festival.");
return;
}
// Check to see if player is in jail
if (activeChar.isInJail()) {
activeChar.sendMessage("You can not escape from jail.");
return;
}
// Check to see if player is in a duel
if (activeChar.isInDuel()) {
activeChar.sendMessage("You cannot use escape skills during a duel.");
return;
}
if (activeChar.isParalyzed()) {
activeChar.sendMessage("You cannot use escape skills during a paralyze.");
return;
}
if (activeChar.isAfraid()) {
activeChar.sendMessage("You cannot use escape skills during a fear.");
return;
}
//activeChar.abortCast();
activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
//SoE Animation section
activeChar.setTarget(activeChar);
// Modified by Tempy - 28 Jul 05 \\
// Check if this is a blessed scroll, if it is then shorten the cast time.
int itemId = item.getItemId();
int escapeSkill = (itemId == 1538 || itemId == 5858 || itemId == 5859 || itemId == 3958 || itemId == 10130) ? 2036 : 2013;
if (!activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false)) {
return;
}
activeChar.disableAllSkills();
L2Skill skill = SkillTable.getInstance().getInfo(escapeSkill, 1);
MagicSkillUse msu = new MagicSkillUse(activeChar, escapeSkill, 1, skill.getHitTime(), 0);
activeChar.broadcastPacket(msu);
SetupGauge sg = new SetupGauge(0, skill.getHitTime());
activeChar.sendPacket(sg);
//End SoE Animation section
SystemMessage sm = new SystemMessage(SystemMessageId.S1_DISAPPEARED);
sm.addItemName(item);
activeChar.sendPacket(sm);
EscapeFinalizer ef = new EscapeFinalizer(activeChar, itemId);
// continue execution later
activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleEffect(ef, skill.getHitTime()));
activeChar.setSkillCastEndTime(10 + GameTimeController.getGameTicks() + skill.getHitTime() / GameTimeController.MILLIS_IN_TICK);
}
static class EscapeFinalizer implements Runnable {
private L2PcInstance _activeChar;
private int _itemId;
EscapeFinalizer(L2PcInstance activeChar, int itemId) {
_activeChar = activeChar;
_itemId = itemId;
}
public void run() {
if (_activeChar.isDead()) {
return;
}
_activeChar.enableAllSkills();
_activeChar.setIsIn7sDungeon(false);
try {
if ((_itemId == 1830 || _itemId == 5859) && CastleManager.getInstance().getCastleByOwner(_activeChar.getClan()) != null) // escape to castle if own's one
{
_activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Castle);
} else if ((_itemId == 10129 || _itemId == 10130) && FortManager.getInstance().getFortByOwner(_activeChar.getClan()) != null) // escape to fortress if own's one
{
_activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Fortress);
} else if ((_itemId == 1829 || _itemId == 5858) && _activeChar.getClan() != null && ClanHallManager.getInstance().getClanHallByOwner(_activeChar.getClan()) != null) // escape to clan hall if own's one
{
_activeChar.teleToLocation(MapRegionTable.TeleportWhereType.ClanHall);
} else if (_itemId == 5858) // do nothing
{
//_activeChar.sendPacket(new SystemMessage(SystemMessageId.CLAN_HAS_NO_CLAN_HALL));
_activeChar.sendMessage("Your clan does not own a clanhall.");
return;
} else if (_itemId == 5859) // do nothing
{
_activeChar.sendMessage("Your clan does not own a castle.");
return;
} else if (_itemId == 10130) // do nothing
{
_activeChar.sendMessage("Your clan does not own a fortress.");
return;
}
else
{
if (_activeChar.getRace() == Race.Human)
{
_activeChar.teleToLocation(-83904, 243169, -3729);
}
else if (_activeChar.getRace() == Race.Elf)
{
_activeChar.teleToLocation(45873, 49288, -3064);
}
else if (_activeChar.getRace() == Race.DarkElf)
{
_activeChar.teleToLocation(12428, 16551, -4588);
}
else if (_activeChar.getRace() == Race.Orc)
{
_activeChar.teleToLocation(-44133, -113911, -244);
}
else if (_activeChar.getRace() == Race.Dwarf)
{
_activeChar.teleToLocation(116551, -182493, -1525);
}
else if (_activeChar.getRace() == Race.Kamael)
{
_activeChar.teleToLocation(-116934, 46616, 368);
}
if (_itemId < 7117)
{
_activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Town);
}
else
{
switch (_itemId)
{
case 20000:
_activeChar.teleToLocation(153729, -14201, -3735, true); // Blazing Swamp
break;
case 20001:
{
Random rnd = new Random();
int chance =rnd.nextInt(2);
switch (chance)
{
case 0:
_activeChar.teleToLocation(-16915, 206878, -3665, true); // Ant Nest
break;
case 1:
_activeChar.teleToLocation(-31089, 189272, -3595, true); // Ant Nest 1
break;
}
}
default:
_activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Town);
break;
}
}
}
}
catch (Throwable e) {
if (Config.DEBUG) {
e.printStackTrace();
}
}
}
}
public int[] getItemIds() {
return ITEM_IDS;
}
}