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();
}
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));
}
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();
}
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());
}
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;
}
Aggregations