mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-10-20 10:03:02 -04:00
Refactored encodable and packets to use NetBuffer
This commit is contained in:
@@ -27,13 +27,11 @@
|
||||
***********************************************************************************/
|
||||
package resources.objects.waypoint;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.projectswg.common.data.location.Location;
|
||||
import com.projectswg.common.data.location.Terrain;
|
||||
import com.projectswg.common.network.NetBuffer;
|
||||
import com.projectswg.common.network.NetBufferStream;
|
||||
|
||||
import network.packets.Packet;
|
||||
import network.packets.swg.zone.baselines.Baseline.BaselineType;
|
||||
import resources.encodables.OutOfBandData;
|
||||
import resources.encodables.OutOfBandPackage;
|
||||
@@ -43,82 +41,90 @@ import resources.player.Player;
|
||||
public class WaypointObject extends IntangibleObject implements OutOfBandData {
|
||||
|
||||
private long cellId;
|
||||
private String name = "New Waypoint";
|
||||
private WaypointColor color = WaypointColor.BLUE;
|
||||
private boolean active = true;
|
||||
private String name;
|
||||
private WaypointColor color;
|
||||
private boolean active;
|
||||
|
||||
public WaypointObject(long objectId) {
|
||||
super(objectId, BaselineType.WAYP);
|
||||
this.cellId = 0;
|
||||
this.name = "New Waypoint";
|
||||
this.color = WaypointColor.BLUE;
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public WaypointColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
public void setColor(WaypointColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
|
||||
public long getCellId() {
|
||||
return cellId;
|
||||
}
|
||||
|
||||
|
||||
public void setCellId(long cellId) {
|
||||
this.cellId = cellId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createObject(Player target) {
|
||||
// NOTE: Client is never sent a WAYP baseline in NGE, WaypointObject's just go inside the Waypoint List in PLAY.
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] encode() {
|
||||
Location loc = getLocation();
|
||||
ByteBuffer bb = ByteBuffer.allocate(42 + name.length() * 2);
|
||||
Packet.addInt(bb, 0);
|
||||
Packet.addFloat(bb, (float) loc.getX());
|
||||
Packet.addFloat(bb, (float) loc.getY());
|
||||
Packet.addFloat(bb, (float) loc.getZ());
|
||||
Packet.addLong(bb, cellId);
|
||||
Packet.addCrc(bb, loc.getTerrain().getName());
|
||||
Packet.addUnicode(bb, name);
|
||||
Packet.addLong(bb, getObjectId());
|
||||
Packet.addByte(bb, color.getValue());
|
||||
Packet.addBoolean(bb, active);
|
||||
return bb.array();
|
||||
NetBuffer data = NetBuffer.allocate(getLength());
|
||||
data.addInt(0);
|
||||
data.addFloat((float) getX());
|
||||
data.addFloat((float) getY());
|
||||
data.addFloat((float) getZ());
|
||||
data.addLong(cellId);
|
||||
data.addInt(getTerrain().getCrc());
|
||||
data.addUnicode(name);
|
||||
data.addLong(getObjectId());
|
||||
data.addByte(color.getValue());
|
||||
data.addBoolean(active);
|
||||
return data.array();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuffer data) {
|
||||
public void decode(NetBuffer data) {
|
||||
data.getInt();
|
||||
Location loc = new Location(data.getFloat(), data.getFloat(), data.getFloat(), null);
|
||||
cellId = Packet.getLong(data);
|
||||
cellId = data.getLong();
|
||||
loc.setTerrain(Terrain.getTerrainFromCrc(data.getInt()));
|
||||
name = Packet.getUnicode(data);
|
||||
Packet.getLong(data); // objectId
|
||||
color = WaypointColor.valueOf(data.get());
|
||||
active = Packet.getBoolean(data);
|
||||
name = data.getUnicode();
|
||||
data.getLong(); // objectId
|
||||
color = WaypointColor.valueOf(data.getByte());
|
||||
active = data.getBoolean();
|
||||
setLocation(loc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 42 + name.length() * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NetBufferStream stream) {
|
||||
super.save(stream);
|
||||
@@ -138,42 +144,43 @@ public class WaypointObject extends IntangibleObject implements OutOfBandData {
|
||||
name = stream.getAscii();
|
||||
color = WaypointColor.valueOf(stream.getAscii());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OutOfBandPackage.Type getOobType() {
|
||||
return OutOfBandPackage.Type.WAYPOINT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getOobPosition() {
|
||||
return -3;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!super.equals(o))
|
||||
if (!(o instanceof WaypointObject))
|
||||
return false;
|
||||
if (o instanceof WaypointObject) {
|
||||
WaypointObject wp = (WaypointObject) o;
|
||||
return wp.name.equals(name) && wp.cellId == cellId && wp.color == color && wp.active == active;
|
||||
}
|
||||
return false;
|
||||
WaypointObject wp = (WaypointObject) o;
|
||||
return wp.name.equals(name) && wp.cellId == cellId && wp.color == color && wp.active == active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((super.hashCode() * 7 + name.hashCode()) * 13 + color.getValue()) * 17 + (int) cellId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WaypointObject[" +
|
||||
"cellId=" + cellId + ", name='" + name + '\'' + ", color=" + color + ", active=" + active +
|
||||
", location=" + getLocation() + "]";
|
||||
return "WaypointObject[" + "cellId=" + cellId + ", name='" + name + '\'' + ", color=" + color + ", active=" + active + ", location=" + getLocation() + "]";
|
||||
}
|
||||
|
||||
public enum WaypointColor{
|
||||
BLUE(1), GREEN(2), ORANGE(3), YELLOW(4), PURPLE(5), WHITE(6), MULTICOLOR(7);
|
||||
|
||||
public enum WaypointColor {
|
||||
BLUE(1),
|
||||
GREEN(2),
|
||||
ORANGE(3),
|
||||
YELLOW(4),
|
||||
PURPLE(5),
|
||||
WHITE(6),
|
||||
MULTICOLOR(7);
|
||||
|
||||
private int i;
|
||||
|
||||
@@ -181,8 +188,10 @@ public class WaypointObject extends IntangibleObject implements OutOfBandData {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getValue() { return i; }
|
||||
|
||||
public int getValue() {
|
||||
return i;
|
||||
}
|
||||
|
||||
public static WaypointColor valueOf(int colorId) {
|
||||
for (WaypointColor color : WaypointColor.values()) {
|
||||
if (color.getValue() == colorId)
|
||||
@@ -190,17 +199,25 @@ public class WaypointObject extends IntangibleObject implements OutOfBandData {
|
||||
}
|
||||
return WaypointColor.BLUE;
|
||||
}
|
||||
|
||||
|
||||
public static WaypointColor fromString(String string) {
|
||||
switch(string) {
|
||||
case "blue": return WaypointColor.BLUE;
|
||||
case "green": return WaypointColor.GREEN;
|
||||
case "orange": return WaypointColor.ORANGE;
|
||||
case "yellow": return WaypointColor.YELLOW;
|
||||
case "purple": return WaypointColor.PURPLE;
|
||||
case "white": return WaypointColor.WHITE;
|
||||
case "multicolor": return WaypointColor.MULTICOLOR;
|
||||
default: return WaypointColor.BLUE;
|
||||
switch (string) {
|
||||
case "blue":
|
||||
return WaypointColor.BLUE;
|
||||
case "green":
|
||||
return WaypointColor.GREEN;
|
||||
case "orange":
|
||||
return WaypointColor.ORANGE;
|
||||
case "yellow":
|
||||
return WaypointColor.YELLOW;
|
||||
case "purple":
|
||||
return WaypointColor.PURPLE;
|
||||
case "white":
|
||||
return WaypointColor.WHITE;
|
||||
case "multicolor":
|
||||
return WaypointColor.MULTICOLOR;
|
||||
default:
|
||||
return WaypointColor.BLUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user