Proper territory spawn z values provided by zone form.

This commit is contained in:
MobiusDevelopment
2021-03-29 09:38:23 +00:00
parent bad735a658
commit 8b870c80cb
105 changed files with 287 additions and 609 deletions

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -680,7 +680,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -680,7 +680,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -680,7 +680,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -24,7 +24,6 @@ import java.util.logging.Logger;
import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.sql.TerritoryTable; 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.data.xml.ZoneData;
import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
@@ -33,7 +32,6 @@ import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.quest.EventType; import org.l2jmobius.gameserver.model.quest.EventType;
import org.l2jmobius.gameserver.model.quest.Quest; 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.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -422,7 +420,7 @@ public class Spawn
int newlocy; int newlocy;
int newlocz; int newlocz;
// If Locx=0 and Locy=0, the NpcInstance must be spawned in an area defined by location // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location.
if ((_locX == 0) && (_locY == 0)) if ((_locX == 0) && (_locY == 0))
{ {
if (_location == 0) if (_location == 0)
@@ -446,31 +444,19 @@ public class Spawn
newlocz = _locZ; newlocz = _locZ;
} }
final boolean monsterCheck = npc.isMonster() && (WalkerRouteData.getInstance().getRouteForNpc(npc.getNpcId()) == null) && (getInstanceId() == 0) && !npc.isRaid() && !npc.isMinion() && !npc.isFlying(); // Check if npc is in water.
final WaterZone water = ZoneData.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneData.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true) < 300) if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
npc.stopAllEffects(); npc.stopAllEffects();

View File

@@ -24,7 +24,6 @@ import java.util.logging.Logger;
import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.sql.TerritoryTable; 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.data.xml.ZoneData;
import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
@@ -33,7 +32,6 @@ import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.quest.EventType; import org.l2jmobius.gameserver.model.quest.EventType;
import org.l2jmobius.gameserver.model.quest.Quest; 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.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -422,7 +420,7 @@ public class Spawn
int newlocy; int newlocy;
int newlocz; int newlocz;
// If Locx=0 and Locy=0, the NpcInstance must be spawned in an area defined by location // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location.
if ((_locX == 0) && (_locY == 0)) if ((_locX == 0) && (_locY == 0))
{ {
if (_location == 0) if (_location == 0)
@@ -446,31 +444,19 @@ public class Spawn
newlocz = _locZ; newlocz = _locZ;
} }
final boolean monsterCheck = npc.isMonster() && (WalkerRouteData.getInstance().getRouteForNpc(npc.getNpcId()) == null) && (getInstanceId() == 0) && !npc.isRaid() && !npc.isMinion() && !npc.isFlying(); // Check if npc is in water.
final WaterZone water = ZoneData.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneData.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true) < 300) if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
npc.stopAllEffects(); npc.stopAllEffects();

View File

@@ -38,7 +38,6 @@ import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.NpcSpawnTerritory; import org.l2jmobius.gameserver.model.zone.type.NpcSpawnTerritory;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
@@ -365,8 +364,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTerritory != null) if (_spawnTerritory != null)
{ {
final Location loc = _spawnTerritory.getRandomPoint(); final Location loc = _spawnTerritory.getRandomPoint();
@@ -388,10 +386,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -403,28 +402,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
npc.stopAllEffects(); npc.stopAllEffects();

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -38,7 +38,6 @@ import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.NpcSpawnTerritory; import org.l2jmobius.gameserver.model.zone.type.NpcSpawnTerritory;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
@@ -365,8 +364,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTerritory != null) if (_spawnTerritory != null)
{ {
final Location loc = _spawnTerritory.getRandomPoint(); final Location loc = _spawnTerritory.getRandomPoint();
@@ -388,10 +386,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -403,28 +402,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
npc.stopAllEffects(); npc.stopAllEffects();

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -680,7 +680,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -678,7 +678,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

View File

@@ -680,7 +680,7 @@ public class ZoneManager implements IXmlReader
* @return zone from given coordinates * @return zone from given coordinates
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type) public <T extends ZoneType> T getZone(int x, int y, int z, Class<T> type)
{ {
for (ZoneType zone : getRegion(x, y).getZones().values()) for (ZoneType zone : getRegion(x, y).getZones().values())
{ {

View File

@@ -37,7 +37,6 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.WaterZone; import org.l2jmobius.gameserver.model.zone.type.WaterZone;
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager; import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.util.Util; import org.l2jmobius.gameserver.util.Util;
@@ -371,8 +370,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
int newlocy = 0; int newlocy = 0;
int newlocz = -10000; int newlocz = -10000;
// If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory // If Locx and Locy are not defined, the NpcInstance must be spawned in an area defined by location or spawn territory.
// New method
if (_spawnTemplate != null) if (_spawnTemplate != null)
{ {
final Location loc = _spawnTemplate.getSpawnLocation(); final Location loc = _spawnTemplate.getSpawnLocation();
@@ -394,10 +392,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
newlocz = getZ(); newlocz = getZ();
} }
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()); // Check if npc is in water.
final WaterZone water = ZoneManager.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled. // If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && monsterCheck) if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && !WalkingManager.getInstance().isTargeted(npc) && (getInstanceId() == 0) && !getTemplate().isUndying() && !npc.isRaid() && !npc.isRaidMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getId()))
{ {
final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); 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); final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE);
@@ -409,28 +408,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
} }
// Correct Z of monsters. // Correct Z of monsters.
if (monsterCheck) if (!npc.isFlying() && (water == null))
{ {
// Do not correct Z when in water zone.
WaterZone water = null;
for (ZoneType zone : ZoneManager.getInstance().getZones(newlocx, newlocy, newlocz))
{
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. // Do not correct Z distances greater than 300.
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, false) < 300) final int geoZ = GeoEngine.getInstance().getHeight(newlocx, newlocy, newlocz);
if (Util.calculateDistance(newlocx, newlocy, newlocz, newlocx, newlocy, geoZ, true, true) < 300)
{ {
newlocz = geoZ; newlocz = geoZ;
} }
} }
}
// Set is not random walk default value // Set is not random walk default value
npc.setRandomWalking(_randomWalk); npc.setRandomWalking(_randomWalk);

View File

@@ -132,6 +132,6 @@ public class ZoneCuboid extends ZoneForm
final int x = Rnd.get(_r.x, _r.x + _r.width); final int x = Rnd.get(_r.x, _r.x + _r.width);
final int y = Rnd.get(_r.y, _r.y + _r.height); final int y = Rnd.get(_r.y, _r.y + _r.height);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -143,6 +143,6 @@ public class ZoneCylinder extends ZoneForm
final int x = (int) ((_rad * r * Math.cos(q)) + _x); final int x = (int) ((_rad * r * Math.cos(q)) + _x);
final int y = (int) ((_rad * r * Math.sin(q)) + _y); final int y = (int) ((_rad * r * Math.sin(q)) + _y);
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
} }

View File

@@ -127,7 +127,7 @@ public class ZoneNPoly extends ZoneForm
y = Rnd.get(minY, maxY); y = Rnd.get(minY, maxY);
} }
return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, _z1)); return new Location(x, y, GeoEngine.getInstance().getHeight(x, y, (_z1 + _z2) / 2));
} }
public int[] getX() public int[] getX()

Some files were not shown because too many files have changed in this diff Show More