use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class NpcSynchronizationMessageEncoder method putAddNpcUpdate.
/**
* Puts an add npc update.
*
* @param seg The segment.
* @param message The message.
* @param builder The builder.
*/
private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0;
Position npc = message.getPosition();
Position other = seg.getPosition();
builder.putBits(14, seg.getIndex());
builder.putBits(5, other.getY() - npc.getY());
builder.putBits(5, other.getX() - npc.getX());
// discard walking queue
builder.putBits(1, 0);
builder.putBits(12, seg.getNpcId());
builder.putBits(1, updateRequired ? 1 : 0);
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method putMovementUpdate.
/**
* Puts a movement update for the specified segment.
*
* @param seg The segment.
* @param message The message.
* @param builder The builder.
*/
private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.TELEPORT) {
Position position = ((TeleportSegment) seg).getDestination();
builder.putBits(1, 1);
builder.putBits(2, 3);
builder.putBits(2, position.getHeight());
builder.putBits(1, message.hasRegionChanged() ? 0 : 1);
builder.putBits(1, updateRequired ? 1 : 0);
builder.putBits(7, position.getLocalY(message.getLastKnownRegion()));
builder.putBits(7, position.getLocalX(message.getLastKnownRegion()));
} else if (seg.getType() == SegmentType.RUN) {
Direction[] directions = ((MovementSegment) seg).getDirections();
builder.putBits(1, 1);
builder.putBits(2, 2);
builder.putBits(3, directions[0].toInteger());
builder.putBits(3, directions[1].toInteger());
builder.putBits(1, updateRequired ? 1 : 0);
} else if (seg.getType() == SegmentType.WALK) {
Direction[] directions = ((MovementSegment) seg).getDirections();
builder.putBits(1, 1);
builder.putBits(2, 1);
builder.putBits(3, directions[0].toInteger());
builder.putBits(1, updateRequired ? 1 : 0);
} else {
if (updateRequired) {
builder.putBits(1, 1);
builder.putBits(2, 0);
} else {
builder.putBits(1, 0);
}
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class TakeTileItemMessageDecoder method decode.
@Override
public TakeTileItemMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
int id = (int) reader.getUnsigned(DataType.SHORT);
int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
return new TakeTileItemMessage(id, new Position(x, y));
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class ThirdObjectActionMessageDecoder method decode.
@Override
public ObjectActionMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
int y = (int) reader.getUnsigned(DataType.SHORT);
int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
return new ObjectActionMessage(3, id, new Position(x, y));
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class WalkMessageDecoder method decode.
@Override
public WalkMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
int length = packet.getLength();
if (packet.getOpcode() == 248) {
// strip off anti-cheat data
length -= 14;
}
int steps = (length - 5) / 2;
int[][] path = new int[steps][2];
int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
for (int i = 0; i < steps; i++) {
path[i][0] = (int) reader.getSigned(DataType.BYTE);
path[i][1] = (int) reader.getSigned(DataType.BYTE);
}
int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
boolean run = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE) == 1;
Position[] positions = new Position[steps + 1];
positions[0] = new Position(x, y);
for (int i = 0; i < steps; i++) {
positions[i + 1] = new Position(path[i][0] + x, path[i][1] + y);
}
return new WalkMessage(positions, run);
}
Aggregations