Search in sources :

Example 1 with GameObject

use of net.runelite.api.GameObject in project runelite by runelite.

the class CannonPlugin method onGameObjectSpawned.

@Subscribe
public void onGameObjectSpawned(GameObjectSpawned event) {
    GameObject gameObject = event.getGameObject();
    Player localPlayer = client.getLocalPlayer();
    if (gameObject.getId() == CANNON_BASE && !cannonPlaced) {
        if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 2 && localPlayer.getAnimation() == AnimationID.BURYING_BONES) {
            cannonPosition = gameObject.getWorldLocation();
            cannon = gameObject;
        }
    }
}
Also used : Player(net.runelite.api.Player) GameObject(net.runelite.api.GameObject) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with GameObject

use of net.runelite.api.GameObject in project runelite by runelite.

the class ConveyorBeltOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    if (!config.showConveyorBelt() || plugin.getConveyorBelt() == null) {
        return null;
    }
    LocalPoint localLocation = client.getLocalPlayer().getLocalLocation();
    Point mousePosition = client.getMouseCanvasPosition();
    GameObject object = plugin.getConveyorBelt();
    LocalPoint location = object.getLocalLocation();
    if (localLocation.distanceTo(location) <= MAX_DISTANCE) {
        Area objectClickbox = object.getClickbox();
        if (objectClickbox != null) {
            if (objectClickbox.contains(mousePosition.getX(), mousePosition.getY())) {
                graphics.setColor(Color.RED.darker());
            } else {
                graphics.setColor(Color.RED);
            }
            graphics.draw(objectClickbox);
            graphics.setColor(new Color(0xFF, 0, 0, 20));
            graphics.fill(objectClickbox);
        }
    }
    return null;
}
Also used : Area(java.awt.geom.Area) LocalPoint(net.runelite.api.coords.LocalPoint) GameObject(net.runelite.api.GameObject) Color(java.awt.Color) LocalPoint(net.runelite.api.coords.LocalPoint) Point(net.runelite.api.Point)

Example 3 with GameObject

use of net.runelite.api.GameObject in project runelite by runelite.

the class TitheFarmPlugin method onGameObjectSpawned.

@Subscribe
public void onGameObjectSpawned(GameObjectSpawned event) {
    GameObject gameObject = event.getGameObject();
    TitheFarmPlantType type = TitheFarmPlantType.getPlantType(gameObject.getId());
    if (type == null) {
        return;
    }
    TitheFarmPlantState state = TitheFarmPlantState.getState(gameObject.getId());
    TitheFarmPlant newPlant = new TitheFarmPlant(state, type, gameObject);
    TitheFarmPlant oldPlant = getPlantFromCollection(gameObject);
    if (oldPlant == null && newPlant.getType() != TitheFarmPlantType.EMPTY) {
        log.debug("Added plant {}", newPlant);
        plants.add(newPlant);
    } else if (oldPlant == null) {
        return;
    } else if (newPlant.getType() == TitheFarmPlantType.EMPTY) {
        log.debug("Removed plant {}", oldPlant);
        plants.remove(oldPlant);
    } else if (oldPlant.getGameObject().getId() != newPlant.getGameObject().getId()) {
        if (oldPlant.getState() != TitheFarmPlantState.WATERED && newPlant.getState() == TitheFarmPlantState.WATERED) {
            log.debug("Updated plant (watered)");
            newPlant.setPlanted(oldPlant.getPlanted());
            plants.remove(oldPlant);
            plants.add(newPlant);
        } else {
            log.debug("Updated plant");
            plants.remove(oldPlant);
            plants.add(newPlant);
        }
    }
}
Also used : GameObject(net.runelite.api.GameObject) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with GameObject

use of net.runelite.api.GameObject 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)

Example 5 with GameObject

use of net.runelite.api.GameObject in project runelite by runelite.

the class RSTileMixin method gameObjectsChanged.

@FieldHook("objects")
@Inject
public void gameObjectsChanged(int idx) {
    if (// this happens from the field assignment
    idx == -1) {
        return;
    }
    if (previousGameObjects == null) {
        previousGameObjects = new GameObject[5];
    }
    // Previous game object
    GameObject previous = previousGameObjects[idx];
    // GameObject that was changed.
    RSGameObject current = (RSGameObject) getGameObjects()[idx];
    // Last game object
    GameObject last = lastGameObject;
    // Update last game object
    lastGameObject = current;
    // Update previous object to current
    previousGameObjects[idx] = current;
    // Duplicate event, return
    if (current != null && current.equals(last)) {
        return;
    }
    // Characters seem to generate a constant stream of new GameObjects
    if (current == null || !(current.getRenderable() instanceof Actor)) {
        if (current == null && previous != null) {
            GameObjectDespawned gameObjectDespawned = new GameObjectDespawned();
            gameObjectDespawned.setTile(this);
            gameObjectDespawned.setGameObject(previous);
            eventBus.post(gameObjectDespawned);
        } else if (current != null && previous == null) {
            GameObjectSpawned gameObjectSpawned = new GameObjectSpawned();
            gameObjectSpawned.setTile(this);
            gameObjectSpawned.setGameObject(current);
            eventBus.post(gameObjectSpawned);
        } else if (current != null && previous != null) {
            GameObjectChanged gameObjectsChanged = new GameObjectChanged();
            gameObjectsChanged.setTile(this);
            gameObjectsChanged.setPrevious(previous);
            gameObjectsChanged.setGameObject(current);
            eventBus.post(gameObjectsChanged);
        }
    }
}
Also used : GameObjectSpawned(net.runelite.api.events.GameObjectSpawned) RSGameObject(net.runelite.rs.api.RSGameObject) GameObject(net.runelite.api.GameObject) RSGameObject(net.runelite.rs.api.RSGameObject) Actor(net.runelite.api.Actor) GameObjectDespawned(net.runelite.api.events.GameObjectDespawned) GameObjectChanged(net.runelite.api.events.GameObjectChanged) Inject(net.runelite.api.mixins.Inject) FieldHook(net.runelite.api.mixins.FieldHook)

Aggregations

GameObject (net.runelite.api.GameObject)13 Subscribe (com.google.common.eventbus.Subscribe)9 LocalPoint (net.runelite.api.coords.LocalPoint)4 Player (net.runelite.api.Player)2 Tile (net.runelite.api.Tile)2 Color (java.awt.Color)1 Area (java.awt.geom.Area)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Actor (net.runelite.api.Actor)1 NPC (net.runelite.api.NPC)1 Point (net.runelite.api.Point)1 Region (net.runelite.api.Region)1 WorldPoint (net.runelite.api.coords.WorldPoint)1 GameObjectChanged (net.runelite.api.events.GameObjectChanged)1 GameObjectDespawned (net.runelite.api.events.GameObjectDespawned)1 GameObjectSpawned (net.runelite.api.events.GameObjectSpawned)1 FieldHook (net.runelite.api.mixins.FieldHook)1 Inject (net.runelite.api.mixins.Inject)1