use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class ItemOnObjectVerificationHandlerTests method terminateIfInvalidSlot.
@Test
public void terminateIfInvalidSlot() throws Exception {
Position playerPosition = new Position(3200, 3200);
Position objectPosition = new Position(3200, 3200);
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));
Inventory inventory = new Inventory(28);
when(player.getInventory()).thenReturn(inventory);
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);
ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, 4151, 30, 1, objectPosition.getX(), objectPosition.getY());
ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world);
itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage);
assertTrue("ObjectVerificationHandler: message not terminated when no valid slot given!", itemOnObjectMessage.terminated());
}
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, DataOrder.LITTLE, DataTransformation.ADD);
int id = (int) reader.getUnsigned(DataType.SHORT);
int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
return new ObjectActionMessage(1, id, new Position(x, y));
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PathfindingAlgorithm method inside.
/**
* Returns whether or not the specified {@link Position} is inside the specified {@code boundary}.
*
* @param position The Position.
* @param boundary The boundary Positions.
* @return {@code true} if the specified Position is inside the boundary, {@code false} if not.
*/
private boolean inside(Position position, Position[] boundary) {
int x = position.getX(), y = position.getY();
Position min = boundary[0], max = boundary[1];
return x >= min.getX() && y >= min.getY() && x <= max.getX() && y <= max.getY();
}
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() == 213) {
// 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);
boolean run = reader.getUnsigned(DataType.BYTE) == 1;
int y = (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, DataTransformation.SUBTRACT);
}
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);
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method putAddPlayerUpdate.
/**
* Puts an add player update.
*
* @param seg The segment.
* @param message The message.
* @param builder The builder.
*/
private static void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0;
Position player = message.getPosition();
Position other = seg.getPosition();
builder.putBits(11, seg.getIndex());
builder.putBits(5, other.getX() - player.getX());
builder.putBits(1, updateRequired ? 1 : 0);
// discard walking queue?
builder.putBits(1, 1);
builder.putBits(5, other.getY() - player.getY());
}
Aggregations