Search in sources :

Example 6 with NPC

use of net.runelite.api.NPC 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 7 with NPC

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

the class NpcIndicatorsPlugin method onGameTick.

@Subscribe
public void onGameTick(GameTick tick) {
    highlightedNpcs = buildNpcsToHighlight();
    taggedNpcs.clear();
    if (npcTags.isEmpty() || !config.isTagEnabled()) {
        return;
    }
    for (NPC npc : client.getNpcs()) {
        if (npcTags.contains(npc.getIndex())) {
            NPCComposition composition = getComposition(npc);
            if (composition == null || composition.getName() == null)
                continue;
            taggedNpcs.add(npc);
        }
    }
}
Also used : NPC(net.runelite.api.NPC) NPCComposition(net.runelite.api.NPCComposition) Subscribe(com.google.common.eventbus.Subscribe)

Example 8 with NPC

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

the class NpcIndicatorsPlugin method buildNpcsToHighlight.

private Map<NPC, String> buildNpcsToHighlight() {
    String configNpcs = config.getNpcToHighlight().toLowerCase();
    if (configNpcs.isEmpty())
        return Collections.EMPTY_MAP;
    Map<NPC, String> npcMap = new HashMap<>();
    List<String> highlightedNpcs = Arrays.asList(configNpcs.split(DELIMITER_REGEX));
    for (NPC npc : client.getNpcs()) {
        NPCComposition composition = getComposition(npc);
        if (npc == null || composition == null || composition.getName() == null)
            continue;
        for (String highlight : highlightedNpcs) {
            String name = composition.getName().replace('\u00A0', ' ');
            if (WildcardMatcher.matches(highlight, name)) {
                npcMap.put(npc, name);
            }
        }
    }
    return npcMap;
}
Also used : NPC(net.runelite.api.NPC) HashMap(java.util.HashMap) NPCComposition(net.runelite.api.NPCComposition)

Example 9 with NPC

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

the class RSActorMixin method getInteracting.

@Inject
@Override
public Actor getInteracting() {
    int i = getRSInteracting();
    if (i == -1) {
        return null;
    }
    if (i < 0x8000) {
        NPC[] npcs = client.getCachedNPCs();
        return npcs[i];
    }
    i -= 0x8000;
    Player[] players = client.getCachedPlayers();
    return players[i];
}
Also used : NPC(net.runelite.api.NPC) Player(net.runelite.api.Player) LocalPoint(net.runelite.api.coords.LocalPoint) Point(net.runelite.api.Point) WorldPoint(net.runelite.api.coords.WorldPoint) Inject(net.runelite.api.mixins.Inject)

Example 10 with NPC

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

the class RSClientMixin method getNpcs.

@Inject
@Override
public List<NPC> getNpcs() {
    int validNpcIndexes = getNpcIndexesCount();
    int[] npcIndexes = getNpcIndices();
    NPC[] cachedNpcs = getCachedNPCs();
    List<NPC> npcs = new ArrayList<NPC>(validNpcIndexes);
    for (int i = 0; i < validNpcIndexes; ++i) {
        npcs.add(cachedNpcs[npcIndexes[i]]);
    }
    return npcs;
}
Also used : RSNPC(net.runelite.rs.api.RSNPC) NPC(net.runelite.api.NPC) ArrayList(java.util.ArrayList) LocalPoint(net.runelite.api.coords.LocalPoint) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Aggregations

NPC (net.runelite.api.NPC)16 NPCComposition (net.runelite.api.NPCComposition)6 LocalPoint (net.runelite.api.coords.LocalPoint)3 Color (java.awt.Color)2 Client (net.runelite.api.Client)2 Player (net.runelite.api.Player)2 Point (net.runelite.api.Point)2 Query (net.runelite.api.Query)2 Inject (net.runelite.api.mixins.Inject)2 NPCQuery (net.runelite.api.queries.NPCQuery)2 Subscribe (com.google.common.eventbus.Subscribe)1 Dimension (java.awt.Dimension)1 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Actor (net.runelite.api.Actor)1 GameObject (net.runelite.api.GameObject)1