Search in sources :

Example 1 with Cache

use of org.powerbot.bot.rt4.client.Cache in project powerbot by powerbot.

the class Npc method id.

@Override
public int id() {
    final Client client = ctx.client();
    if (client == null) {
        return -1;
    }
    final NpcConfig c = npc == null ? new NpcConfig(client.reflector, null) : npc.getConfig();
    if (c.isNull()) {
        return -1;
    }
    final int varbit = c.getVarbit(), si = c.getVarpbitIndex();
    int index = -1;
    if (varbit != -1) {
        final Cache cache = client.getVarbitCache();
        final Varbit varBit = HashTable.lookup(cache.getTable(), varbit, Varbit.class);
        if (!varBit.isNull()) {
            final int mask = lookup[varBit.getEndBit() - varBit.getStartBit()];
            index = ctx.varpbits.varpbit(varBit.getIndex()) >> varBit.getStartBit() & mask;
        }
    } else if (si != -1) {
        index = ctx.varpbits.varpbit(si);
    }
    if (index >= 0) {
        final int[] configs = c.getConfigs();
        if (index < configs.length && configs[index] != -1) {
            return configs[index];
        }
    }
    return c.getId();
}
Also used : NpcConfig(org.powerbot.bot.rt4.client.NpcConfig) Varbit(org.powerbot.bot.rt4.client.Varbit) Client(org.powerbot.bot.rt4.client.Client) Cache(org.powerbot.bot.rt4.client.Cache)

Example 2 with Cache

use of org.powerbot.bot.rt4.client.Cache in project powerbot by powerbot.

the class GameObject method id.

@Override
public int id() {
    final Client client = ctx.client();
    if (client == null) {
        return -1;
    }
    final int id = object != null ? (object.getUid() >> 14) & 0xffff : -1;
    if (object == null) {
        return id;
    }
    int index = -1;
    final CacheObjectConfig c = CacheObjectConfig.load(Bot.CACHE_WORKER, id);
    if (c == null) {
        return id;
    }
    if (c.stageOperationId != -1) {
        final Cache cache = client.getVarbitCache();
        final Varbit varBit = new Varbit(object.object.reflector, HashTable.lookup(cache.getTable(), c.stageOperationId, Varbit.class));
        if (varBit.obj.get() != null) {
            final int mask = lookup[varBit.getEndBit() - varBit.getStartBit()];
            index = ctx.varpbits.varpbit(varBit.getIndex()) >> varBit.getStartBit() & mask;
        }
    } else if (c.stageIndex >= 0) {
        index = ctx.varpbits.varpbit(c.stageIndex);
    }
    if (index >= 0) {
        final int[] configs = c.materialPointers;
        if (configs != null && index < configs.length && configs[index] != -1) {
            return configs[index];
        }
    }
    return id;
}
Also used : Varbit(org.powerbot.bot.rt4.client.Varbit) Client(org.powerbot.bot.rt4.client.Client) Point(java.awt.Point) Cache(org.powerbot.bot.rt4.client.Cache)

Aggregations

Cache (org.powerbot.bot.rt4.client.Cache)2 Client (org.powerbot.bot.rt4.client.Client)2 Varbit (org.powerbot.bot.rt4.client.Varbit)2 Point (java.awt.Point)1 NpcConfig (org.powerbot.bot.rt4.client.NpcConfig)1