Refactored WaypointObject

This commit is contained in:
Treeku
2014-08-10 13:58:17 +01:00
parent dddf1d2c44
commit f8e5d0105d
8 changed files with 161 additions and 161 deletions
+134 -143
View File
@@ -22,171 +22,162 @@
package resources.objects.waypoint;
import java.io.Serializable;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.buffer.SimpleBufferAllocator;
import resources.objects.intangible.IntangibleObject;
import engine.clients.Client;
import engine.resources.common.StringUtilities;
import engine.resources.common.UString;
import engine.resources.objects.Baseline;
import engine.resources.objects.IDelta;
import engine.resources.objects.SWGObject;
import resources.objects.intangible.IntangibleObject;
import engine.clients.Client;
import engine.resources.scene.Planet;
import engine.resources.scene.Point3D;
import engine.resources.scene.Quaternion;
public class WaypointObject extends IntangibleObject implements Serializable, IDelta {
public class WaypointObject extends IntangibleObject implements IDelta, Serializable {
private static final long serialVersionUID = 1L;
private int cellId; // ???
private long locationNetworkId;
private int planetCRC;
private String name = "";
private byte color;
private boolean isActive;
private transient static SimpleBufferAllocator bufferPool = new SimpleBufferAllocator();
public static final byte BLUE = 1, GREEN = 2, ORANGE = 3, YELLOW = 4, PURPLE = 5, WHITE = 6, MULTICOLOR = 7;
public static final byte BLUE = 1;
public static final byte GREEN = 2;
public static final byte ORANGE = 3;
public static final byte YELLOW = 4;
public static final byte PURPLE = 5;
public static final byte WHITE = 6;
public static final byte MULTICOLOR = 7; // JTL waypoint
public WaypointObject() { }
public WaypointObject(long objectID, Planet planet, Point3D position) {
super(objectID, planet, position, new Quaternion(0, 0, 0, 1), "object/waypoint/shared_waypoint.iff");
super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(0, 0, 0, 1), "object/waypoint/shared_waypoint.iff");
}
public WaypointObject() {
super();
}
@Override
public void initAfterDBLoad() {
super.init();
}
public int getCellId() {
synchronized(objectMutex) {
return cellId;
}
}
public void setCellId(int cellId) {
synchronized(objectMutex) {
this.cellId = cellId;
}
}
public long getLocationNetworkId() {
synchronized(objectMutex) {
return locationNetworkId;
}
}
public void setLocationNetworkId(long locationNetworkId) {
synchronized(objectMutex) {
this.locationNetworkId = locationNetworkId;
}
}
public int getPlanetCRC() {
synchronized(objectMutex) {
return planetCRC;
}
}
public void setPlanetCRC(int planetCRC) {
synchronized(objectMutex) {
this.planetCRC = planetCRC;
}
}
public String getName() {
synchronized(objectMutex) {
return name;
}
}
public void setName(String name) {
synchronized(objectMutex) {
this.name = name;
}
}
public byte getColor() {
synchronized(objectMutex) {
return color;
}
}
public void setColor(byte color) {
synchronized(objectMutex) {
this.color = color;
}
}
public boolean isActive() {
synchronized(objectMutex) {
return isActive;
}
}
public void setActive(boolean isActive) {
synchronized(objectMutex) {
this.isActive = isActive;
}
}
@Override
public void sendBaselines(Client client) {
// TODO Auto-generated method stub
}
@Override
public byte[] getBytes() {
IoBuffer buffer = bufferPool.allocate(42 + name.length() * 2, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(getCellId());
buffer.putFloat(getPosition().x);
buffer.putFloat(getPosition().y);
buffer.putFloat(getPosition().z);
buffer.putLong(0); // networklocationId
buffer.putInt(getPlanetCRC());
buffer.put(StringUtilities.getUnicodeString(getName()));
buffer.putLong(getObjectID());
buffer.put((byte) getColor());
if (isActive())
buffer.put((byte) 1);
else
buffer.put((byte) 0);
return buffer.flip().array();
}
@Override
public void init(SWGObject arg0) {
// TODO Auto-generated method stub
public void init(SWGObject object) {
}
public Baseline getOtherVariables() {
Baseline baseline = super.getOtherVariables();
return baseline;
}
public Baseline getBaseline3() {
Baseline baseline = super.getBaseline3();
baseline.put("cellNumber", 0);
baseline.put("position", new Point3D(0, 0, 0));
baseline.put("targetId", (long) 0);
baseline.put("planetCrc", 0);
baseline.put("name", new UString("Waypoint"));
baseline.put("color", (byte) 1);
baseline.put("active", false);
return baseline;
}
public Baseline getBaseline6() {
Baseline baseline = super.getBaseline6();
return baseline;
}
@Override
public Baseline getBaseline8() {
Baseline baseline = super.getBaseline8();
return baseline;
}
@Override
public Baseline getBaseline9() {
Baseline baseline = super.getBaseline9();
return baseline;
}
public int getCellNumber() {
return (int) getBaseline(3).get("cellNumber");
}
public void setCellNumber(int cellNumber) {
getBaseline(3).set("cellNumber", cellNumber);
}
public void setPosition(Point3D position) {
getBaseline(3).set("position", position);
}
public long getTargetId() {
return (long) getBaseline(3).get("targetId");
}
public void setTargetId(long targetId) {
getBaseline(3).set("targetId", targetId);
}
public int getPlanetCrc() {
return (int) getBaseline(3).get("planetCrc");
}
public void setPlanetCrc(int planetCrc) {
getBaseline(3).set("planetCrc", planetCrc);
}
public String getName() {
return ((UString) getBaseline(3).get("name")).get();
}
public void setName(String name) {
getBaseline(3).set("name", new UString(name));
}
public byte getColor() {
return (byte) getBaseline(3).get("color");
}
public void setColor(byte color) {
getBaseline(3).set("color", color);
}
public boolean isActive() {
return (boolean) getBaseline(3).get("active");
}
public void setActive(boolean active) {
getBaseline(3).set("active", active);
}
public void toggleActive() {
setActive(!isActive());
}
@Override
public void sendBaselines(Client destination) {
}
public byte[] getBytes() {
synchronized(objectMutex) {
IoBuffer buffer = Baseline.createBuffer(38 + StringUtilities.getUnicodeString(getName()).length);
buffer.putInt(getCellNumber());
buffer.put(Baseline.toBytes(getBaseline(3).get("position")));
buffer.putLong(getTargetId());
buffer.putInt(getPlanetCrc());
buffer.put(StringUtilities.getUnicodeString(getName()));
buffer.putLong(getObjectID());
buffer.put(getColor());
buffer.put(Baseline.getBoolean(isActive()));
return buffer.flip().array();
}
}
@Deprecated public int getCellId() { return getCellNumber(); }
@Deprecated public void setCellId(int cellId) { setCellNumber(cellId); }
@Deprecated public long getLocationNetworkId() { return getTargetId(); }
@Deprecated public void setLocationNetworkId(long locationNetworkId) { setTargetId(locationNetworkId); }
@Deprecated public int getPlanetCRC() { return getPlanetCrc(); }
@Deprecated public void setPlanetCRC(int planetCRC) { setPlanetCrc(planetCRC); }
}