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