Store door objects in regions.
This commit is contained in:
@@ -31,6 +31,8 @@ import org.l2jmobius.gameserver.instancemanager.ClanHallManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.IdManager;
|
||||
import org.l2jmobius.gameserver.model.Location;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.WorldRegion;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.DoorInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
|
||||
import org.l2jmobius.gameserver.model.residences.ClanHall;
|
||||
@@ -239,22 +241,15 @@ public class DoorData implements IXmlReader
|
||||
|
||||
public boolean checkIfDoorsBetween(int x, int y, int z, int tx, int ty, int tz)
|
||||
{
|
||||
int region;
|
||||
try
|
||||
{
|
||||
region = MapRegionData.getInstance().getMapRegion(x, y);
|
||||
}
|
||||
catch (Exception e)
|
||||
final WorldRegion region = World.getInstance().getRegion(x, y);
|
||||
final Collection<DoorInstance> doors = region != null ? region.getDoors() : null;
|
||||
if ((doors == null) || doors.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (DoorInstance doorInst : DOORS.values())
|
||||
for (DoorInstance doorInst : doors)
|
||||
{
|
||||
if (doorInst.getMapRegion() != region)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (doorInst.getXMax() == 0)
|
||||
{
|
||||
continue;
|
||||
|
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@@ -29,6 +30,7 @@ import org.l2jmobius.gameserver.ai.SiegeGuardAI;
|
||||
import org.l2jmobius.gameserver.data.sql.SpawnTable;
|
||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.DoorInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
|
||||
import org.l2jmobius.gameserver.model.spawn.Spawn;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneManager;
|
||||
@@ -42,6 +44,7 @@ public class WorldRegion
|
||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
||||
|
||||
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
|
||||
private final List<DoorInstance> _doors = new ArrayList<>(1);
|
||||
private WorldRegion[] _surroundingRegions;
|
||||
private final int _regionX;
|
||||
private final int _regionY;
|
||||
@@ -315,6 +318,14 @@ public class WorldRegion
|
||||
|
||||
_visibleObjects.addIfAbsent(object);
|
||||
|
||||
if (object.isDoor())
|
||||
{
|
||||
for (int i = 0; i < _surroundingRegions.length; i++)
|
||||
{
|
||||
_surroundingRegions[i].addDoor((DoorInstance) object);
|
||||
}
|
||||
}
|
||||
|
||||
// If this is the first player to enter the region, activate self and neighbors.
|
||||
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)
|
||||
{
|
||||
@@ -342,6 +353,14 @@ public class WorldRegion
|
||||
|
||||
_visibleObjects.remove(object);
|
||||
|
||||
if (object.isDoor())
|
||||
{
|
||||
for (int i = 0; i < _surroundingRegions.length; i++)
|
||||
{
|
||||
removeDoor((DoorInstance) object);
|
||||
}
|
||||
}
|
||||
|
||||
if (object.isPlayable() && areNeighborsEmpty() && !Config.GRIDS_ALWAYS_ON)
|
||||
{
|
||||
startDeactivation();
|
||||
@@ -377,6 +396,24 @@ public class WorldRegion
|
||||
return _visibleObjects;
|
||||
}
|
||||
|
||||
public synchronized void addDoor(DoorInstance door)
|
||||
{
|
||||
if (!_doors.contains(door))
|
||||
{
|
||||
_doors.add(door);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void removeDoor(DoorInstance door)
|
||||
{
|
||||
_doors.remove(door);
|
||||
}
|
||||
|
||||
public List<DoorInstance> getDoors()
|
||||
{
|
||||
return _doors;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return "(" + _regionX + ", " + _regionY + ")";
|
||||
|
Reference in New Issue
Block a user