Store WorldObject location in a Location object.

This commit is contained in:
MobiusDevelopment
2021-11-23 00:45:29 +00:00
parent 75e8deebad
commit 3227e80226
65 changed files with 872 additions and 1352 deletions

View File

@ -55,22 +55,16 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
private int _objectId;
/** World Region */
private WorldRegion _worldRegion;
/** Location */
private final Location _location = new Location(0, 0, -10000);
/** Instance */
private Instance _instance;
/** Instance type */
private InstanceType _instanceType;
private Map<String, Object> _scripts;
/** X coordinate */
private volatile int _x = 0;
/** Y coordinate */
private volatile int _y = 0;
/** Z coordinate */
private volatile int _z = -10000;
/** Orientation */
private volatile int _heading = 0;
/** Instance id of object. 0 - Global */
private Instance _instance;
private boolean _isSpawned;
private boolean _isInvisible;
private boolean _isTargetable = true;
private Map<String, Object> _scripts;
public WorldObject(int objectId)
{
@ -567,7 +561,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
@Override
public int getX()
{
return _x;
return _location.getX();
}
/**
@ -577,7 +571,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
@Override
public int getY()
{
return _y;
return _location.getY();
}
/**
@ -587,7 +581,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
@Override
public int getZ()
{
return _z;
return _location.getZ();
}
/**
@ -597,7 +591,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
@Override
public int getHeading()
{
return _heading;
return _location.getHeading();
}
/**
@ -635,7 +629,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
@Override
public Location getLocation()
{
return new Location(_x, _y, _z, _heading);
return _location;
}
/**
@ -647,9 +641,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
@Override
public void setXYZ(int newX, int newY, int newZ)
{
_x = newX;
_y = newY;
_z = newZ;
_location.setXYZ(newX, newY, newZ);
if (_isSpawned)
{
@ -684,7 +676,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
@Override
public void setHeading(int newHeading)
{
_heading = newHeading;
_location.setHeading(newHeading);
}
/**
@ -736,10 +728,8 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
@Override
public void setLocation(Location loc)
{
_x = loc.getX();
_y = loc.getY();
_z = loc.getZ();
_heading = loc.getHeading();
_location.setXYZ(loc.getX(), loc.getY(), loc.getZ());
_location.setHeading(loc.getHeading());
}
/**
@ -751,7 +741,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
*/
public double calculateDistance2D(int x, int y, int z)
{
return Math.sqrt(Math.pow(x - _x, 2) + Math.pow(y - _y, 2));
return Math.sqrt(Math.pow(x - getX(), 2) + Math.pow(y - getY(), 2));
}
/**
@ -773,7 +763,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
*/
public double calculateDistance3D(int x, int y, int z)
{
return Math.sqrt(Math.pow(x - _x, 2) + Math.pow(y - _y, 2) + Math.pow(z - _z, 2));
return Math.sqrt(Math.pow(x - getX(), 2) + Math.pow(y - getY(), 2) + Math.pow(z - getZ(), 2));
}
/**
@ -795,7 +785,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
*/
public double calculateDistanceSq2D(int x, int y, int z)
{
return Math.pow(x - _x, 2) + Math.pow(y - _y, 2);
return Math.pow(x - getX(), 2) + Math.pow(y - getY(), 2);
}
/**
@ -817,7 +807,7 @@ public abstract class WorldObject extends ListenersContainer implements IIdentif
*/
public double calculateDistanceSq3D(int x, int y, int z)
{
return Math.pow(x - _x, 2) + Math.pow(y - _y, 2) + Math.pow(z - _z, 2);
return Math.pow(x - getX(), 2) + Math.pow(y - getY(), 2) + Math.pow(z - getZ(), 2);
}
/**