Search in sources :

Example 1 with Appearance

use of org.apollo.game.model.Appearance 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);
    }
}
Also used : Path(java.nio.file.Path) MembershipStatus(org.apollo.game.model.entity.setting.MembershipStatus) Player(org.apollo.game.model.entity.Player) 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) ArrayList(java.util.ArrayList) PrivacyState(org.apollo.game.model.entity.setting.PrivacyState) Gender(org.apollo.game.model.entity.setting.Gender) DataInputStream(java.io.DataInputStream) PrivilegeLevel(org.apollo.game.model.entity.setting.PrivilegeLevel) Appearance(org.apollo.game.model.Appearance) Skill(org.apollo.game.model.entity.Skill) ScreenBrightness(org.apollo.game.model.entity.setting.ScreenBrightness) BufferedInputStream(java.io.BufferedInputStream) SkillSet(org.apollo.game.model.entity.SkillSet)

Example 2 with Appearance

use of org.apollo.game.model.Appearance in project apollo by apollo-rsps.

the class PlayerSynchronizationMessageEncoder method putAppearanceBlock.

/**
 * Puts an appearance block into the specified builder.
 *
 * @param block The block.
 * @param builder The builder.
 */
private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
    Appearance appearance = block.getAppearance();
    GamePacketBuilder playerProperties = new GamePacketBuilder();
    playerProperties.put(DataType.BYTE, appearance.getGender().toInteger());
    playerProperties.put(DataType.BYTE, 0);
    if (block.appearingAsNpc()) {
        playerProperties.put(DataType.BYTE, 255);
        playerProperties.put(DataType.BYTE, 255);
        playerProperties.put(DataType.SHORT, block.getNpcId());
    } else {
        Inventory equipment = block.getEquipment();
        int[] style = appearance.getStyle();
        Item item, chest, helm;
        for (int slot = 0; slot < 4; slot++) {
            if ((item = equipment.get(slot)) != null) {
                playerProperties.put(DataType.SHORT, 0x200 + item.getId());
            } else {
                playerProperties.put(DataType.BYTE, 0);
            }
        }
        if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + chest.getId());
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[2]);
        }
        if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + item.getId());
        } else {
            playerProperties.put(DataType.BYTE, 0);
        }
        if (chest != null) {
            EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId());
            if (def != null && !def.isFullBody()) {
                playerProperties.put(DataType.SHORT, 0x100 + style[3]);
            } else {
                playerProperties.put(DataType.BYTE, 0);
            }
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[3]);
        }
        if ((item = equipment.get(EquipmentConstants.LEGS)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + item.getId());
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[5]);
        }
        if ((helm = equipment.get(EquipmentConstants.HAT)) != null) {
            EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId());
            if (def != null && !def.isFullHat() && !def.isFullMask()) {
                playerProperties.put(DataType.SHORT, 0x100 + style[0]);
            } else {
                playerProperties.put(DataType.BYTE, 0);
            }
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[0]);
        }
        if ((item = equipment.get(EquipmentConstants.HANDS)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + item.getId());
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[4]);
        }
        if ((item = equipment.get(EquipmentConstants.FEET)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + item.getId());
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[6]);
        }
        EquipmentDefinition def = null;
        if (helm != null) {
            def = EquipmentDefinition.lookup(helm.getId());
        }
        if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) {
            playerProperties.put(DataType.BYTE, 0);
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[1]);
        }
    }
    int[] colors = appearance.getColors();
    for (int color : colors) {
        playerProperties.put(DataType.BYTE, color);
    }
    // stand
    playerProperties.put(DataType.SHORT, 0x328);
    // stand turn
    playerProperties.put(DataType.SHORT, 0x337);
    // walk
    playerProperties.put(DataType.SHORT, 0x333);
    // turn 180
    playerProperties.put(DataType.SHORT, 0x334);
    // turn 90 cw
    playerProperties.put(DataType.SHORT, 0x335);
    // turn 90 ccw
    playerProperties.put(DataType.SHORT, 0x336);
    // run
    playerProperties.put(DataType.SHORT, 0x338);
    playerProperties.put(DataType.LONG, block.getName());
    playerProperties.put(DataType.BYTE, block.getCombatLevel());
    playerProperties.put(DataType.SHORT, block.getSkillLevel());
    builder.put(DataType.BYTE, DataTransformation.NEGATE, playerProperties.getLength());
    builder.putRawBuilder(playerProperties);
}
Also used : Item(org.apollo.game.model.Item) EquipmentDefinition(org.apollo.cache.def.EquipmentDefinition) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) Appearance(org.apollo.game.model.Appearance) Inventory(org.apollo.game.model.inv.Inventory)

Example 3 with Appearance

use of org.apollo.game.model.Appearance in project apollo by apollo-rsps.

the class PlayerDesignMessageDecoder method decode.

@Override
public PlayerDesignMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int genderIntValue = (int) reader.getUnsigned(DataType.BYTE);
    int[] style = new int[7];
    for (int i = 0; i < style.length; i++) {
        style[i] = (int) reader.getUnsigned(DataType.BYTE);
    }
    int[] color = new int[5];
    for (int i = 0; i < color.length; i++) {
        color[i] = (int) reader.getUnsigned(DataType.BYTE);
    }
    Gender gender = genderIntValue == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE;
    return new PlayerDesignMessage(new Appearance(gender, style, color));
}
Also used : PlayerDesignMessage(org.apollo.game.message.impl.PlayerDesignMessage) GamePacketReader(org.apollo.net.codec.game.GamePacketReader) Gender(org.apollo.game.model.entity.setting.Gender) Appearance(org.apollo.game.model.Appearance)

Example 4 with Appearance

use of org.apollo.game.model.Appearance in project apollo by apollo-rsps.

the class PlayerSynchronizationMessageEncoder method putAppearanceBlock.

/**
 * Puts an Appearance block into the specified builder.
 *
 * @param block The block.
 * @param builder The builder.
 */
private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
    Appearance appearance = block.getAppearance();
    GamePacketBuilder playerProperties = new GamePacketBuilder();
    playerProperties.put(DataType.BYTE, appearance.getGender().toInteger());
    playerProperties.put(DataType.BYTE, block.isSkulled() ? 1 : -1);
    playerProperties.put(DataType.BYTE, block.getHeadIcon());
    if (block.appearingAsNpc()) {
        playerProperties.put(DataType.BYTE, 255);
        playerProperties.put(DataType.BYTE, 255);
        playerProperties.put(DataType.SHORT, block.getNpcId());
    } else {
        Inventory equipment = block.getEquipment();
        int[] style = appearance.getStyle();
        Item item, chest, helm;
        for (int slot = 0; slot < 4; slot++) {
            if ((item = equipment.get(slot)) != null) {
                playerProperties.put(DataType.SHORT, 0x200 + item.getId());
            } else {
                playerProperties.put(DataType.BYTE, 0);
            }
        }
        if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + chest.getId());
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[2]);
        }
        if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + item.getId());
        } else {
            playerProperties.put(DataType.BYTE, 0);
        }
        if (chest != null) {
            EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId());
            if (def != null && !def.isFullBody()) {
                playerProperties.put(DataType.SHORT, 0x100 + style[3]);
            } else {
                playerProperties.put(DataType.BYTE, 0);
            }
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[3]);
        }
        if ((item = equipment.get(EquipmentConstants.LEGS)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + item.getId());
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[5]);
        }
        if ((helm = equipment.get(EquipmentConstants.HAT)) != null) {
            EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId());
            if (def != null && !def.isFullHat() && !def.isFullMask()) {
                playerProperties.put(DataType.SHORT, 0x100 + style[0]);
            } else {
                playerProperties.put(DataType.BYTE, 0);
            }
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[0]);
        }
        if ((item = equipment.get(EquipmentConstants.HANDS)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + item.getId());
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[4]);
        }
        if ((item = equipment.get(EquipmentConstants.FEET)) != null) {
            playerProperties.put(DataType.SHORT, 0x200 + item.getId());
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[6]);
        }
        EquipmentDefinition def = null;
        if (helm != null) {
            def = EquipmentDefinition.lookup(helm.getId());
        }
        if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) {
            playerProperties.put(DataType.BYTE, 0);
        } else {
            playerProperties.put(DataType.SHORT, 0x100 + style[1]);
        }
    }
    int[] colors = appearance.getColors();
    for (int color : colors) {
        playerProperties.put(DataType.BYTE, color);
    }
    // stand
    playerProperties.put(DataType.SHORT, 0x328);
    // stand turn
    playerProperties.put(DataType.SHORT, 0x337);
    // walk
    playerProperties.put(DataType.SHORT, 0x333);
    // turn 180
    playerProperties.put(DataType.SHORT, 0x334);
    // turn 90 cw
    playerProperties.put(DataType.SHORT, 0x335);
    // turn 90 ccw
    playerProperties.put(DataType.SHORT, 0x336);
    // run
    playerProperties.put(DataType.SHORT, 0x338);
    playerProperties.put(DataType.LONG, block.getName());
    playerProperties.put(DataType.BYTE, block.getCombatLevel());
    playerProperties.put(DataType.SHORT, block.getSkillLevel());
    builder.put(DataType.BYTE, playerProperties.getLength());
    builder.putRawBuilderReverse(playerProperties);
}
Also used : Item(org.apollo.game.model.Item) EquipmentDefinition(org.apollo.cache.def.EquipmentDefinition) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) Appearance(org.apollo.game.model.Appearance) Inventory(org.apollo.game.model.inv.Inventory)

Example 5 with Appearance

use of org.apollo.game.model.Appearance in project apollo by apollo-rsps.

the class PlayerDesignMessageDecoder method decode.

@Override
public PlayerDesignMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int genderIntValue = (int) reader.getUnsigned(DataType.BYTE);
    int[] style = new int[7];
    for (int i = 0; i < style.length; i++) {
        style[i] = (int) reader.getUnsigned(DataType.BYTE);
    }
    int[] color = new int[5];
    for (int i = 0; i < color.length; i++) {
        color[i] = (int) reader.getUnsigned(DataType.BYTE);
    }
    Gender gender = genderIntValue == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE;
    return new PlayerDesignMessage(new Appearance(gender, style, color));
}
Also used : PlayerDesignMessage(org.apollo.game.message.impl.PlayerDesignMessage) GamePacketReader(org.apollo.net.codec.game.GamePacketReader) Gender(org.apollo.game.model.entity.setting.Gender) Appearance(org.apollo.game.model.Appearance)

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