Search in sources :

Example 1 with NumericalAttribute

use of org.apollo.game.model.entity.attr.NumericalAttribute in project apollo by apollo-rsps.

the class BinaryPlayerSerializer method readAttributes.

/**
 * Reads the player's {@link Attribute}s.
 *
 * @param in The input stream.
 * @return The {@link Map} of attribute names to attributes.
 * @throws IOException If there is an error reading from the stream.
 */
private Map<String, Attribute<?>> readAttributes(DataInputStream in) throws IOException {
    int count = in.readInt();
    Map<String, Attribute<?>> attributes = new HashMap<>(count);
    for (int times = 0; times < count; times++) {
        String name = StreamUtil.readString(in);
        AttributeType type = AttributeType.valueOf(in.read());
        Attribute<?> attribute;
        switch(type) {
            case BOOLEAN:
                attribute = new BooleanAttribute(in.read() == 1);
                break;
            case DOUBLE:
                attribute = new NumericalAttribute(in.readDouble());
                break;
            case LONG:
                attribute = new NumericalAttribute(in.readLong());
                break;
            case STRING:
            case SYMBOL:
                attribute = new StringAttribute(StreamUtil.readString(in), type == AttributeType.SYMBOL);
                break;
            default:
                throw new IllegalArgumentException("Undefined attribute type: " + type + ".");
        }
        attributes.put(name, attribute);
    }
    return attributes;
}
Also used : BooleanAttribute(org.apollo.game.model.entity.attr.BooleanAttribute) 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) HashMap(java.util.HashMap) AttributeType(org.apollo.game.model.entity.attr.AttributeType) NumericalAttribute(org.apollo.game.model.entity.attr.NumericalAttribute) StringAttribute(org.apollo.game.model.entity.attr.StringAttribute)

Example 2 with NumericalAttribute

use of org.apollo.game.model.entity.attr.NumericalAttribute in project apollo by apollo-rsps.

the class Player method setRunEnergy.

/**
 * Sets the player's run energy.
 *
 * @param energy The energy.
 */
public void setRunEnergy(int energy) {
    attributes.set("run_energy", new NumericalAttribute(energy));
    send(new UpdateRunEnergyMessage(energy));
}
Also used : NumericalAttribute(org.apollo.game.model.entity.attr.NumericalAttribute) UpdateRunEnergyMessage(org.apollo.game.message.impl.UpdateRunEnergyMessage)

Aggregations

NumericalAttribute (org.apollo.game.model.entity.attr.NumericalAttribute)2 HashMap (java.util.HashMap)1 UpdateRunEnergyMessage (org.apollo.game.message.impl.UpdateRunEnergyMessage)1 Attribute (org.apollo.game.model.entity.attr.Attribute)1 AttributeType (org.apollo.game.model.entity.attr.AttributeType)1 BooleanAttribute (org.apollo.game.model.entity.attr.BooleanAttribute)1 StringAttribute (org.apollo.game.model.entity.attr.StringAttribute)1