Use template ids for instance creation.

This commit is contained in:
MobiusDev
2018-04-28 18:37:40 +00:00
parent c4b4ec5751
commit 7cf3218f7f
168 changed files with 2182 additions and 323 deletions

View File

@@ -1081,7 +1081,7 @@ public final class Config
public static boolean CHAMPION_ENABLE_IN_INSTANCES;
public static boolean TVT_EVENT_ENABLED;
public static boolean TVT_EVENT_IN_INSTANCE;
public static String TVT_EVENT_INSTANCE_FILE;
public static int TVT_EVENT_INSTANCE_ID;
public static String[] TVT_EVENT_INTERVAL;
public static int TVT_EVENT_PARTICIPATION_TIME;
public static int TVT_EVENT_RUNNING_TIME;
@@ -3025,7 +3025,7 @@ public final class Config
TVT_EVENT_ENABLED = TeamVersusTeam.getBoolean("TvTEventEnabled", false);
TVT_EVENT_IN_INSTANCE = TeamVersusTeam.getBoolean("TvTEventInInstance", false);
TVT_EVENT_INSTANCE_FILE = TeamVersusTeam.getString("TvTEventInstanceFile", "coliseum.xml");
TVT_EVENT_INSTANCE_ID = TeamVersusTeam.getInt("TvTEventInstanceId", 3049);
TVT_EVENT_INTERVAL = TeamVersusTeam.getString("TvTEventInterval", "20:00").split(",");
TVT_EVENT_PARTICIPATION_TIME = TeamVersusTeam.getInt("TvTEventParticipationTime", 3600);
TVT_EVENT_RUNNING_TIME = TeamVersusTeam.getInt("TvTEventRunningTime", 1800);

View File

@@ -16,13 +16,10 @@
*/
package com.l2jmobius.gameserver.instancemanager;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import com.l2jmobius.commons.util.Rnd;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Duel;
import com.l2jmobius.gameserver.model.skills.Skill;
@@ -30,7 +27,6 @@ import com.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
public final class DuelManager
{
private static final List<String> ARENAS = Arrays.asList("OlympiadGrassyArena.xml", "OlympiadThreeBridgesArena.xml", "OlympiadHerossVestigesArena.xml", "OlympiadOrbisArena.xml");
private final Map<Integer, Duel> _duels = new ConcurrentHashMap<>();
private final AtomicInteger _currentDuelId = new AtomicInteger();
@@ -210,15 +206,6 @@ public final class DuelManager
}
}
/**
* Gets new a random Olympiad Stadium instance name.
* @return an instance name
*/
public String getDuelArena()
{
return ARENAS.get(Rnd.get(ARENAS.size()));
}
public static DuelManager getInstance()
{
return SingletonHolder._instance;

View File

@@ -44,6 +44,8 @@ public final class InstanceManager implements IGameXmlReader
private int _dynamic = 300000;
// InstanceId Names
private static final Map<Integer, String> _instanceIdNames = new HashMap<>();
// Instance templates
private final Map<Integer, String> _instanceTemplates = new HashMap<>();
private final Map<Integer, Map<Integer, Long>> _playerInstanceTimes = new ConcurrentHashMap<>();
// SQL Queries
private static final String ADD_INSTANCE_TIME = "INSERT INTO character_instance_time (charId,instanceId,time) values (?,?,?) ON DUPLICATE KEY UPDATE time=?";
@@ -53,10 +55,10 @@ public final class InstanceManager implements IGameXmlReader
protected InstanceManager()
{
// Creates the multiverse.
INSTANCES.put(-1, new Instance(-1, "multiverse"));
INSTANCES.put(-1, new Instance(-1));
LOGGER.info(getClass().getSimpleName() + ": Multiverse Instance created.");
// Creates the universe.
INSTANCES.put(0, new Instance(0, "universe"));
INSTANCES.put(0, new Instance(0));
LOGGER.info(getClass().getSimpleName() + ": Universe Instance created.");
load();
}
@@ -67,6 +69,10 @@ public final class InstanceManager implements IGameXmlReader
_instanceIdNames.clear();
parseDatapackFile("data/InstanceNames.xml");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _instanceIdNames.size() + " instance names.");
// Load instance templates
_instanceTemplates.clear();
parseDatapackDirectory("data/instances", true);
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _instanceTemplates.size() + " instance templates.");
}
/**
@@ -203,16 +209,26 @@ public final class InstanceManager implements IGameXmlReader
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equals(n.getNodeName()))
switch (n.getNodeName())
{
NamedNodeMap attrs;
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
case "list":
{
if ("instance".equals(d.getNodeName()))
NamedNodeMap attrs;
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
attrs = d.getAttributes();
_instanceIdNames.put(parseInteger(attrs, "id"), attrs.getNamedItem("name").getNodeValue());
if ("instance".equals(d.getNodeName()))
{
attrs = d.getAttributes();
_instanceIdNames.put(parseInteger(attrs, "id"), attrs.getNamedItem("name").getNodeValue());
}
}
break;
}
case "instance":
{
NamedNodeMap attrs = n.getAttributes();
_instanceTemplates.put(parseInteger(attrs, "id"), new File("data/instances/").toURI().relativize(f.toURI()).getPath());
break;
}
}
}
@@ -314,10 +330,10 @@ public final class InstanceManager implements IGameXmlReader
/**
* @param id
* @param template
* @param templateId
* @return
*/
public boolean createInstanceFromTemplate(int id, String template)
public boolean createInstanceFromTemplate(int id, int templateId)
{
if (getInstance(id) != null)
{
@@ -326,7 +342,7 @@ public final class InstanceManager implements IGameXmlReader
final Instance instance = new Instance(id);
INSTANCES.put(id, instance);
instance.loadInstanceTemplate(template);
instance.loadInstanceTemplate(templateId);
instance.spawnDoors();
instance.spawnGroup("general");
return true;
@@ -334,10 +350,10 @@ public final class InstanceManager implements IGameXmlReader
/**
* Create a new instance with a dynamic instance id based on a template (or null)
* @param template xml file
* @param templateId the instance template id
* @return
*/
public int createDynamicInstance(String template)
public int createDynamicInstance(int templateId)
{
while (getInstance(_dynamic) != null)
{
@@ -350,15 +366,25 @@ public final class InstanceManager implements IGameXmlReader
}
final Instance instance = new Instance(_dynamic);
INSTANCES.put(_dynamic, instance);
if (template != null)
if (templateId > 0)
{
instance.loadInstanceTemplate(template);
instance.loadInstanceTemplate(templateId);
instance.spawnDoors();
instance.spawnGroup("general");
}
return _dynamic;
}
/**
* Get instance template file name by template ID.
* @param id template id of instance
* @return instance template if found, otherwise {@code null}
*/
public String getInstanceTemplateFileName(int id)
{
return _instanceTemplates.get(id);
}
/**
* Gets the single instance of {@code InstanceManager}.
* @return single instance of {@code InstanceManager}

View File

@@ -594,8 +594,7 @@ public class Duel
return;
}
final String instanceName = DuelManager.getInstance().getDuelArena();
_duelInstanceId = InstanceManager.getInstance().createDynamicInstance(instanceName);
_duelInstanceId = InstanceManager.getInstance().createDynamicInstance(Rnd.get(147, 150)); // Random Olympiad arena.
final L2OlympiadStadiumZone zone = ZoneManager.getInstance().getZone(InstanceManager.getInstance().getInstance(_duelInstanceId).getNpcs().get(0), L2OlympiadStadiumZone.class);
if (zone == null)
{

View File

@@ -268,7 +268,7 @@ public class TvTEvent
{
try
{
_TvTEventInstance = InstanceManager.getInstance().createDynamicInstance(Config.TVT_EVENT_INSTANCE_FILE);
_TvTEventInstance = InstanceManager.getInstance().createDynamicInstance(Config.TVT_EVENT_INSTANCE_ID);
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);

View File

@@ -69,7 +69,6 @@ public final class Instance
private static final Logger LOGGER = 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;
@@ -78,7 +77,6 @@ public final class Instance
private final List<StatsSet> _doorTemplates = new CopyOnWriteArrayList<>();
private final Map<Integer, L2DoorInstance> _doors = new ConcurrentHashMap<>();
private final List<StatsSet> _spawnTemplates = new CopyOnWriteArrayList<>();
// private StartPosType _enterLocationOrder; TODO implement me
private List<Location> _enterLocations = null;
private Location _exitLocation = null;
private boolean _allowSummon = true;
@@ -106,13 +104,6 @@ public final class Instance
_instanceStartTime = System.currentTimeMillis();
}
public Instance(int id, String name)
{
_id = id;
_name = name;
_instanceStartTime = System.currentTimeMillis();
}
/**
* @return the ID of this instance.
*/
@@ -121,19 +112,6 @@ public final class Instance
return _id;
}
/**
* @return the name of this instance
*/
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
/**
* @return the eject time
*/
@@ -474,11 +452,11 @@ public final class Instance
return spawnedNpcs;
}
public void loadInstanceTemplate(String filename)
public void loadInstanceTemplate(int templateId)
{
// TODO: Cache templates.
Document doc = null;
final File xml = new File(Config.DATAPACK_ROOT, "data/instances/" + filename);
final File xml = new File(Config.DATAPACK_ROOT, "data/instances/" + InstanceManager.getInstance().getInstanceTemplateFileName(templateId));
try
{
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -506,7 +484,6 @@ public final class Instance
private void parseInstance(Node n) throws Exception
{
_name = n.getAttributes().getNamedItem("name").getNodeValue();
Node a = n.getAttributes().getNamedItem("ejectTime");
if (a != null)
{

View File

@@ -53,22 +53,22 @@ public class OlympiadGameManager implements Runnable
{
case "Grassy Arena":
{
instanceId = InstanceManager.getInstance().createDynamicInstance("OlympiadGrassyArena.xml");
instanceId = InstanceManager.getInstance().createDynamicInstance(147);
break;
}
case "Three Bridges Arena":
{
instanceId = InstanceManager.getInstance().createDynamicInstance("OlympiadThreeBridgesArena.xml");
instanceId = InstanceManager.getInstance().createDynamicInstance(148);
break;
}
case "Heros's Vestiges Arena":
{
instanceId = InstanceManager.getInstance().createDynamicInstance("OlympiadHerossVestigesArena.xml");
instanceId = InstanceManager.getInstance().createDynamicInstance(149);
break;
}
case "Orbis Arena":
{
instanceId = InstanceManager.getInstance().createDynamicInstance("OlympiadOrbisArena.xml");
instanceId = InstanceManager.getInstance().createDynamicInstance(150);
break;
}
}