Search in sources :

Example 1 with PlayerQuery

use of net.runelite.api.queries.PlayerQuery in project runelite by runelite.

the class HunterPlugin method onGameObjectSpawned.

@Subscribe
public void onGameObjectSpawned(GameObjectSpawned event) {
    final GameObject gameObject = event.getGameObject();
    final HunterTrap myTrap = traps.get(gameObject.getWorldLocation());
    final Player localPlayer = client.getLocalPlayer();
    switch(gameObject.getId()) {
        // Deadfall trap placed
        case ObjectID.DEADFALL:
        case // Maniacal monkey trap placed
        ObjectID.MONKEY_TRAP:
            // If player is right next to "object" trap assume that player placed the trap
            if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 1) {
                log.debug("Trap placed by \"{}\" on {}", localPlayer.getName(), gameObject.getWorldLocation());
                traps.put(gameObject.getWorldLocation(), new HunterTrap(gameObject));
                lastActionTime = Instant.now();
            }
            break;
        // Imp box placed
        case ObjectID.MAGIC_BOX:
        // Box trap placed
        case ObjectID.BOX_TRAP_9380:
        // Bird snare placed
        case ObjectID.BIRD_SNARE_9345:
        // Net trap placed at green sallys
        case ObjectID.NET_TRAP_9343:
        // Net trap placed at orange sallys
        case ObjectID.NET_TRAP:
        // Net trap placed at red sallys
        case ObjectID.NET_TRAP_8992:
        case // Net trap placed at black sallys
        ObjectID.NET_TRAP_9002:
            // Look for players that are on the same tile
            final PlayerQuery playerQuery = new PlayerQuery().atLocalLocation(gameObject.getLocalLocation());
            final List<Player> possiblePlayers = Arrays.asList(queryRunner.runQuery(playerQuery));
            // If the player is on that tile, assume he is the one that placed the trap
            if (possiblePlayers.contains(localPlayer)) {
                log.debug("Trap placed by \"{}\" on {}", localPlayer.getName(), localPlayer.getWorldLocation());
                traps.put(gameObject.getWorldLocation(), new HunterTrap(gameObject));
                lastActionTime = Instant.now();
            }
            break;
        // Imp caught
        case ObjectID.MAGIC_BOX_19226:
        // Black chinchompa caught
        case ObjectID.SHAKING_BOX:
        // Grey chinchompa caught
        case ObjectID.SHAKING_BOX_9382:
        // Red chinchompa caught
        case ObjectID.SHAKING_BOX_9383:
        // Prickly kebbit caught
        case ObjectID.BOULDER_20648:
        // Sabre-tooth kebbit caught
        case ObjectID.BOULDER_20649:
        // Barb-tailed kebbit caught
        case ObjectID.BOULDER_20650:
        // Wild kebbit caught
        case ObjectID.BOULDER_20651:
        // Crimson swift caught
        case ObjectID.BIRD_SNARE_9373:
        // Cerulean twitch caught
        case ObjectID.BIRD_SNARE_9375:
        // Golden warbler caught
        case ObjectID.BIRD_SNARE_9377:
        // Copper longtail caught
        case ObjectID.BIRD_SNARE_9379:
        // Tropical wagtail caught
        case ObjectID.BIRD_SNARE_9348:
        // Green sally caught
        case ObjectID.NET_TRAP_9004:
        // Red sally caught
        case ObjectID.NET_TRAP_8986:
        // Orange sally caught
        case ObjectID.NET_TRAP_8734:
        // Black sally caught
        case ObjectID.NET_TRAP_8996:
        // Maniacal monkey tail obtained
        case ObjectID.LARGE_BOULDER_28830:
        case // Maniacal monkey tail obtained
        ObjectID.LARGE_BOULDER_28831:
            if (myTrap != null) {
                myTrap.setState(HunterTrap.State.FULL);
                myTrap.resetTimer();
                lastActionTime = Instant.now();
                if (config.maniacalMonkeyNotify() && myTrap.getObjectId() == ObjectID.MONKEY_TRAP) {
                    notifier.notify("You've caught part of a monkey's tail.");
                }
            }
            break;
        // Empty imp box
        case ObjectID.MAGIC_BOX_FAILED:
        // Empty box trap
        case ObjectID.BOX_TRAP_9385:
        case // Empty box trap
        ObjectID.BIRD_SNARE:
            if (myTrap != null) {
                myTrap.setState(HunterTrap.State.EMPTY);
                myTrap.resetTimer();
                lastActionTime = Instant.now();
            }
            break;
        // Imp entering box
        case ObjectID.MAGIC_BOX_19225:
        // Black chin shaking box
        case ObjectID.BOX_TRAP:
        case ObjectID.BOX_TRAP_2026:
        case ObjectID.BOX_TRAP_2028:
        case ObjectID.BOX_TRAP_2029:
        // Red chin shaking box
        case ObjectID.BOX_TRAP_9381:
        case ObjectID.BOX_TRAP_9390:
        case ObjectID.BOX_TRAP_9391:
        case ObjectID.BOX_TRAP_9392:
        case ObjectID.BOX_TRAP_9393:
        // Grey chin shaking box
        case ObjectID.BOX_TRAP_9386:
        case ObjectID.BOX_TRAP_9387:
        case ObjectID.BOX_TRAP_9388:
        // Bird traps
        case ObjectID.BIRD_SNARE_9346:
        case ObjectID.BIRD_SNARE_9347:
        case ObjectID.BIRD_SNARE_9349:
        case ObjectID.BIRD_SNARE_9374:
        case ObjectID.BIRD_SNARE_9376:
        case ObjectID.BIRD_SNARE_9378:
        // Deadfall trap
        case ObjectID.DEADFALL_19218:
        case ObjectID.DEADFALL_19851:
        case ObjectID.DEADFALL_20128:
        case ObjectID.DEADFALL_20129:
        case ObjectID.DEADFALL_20130:
        case ObjectID.DEADFALL_20131:
        // Net trap
        case ObjectID.NET_TRAP_9003:
        case ObjectID.NET_TRAP_9005:
        case ObjectID.NET_TRAP_8972:
        case ObjectID.NET_TRAP_8974:
        case ObjectID.NET_TRAP_8985:
        case ObjectID.NET_TRAP_8987:
        case ObjectID.NET_TRAP_8993:
        case ObjectID.NET_TRAP_8997:
        // Maniacal monkey boulder trap
        case ObjectID.MONKEY_TRAP_28828:
        case ObjectID.MONKEY_TRAP_28829:
            if (myTrap != null) {
                myTrap.setState(HunterTrap.State.TRANSITION);
            }
            break;
    }
}
Also used : Player(net.runelite.api.Player) GameObject(net.runelite.api.GameObject) PlayerQuery(net.runelite.api.queries.PlayerQuery) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)1 GameObject (net.runelite.api.GameObject)1 Player (net.runelite.api.Player)1 PlayerQuery (net.runelite.api.queries.PlayerQuery)1