Search in sources :

Example 6 with Appearance

use of org.apollo.game.model.Appearance 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());
        }
    }
}
Also used : Path(java.nio.file.Path) Position(org.apollo.game.model.Position) NumericalAttribute(org.apollo.game.model.entity.attr.NumericalAttribute) BooleanAttribute(org.apollo.game.model.entity.attr.BooleanAttribute) Attribute(org.apollo.game.model.entity.attr.Attribute) StringAttribute(org.apollo.game.model.entity.attr.StringAttribute) DataOutputStream(java.io.DataOutputStream) Appearance(org.apollo.game.model.Appearance) Skill(org.apollo.game.model.entity.Skill) Entry(java.util.Map.Entry) SkillSet(org.apollo.game.model.entity.SkillSet)

Aggregations

Appearance (org.apollo.game.model.Appearance)6 Gender (org.apollo.game.model.entity.setting.Gender)3 Path (java.nio.file.Path)2 EquipmentDefinition (org.apollo.cache.def.EquipmentDefinition)2 PlayerDesignMessage (org.apollo.game.message.impl.PlayerDesignMessage)2 Item (org.apollo.game.model.Item)2 Position (org.apollo.game.model.Position)2 Skill (org.apollo.game.model.entity.Skill)2 SkillSet (org.apollo.game.model.entity.SkillSet)2 Attribute (org.apollo.game.model.entity.attr.Attribute)2 BooleanAttribute (org.apollo.game.model.entity.attr.BooleanAttribute)2 NumericalAttribute (org.apollo.game.model.entity.attr.NumericalAttribute)2 StringAttribute (org.apollo.game.model.entity.attr.StringAttribute)2 Inventory (org.apollo.game.model.inv.Inventory)2 GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)2 GamePacketReader (org.apollo.net.codec.game.GamePacketReader)2 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1