use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class WorldObjectsDecoder method run.
/**
* Decode the {@code MapObject}s from the cache and register them with the world.
*/
@Override
public void run() {
Map<Integer, MapIndex> mapIndices = MapIndex.getIndices();
try {
for (MapIndex index : mapIndices.values()) {
MapObjectsDecoder decoder = MapObjectsDecoder.create(fs, index);
List<MapObject> objects = decoder.decode();
int mapX = index.getX(), mapY = index.getY();
for (MapObject object : objects) {
Position position = new Position(mapX + object.getLocalX(), mapY + object.getLocalY(), object.getHeight());
StaticGameObject gameObject = new StaticGameObject(world, object.getId(), position, object.getType(), object.getOrientation());
regionRepository.fromPosition(position).addEntity(gameObject, false);
}
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class BinaryPlayerSerializer method loadPlayer.
@Override
public PlayerLoaderResponse loadPlayer(PlayerCredentials credentials) throws IOException {
Path path = getFile(credentials.getUsername());
if (!Files.exists(path)) {
Player player = new Player(world, credentials, TUTORIAL_ISLAND_SPAWN);
credentials.setPassword(SCryptUtil.scrypt(credentials.getPassword(), 16384, 8, 1));
return new PlayerLoaderResponse(LoginConstants.STATUS_OK, player);
}
try (DataInputStream in = new DataInputStream(new BufferedInputStream(Files.newInputStream(path)))) {
String name = StreamUtil.readString(in);
String password = StreamUtil.readString(in);
if (!name.equalsIgnoreCase(credentials.getUsername()) || !SCryptUtil.check(credentials.getPassword(), password)) {
return new PlayerLoaderResponse(LoginConstants.STATUS_INVALID_CREDENTIALS);
}
// Update password to the hashed one.
credentials.setPassword(password);
PrivilegeLevel privilege = PrivilegeLevel.valueOf(in.readByte());
MembershipStatus members = MembershipStatus.valueOf(in.readByte());
PrivacyState chatPrivacy = PrivacyState.valueOf(in.readByte(), true);
PrivacyState friendPrivacy = PrivacyState.valueOf(in.readByte(), false);
PrivacyState tradePrivacy = PrivacyState.valueOf(in.readByte(), false);
ScreenBrightness brightness = ScreenBrightness.valueOf(in.readByte());
int x = in.readUnsignedShort();
int y = in.readUnsignedShort();
int height = in.readUnsignedByte();
Gender gender = in.readUnsignedByte() == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE;
int[] style = new int[7];
for (int slot = 0; slot < style.length; slot++) {
style[slot] = in.readUnsignedByte();
}
int[] colors = new int[5];
for (int slot = 0; slot < colors.length; slot++) {
colors[slot] = in.readUnsignedByte();
}
Player player = new Player(world, credentials, new Position(x, y, height));
player.setPrivilegeLevel(privilege);
player.setMembers(members);
player.setChatPrivacy(chatPrivacy);
player.setFriendPrivacy(friendPrivacy);
player.setTradePrivacy(tradePrivacy);
player.setScreenBrightness(brightness);
player.setAppearance(new Appearance(gender, style, colors));
readInventory(in, player.getInventory());
readInventory(in, player.getEquipment());
readInventory(in, player.getBank());
int size = in.readUnsignedByte();
SkillSet skills = player.getSkillSet();
skills.stopFiringEvents();
try {
for (int i = 0; i < size; i++) {
int level = in.readUnsignedByte();
double experience = in.readDouble();
skills.setSkill(i, new Skill(experience, level, SkillSet.getLevelForExperience(experience)));
}
} finally {
skills.calculateCombatLevel();
skills.startFiringEvents();
}
int friendCount = in.readByte();
List<String> friends = new ArrayList<>(friendCount);
for (int i = 0; i < friendCount; i++) {
friends.add(NameUtil.decodeBase37(in.readLong()));
}
player.setFriendUsernames(friends);
int ignoreCount = in.readByte();
List<String> ignores = new ArrayList<>(ignoreCount);
for (int times = 0; times < ignoreCount; times++) {
ignores.add(NameUtil.decodeBase37(in.readLong()));
}
player.setIgnoredUsernames(ignores);
Map<String, Attribute<?>> attributes = readAttributes(in);
attributes.forEach(player::setAttribute);
if (player.isBanned()) {
return new PlayerLoaderResponse(LoginConstants.STATUS_ACCOUNT_DISABLED);
}
return new PlayerLoaderResponse(LoginConstants.STATUS_OK, player);
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class ObjectActionVerificationHandler method handle.
@Override
public void handle(Player player, ObjectActionMessage message) {
int id = message.getId();
if (id < 0 || id >= 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) || !containsObject(id, objects)) {
message.terminate();
return;
}
ObjectDefinition definition = ObjectDefinition.lookup(id);
if (message.getOption() >= definition.getMenuActions().length) {
message.terminate();
return;
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class WorldMapDecoder method markTiles.
/**
* Mark any tiles in the given {@link MapPlane} as blocked or bridged in the {@link CollisionManager}.
*
* @param mapX The X coordinate of the map file.
* @param mapY The Y coordinate of the map file.
* @param plane The {@link MapPlane} to load tiles from.
*/
private void markTiles(int mapX, int mapY, MapPlane plane) {
for (int x = 0; x < MapConstants.MAP_WIDTH; x++) {
for (int y = 0; y < MapConstants.MAP_WIDTH; y++) {
Tile tile = plane.getTile(x, y);
Position position = new Position(mapX + x, mapY + y, plane.getLevel());
if ((tile.getAttributes() & BLOCKED_TILE) == BLOCKED_TILE) {
collisionManager.block(position);
}
if ((tile.getAttributes() & BRIDGE_TILE) == BRIDGE_TILE) {
collisionManager.markBridged(position);
}
}
}
}
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(1, updateRequired ? 1 : 0);
// discard walking queue?
builder.putBits(1, 1);
builder.putBits(5, other.getY() - player.getY());
builder.putBits(5, other.getX() - player.getX());
}
Aggregations