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);
}
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);
}
}
}
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;
}
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];
}
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;
}
Aggregations