use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method putMovementUpdate.
/**
* Puts a movement update for the specified segment.
*
* @param seg The segment.
* @param message The message.
* @param builder The builder.
*/
private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.TELEPORT) {
Position pos = ((TeleportSegment) seg).getDestination();
builder.putBits(1, 1);
builder.putBits(2, 3);
builder.putBits(1, message.hasRegionChanged() ? 0 : 1);
builder.putBits(2, pos.getHeight());
builder.putBits(7, pos.getLocalY(message.getLastKnownRegion()));
builder.putBits(7, pos.getLocalX(message.getLastKnownRegion()));
builder.putBits(1, updateRequired ? 1 : 0);
} else if (seg.getType() == SegmentType.RUN) {
Direction[] directions = ((MovementSegment) seg).getDirections();
builder.putBits(1, 1);
builder.putBits(2, 2);
builder.putBits(3, directions[0].toInteger());
builder.putBits(3, directions[1].toInteger());
builder.putBits(1, updateRequired ? 1 : 0);
} else if (seg.getType() == SegmentType.WALK) {
Direction[] directions = ((MovementSegment) seg).getDirections();
builder.putBits(1, 1);
builder.putBits(2, 1);
builder.putBits(3, directions[0].toInteger());
builder.putBits(1, updateRequired ? 1 : 0);
} else {
if (updateRequired) {
builder.putBits(1, 1);
builder.putBits(2, 0);
} else {
builder.putBits(1, 0);
}
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PositionHintIconMessageEncoder method encode.
@Override
public GamePacket encode(PositionHintIconMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(199);
HintIconMessage.Type type = message.getType();
if (type == Type.PLAYER || type == Type.NPC) {
throw new IllegalStateException("Unsupported hint icon type " + type + ".");
}
builder.put(DataType.BYTE, type.getValue());
Position position = message.getPosition();
builder.put(DataType.SHORT, position.getX());
builder.put(DataType.SHORT, position.getY());
builder.put(DataType.BYTE, message.getHeight());
return builder.toGamePacket();
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class SendProjectileMessageEncoder method encode.
@Override
public GamePacket encode(SendProjectileMessage message) {
Projectile projectile = message.getProjectile();
Position source = projectile.getPosition();
Position destination = projectile.getDestination();
GamePacketBuilder builder = new GamePacketBuilder(181);
builder.put(DataType.BYTE, message.getPositionOffset());
builder.put(DataType.BYTE, destination.getX() - source.getX());
builder.put(DataType.BYTE, destination.getY() - source.getY());
builder.put(DataType.SHORT, projectile.getTarget());
builder.put(DataType.SHORT, projectile.getGraphic());
builder.put(DataType.BYTE, projectile.getStartHeight());
builder.put(DataType.BYTE, projectile.getEndHeight());
builder.put(DataType.SHORT, projectile.getDelay());
builder.put(DataType.SHORT, projectile.getLifetime());
builder.put(DataType.BYTE, projectile.getPitch());
builder.put(DataType.BYTE, projectile.getOffset());
return builder.toGamePacket();
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class BinaryPlayerSerializer method savePlayer.
@Override
public void savePlayer(Player player) throws IOException {
Path file = getFile(player.getUsername());
try (DataOutputStream out = new DataOutputStream(Files.newOutputStream(file))) {
StreamUtil.writeString(out, player.getUsername());
StreamUtil.writeString(out, player.getCredentials().getPassword());
out.writeByte(player.getPrivilegeLevel().toInteger());
out.writeByte(player.getMembershipStatus().getValue());
out.writeByte(player.getChatPrivacy().toInteger(true));
out.writeByte(player.getFriendPrivacy().toInteger(false));
out.writeByte(player.getTradePrivacy().toInteger(false));
out.writeByte(player.getScreenBrightness().toInteger());
Position position = player.getPosition();
out.writeShort(position.getX());
out.writeShort(position.getY());
out.writeByte(position.getHeight());
Appearance appearance = player.getAppearance();
out.writeByte(appearance.getGender().toInteger());
int[] style = appearance.getStyle();
for (int element : style) {
out.writeByte(element);
}
int[] colors = appearance.getColors();
for (int color : colors) {
out.writeByte(color);
}
writeInventory(out, player.getInventory());
writeInventory(out, player.getEquipment());
writeInventory(out, player.getBank());
SkillSet skills = player.getSkillSet();
out.writeByte(skills.size());
for (int id = 0; id < skills.size(); id++) {
Skill skill = skills.getSkill(id);
out.writeByte(skill.getCurrentLevel());
out.writeDouble(skill.getExperience());
}
List<String> usernames = player.getFriendUsernames();
out.writeByte(usernames.size());
for (String username : usernames) {
out.writeLong(NameUtil.encodeBase37(username));
}
usernames = player.getIgnoredUsernames();
out.writeByte(usernames.size());
for (String username : usernames) {
out.writeLong(NameUtil.encodeBase37(username));
}
Set<Entry<String, Attribute<?>>> attributes = player.getAttributes().entrySet();
attributes.removeIf(e -> AttributeMap.getDefinition(e.getKey()).getPersistence() != AttributePersistence.PERSISTENT);
out.writeInt(attributes.size());
for (Entry<String, Attribute<?>> entry : attributes) {
String name = entry.getKey();
StreamUtil.writeString(out, name);
Attribute<?> attribute = entry.getValue();
out.writeByte(attribute.getType().getValue());
out.write(attribute.encode());
}
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class ItemOnObjectVerificationHandler method handle.
@Override
public void handle(Player player, ItemOnObjectMessage message) {
if (message.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID && message.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) {
message.terminate();
return;
}
Inventory inventory = player.getInventory();
int slot = message.getSlot();
if (slot < 0 || slot >= inventory.capacity()) {
message.terminate();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != message.getId()) {
message.terminate();
return;
}
int objectId = message.getObjectId();
if (objectId < 0 || objectId >= ObjectDefinition.count()) {
message.terminate();
return;
}
Position position = message.getPosition();
Region region = world.getRegionRepository().fromPosition(position);
Set<GameObject> objects = region.getEntities(position, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT);
if (!player.getPosition().isWithinDistance(position, 15) || !ObjectActionVerificationHandler.containsObject(objectId, objects)) {
message.terminate();
return;
}
}
Aggregations