Search in sources :

Example 1 with ObjectDefinition

use of org.apollo.cache.def.ObjectDefinition 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;
    }
}
Also used : Position(org.apollo.game.model.Position) GameObject(org.apollo.game.model.entity.obj.GameObject) Region(org.apollo.game.model.area.Region) ObjectDefinition(org.apollo.cache.def.ObjectDefinition)

Example 2 with ObjectDefinition

use of org.apollo.cache.def.ObjectDefinition in project apollo by apollo-rsps.

the class ObjectDefinitionDecoder method decode.

/**
 * Decodes data from the cache into an {@link ObjectDefinition}.
 *
 * @param id The id of the object.
 * @param data The {@link ByteBuffer} containing the data.
 * @return The object definition.
 */
private ObjectDefinition decode(int id, ByteBuffer data) {
    ObjectDefinition definition = new ObjectDefinition(id);
    while (true) {
        int opcode = data.get() & 0xFF;
        if (opcode == 0) {
            return definition;
        } else if (opcode == 1) {
            int amount = data.get() & 0xFF;
            for (int i = 0; i < amount; i++) {
                data.getShort();
                data.get();
            }
        } else if (opcode == 2) {
            definition.setName(BufferUtil.readString(data));
        } else if (opcode == 3) {
            definition.setDescription(BufferUtil.readString(data));
        } else if (opcode == 5) {
            int amount = data.get() & 0xFF;
            for (int i = 0; i < amount; i++) {
                data.getShort();
            }
        } else if (opcode == 14) {
            definition.setWidth(data.get() & 0xFF);
        } else if (opcode == 15) {
            definition.setLength(data.get() & 0xFF);
        } else if (opcode == 17) {
            definition.setSolid(false);
        } else if (opcode == 18) {
            definition.setImpenetrable(false);
        } else if (opcode == 19) {
            definition.setInteractive((data.get() & 0xFF) == 1);
        } else if (opcode == 24) {
            data.getShort();
        } else if (opcode == 28 || opcode == 29) {
            data.get();
        } else if (opcode >= 30 && opcode < 39) {
            String[] actions = definition.getMenuActions();
            if (actions == null) {
                actions = new String[10];
            }
            String action = BufferUtil.readString(data);
            actions[opcode - 30] = action;
            definition.setMenuActions(actions);
        } else if (opcode == 39) {
            data.get();
        } else if (opcode == 40) {
            int amount = data.get() & 0xFF;
            for (int i = 0; i < amount; i++) {
                data.getShort();
                data.getShort();
            }
        } else if (opcode == 60 || opcode >= 65 && opcode <= 68) {
            data.getShort();
        } else if (opcode == 69) {
            data.get();
        } else if (opcode >= 70 && opcode <= 72) {
            data.getShort();
        } else if (opcode == 73) {
            definition.setObstructive(true);
        } else if (opcode == 75) {
            data.get();
        } else if (opcode == 77) {
            data.getShort();
            data.getShort();
            int count = data.get();
            for (int i = 0; i <= count; i++) {
                data.getShort();
            }
        } else {
            continue;
        }
    }
}
Also used : ObjectDefinition(org.apollo.cache.def.ObjectDefinition)

Example 3 with ObjectDefinition

use of org.apollo.cache.def.ObjectDefinition in project apollo by apollo-rsps.

the class ObjectDefinitionDecoder method run.

@Override
public void run() {
    try {
        Archive config = fs.getArchive(0, 2);
        ByteBuffer data = config.getEntry("loc.dat").getBuffer();
        ByteBuffer idx = config.getEntry("loc.idx").getBuffer();
        int count = idx.getShort(), index = 2;
        int[] indices = new int[count];
        for (int i = 0; i < count; i++) {
            indices[i] = index;
            index += idx.getShort();
        }
        ObjectDefinition[] definitions = new ObjectDefinition[count];
        for (int i = 0; i < count; i++) {
            data.position(indices[i]);
            definitions[i] = decode(i, data);
        }
        ObjectDefinition.init(definitions);
    } catch (IOException e) {
        throw new UncheckedIOException("Error decoding ObjectDefinitions.", e);
    }
}
Also used : Archive(org.apollo.cache.archive.Archive) ObjectDefinition(org.apollo.cache.def.ObjectDefinition) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 4 with ObjectDefinition

use of org.apollo.cache.def.ObjectDefinition in project apollo by apollo-rsps.

the class CollisionManagerTests method setupObjectDefinitions.

/**
 * Setup some simple object definitions to use in collision tests.
 */
@BeforeClass
public static void setupObjectDefinitions() {
    ObjectDefinition wall = new ObjectDefinition(WALL);
    ObjectDefinition squareObject = new ObjectDefinition(SQUARE_OBJECT);
    squareObject.setLength(2);
    squareObject.setWidth(2);
    ObjectDefinition.init(new ObjectDefinition[] { wall, squareObject });
}
Also used : ObjectDefinition(org.apollo.cache.def.ObjectDefinition) BeforeClass(org.junit.BeforeClass)

Aggregations

ObjectDefinition (org.apollo.cache.def.ObjectDefinition)4 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ByteBuffer (java.nio.ByteBuffer)1 Archive (org.apollo.cache.archive.Archive)1 Position (org.apollo.game.model.Position)1 Region (org.apollo.game.model.area.Region)1 GameObject (org.apollo.game.model.entity.obj.GameObject)1 BeforeClass (org.junit.BeforeClass)1