From 82647a93300d1a9893b45d72a0a7e18cb9e63235 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Wed, 7 Apr 2021 12:28:09 +0000 Subject: [PATCH] Keep track of inactive regions to prevent object creations. --- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 83 ++++++++++++------- .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 83 ++++++++++++------- .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- .../gameserver/model/WorldRegion.java | 32 +++++++ .../gameserver/model/actor/Creature.java | 22 ++++- 46 files changed, 1196 insertions(+), 148 deletions(-) diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java index e4759b6e05..cc53a96f98 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java index e4759b6e05..cc53a96f98 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java index f3759cf259..b98849a0f5 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java index f3759cf259..b98849a0f5 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java index 8979c5a98a..83a014aa99 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java index 8979c5a98a..83a014aa99 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java index 8979c5a98a..83a014aa99 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Creature.java index 2c3bbe56d7..4ecb85e742 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Creature.java index 2c3bbe56d7..4ecb85e742 100644 --- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Creature.java index 2c3bbe56d7..4ecb85e742 100644 --- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/WorldRegion.java index f9f32ee7a7..517c67d281 100644 --- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; import org.l2jmobius.Config; @@ -52,6 +53,7 @@ public class WorldRegion private final int _regionY; private Boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); private ZoneManager _zoneManager; public WorldRegion(int regionX, int regionY) @@ -207,8 +209,21 @@ public class WorldRegion return _active; } - // check if all 9 neighbors (including self) are inactive or active but with no players. - // returns true if the above condition is met. + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -243,6 +258,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } @@ -380,30 +410,6 @@ public class WorldRegion } } - public void setSurroundingRegions(WorldRegion[] regions) - { - _surroundingRegions = regions; - - // Make sure that this region is always the first region to improve bulk operations when this region should be updated first. - for (int i = 0; i < _surroundingRegions.length; i++) - { - if (_surroundingRegions[i] == this) - { - final WorldRegion first = _surroundingRegions[0]; - _surroundingRegions[0] = this; - _surroundingRegions[i] = first; - } - } - } - - /** - * @return the list _surroundingRegions containing all WorldRegion around the current WorldRegion - */ - public WorldRegion[] getSurroundingRegions() - { - return _surroundingRegions; - } - public List getVisibleObjects() { return _visibleObjects; @@ -445,9 +451,25 @@ public class WorldRegion return _fences; } - public String getName() + public void setSurroundingRegions(WorldRegion[] regions) { - return "(" + _regionX + ", " + _regionY + ")"; + _surroundingRegions = regions; + + // Make sure that this region is always the first region to improve bulk operations when this region should be updated first. + for (int i = 0; i < _surroundingRegions.length; i++) + { + if (_surroundingRegions[i] == this) + { + final WorldRegion first = _surroundingRegions[0]; + _surroundingRegions[0] = this; + _surroundingRegions[i] = first; + } + } + } + + public WorldRegion[] getSurroundingRegions() + { + return _surroundingRegions; } /** @@ -532,4 +554,9 @@ public class WorldRegion } return true; } + + public String getName() + { + return "(" + _regionX + ", " + _regionY + ")"; + } } diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/Creature.java index 4a7d962ba9..f81c311623 100644 --- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -389,20 +389,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new CharMoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new CharMoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/WorldRegion.java index f9f32ee7a7..517c67d281 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; import org.l2jmobius.Config; @@ -52,6 +53,7 @@ public class WorldRegion private final int _regionY; private Boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); private ZoneManager _zoneManager; public WorldRegion(int regionX, int regionY) @@ -207,8 +209,21 @@ public class WorldRegion return _active; } - // check if all 9 neighbors (including self) are inactive or active but with no players. - // returns true if the above condition is met. + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -243,6 +258,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } @@ -380,30 +410,6 @@ public class WorldRegion } } - public void setSurroundingRegions(WorldRegion[] regions) - { - _surroundingRegions = regions; - - // Make sure that this region is always the first region to improve bulk operations when this region should be updated first. - for (int i = 0; i < _surroundingRegions.length; i++) - { - if (_surroundingRegions[i] == this) - { - final WorldRegion first = _surroundingRegions[0]; - _surroundingRegions[0] = this; - _surroundingRegions[i] = first; - } - } - } - - /** - * @return the list _surroundingRegions containing all WorldRegion around the current WorldRegion - */ - public WorldRegion[] getSurroundingRegions() - { - return _surroundingRegions; - } - public List getVisibleObjects() { return _visibleObjects; @@ -445,9 +451,25 @@ public class WorldRegion return _fences; } - public String getName() + public void setSurroundingRegions(WorldRegion[] regions) { - return "(" + _regionX + ", " + _regionY + ")"; + _surroundingRegions = regions; + + // Make sure that this region is always the first region to improve bulk operations when this region should be updated first. + for (int i = 0; i < _surroundingRegions.length; i++) + { + if (_surroundingRegions[i] == this) + { + final WorldRegion first = _surroundingRegions[0]; + _surroundingRegions[0] = this; + _surroundingRegions[i] = first; + } + } + } + + public WorldRegion[] getSurroundingRegions() + { + return _surroundingRegions; } /** @@ -532,4 +554,9 @@ public class WorldRegion } return true; } + + public String getName() + { + return "(" + _regionX + ", " + _regionY + ")"; + } } diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java index f86b9bcfc9..f7075a44d2 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -391,20 +391,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new CharMoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new CharMoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/Creature.java index 2cd0b067e3..c6f5823ac2 100644 --- a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -574,20 +574,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java index 0c58228015..18c61328b9 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -575,20 +575,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java index b4ffc3688f..af78245ab3 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java index b4ffc3688f..af78245ab3 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java index efa0272c71..dea38922d3 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java index 51d63e116e..17c5758bf8 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -653,20 +653,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java index 51d63e116e..17c5758bf8 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -653,20 +653,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/Creature.java index fa71b739e9..df51b03169 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -653,20 +653,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java index b4ffc3688f..af78245ab3 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/Creature.java index 810c3d465f..ccc4dc40ac 100644 --- a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -653,20 +653,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /** diff --git a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/WorldRegion.java b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/WorldRegion.java index 787947f2d7..68503b03d8 100644 --- a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/WorldRegion.java +++ b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/WorldRegion.java @@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; import org.l2jmobius.Config; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -43,6 +44,7 @@ public class WorldRegion private final int _regionY; private boolean _active = Config.GRIDS_ALWAYS_ON; private ScheduledFuture _neighborsTask = null; + private final AtomicInteger _activeNeighbors = new AtomicInteger(); public WorldRegion(int regionX, int regionY) { @@ -127,6 +129,21 @@ public class WorldRegion return _active; } + public void incrementActiveNeighbors() + { + _activeNeighbors.incrementAndGet(); + } + + public void decrementActiveNeighbors() + { + _activeNeighbors.decrementAndGet(); + } + + public boolean areNeighborsActive() + { + return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0); + } + public boolean areNeighborsEmpty() { for (int i = 0; i < _surroundingRegions.length; i++) @@ -161,6 +178,21 @@ public class WorldRegion _active = value; + if (value) + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].incrementActiveNeighbors(); + } + } + else + { + for (int i = 0; i < _surroundingRegions.length; i++) + { + _surroundingRegions[i].decrementActiveNeighbors(); + } + } + // Turn the AI on or off to match the region's activation. switchAI(value); } diff --git a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/actor/Creature.java index 887c723c83..2b1d3a6988 100644 --- a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -653,20 +653,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe public void broadcastMoveToLocation() { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new MoveToLocation(this)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new MoveToLocation(this)); + } + } } public void broadcastSocialAction(int id) { - final WorldRegion region = getWorldRegion(); - if ((region != null) && region.isActive()) + if (isPlayable()) { broadcastPacket(new SocialAction(getObjectId(), id)); } + else + { + final WorldRegion region = getWorldRegion(); + if ((region != null) && region.areNeighborsActive()) + { + broadcastPacket(new SocialAction(getObjectId(), id)); + } + } } /**