Search in sources :

Example 61 with Position

use of org.apollo.game.model.Position in project apollo by apollo-rsps.

the class ClearRegionMessageEncoder method encode.

@Override
public GamePacket encode(ClearRegionMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(40);
    Position player = message.getPlayerPosition(), region = message.getRegionPosition();
    builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player));
    builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player));
    return builder.toGamePacket();
}
Also used : Position(org.apollo.game.model.Position) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 62 with Position

use of org.apollo.game.model.Position in project apollo by apollo-rsps.

the class FirstObjectActionMessageDecoder method decode.

@Override
public ObjectActionMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
    int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
    int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
    return new ObjectActionMessage(1, 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 63 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(85);
    Position player = message.getPlayerPosition(), region = message.getRegionPosition();
    builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalY(player));
    builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player));
    return builder.toGamePacket();
}
Also used : Position(org.apollo.game.model.Position) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 64 with Position

use of org.apollo.game.model.Position in project apollo by apollo-rsps.

the class ObjectActionVerificationHandlerTests method terminateIfOutOfRange.

@Test
public void terminateIfOutOfRange() throws Exception {
    Position playerPosition = new Position(3200, 3200);
    Position objectPosition = new Position(3200, 3216);
    World world = mock(World.class);
    Region region = mock(Region.class);
    RegionRepository regionRepository = mock(RegionRepository.class);
    Player player = mock(Player.class);
    Set<Entity> entitySet = new HashSet<>();
    entitySet.add(new StaticGameObject(world, 4151, objectPosition, 0, 0));
    when(world.getRegionRepository()).thenReturn(regionRepository);
    when(regionRepository.fromPosition(objectPosition)).thenReturn(region);
    when(player.getPosition()).thenReturn(playerPosition);
    when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)).thenReturn(entitySet);
    ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition);
    ObjectActionVerificationHandler objectActionVerificationHandler = new ObjectActionVerificationHandler(world);
    objectActionVerificationHandler.handle(player, objectActionMessage);
    assertTrue("ObjectVerificationHandler: message not terminated when out of range!", objectActionMessage.terminated());
}
Also used : Entity(org.apollo.game.model.entity.Entity) Player(org.apollo.game.model.entity.Player) ObjectActionMessage(org.apollo.game.message.impl.ObjectActionMessage) Position(org.apollo.game.model.Position) RegionRepository(org.apollo.game.model.area.RegionRepository) Region(org.apollo.game.model.area.Region) StaticGameObject(org.apollo.game.model.entity.obj.StaticGameObject) World(org.apollo.game.model.World) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 65 with Position

use of org.apollo.game.model.Position in project apollo by apollo-rsps.

the class CollisionManagerTests method createCollisionManager.

/**
 * Sets up dependencies for and creates a stub {@link CollisionManager}, then builds the collision matrices
 * using the {@code objects} given.
 *
 * @param objects The objects to build collision matrices from.
 * @return A new {@link CollisionManager} with a valid {@link RegionRepository} and every {@link CollisionMatrix}
 * built.
 */
private static CollisionManager createCollisionManager(MapObject... objects) {
    World world = new World();
    RegionRepository regions = world.getRegionRepository();
    CollisionManager collisionManager = world.getCollisionManager();
    for (MapObject object : objects) {
        // treat local coordinates as absolute for simplicity
        int x = object.getLocalX(), y = object.getLocalY();
        int height = object.getHeight();
        Position position = new Position(x, y, height);
        Region region = regions.fromPosition(position);
        region.addEntity(new StaticGameObject(world, object.getId(), position, object.getType(), object.getOrientation()), false);
    }
    collisionManager.build(false);
    return collisionManager;
}
Also used : Position(org.apollo.game.model.Position) RegionRepository(org.apollo.game.model.area.RegionRepository) Region(org.apollo.game.model.area.Region) StaticGameObject(org.apollo.game.model.entity.obj.StaticGameObject) World(org.apollo.game.model.World) MapObject(org.apollo.cache.map.MapObject)

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