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 id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
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 y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
int x = (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 SetUpdatedRegionMessageEncoder method encode.
@Override
public GamePacket encode(SetUpdatedRegionMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(75);
Position base = message.getPlayerPosition(), position = message.getRegionPosition();
builder.put(DataType.BYTE, DataTransformation.NEGATE, position.getLocalX(base));
builder.put(DataType.BYTE, DataTransformation.ADD, position.getLocalY(base));
return builder.toGamePacket();
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class NpcMovementTask method execute.
@Override
public void execute() {
int count = RANDOM.nextInt(npcs.size() / 50 + 5);
for (int iterations = 0; iterations < count; iterations++) {
Npc npc = npcs.poll();
if (npc == null) {
break;
}
Position[] boundary = npc.getBoundaries().get();
Position current = npc.getPosition();
Position min = boundary[0], max = boundary[1];
int currentX = current.getX(), currentY = current.getY();
boolean negativeX = RANDOM.nextBoolean(), negativeY = RANDOM.nextBoolean();
int x = RANDOM.nextInt(negativeX ? currentX - min.getX() : max.getX() - currentX);
int y = RANDOM.nextInt(negativeY ? currentY - min.getY() : max.getY() - currentY);
int dx = negativeX ? -x : x;
int dy = negativeY ? -y : y;
Position next = new Position(currentX + dx, currentY + dy);
Deque<Position> positions = algorithm.find(current, next, boundary);
WalkingQueue queue = npc.getWalkingQueue();
Position first = positions.pollFirst();
if (first != null) {
queue.addFirstStep(first);
positions.forEach(queue::addStep);
}
npcs.offer(npc);
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PrePlayerSynchronizationTask method run.
@Override
public void run() {
Position old = player.getPosition();
player.getWalkingQueue().pulse();
boolean local = true;
if (player.isTeleporting()) {
player.resetViewingDistance();
local = false;
}
Position position = player.getPosition();
if (!player.hasLastKnownRegion() || isRegionUpdateRequired()) {
player.setRegionChanged(true);
local = false;
player.setLastKnownRegion(position);
player.send(new RegionChangeMessage(position));
}
RegionRepository repository = player.getWorld().getRegionRepository();
Set<RegionCoordinates> oldViewable = repository.fromPosition(old).getSurrounding();
Set<RegionCoordinates> newViewable = repository.fromPosition(position).getSurrounding();
Set<RegionCoordinates> differences = new HashSet<>(newViewable);
differences.retainAll(oldViewable);
Set<RegionCoordinates> full = new HashSet<>(newViewable);
if (local) {
full.removeAll(oldViewable);
}
sendUpdates(player.getLastKnownRegion(), differences, full);
}
Aggregations