diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/spawn/Spawn.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/spawn/Spawn.java index 27ac21ef91..7974dc9934 100644 --- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/spawn/Spawn.java +++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/spawn/Spawn.java @@ -24,6 +24,8 @@ import java.util.logging.Logger; import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.sql.TerritoryTable; +import org.l2jmobius.gameserver.data.xml.WalkerRouteData; +import org.l2jmobius.gameserver.data.xml.ZoneData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.model.WorldObject; @@ -31,6 +33,8 @@ import org.l2jmobius.gameserver.model.actor.instance.NpcInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.quest.EventType; import org.l2jmobius.gameserver.model.quest.Quest; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -442,14 +446,29 @@ public class Spawn newlocz = _locZ; } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + final boolean monsterCheck = npc.isMonster() && (WalkerRouteData.getInstance().getRouteForNpc(npc.getNpcId()) == null) && (getInstanceId() == 0) && !npc.isRaid() && !npc.isMinion() && !npc.isFlying(); + + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneData.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/spawn/Spawn.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/spawn/Spawn.java index 27ac21ef91..7974dc9934 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/spawn/Spawn.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/spawn/Spawn.java @@ -24,6 +24,8 @@ import java.util.logging.Logger; import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.sql.TerritoryTable; +import org.l2jmobius.gameserver.data.xml.WalkerRouteData; +import org.l2jmobius.gameserver.data.xml.ZoneData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.model.WorldObject; @@ -31,6 +33,8 @@ import org.l2jmobius.gameserver.model.actor.instance.NpcInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.quest.EventType; import org.l2jmobius.gameserver.model.quest.Quest; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -442,14 +446,29 @@ public class Spawn newlocz = _locZ; } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + final boolean monsterCheck = npc.isMonster() && (WalkerRouteData.getInstance().getRouteForNpc(npc.getNpcId()) == null) && (getInstanceId() == 0) && !npc.isRaid() && !npc.isMinion() && !npc.isFlying(); + + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneData.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/Spawn.java index 3eb2e322c4..986434f0c5 100644 --- a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/Spawn.java @@ -31,14 +31,16 @@ import org.l2jmobius.gameserver.data.NpcPersonalAIData; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Attackable; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; import org.l2jmobius.gameserver.model.zone.type.NpcSpawnTerritory; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -386,27 +388,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, getInstanceId()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, getInstanceId())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/Spawn.java index 12ce64a85a..cda0b11b68 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/Spawn.java @@ -31,14 +31,16 @@ import org.l2jmobius.gameserver.data.NpcPersonalAIData; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Attackable; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; import org.l2jmobius.gameserver.model.zone.type.NpcSpawnTerritory; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -386,27 +388,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, getInstanceId()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, getInstanceId())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } } diff --git a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/Spawn.java index aa9995dbfa..1d092bf00c 100644 --- a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/Spawn.java +++ b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/Spawn.java @@ -29,6 +29,7 @@ import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.NpcData; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.instancemanager.WalkingManager; +import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; @@ -36,7 +37,8 @@ import org.l2jmobius.gameserver.model.instancezone.Instance; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; -import org.l2jmobius.gameserver.model.zone.ZoneId; +import org.l2jmobius.gameserver.model.zone.ZoneType; +import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.util.Util; @@ -392,27 +394,41 @@ public class Spawn extends Location implements IIdentifiable, INamable newlocz = getZ(); } - // If random spawn system is enabled - if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + final boolean monsterCheck = npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()); + + // If random spawn system is enabled. + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) { final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); - - if (npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && !npc.isInsideZone(ZoneId.NO_BOOKMARK) && (getInstanceId() == 0) && GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld()) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId())) + if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, npc.getInstanceWorld())) { newlocx = randX; newlocy = randY; } } - // Correct Z of monsters. Do not correct Z of flying NPCs. - if (npc.isMonster() && !npc.isFlying()) + // Correct Z of monsters. + if (monsterCheck) { - final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; - // Do not correct Z distances greater than 300. - if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + // Do not correct Z when in water zone. + WaterZone water = null; + for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz)) { - newlocz = geoZ; + if (zone instanceof WaterZone) + { + water = (WaterZone) zone; + break; + } + } + if (water == null) + { + final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz) + 64; + // Do not correct Z distances greater than 300. + if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) + { + newlocz = geoZ; + } } }