Search in sources :

Example 1 with Actor

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

Example 2 with Actor

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

the class OpponentInfoOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    Actor opponent = getOpponent();
    // If opponent is null, try to use last opponent
    if (opponent == null) {
        if (lastOpponent != null && clientNpcs[lastOpponent.getIndex()] != lastOpponent) {
            // lastOpponent is no longer valid
            lastOpponent = null;
        } else {
            opponent = lastOpponent;
        }
    } else {
        // Update last opponent
        lastOpponent = opponent instanceof NPC ? (NPC) opponent : null;
    }
    if (opponent != null && opponent.getHealth() > 0) {
        lastTime = Instant.now();
        lastRatio = (float) opponent.getHealthRatio() / (float) opponent.getHealth();
        opponentName = Text.removeTags(opponent.getName());
        lastMaxHealth = oppInfoHealth.get(opponentName + "_" + opponent.getCombatLevel());
        Actor opponentsOpponent = opponent.getInteracting();
        if (opponentsOpponent != null && (opponentsOpponent != client.getLocalPlayer() || client.getSetting(Varbits.MULTICOMBAT_AREA) == 1)) {
            opponentsOpponentName = Text.removeTags(opponentsOpponent.getName());
        } else {
            opponentsOpponentName = null;
        }
    }
    if (Duration.between(Instant.now(), lastTime).abs().compareTo(WAIT) > 0) {
        // don't draw anything.
        return null;
    }
    FontMetrics fm = graphics.getFontMetrics();
    // opponent name
    int height = TOP_BORDER + fm.getHeight();
    if (lastRatio >= 0) {
        height += BAR_HEIGHT + 6;
    }
    if (opponentsOpponentName != null) {
        height += fm.getHeight() + 3;
    }
    height += 3;
    height += BOTTOM_BORDER;
    final BackgroundComponent backgroundComponent = new BackgroundComponent();
    backgroundComponent.setRectangle(new Rectangle(0, 0, WIDTH, height));
    backgroundComponent.render(graphics);
    int y = TOP_BORDER + fm.getHeight();
    {
        int x = (WIDTH - fm.stringWidth(opponentName)) / 2;
        final TextComponent textComponent = new TextComponent();
        textComponent.setPosition(new Point(x, y));
        textComponent.setText(opponentName);
        textComponent.render(graphics);
        y += 3;
    }
    if (lastRatio >= 0) {
        int barWidth = (int) (lastRatio * (float) BAR_WIDTH);
        y += 3;
        graphics.setColor(HP_GREEN);
        graphics.fillRect((WIDTH - BAR_WIDTH) / 2, y, barWidth, BAR_HEIGHT);
        graphics.setColor(HP_RED);
        graphics.fillRect(((WIDTH - BAR_WIDTH) / 2) + barWidth, y, BAR_WIDTH - barWidth, BAR_HEIGHT);
        String str;
        if (lastMaxHealth != null) {
            int currHealth = (int) (lastRatio * lastMaxHealth);
            str = currHealth + "/" + lastMaxHealth;
        } else {
            str = df.format(lastRatio * 100) + "%";
        }
        y += BAR_HEIGHT;
        final TextComponent textComponent1 = new TextComponent();
        textComponent1.setText(str);
        textComponent1.setPosition(new Point((WIDTH - fm.stringWidth(str)) / 2, y));
        textComponent1.render(graphics);
        y += 3;
    }
    if (opponentsOpponentName != null) {
        y += fm.getHeight();
        int x = (WIDTH - fm.stringWidth(opponentsOpponentName)) / 2;
        final TextComponent textComponent = new TextComponent();
        textComponent.setPosition(new Point(x, y));
        textComponent.setText(opponentsOpponentName);
        textComponent.render(graphics);
    }
    return new Dimension(WIDTH, height);
}
Also used : NPC(net.runelite.api.NPC) TextComponent(net.runelite.client.ui.overlay.components.TextComponent) BackgroundComponent(net.runelite.client.ui.overlay.components.BackgroundComponent) FontMetrics(java.awt.FontMetrics) Actor(net.runelite.api.Actor) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 3 with Actor

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

the class BossTimersPlugin method onActorDeath.

@Subscribe
public void onActorDeath(ActorDeath death) {
    Actor actor = death.getActor();
    Boss boss = Boss.find(actor.getName());
    if (boss == null) {
        return;
    }
    // remove existing timer
    infoBoxManager.removeIf(t -> t instanceof RespawnTimer && ((RespawnTimer) t).getBoss() == boss);
    log.debug("Creating spawn timer for {} ({} seconds)", actor.getName(), boss.getSpawnTime());
    RespawnTimer timer = new RespawnTimer(boss, itemManager.getImage(boss.getItemSpriteId()), this);
    timer.setTooltip(boss.getName());
    infoBoxManager.addInfoBox(timer);
}
Also used : Actor(net.runelite.api.Actor) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with Actor

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

the class IdleNotifierPlugin method checkOutOfCombat.

private boolean checkOutOfCombat(Duration waitDuration, Player local) {
    Actor opponent = local.getInteracting();
    boolean isPlayer = opponent instanceof Player;
    if (opponent != null && !isPlayer && opponent.getCombatLevel() > 0) {
        resetTimers();
        lastOpponent = opponent;
    } else if (opponent == null) {
        lastOpponent = null;
    }
    if (lastOpponent != null && opponent == lastOpponent) {
        lastInteracting = Instant.now();
    }
    if (lastInteracting != null && Instant.now().compareTo(lastInteracting.plus(waitDuration)) >= 0) {
        lastInteracting = null;
        return true;
    }
    return false;
}
Also used : Player(net.runelite.api.Player) Actor(net.runelite.api.Actor)

Example 5 with Actor

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

the class DevToolsOverlay method renderProjectiles.

private void renderProjectiles(Graphics2D graphics) {
    List<Projectile> projectiles = client.getProjectiles();
    for (Projectile projectile : projectiles) {
        int originX = projectile.getX1();
        int originY = projectile.getY1();
        LocalPoint tilePoint = new LocalPoint(originX, originY);
        Polygon poly = Perspective.getCanvasTilePoly(client, tilePoint);
        if (poly != null) {
            OverlayUtil.renderPolygon(graphics, poly, Color.RED);
        }
        int projectileId = projectile.getId();
        Actor projectileInteracting = projectile.getInteracting();
        String infoString = "";
        if (projectileInteracting == null) {
            infoString += "AoE";
        } else {
            infoString += "Targeted (T: " + projectileInteracting.getName() + ")";
        }
        infoString += " (ID: " + projectileId + ")";
        if (projectileInteracting != null) {
            OverlayUtil.renderActorOverlay(graphics, projectile.getInteracting(), infoString, Color.RED);
        }
    }
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) Actor(net.runelite.api.Actor) Polygon(java.awt.Polygon) LocalPoint(net.runelite.api.coords.LocalPoint) Projectile(net.runelite.api.Projectile)

Aggregations

Actor (net.runelite.api.Actor)5 Subscribe (com.google.common.eventbus.Subscribe)1 Dimension (java.awt.Dimension)1 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1 Polygon (java.awt.Polygon)1 Rectangle (java.awt.Rectangle)1 GameObject (net.runelite.api.GameObject)1 NPC (net.runelite.api.NPC)1 Player (net.runelite.api.Player)1 Projectile (net.runelite.api.Projectile)1 LocalPoint (net.runelite.api.coords.LocalPoint)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 BackgroundComponent (net.runelite.client.ui.overlay.components.BackgroundComponent)1 TextComponent (net.runelite.client.ui.overlay.components.TextComponent)1 RSGameObject (net.runelite.rs.api.RSGameObject)1