New constructors, functions and use of parameters for instances.
This commit is contained in:
@@ -30,6 +30,7 @@ import org.w3c.dom.Node;
|
||||
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||
import com.l2jmobius.gameserver.model.L2Object;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.instancezone.Instance;
|
||||
import com.l2jmobius.gameserver.model.instancezone.InstanceWorld;
|
||||
@@ -251,6 +252,15 @@ public final class InstanceManager implements IGameXmlReader
|
||||
return _instanceWorlds.get(instanceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object
|
||||
* @return the InstanceWorld of the object
|
||||
*/
|
||||
public InstanceWorld getWorld(L2Object object)
|
||||
{
|
||||
return _instanceWorlds.get(object.getInstanceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player have a World Instance where it's allowed to enter.
|
||||
* @param player the player to check
|
||||
@@ -353,7 +363,7 @@ public final class InstanceManager implements IGameXmlReader
|
||||
* @param templateId the instance template id
|
||||
* @return
|
||||
*/
|
||||
public int createDynamicInstance(int templateId)
|
||||
public Instance createDynamicInstance(int templateId)
|
||||
{
|
||||
while (getInstance(_dynamic) != null)
|
||||
{
|
||||
@@ -372,7 +382,7 @@ public final class InstanceManager implements IGameXmlReader
|
||||
instance.spawnDoors();
|
||||
instance.spawnGroup("general");
|
||||
}
|
||||
return _dynamic;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -55,6 +55,6 @@ public class ConditionPlayerInstanceId extends Condition
|
||||
}
|
||||
|
||||
final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(effector.getActingPlayer());
|
||||
return (world != null) && (world.getInstanceId() == instanceId) && _instanceIds.contains(world.getTemplateId());
|
||||
return (world != null) && (world.getInstanceId() == instanceId) && _instanceIds.contains(world.getInstance().getTemplateId());
|
||||
}
|
||||
}
|
||||
|
@@ -594,7 +594,7 @@ public class Duel
|
||||
return;
|
||||
}
|
||||
|
||||
_duelInstanceId = InstanceManager.getInstance().createDynamicInstance(Rnd.get(147, 150)); // Random Olympiad arena.
|
||||
_duelInstanceId = InstanceManager.getInstance().createDynamicInstance(Rnd.get(147, 150)).getId(); // Random Olympiad arena.
|
||||
final L2OlympiadStadiumZone zone = ZoneManager.getInstance().getZone(InstanceManager.getInstance().getInstance(_duelInstanceId).getNpcs().get(0), L2OlympiadStadiumZone.class);
|
||||
if (zone == null)
|
||||
{
|
||||
|
@@ -268,7 +268,7 @@ public class TvTEvent
|
||||
{
|
||||
try
|
||||
{
|
||||
_TvTEventInstance = InstanceManager.getInstance().createDynamicInstance(Config.TVT_EVENT_INSTANCE_ID);
|
||||
_TvTEventInstance = InstanceManager.getInstance().createDynamicInstance(Config.TVT_EVENT_INSTANCE_ID).getId();
|
||||
InstanceManager.getInstance().getInstance(_TvTEventInstance).setAllowSummon(false);
|
||||
InstanceManager.getInstance().getInstance(_TvTEventInstance).setIsPvP(true);
|
||||
InstanceManager.getInstance().getInstance(_TvTEventInstance).setEmptyDestroyTime((Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY * 1000) + 60000L);
|
||||
|
@@ -69,6 +69,7 @@ public final class Instance
|
||||
private static final Logger LOGGER = Logger.getLogger(Instance.class.getName());
|
||||
|
||||
private final int _id;
|
||||
private int _templateId = -1;
|
||||
private int _ejectTime = Config.EJECT_DEAD_PLAYER_TIME;
|
||||
/** Allow random walk for NPCs, global parameter. */
|
||||
private boolean _allowRandomWalk = true;
|
||||
@@ -112,6 +113,15 @@ public final class Instance
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template ID of instance world.
|
||||
* @return instance template ID
|
||||
*/
|
||||
public int getTemplateId()
|
||||
{
|
||||
return _templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the eject time
|
||||
*/
|
||||
@@ -484,6 +494,7 @@ public final class Instance
|
||||
|
||||
private void parseInstance(Node n) throws Exception
|
||||
{
|
||||
_templateId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
|
||||
Node a = n.getAttributes().getNamedItem("ejectTime");
|
||||
if (a != null)
|
||||
{
|
||||
|
@@ -18,10 +18,13 @@ package com.l2jmobius.gameserver.model.instancezone;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.l2jmobius.commons.util.CommonUtil;
|
||||
import com.l2jmobius.gameserver.instancemanager.InstanceManager;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||
import com.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
@@ -31,8 +34,7 @@ import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
*/
|
||||
public class InstanceWorld
|
||||
{
|
||||
private int _instanceId;
|
||||
private int _templateId = -1;
|
||||
private Instance _instance;
|
||||
private final List<Integer> _allowed = new CopyOnWriteArrayList<>();
|
||||
private final StatsSet _parameters = new StatsSet();
|
||||
|
||||
@@ -56,40 +58,31 @@ public class InstanceWorld
|
||||
return _allowed.contains(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the instance.
|
||||
* @param instance the instance
|
||||
*/
|
||||
public void setInstance(Instance instance)
|
||||
{
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the instance.
|
||||
* @return the instance
|
||||
*/
|
||||
public Instance getInstance()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the dynamically generated instance ID.
|
||||
* @return the instance ID
|
||||
*/
|
||||
public int getInstanceId()
|
||||
{
|
||||
return _instanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the instance ID.
|
||||
* @param instanceId the instance ID
|
||||
*/
|
||||
public void setInstanceId(int instanceId)
|
||||
{
|
||||
_instanceId = instanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client's template instance ID.
|
||||
* @return the template ID
|
||||
*/
|
||||
public int getTemplateId()
|
||||
{
|
||||
return _templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the template ID.
|
||||
* @param templateId the template ID
|
||||
*/
|
||||
public void setTemplateId(int templateId)
|
||||
{
|
||||
_templateId = templateId;
|
||||
return _instance.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,4 +170,78 @@ public class InstanceWorld
|
||||
victim.getActingPlayer().sendPacket(sm);
|
||||
instance.addEjectDeadTask(victim.getActingPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get spawned NPCs from instance.
|
||||
* @return set of NPCs from instance
|
||||
*/
|
||||
public List<L2Npc> getNpcs()
|
||||
{
|
||||
return _instance.getNpcs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get alive NPCs from instance.
|
||||
* @return set of NPCs from instance
|
||||
*/
|
||||
public List<L2Npc> getAliveNpcs()
|
||||
{
|
||||
return getNpcs().stream().filter(n -> n.getCurrentHp() > 0).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get spawned NPCs from instance with specific IDs.
|
||||
* @param id IDs of NPCs which should be found
|
||||
* @return list of filtered NPCs from instance
|
||||
*/
|
||||
public List<L2Npc> getNpcs(int... id)
|
||||
{
|
||||
return getNpcs().stream().filter(n -> CommonUtil.contains(id, n.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get spawned NPCs from instance with specific IDs and class type.
|
||||
* @param <T>
|
||||
* @param clazz
|
||||
* @param ids IDs of NPCs which should be found
|
||||
* @return list of filtered NPCs from instance
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final <T extends L2Character> List<T> getNpcs(Class<T> clazz, int... ids)
|
||||
{
|
||||
return getNpcs().stream().filter(n -> (ids.length == 0) || CommonUtil.contains(ids, n.getId())).filter(clazz::isInstance).map(clazz::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get spawned and alive NPCs from instance with specific IDs and class type.
|
||||
* @param <T>
|
||||
* @param clazz
|
||||
* @param ids IDs of NPCs which should be found
|
||||
* @return list of filtered NPCs from instance
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final <T extends L2Character> List<T> getAliveNpcs(Class<T> clazz, int... ids)
|
||||
{
|
||||
return getNpcs().stream().filter(n -> ((ids.length == 0) || CommonUtil.contains(ids, n.getId())) && (n.getCurrentHp() > 0)).filter(clazz::isInstance).map(clazz::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get alive NPCs from instance with specific IDs.
|
||||
* @param id IDs of NPCs which should be found
|
||||
* @return list of filtered NPCs from instance
|
||||
*/
|
||||
public List<L2Npc> getAliveNpcs(int... id)
|
||||
{
|
||||
return getNpcs().stream().filter(n -> (n.getCurrentHp() > 0) && CommonUtil.contains(id, n.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get first found spawned NPC with specific ID.
|
||||
* @param id ID of NPC to be found
|
||||
* @return first found NPC with specified ID, otherwise {@code null}
|
||||
*/
|
||||
public L2Npc getNpc(int id)
|
||||
{
|
||||
return getNpcs().stream().filter(n -> n.getId() == id).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
@@ -53,22 +53,22 @@ public class OlympiadGameManager implements Runnable
|
||||
{
|
||||
case "Grassy Arena":
|
||||
{
|
||||
instanceId = InstanceManager.getInstance().createDynamicInstance(147);
|
||||
instanceId = InstanceManager.getInstance().createDynamicInstance(147).getId();
|
||||
break;
|
||||
}
|
||||
case "Three Bridges Arena":
|
||||
{
|
||||
instanceId = InstanceManager.getInstance().createDynamicInstance(148);
|
||||
instanceId = InstanceManager.getInstance().createDynamicInstance(148).getId();
|
||||
break;
|
||||
}
|
||||
case "Heros's Vestiges Arena":
|
||||
{
|
||||
instanceId = InstanceManager.getInstance().createDynamicInstance(149);
|
||||
instanceId = InstanceManager.getInstance().createDynamicInstance(149).getId();
|
||||
break;
|
||||
}
|
||||
case "Orbis Arena":
|
||||
{
|
||||
instanceId = InstanceManager.getInstance().createDynamicInstance(150);
|
||||
instanceId = InstanceManager.getInstance().createDynamicInstance(150).getId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -201,8 +201,8 @@ public abstract class L2ZoneType extends ListenersContainer
|
||||
// Check instance
|
||||
if (_instanceTemplateId > 0)
|
||||
{
|
||||
final InstanceWorld world = InstanceManager.getInstance().getWorld(character.getInstanceId());
|
||||
if ((world != null) && (world.getTemplateId() != _instanceTemplateId))
|
||||
final InstanceWorld world = InstanceManager.getInstance().getWorld(character);
|
||||
if ((world != null) && (world.getInstance().getTemplateId() != _instanceTemplateId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user