int mobId, doorId, respawn, respawnRnd, count;
// 0 - точечный, в каждой указанной точке; 1 - один точечный спаун в рандомной точке; 2 - локационный
int spawnType;
L2Spawn spawnDat;
L2NpcTemplate template;
L2DoorInstance door;
InstancedZone instancedZone;
for(Node iz = doc.getFirstChild(); iz != null; iz = iz.getNextSibling())
{
if("list".equalsIgnoreCase(iz.getNodeName()))
{
for(Node area = iz.getFirstChild(); area != null; area = area.getNextSibling())
{
if("instance".equalsIgnoreCase(area.getNodeName()))
{
attrs = area.getAttributes();
instanceId = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
name = attrs.getNamedItem("name").getNodeValue();
if(!_names.contains(name))
{
_names.add(name);
}
resetReuse = new Crontab(attrs.getNamedItem("resetReuse").getNodeValue());
Node nodeTimelimit = attrs.getNamedItem("timelimit");
if(nodeTimelimit != null)
{
timelimit = Integer.parseInt(nodeTimelimit.getNodeValue());
}
Node nodeDispellBuffs = attrs.getNamedItem("dispellBuffs");
dispellBuffs = nodeDispellBuffs != null ? Boolean.parseBoolean(nodeDispellBuffs.getNodeValue()) : true;
int minLevel = 0, maxLevel = 0, minParty = 1, maxParty = 9;
Location tele = new Location();
Location ret = new Location();
for(Node room = area.getFirstChild(); room != null; room = room.getNextSibling())
{
if("level".equalsIgnoreCase(room.getNodeName()))
{
attrs = room.getAttributes();
minLevel = Integer.parseInt(attrs.getNamedItem("min").getNodeValue());
maxLevel = Integer.parseInt(attrs.getNamedItem("max").getNodeValue());
}
}
for(Node room = area.getFirstChild(); room != null; room = room.getNextSibling())
{
if("party".equalsIgnoreCase(room.getNodeName()))
{
attrs = room.getAttributes();
minParty = Integer.parseInt(attrs.getNamedItem("min").getNodeValue());
maxParty = Integer.parseInt(attrs.getNamedItem("max").getNodeValue());
}
}
for(Node room = area.getFirstChild(); room != null; room = room.getNextSibling())
{
if("return".equalsIgnoreCase(room.getNodeName()))
{
ret = new Location(room.getAttributes().getNamedItem("loc").getNodeValue());
}
}
for(Node room = area.getFirstChild(); room != null; room = room.getNextSibling())
{
if("location".equalsIgnoreCase(room.getNodeName()))
{
attrs = room.getAttributes();
roomId = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
for(Node coord = room.getFirstChild(); coord != null; coord = coord.getNextSibling())
{
if("teleport".equalsIgnoreCase(coord.getNodeName()))
{
tele = new Location(coord.getAttributes().getNamedItem("loc").getNodeValue());
}
}
if(!_instancedZones.containsKey(instanceId))
{
_instancedZones.put(instanceId, new FastMap<Integer, InstancedZone>().setShared(true));
}
instancedZone = new InstancedZone(name, resetReuse, timelimit, minLevel, maxLevel, minParty, maxParty, tele, ret);
instancedZone.setDispellBuffs(dispellBuffs);
_instancedZones.get(instanceId).put(roomId, instancedZone);
for(Node spawn = room.getFirstChild(); spawn != null; spawn = spawn.getNextSibling())
{
if("spawn".equalsIgnoreCase(spawn.getNodeName()))
{
attrs = spawn.getAttributes();
String[] mobs = attrs.getNamedItem("mobId").getNodeValue().split(" ");
Node respawnNode = attrs.getNamedItem("respawn");
respawn = respawnNode != null ? Integer.parseInt(respawnNode.getNodeValue()) : 0;
Node respawnRndNode = attrs.getNamedItem("respawnRnd");
respawnRnd = respawnRndNode != null ? Integer.parseInt(respawnRndNode.getNodeValue()) : 0;
Node countNode = attrs.getNamedItem("count");
count = countNode != null ? Integer.parseInt(countNode.getNodeValue()) : 1;
Node spawnTypeNode = attrs.getNamedItem("type");
if(spawnTypeNode == null || spawnTypeNode.getNodeValue().equalsIgnoreCase("point"))
{
spawnType = 0;
}
else if(spawnTypeNode.getNodeValue().equalsIgnoreCase("rnd"))
{
spawnType = 1;
}
else if(spawnTypeNode.getNodeValue().equalsIgnoreCase("loc"))
{
spawnType = 2;
}
else
{
spawnType = 0;
_log.warning("Spawn type '" + spawnTypeNode.getNodeValue() + "' is unknown!");
}
int locId = IdFactory.getInstance().getNextId();
L2Territory territory = new L2Territory(locId);
for(Node location = spawn.getFirstChild(); location != null; location = location.getNextSibling())
{
if("coords".equalsIgnoreCase(location.getNodeName()))
{
territory.add(new Location(location.getAttributes().getNamedItem("loc").getNodeValue()));
}
}
if(spawnType == 2) //точечный спавн не проверять
{
territory.validate();
}
TerritoryTable.getInstance().getLocations().put(locId, territory);
L2World.addTerritory(territory);
for(String mob : mobs)
{
mobId = Integer.parseInt(mob);
template = NpcTable.getTemplate(mobId);
if(template == null)
{
_log.warning("Template " + mobId + " not found!");
}
if(template != null && _instancedZones.containsKey(instanceId) && _instancedZones.get(instanceId).containsKey(roomId))
{
spawnDat = new L2Spawn(template);
spawnDat.setLocation(locId);
spawnDat.setRespawnDelay(respawn, respawnRnd);
spawnDat.setAmount(count);
if(respawn > 0)
{
spawnDat.startRespawn();
}
_instancedZones.get(instanceId).get(roomId).getSpawnsInfo().add(new SpawnInfo(locId, spawnDat, spawnType));
countGood++;
try
{
for(Node event = spawn.getFirstChild(); event != null; event = event.getNextSibling())
{
if("event".equalsIgnoreCase(event.getNodeName()))
{
attrs = event.getAttributes();
String trigger = attrs.getNamedItem("trigger").getNodeValue();
GArray<String> pars = new GArray<String>();
for(Node param = event.getFirstChild(); param != null; param = param.getNextSibling())
{
if("param".equalsIgnoreCase(param.getNodeName()))
{
pars.add(param.getAttributes().getNamedItem("value").getNodeValue());
}
}
String cl = attrs.getNamedItem("class").getNodeValue();
String me = attrs.getNamedItem("method").getNodeValue();
Integer del = Integer.parseInt(attrs.getNamedItem("delay").getNodeValue());
String[] param = pars.toArray(new String[pars.size()]);
SchedulableEvent se = new SchedulableEvent(cl, me, param, del);
if(spawnDat._events == null)
{
spawnDat._events = new HashMap<String, GArray<SchedulableEvent>>();
}
GArray<SchedulableEvent> arr = spawnDat._events.get(trigger);
if(arr == null)
{
arr = new GArray<SchedulableEvent>();
spawnDat._events.put(trigger, arr);
}
arr.add(se);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
else
{
countBad++;
}
}
}
}
}
}
for(Node room = area.getFirstChild(); room != null; room = room.getNextSibling())
{
if("door".equalsIgnoreCase(room.getNodeName()))
{
attrs = room.getAttributes();
doorId = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
Node openedNode = attrs.getNamedItem("opened");
boolean opened = openedNode == null ? false : Boolean.parseBoolean(openedNode.getNodeValue());
Node invulNode = attrs.getNamedItem("invul");
boolean invul = invulNode == null ? true : Boolean.parseBoolean(invulNode.getNodeValue());
L2DoorInstance newDoor = DoorTable.getInstance().getDoor(doorId);
if(newDoor == null)
{
_log.warning("Door " + doorId + " not found!");
}
else
{
door = newDoor.clone();
door.setOpen(opened);
door.setHPVisible(!invul);
door.setIsInvul(invul);
if(!_instancedZones.get(instanceId).get(0).getDoors().add(door))
{