Search in sources :

Example 11 with Position

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));
}
Also used : GamePacketReader(org.apollo.net.codec.game.GamePacketReader) Position(org.apollo.game.model.Position) TakeTileItemMessage(org.apollo.game.message.impl.TakeTileItemMessage)

Example 12 with Position

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));
}
Also used : ObjectActionMessage(org.apollo.game.message.impl.ObjectActionMessage) GamePacketReader(org.apollo.net.codec.game.GamePacketReader) Position(org.apollo.game.model.Position)

Example 13 with Position

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();
}
Also used : Position(org.apollo.game.model.Position) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 14 with Position

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);
    }
}
Also used : Npc(org.apollo.game.model.entity.Npc) Position(org.apollo.game.model.Position) WalkingQueue(org.apollo.game.model.entity.WalkingQueue)

Example 15 with Position

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);
}
Also used : RegionCoordinates(org.apollo.game.model.area.RegionCoordinates) Position(org.apollo.game.model.Position) RegionRepository(org.apollo.game.model.area.RegionRepository) RegionChangeMessage(org.apollo.game.message.impl.RegionChangeMessage) HashSet(java.util.HashSet)

Aggregations

Position (org.apollo.game.model.Position)66 Region (org.apollo.game.model.area.Region)14 RegionRepository (org.apollo.game.model.area.RegionRepository)10 GamePacketReader (org.apollo.net.codec.game.GamePacketReader)10 GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)9 ObjectActionMessage (org.apollo.game.message.impl.ObjectActionMessage)8 Direction (org.apollo.game.model.Direction)8 Entity (org.apollo.game.model.entity.Entity)8 HashSet (java.util.HashSet)7 World (org.apollo.game.model.World)7 Player (org.apollo.game.model.entity.Player)7 Test (org.junit.Test)7 StaticGameObject (org.apollo.game.model.entity.obj.StaticGameObject)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ArrayList (java.util.ArrayList)3 ItemOnObjectMessage (org.apollo.game.message.impl.ItemOnObjectMessage)3 RegionCoordinates (org.apollo.game.model.area.RegionCoordinates)3 GroupableEntity (org.apollo.game.model.area.update.GroupableEntity)3 Inventory (org.apollo.game.model.inv.Inventory)3 MovementSegment (org.apollo.game.sync.seg.MovementSegment)3