123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932 |
- /*
- * Copyright (C) 2004-2015 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server 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 Server 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 com.l2jserver.gameserver.model.entity;
- import java.io.File;
- import java.io.IOException;
- import java.time.DayOfWeek;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.concurrent.ScheduledFuture;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javolution.util.FastList;
- import javolution.util.FastMap;
- import org.w3c.dom.Document;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.ThreadPoolManager;
- import com.l2jserver.gameserver.data.xml.impl.DoorData;
- import com.l2jserver.gameserver.enums.InstanceReenterType;
- import com.l2jserver.gameserver.enums.InstanceRemoveBuffType;
- import com.l2jserver.gameserver.instancemanager.InstanceManager;
- import com.l2jserver.gameserver.model.L2Spawn;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.L2WorldRegion;
- import com.l2jserver.gameserver.model.Location;
- import com.l2jserver.gameserver.model.StatsSet;
- import com.l2jserver.gameserver.model.TeleportWhereType;
- import com.l2jserver.gameserver.model.actor.L2Attackable;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.actor.L2Npc;
- import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.actor.templates.L2DoorTemplate;
- import com.l2jserver.gameserver.model.holders.InstanceReenterTimeHolder;
- import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.clientpackets.Say2;
- import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- import com.l2jserver.gameserver.util.Broadcast;
- /**
- * Main class for game instances.
- * @author evill33t, GodKratos
- */
- public final class Instance
- {
- private static final Logger _log = Logger.getLogger(Instance.class.getName());
-
- private final int _id;
- private String _name;
- private int _ejectTime = Config.EJECT_DEAD_PLAYER_TIME;
- /** Allow random walk for NPCs, global parameter. */
- private boolean _allowRandomWalk = true;
- private final List<Integer> _players = new FastList<Integer>().shared();
- private final List<L2Npc> _npcs = new FastList<L2Npc>().shared();
- private final Map<Integer, L2DoorInstance> _doors = new ConcurrentHashMap<>();
- private final Map<String, List<L2Spawn>> _manualSpawn = new HashMap<>();
- private Location _spawnLoc = null;
- private boolean _allowSummon = true;
- private long _emptyDestroyTime = -1;
- private long _lastLeft = -1;
- private long _instanceStartTime = -1;
- private long _instanceEndTime = -1;
- private boolean _isPvPInstance = false;
- private boolean _showTimer = false;
- private boolean _isTimerIncrease = true;
- private String _timerText = "";
- // Instance reset data
- private InstanceReenterType _type = InstanceReenterType.NONE;
- private final List<InstanceReenterTimeHolder> _resetData = new ArrayList<>();
- // Instance remove buffs data
- private InstanceRemoveBuffType _removeBuffType = InstanceRemoveBuffType.NONE;
- private final List<Integer> _exceptionList = new ArrayList<>();
-
- protected ScheduledFuture<?> _checkTimeUpTask = null;
- protected final Map<Integer, ScheduledFuture<?>> _ejectDeadTasks = new FastMap<>();
-
- public Instance(int id)
- {
- _id = id;
- _instanceStartTime = System.currentTimeMillis();
- }
-
- public Instance(int id, String name)
- {
- _id = id;
- _name = name;
- _instanceStartTime = System.currentTimeMillis();
- }
-
- /**
- * @return the ID of this instance.
- */
- public int getId()
- {
- return _id;
- }
-
- /**
- * @return the name of this instance
- */
- public String getName()
- {
- return _name;
- }
-
- public void setName(String name)
- {
- _name = name;
- }
-
- /**
- * @return the eject time
- */
- public int getEjectTime()
- {
- return _ejectTime;
- }
-
- /**
- * @param ejectTime the player eject time upon death
- */
- public void setEjectTime(int ejectTime)
- {
- _ejectTime = ejectTime;
- }
-
- /**
- * @return whether summon friend type skills are allowed for this instance
- */
- public boolean isSummonAllowed()
- {
- return _allowSummon;
- }
-
- /**
- * Sets the status for the instance for summon friend type skills
- * @param b
- */
- public void setAllowSummon(boolean b)
- {
- _allowSummon = b;
- }
-
- /**
- * Returns true if entire instance is PvP zone
- * @return
- */
- public boolean isPvPInstance()
- {
- return _isPvPInstance;
- }
-
- /**
- * Sets PvP zone status of the instance
- * @param b
- */
- public void setPvPInstance(boolean b)
- {
- _isPvPInstance = b;
- }
-
- /**
- * Set the instance duration task
- * @param duration in milliseconds
- */
- public void setDuration(int duration)
- {
- if (_checkTimeUpTask != null)
- {
- _checkTimeUpTask.cancel(true);
- }
-
- _checkTimeUpTask = ThreadPoolManager.getInstance().scheduleGeneral(new CheckTimeUp(duration), 500);
- _instanceEndTime = System.currentTimeMillis() + duration + 500;
- }
-
- /**
- * Set time before empty instance will be removed
- * @param time in milliseconds
- */
- public void setEmptyDestroyTime(long time)
- {
- _emptyDestroyTime = time;
- }
-
- /**
- * Checks if the player exists within this instance
- * @param objectId
- * @return true if player exists in instance
- */
- public boolean containsPlayer(int objectId)
- {
- return _players.contains(objectId);
- }
-
- /**
- * Adds the specified player to the instance
- * @param objectId Players object ID
- */
- public void addPlayer(int objectId)
- {
- _players.add(objectId);
- }
-
- /**
- * Removes the specified player from the instance list.
- * @param objectId the player's object Id
- */
- public void removePlayer(Integer objectId)
- {
- _players.remove(objectId);
- if (_players.isEmpty() && (_emptyDestroyTime >= 0))
- {
- _lastLeft = System.currentTimeMillis();
- setDuration((int) (_instanceEndTime - System.currentTimeMillis() - 500));
- }
- }
-
- public void addNpc(L2Npc npc)
- {
- _npcs.add(npc);
- }
-
- public void removeNpc(L2Npc npc)
- {
- if (npc.getSpawn() != null)
- {
- npc.getSpawn().stopRespawn();
- }
- _npcs.remove(npc);
- }
-
- /**
- * Adds a door into the instance
- * @param doorId - from doors.xml
- * @param set - StatsSet for initializing door
- */
- public void addDoor(int doorId, StatsSet set)
- {
- if (_doors.containsKey(doorId))
- {
- _log.warning("Door ID " + doorId + " already exists in instance " + getId());
- return;
- }
-
- final L2DoorInstance newdoor = new L2DoorInstance(new L2DoorTemplate(set));
- newdoor.setInstanceId(getId());
- newdoor.setCurrentHp(newdoor.getMaxHp());
- newdoor.spawnMe(newdoor.getTemplate().getX(), newdoor.getTemplate().getY(), newdoor.getTemplate().getZ());
- _doors.put(doorId, newdoor);
- }
-
- public List<Integer> getPlayers()
- {
- return _players;
- }
-
- public List<L2Npc> getNpcs()
- {
- return _npcs;
- }
-
- public Collection<L2DoorInstance> getDoors()
- {
- return _doors.values();
- }
-
- public L2DoorInstance getDoor(int id)
- {
- return _doors.get(id);
- }
-
- public long getInstanceEndTime()
- {
- return _instanceEndTime;
- }
-
- public long getInstanceStartTime()
- {
- return _instanceStartTime;
- }
-
- public boolean isShowTimer()
- {
- return _showTimer;
- }
-
- public boolean isTimerIncrease()
- {
- return _isTimerIncrease;
- }
-
- public String getTimerText()
- {
- return _timerText;
- }
-
- /**
- * @return the spawn location for this instance to be used when leaving the instance
- */
- public Location getSpawnLoc()
- {
- return _spawnLoc;
- }
-
- /**
- * Sets the spawn location for this instance to be used when leaving the instance
- * @param loc
- */
- public void setSpawnLoc(Location loc)
- {
- _spawnLoc = loc;
- }
-
- public void removePlayers()
- {
- for (Integer objectId : _players)
- {
- final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
- if ((player != null) && (player.getInstanceId() == getId()))
- {
- player.setInstanceId(0);
- if (getSpawnLoc() != null)
- {
- player.teleToLocation(getSpawnLoc(), true);
- }
- else
- {
- player.teleToLocation(TeleportWhereType.TOWN);
- }
- }
- }
- _players.clear();
- }
-
- public void removeNpcs()
- {
- for (L2Npc mob : _npcs)
- {
- if (mob != null)
- {
- if (mob.getSpawn() != null)
- {
- mob.getSpawn().stopRespawn();
- }
- mob.deleteMe();
- }
- }
- _npcs.clear();
- _manualSpawn.clear();
- }
-
- public void removeDoors()
- {
- for (L2DoorInstance door : _doors.values())
- {
- if (door != null)
- {
- L2WorldRegion region = door.getWorldRegion();
- door.decayMe();
-
- if (region != null)
- {
- region.removeVisibleObject(door);
- }
-
- door.getKnownList().removeAllKnownObjects();
- L2World.getInstance().removeObject(door);
- }
- }
- _doors.clear();
- }
-
- /**
- * Spawns group of instance NPC's
- * @param groupName - name of group from XML definition to spawn
- * @return list of spawned NPC's
- */
- public List<L2Npc> spawnGroup(String groupName)
- {
- List<L2Npc> ret = null;
- if (_manualSpawn.containsKey(groupName))
- {
- final List<L2Spawn> manualSpawn = _manualSpawn.get(groupName);
- ret = new ArrayList<>(manualSpawn.size());
-
- for (L2Spawn spawnDat : manualSpawn)
- {
- ret.add(spawnDat.doSpawn());
- }
- }
- else
- {
- _log.warning(getName() + " instance: cannot spawn NPC's, wrong group name: " + groupName);
- }
-
- return ret;
- }
-
- public void loadInstanceTemplate(String filename)
- {
- Document doc = null;
- File xml = new File(Config.DATAPACK_ROOT, "data/instances/" + filename);
-
- try
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setValidating(false);
- factory.setIgnoringComments(true);
- doc = factory.newDocumentBuilder().parse(xml);
-
- for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
- {
- if ("instance".equalsIgnoreCase(n.getNodeName()))
- {
- parseInstance(n);
- }
- }
- }
- catch (IOException e)
- {
- _log.log(Level.WARNING, "Instance: can not find " + xml.getAbsolutePath() + " ! " + e.getMessage(), e);
- }
- catch (Exception e)
- {
- _log.log(Level.WARNING, "Instance: error while loading " + xml.getAbsolutePath() + " ! " + e.getMessage(), e);
- }
- }
-
- private void parseInstance(Node n) throws Exception
- {
- _name = n.getAttributes().getNamedItem("name").getNodeValue();
- Node a = n.getAttributes().getNamedItem("ejectTime");
- if (a != null)
- {
- _ejectTime = 1000 * Integer.parseInt(a.getNodeValue());
- }
- a = n.getAttributes().getNamedItem("allowRandomWalk");
- if (a != null)
- {
- _allowRandomWalk = Boolean.parseBoolean(a.getNodeValue());
- }
- Node first = n.getFirstChild();
- for (n = first; n != null; n = n.getNextSibling())
- {
- if ("activityTime".equalsIgnoreCase(n.getNodeName()))
- {
- a = n.getAttributes().getNamedItem("val");
- if (a != null)
- {
- _checkTimeUpTask = ThreadPoolManager.getInstance().scheduleGeneral(new CheckTimeUp(Integer.parseInt(a.getNodeValue()) * 60000), 15000);
- _instanceEndTime = System.currentTimeMillis() + (Long.parseLong(a.getNodeValue()) * 60000) + 15000;
- }
- }
- // @formatter:off
- /*
- else if ("timeDelay".equalsIgnoreCase(n.getNodeName()))
- {
- a = n.getAttributes().getNamedItem("val");
- if (a != null)
- {
- instance.setTimeDelay(Integer.parseInt(a.getNodeValue()));
- }
- }
- */
- // @formatter:on
- else if ("allowSummon".equalsIgnoreCase(n.getNodeName()))
- {
- a = n.getAttributes().getNamedItem("val");
- if (a != null)
- {
- setAllowSummon(Boolean.parseBoolean(a.getNodeValue()));
- }
- }
- else if ("emptyDestroyTime".equalsIgnoreCase(n.getNodeName()))
- {
- a = n.getAttributes().getNamedItem("val");
- if (a != null)
- {
- _emptyDestroyTime = Long.parseLong(a.getNodeValue()) * 1000;
- }
- }
- else if ("showTimer".equalsIgnoreCase(n.getNodeName()))
- {
- a = n.getAttributes().getNamedItem("val");
- if (a != null)
- {
- _showTimer = Boolean.parseBoolean(a.getNodeValue());
- }
- a = n.getAttributes().getNamedItem("increase");
- if (a != null)
- {
- _isTimerIncrease = Boolean.parseBoolean(a.getNodeValue());
- }
- a = n.getAttributes().getNamedItem("text");
- if (a != null)
- {
- _timerText = a.getNodeValue();
- }
- }
- else if ("PvPInstance".equalsIgnoreCase(n.getNodeName()))
- {
- a = n.getAttributes().getNamedItem("val");
- if (a != null)
- {
- setPvPInstance(Boolean.parseBoolean(a.getNodeValue()));
- }
- }
- else if ("doorlist".equalsIgnoreCase(n.getNodeName()))
- {
- for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
- {
- int doorId = 0;
- if ("door".equalsIgnoreCase(d.getNodeName()))
- {
- doorId = Integer.parseInt(d.getAttributes().getNamedItem("doorId").getNodeValue());
- StatsSet set = new StatsSet();
- set.add(DoorData.getInstance().getDoorTemplate(doorId));
- for (Node bean = d.getFirstChild(); bean != null; bean = bean.getNextSibling())
- {
- if ("set".equalsIgnoreCase(bean.getNodeName()))
- {
- NamedNodeMap attrs = bean.getAttributes();
- String setname = attrs.getNamedItem("name").getNodeValue();
- String value = attrs.getNamedItem("val").getNodeValue();
- set.set(setname, value);
- }
- }
- addDoor(doorId, set);
- }
- }
- }
- else if ("spawnlist".equalsIgnoreCase(n.getNodeName()))
- {
- for (Node group = n.getFirstChild(); group != null; group = group.getNextSibling())
- {
- if ("group".equalsIgnoreCase(group.getNodeName()))
- {
- String spawnGroup = group.getAttributes().getNamedItem("name").getNodeValue();
- List<L2Spawn> manualSpawn = new ArrayList<>();
- for (Node d = group.getFirstChild(); d != null; d = d.getNextSibling())
- {
- int npcId = 0, x = 0, y = 0, z = 0, heading = 0, respawn = 0, respawnRandom = 0, delay = -1;
- Boolean allowRandomWalk = null;
- if ("spawn".equalsIgnoreCase(d.getNodeName()))
- {
-
- npcId = Integer.parseInt(d.getAttributes().getNamedItem("npcId").getNodeValue());
- x = Integer.parseInt(d.getAttributes().getNamedItem("x").getNodeValue());
- y = Integer.parseInt(d.getAttributes().getNamedItem("y").getNodeValue());
- z = Integer.parseInt(d.getAttributes().getNamedItem("z").getNodeValue());
- heading = Integer.parseInt(d.getAttributes().getNamedItem("heading").getNodeValue());
- respawn = Integer.parseInt(d.getAttributes().getNamedItem("respawn").getNodeValue());
- if (d.getAttributes().getNamedItem("onKillDelay") != null)
- {
- delay = Integer.parseInt(d.getAttributes().getNamedItem("onKillDelay").getNodeValue());
- }
- if (d.getAttributes().getNamedItem("respawnRandom") != null)
- {
- respawnRandom = Integer.parseInt(d.getAttributes().getNamedItem("respawnRandom").getNodeValue());
- }
- if (d.getAttributes().getNamedItem("allowRandomWalk") != null)
- {
- allowRandomWalk = Boolean.valueOf(d.getAttributes().getNamedItem("allowRandomWalk").getNodeValue());
- }
-
- final L2Spawn spawnDat = new L2Spawn(npcId);
- spawnDat.setX(x);
- spawnDat.setY(y);
- spawnDat.setZ(z);
- spawnDat.setAmount(1);
- spawnDat.setHeading(heading);
- spawnDat.setRespawnDelay(respawn, respawnRandom);
- if (respawn == 0)
- {
- spawnDat.stopRespawn();
- }
- else
- {
- spawnDat.startRespawn();
- }
- spawnDat.setInstanceId(getId());
- if (allowRandomWalk == null)
- {
- spawnDat.setIsNoRndWalk(!_allowRandomWalk);
- }
- else
- {
- spawnDat.setIsNoRndWalk(!allowRandomWalk);
- }
- if (spawnGroup.equals("general"))
- {
- L2Npc spawned = spawnDat.doSpawn();
- if ((delay >= 0) && (spawned instanceof L2Attackable))
- {
- ((L2Attackable) spawned).setOnKillDelay(delay);
- }
- }
- else
- {
- manualSpawn.add(spawnDat);
- }
- }
- }
- if (!manualSpawn.isEmpty())
- {
- _manualSpawn.put(spawnGroup, manualSpawn);
- }
- }
- }
- }
- else if ("spawnpoint".equalsIgnoreCase(n.getNodeName()))
- {
- try
- {
- int x = Integer.parseInt(n.getAttributes().getNamedItem("spawnX").getNodeValue());
- int y = Integer.parseInt(n.getAttributes().getNamedItem("spawnY").getNodeValue());
- int z = Integer.parseInt(n.getAttributes().getNamedItem("spawnZ").getNodeValue());
- _spawnLoc = new Location(x, y, z);
- }
- catch (Exception e)
- {
- _log.log(Level.WARNING, "Error parsing instance xml: " + e.getMessage(), e);
- _spawnLoc = null;
- }
- }
- else if ("reenter".equalsIgnoreCase(n.getNodeName()))
- {
- a = n.getAttributes().getNamedItem("additionStyle");
- if (a != null)
- {
- _type = InstanceReenterType.valueOf(a.getNodeValue());
- }
-
- for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
- {
- long time = -1;
- DayOfWeek day = null;
- int hour = -1;
- int minute = -1;
-
- if ("reset".equalsIgnoreCase(d.getNodeName()))
- {
- a = d.getAttributes().getNamedItem("time");
- if (a != null)
- {
- time = Long.parseLong(a.getNodeValue());
-
- if (time > 0)
- {
- _resetData.add(new InstanceReenterTimeHolder(time));
- break;
- }
- }
- else if (time == -1)
- {
- a = d.getAttributes().getNamedItem("day");
- if (a != null)
- {
- day = DayOfWeek.valueOf(a.getNodeValue().toUpperCase());
- }
-
- a = d.getAttributes().getNamedItem("hour");
- if (a != null)
- {
- hour = Integer.parseInt(a.getNodeValue());
- }
-
- a = d.getAttributes().getNamedItem("minute");
- if (a != null)
- {
- minute = Integer.parseInt(a.getNodeValue());
- }
- _resetData.add(new InstanceReenterTimeHolder(day, hour, minute));
- }
- }
- }
- }
- else if ("removeBuffs".equalsIgnoreCase(n.getNodeName()))
- {
- a = n.getAttributes().getNamedItem("type");
- if (a != null)
- {
- _removeBuffType = InstanceRemoveBuffType.valueOf(a.getNodeValue().toUpperCase());
- }
-
- for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
- {
- if ("skill".equalsIgnoreCase(d.getNodeName()))
- {
- a = d.getAttributes().getNamedItem("id");
- if (a != null)
- {
- _exceptionList.add(Integer.parseInt(a.getNodeValue()));
- }
- }
- }
- }
- }
- }
-
- protected void doCheckTimeUp(int remaining)
- {
- CreatureSay cs = null;
- int timeLeft;
- int interval;
-
- if (_players.isEmpty() && (_emptyDestroyTime == 0))
- {
- remaining = 0;
- interval = 500;
- }
- else if (_players.isEmpty() && (_emptyDestroyTime > 0))
- {
-
- Long emptyTimeLeft = (_lastLeft + _emptyDestroyTime) - System.currentTimeMillis();
- if (emptyTimeLeft <= 0)
- {
- interval = 0;
- remaining = 0;
- }
- else if ((remaining > 300000) && (emptyTimeLeft > 300000))
- {
- interval = 300000;
- remaining = remaining - 300000;
- }
- else if ((remaining > 60000) && (emptyTimeLeft > 60000))
- {
- interval = 60000;
- remaining = remaining - 60000;
- }
- else if ((remaining > 30000) && (emptyTimeLeft > 30000))
- {
- interval = 30000;
- remaining = remaining - 30000;
- }
- else
- {
- interval = 10000;
- remaining = remaining - 10000;
- }
- }
- else if (remaining > 300000)
- {
- timeLeft = remaining / 60000;
- interval = 300000;
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.DUNGEON_EXPIRES_IN_S1_MINUTES);
- sm.addString(Integer.toString(timeLeft));
- Broadcast.toPlayersInInstance(sm, getId());
- remaining = remaining - 300000;
- }
- else if (remaining > 60000)
- {
- timeLeft = remaining / 60000;
- interval = 60000;
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.DUNGEON_EXPIRES_IN_S1_MINUTES);
- sm.addString(Integer.toString(timeLeft));
- Broadcast.toPlayersInInstance(sm, getId());
- remaining = remaining - 60000;
- }
- else if (remaining > 30000)
- {
- timeLeft = remaining / 1000;
- interval = 30000;
- cs = new CreatureSay(0, Say2.ALLIANCE, "Notice", timeLeft + " seconds left.");
- remaining = remaining - 30000;
- }
- else
- {
- timeLeft = remaining / 1000;
- interval = 10000;
- cs = new CreatureSay(0, Say2.ALLIANCE, "Notice", timeLeft + " seconds left.");
- remaining = remaining - 10000;
- }
- if (cs != null)
- {
- for (Integer objectId : _players)
- {
- final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
- if ((player != null) && (player.getInstanceId() == getId()))
- {
- player.sendPacket(cs);
- }
- }
- }
- cancelTimer();
- if (remaining >= 10000)
- {
- _checkTimeUpTask = ThreadPoolManager.getInstance().scheduleGeneral(new CheckTimeUp(remaining), interval);
- }
- else
- {
- _checkTimeUpTask = ThreadPoolManager.getInstance().scheduleGeneral(new TimeUp(), interval);
- }
- }
-
- public void cancelTimer()
- {
- if (_checkTimeUpTask != null)
- {
- _checkTimeUpTask.cancel(true);
- }
- }
-
- public void cancelEjectDeadPlayer(L2PcInstance player)
- {
- final ScheduledFuture<?> task = _ejectDeadTasks.remove(player.getObjectId());
- if (task != null)
- {
- task.cancel(true);
- }
- }
-
- public void addEjectDeadTask(L2PcInstance player)
- {
- if ((player != null))
- {
- _ejectDeadTasks.put(player.getObjectId(), ThreadPoolManager.getInstance().scheduleGeneral(() ->
- {
- if (player.isDead() && (player.getInstanceId() == getId()))
- {
- player.setInstanceId(0);
- if (getSpawnLoc() != null)
- {
- player.teleToLocation(getSpawnLoc(), true);
- }
- else
- {
- player.teleToLocation(TeleportWhereType.TOWN);
- }
- }
- }, _ejectTime));
- }
- }
-
- /**
- * @param killer the character that killed the {@code victim}
- * @param victim the character that was killed by the {@code killer}
- */
- public final void notifyDeath(L2Character killer, L2Character victim)
- {
- final InstanceWorld instance = InstanceManager.getInstance().getPlayerWorld(victim.getActingPlayer());
- if (instance != null)
- {
- instance.onDeath(killer, victim);
- }
- }
-
- public class CheckTimeUp implements Runnable
- {
- private final int _remaining;
-
- public CheckTimeUp(int remaining)
- {
- _remaining = remaining;
- }
-
- @Override
- public void run()
- {
- doCheckTimeUp(_remaining);
- }
- }
-
- public class TimeUp implements Runnable
- {
- @Override
- public void run()
- {
- InstanceManager.getInstance().destroyInstance(getId());
- }
- }
-
- public InstanceReenterType getReenterType()
- {
- return _type;
- }
-
- public void setReenterType(InstanceReenterType type)
- {
- _type = type;
- }
-
- public List<InstanceReenterTimeHolder> getReenterData()
- {
- return _resetData;
- }
-
- public boolean isRemoveBuffEnabled()
- {
- return getRemoveBuffType() != InstanceRemoveBuffType.NONE;
- }
-
- public InstanceRemoveBuffType getRemoveBuffType()
- {
- return _removeBuffType;
- }
-
- public List<Integer> getBuffExceptionList()
- {
- return _exceptionList;
- }
- }
|