net.runelite.api.NPC Java Examples
The following examples show how to use
net.runelite.api.NPC.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CorpPlugin.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Subscribe public void onNpcSpawned(NpcSpawned npcSpawned) { NPC npc = npcSpawned.getNpc(); switch (npc.getId()) { case NpcID.CORPOREAL_BEAST: log.debug("Corporeal beast spawn: {}", npc); corp = npc; yourDamage = 0; totalDamage = 0; players.clear(); break; case NpcID.DARK_ENERGY_CORE: core = npc; break; } }
Example #2
Source File: Game.java From plugins with GNU General Public License v3.0 | 6 votes |
private void loadPortalLocations() { NPC squire = null; for (NPC npc : client.getNpcs()) { if (PestControlNpc.isIngameSquireId(npc.getId())) { squire = npc; break; } } if (squire != null) { log.debug("In-game Squire found: {}", squire); setPortalLocations(squire.getWorldLocation()); } }
Example #3
Source File: NpcIndicatorsPluginTest.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testDeadNpcMenuHighlight() { when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin"); when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED); ConfigChanged configChanged = new ConfigChanged(); configChanged.setGroup("npcindicators"); npcIndicatorsPlugin.onConfigChanged(configChanged); NPC npc = mock(NPC.class); when(npc.getName()).thenReturn("Goblin"); when(npc.isDead()).thenReturn(true); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0 when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()}); MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); MenuEntry target = new MenuEntry(); target.setTarget("<col=ff0000>Goblin"); // red verify(client).setMenuEntries(new MenuEntry[]{target}); }
Example #4
Source File: BarbarianAssaultPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
@Subscribe private void onNpcSpawned(NpcSpawned event) { if (!isInGame()) { return; } NPC npc = event.getNpc(); if (npc == null) { return; } String name = event.getNpc().getName(); if (name.equals("Penance Healer") && !healers.containsKey(npc.getIndex())) { healers.put(npc.getIndex(), new Healer(npc, healers.size(), stage)); } }
Example #5
Source File: ImplingsOverlay.java From plugins with GNU General Public License v3.0 | 6 votes |
private void drawDynamicSpawn(Graphics2D graphics, Integer spawnID, String text, Color color) { List<NPC> npcs = client.getNpcs(); for (NPC npc : npcs) { if (npc.getDefinition().getId() == spawnID) { NPCDefinition composition = npc.getDefinition(); if (composition.getConfigs() != null) { NPCDefinition transformedComposition = composition.transform(); if (transformedComposition == null) { OverlayUtil.renderActorOverlay(graphics, npc, text, color); } } } } }
Example #6
Source File: BossTimersPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
@Subscribe private void onNpcDespawned(NpcDespawned npcDespawned) { NPC npc = npcDespawned.getNpc(); if (!npc.isDead()) { return; } int npcId = npc.getId(); Boss boss = Boss.find(npcId); if (boss == null) { return; } // remove existing timer infoBoxManager.removeIf(t -> t instanceof RespawnTimer && ((RespawnTimer) t).getBoss() == boss); RespawnTimer timer = new RespawnTimer(boss, itemManager.getImage(boss.getItemSpriteId()), this); timer.setTooltip(npc.getName()); infoBoxManager.addInfoBox(timer); }
Example #7
Source File: FishingPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
private void inverseSortSpotDistanceFromPlayer() { if (fishingSpots.isEmpty()) { return; } final LocalPoint cameraPoint = new LocalPoint(client.getCameraX(), client.getCameraY()); fishingSpots.sort( Comparator.comparing( // Negate to have the furthest first (NPC npc) -> -npc.getLocalLocation().distanceTo(cameraPoint)) // Order by position .thenComparing(NPC::getLocalLocation, Comparator.comparing(LocalPoint::getX) .thenComparing(LocalPoint::getY)) // And then by id .thenComparing(NPC::getId) ); }
Example #8
Source File: TargetWeaknessOverlay.java From plugins with GNU General Public License v3.0 | 6 votes |
private void renderTargetItem(Graphics2D graphics, NPC actor, BufferedImage image) { final LocalPoint actorPosition = actor.getLocalLocation(); final int offset = actor.getLogicalHeight() + 40; if (actorPosition == null || image == null) { return; } final Point imageLoc = Perspective.getCanvasImageLocation(client, actorPosition, image, offset); if (imageLoc != null) { OverlayUtil.renderImageLocation(graphics, imageLoc, image); } }
Example #9
Source File: TargetWeaknessOverlay.java From plugins with GNU General Public License v3.0 | 6 votes |
private int calculateHealth(NPC target) { // Based on OpponentInfoOverlay HP calculation if (target == null || target.getName() == null) { return -1; } final int healthScale = target.getHealthScale(); final int healthRatio = target.getHealthRatio(); final int maxHealth = npcManager.getHealth(target.getId()); if (healthRatio < 0 || healthScale <= 0 || maxHealth == -1) { return -1; } return (int) ((maxHealth * healthRatio / healthScale) + 0.5f); }
Example #10
Source File: NpcIndicatorsPluginTest.java From plugins with GNU General Public License v3.0 | 6 votes |
@Test public void testDeadNpcMenuHighlight() { when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin"); when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED); ConfigChanged configChanged = new ConfigChanged(); configChanged.setGroup("npcindicators"); npcIndicatorsPlugin.onConfigChanged(configChanged); NPC npc = mock(NPC.class); when(npc.getName()).thenReturn("Goblin"); when(npc.isDead()).thenReturn(true); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0 when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()}); MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuOpcode.NPC_FIRST_OPTION.getId(), 0, -1, -1, false); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); MenuEntry target = new MenuEntry(); target.setTarget("<col=ff0000>Goblin"); // red verify(client).setMenuEntries(new MenuEntry[]{target}); }
Example #11
Source File: ImplingsPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
@Subscribe private void onNpcDefinitionChanged(NpcDefinitionChanged npcCompositionChanged) { NPC npc = npcCompositionChanged.getNpc(); Impling impling = Impling.findImpling(npc.getId()); if (impling != null) { if (showImplingType(impling.getImplingType()) == ImplingsConfig.ImplingMode.NOTIFY) { notifier.notify(impling.getImplingType().getName() + " impling is in the area"); } if (!implings.contains(npc)) { implings.add(npc); } } }
Example #12
Source File: TargetMinimapOverlay.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Dimension render(Graphics2D graphics) { if (!config.highlightTargets()) { return null; } List<NPC> targets = plugin.getHighlightedTargets(); for (NPC target : targets) { renderTargetOverlay(graphics, target, config.getTargetColor()); } return null; }
Example #13
Source File: SpecialCounterPluginTest.java From plugins with GNU General Public License v3.0 | 6 votes |
@Test public void testSpecDamage() { NPC target = mock(NPC.class); Player player = mock(Player.class); when(client.getLocalPlayer()).thenReturn(player); // spec npc when(client.getVar(VarPlayer.SPECIAL_ATTACK_PERCENT)).thenReturn(50); specialCounterPlugin.onVarbitChanged(new VarbitChanged()); lenient().when(player.getInteracting()).thenReturn(target); specialCounterPlugin.onInteractingChanged(new InteractingChanged(player, target)); // hit 1 specialCounterPlugin.onHitsplatApplied(hitsplat(target, Hitsplat.HitsplatType.DAMAGE_ME)); verify(infoBoxManager).addInfoBox(any(SpecialCounter.class)); }
Example #14
Source File: SpecialCounterPluginTest.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testSpecBlock() { NPC target = mock(NPC.class); Player player = mock(Player.class); when(client.getLocalPlayer()).thenReturn(player); // spec npc when(client.getVar(VarPlayer.SPECIAL_ATTACK_PERCENT)).thenReturn(50); specialCounterPlugin.onVarbitChanged(new VarbitChanged()); lenient().when(player.getInteracting()).thenReturn(target); specialCounterPlugin.onInteractingChanged(new InteractingChanged(player, target)); // block 0 specialCounterPlugin.onHitsplatApplied(hitsplat(target, Hitsplat.HitsplatType.BLOCK_ME)); // hit 1 specialCounterPlugin.onHitsplatApplied(hitsplat(target, Hitsplat.HitsplatType.DAMAGE_ME)); verify(infoBoxManager, never()).addInfoBox(any(SpecialCounter.class)); }
Example #15
Source File: NpcMinimapOverlay.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
private void renderNpcOverlay(Graphics2D graphics, NPC actor, String name, Color color) { NPCComposition npcComposition = actor.getTransformedComposition(); if (npcComposition == null || !npcComposition.isInteractible() || (actor.isDead() && config.ignoreDeadNpcs())) { return; } Point minimapLocation = actor.getMinimapLocation(); if (minimapLocation != null) { OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker()); if (config.drawMinimapNames()) { OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color); } } }
Example #16
Source File: SpecialCounterPluginTest.java From plugins with GNU General Public License v3.0 | 6 votes |
@Test public void testUnaggro() { NPC target = mock(NPC.class); Player player = mock(Player.class); when(client.getLocalPlayer()).thenReturn(player); // tick 1: attack npc when(player.getInteracting()).thenReturn(target); specialCounterPlugin.onInteractingChanged(new InteractingChanged(player, target)); // tick 2: spec fires and un-interact npc when(client.getVar(VarPlayer.SPECIAL_ATTACK_PERCENT)).thenReturn(50); specialCounterPlugin.onVarbitChanged(new VarbitChanged()); lenient().when(player.getInteracting()).thenReturn(null); specialCounterPlugin.onInteractingChanged(new InteractingChanged(player, null)); // tick 3: hit 1 specialCounterPlugin.onHitsplatApplied(hitsplat(target, Hitsplat.HitsplatType.DAMAGE_ME)); verify(infoBoxManager).addInfoBox(any(SpecialCounter.class)); }
Example #17
Source File: StealingArtefactsPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
private void addHintArrow() { if (stealingArtefactsHouse == StealingArtefactsHouse.CAPTAIN_KHALED) { for (NPC npc : client.getCachedNPCs()) { if (npc == null) { continue; } if (Objects.equals(npc.getName(), NPC_NAME_CAPTAIN_KHALED)) { client.setHintArrow(npc); return; } } } client.setHintArrow(stealingArtefactsHouse.getWorldPoint()); }
Example #18
Source File: TimersPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
@Subscribe private void onNpcDespawned(NpcDespawned npcDespawned) { NPC npc = npcDespawned.getNpc(); if (!npc.isDead()) { return; } int npcId = npc.getId(); if (npcId == NpcID.ZOMBIFIED_SPAWN || npcId == NpcID.ZOMBIFIED_SPAWN_8063) { removeGameTimer(ICEBARRAGE); } }
Example #19
Source File: ImplingsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Subscribe public void onNpcChanged(NpcChanged npcCompositionChanged) { NPC npc = npcCompositionChanged.getNpc(); Impling impling = Impling.findImpling(npc.getId()); if (impling != null) { if (showImplingType(impling.getImplingType()) == ImplingsConfig.ImplingMode.NOTIFY) { notifier.notify(impling.getImplingType().getName() + " impling is in the area"); } if (!implings.contains(npc)) { implings.add(npc); } } }
Example #20
Source File: NpcIndicatorsPluginTest.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testAliveNpcMenuHighlight() { when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin"); when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true); when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE); ConfigChanged configChanged = new ConfigChanged(); configChanged.setGroup("npcindicators"); npcIndicatorsPlugin.onConfigChanged(configChanged); NPC npc = mock(NPC.class); when(npc.getName()).thenReturn("Goblin"); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0 when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()}); MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); MenuEntry target = new MenuEntry(); target.setTarget("<col=0000ff>Goblin"); // blue verify(client).setMenuEntries(new MenuEntry[]{target}); }
Example #21
Source File: DevToolsOverlay.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
private void renderNpcs(Graphics2D graphics) { List<NPC> npcs = client.getNpcs(); for (NPC npc : npcs) { NPCComposition composition = npc.getComposition(); Color color = composition.getCombatLevel() > 1 ? YELLOW : ORANGE; if (composition.getConfigs() != null) { NPCComposition transformedComposition = composition.transform(); if (transformedComposition == null) { color = GRAY; } else { composition = transformedComposition; } } String text = composition.getName() + " (ID:" + composition.getId() + ")" + " (A: " + npc.getAnimation() + ") (P: " + npc.getPoseAnimation() + ") (G: " + npc.getGraphic() + ")"; OverlayUtil.renderActorOverlay(graphics, npc, text, color); } }
Example #22
Source File: TargetWeaknessOverlay.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
private int calculateHealth(NPC target) { // Based on OpponentInfoOverlay HP calculation if (target == null || target.getName() == null) { return -1; } final int healthScale = target.getHealthScale(); final int healthRatio = target.getHealthRatio(); final Integer maxHealth = npcManager.getHealth(target.getId()); if (healthRatio < 0 || healthScale <= 0 || maxHealth == null) { return -1; } return (int)((maxHealth * healthRatio / healthScale) + 0.5f); }
Example #23
Source File: NpcIndicatorsPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
private void highlightNpcIfMatch(final NPC npc) { if (npcTags.contains(npc.getIndex())) { if (!client.isInInstancedRegion()) { memorizeNpc(npc); } highlightedNpcs.add(npc); return; } final String npcName = npc.getName(); if (npcName != null) { for (String highlight : highlights) { if (WildcardMatcher.matches(highlight, npcName)) { if (!client.isInInstancedRegion()) { memorizeNpc(npc); } highlightedNpcs.add(npc); return; } } } highlightedNpcs.remove(npc); }
Example #24
Source File: AnagramClue.java From plugins with GNU General Public License v3.0 | 5 votes |
@Override public void makeWorldOverlayHint(Graphics2D graphics, ClueScrollPlugin plugin) { if (!getLocation().isInScene(plugin.getClient())) { return; } // Mark NPC if (objectId == -1 && plugin.getNpcsToMark() != null) { for (NPC npc : plugin.getNpcsToMark()) { OverlayUtil.renderActorOverlayImage(graphics, npc, plugin.getClueScrollImage(), Color.ORANGE, IMAGE_Z_OFFSET); } } // Mark game object if (objectId != -1) { net.runelite.api.Point mousePosition = plugin.getClient().getMouseCanvasPosition(); for (TileObject gameObject : plugin.getObjectsToMark()) { OverlayUtil.renderHoverableArea(graphics, gameObject.getClickbox(), mousePosition, CLICKBOX_FILL_COLOR, CLICKBOX_BORDER_COLOR, CLICKBOX_HOVER_BORDER_COLOR); OverlayUtil.renderImageLocation(plugin.getClient(), graphics, gameObject.getLocalLocation(), plugin.getClueScrollImage(), IMAGE_Z_OFFSET); } } }
Example #25
Source File: PerformanceStatsPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
/** * Calculates damage dealt based on HP xp gained accounting for multipliers such as DMM mode * * @param diff HP xp gained * @return damage dealt */ private double calculateDamageDealt(double diff) { double damageDealt = diff / HITPOINT_RATIO; // DeadMan mode has an XP modifier if (client.getWorldType().contains(WorldType.DEADMAN)) { damageDealt = damageDealt / DMM_MULTIPLIER_RATIO; } // Some NPCs have an XP modifier, account for it here. Actor a = client.getLocalPlayer().getInteracting(); if (!(a instanceof NPC)) { // If we are interacting with nothing we may have clicked away at the perfect time fall back to last tick if (!(oldTarget instanceof NPC)) { log.warn("Couldn't find current or past target for experienced gain..."); return damageDealt; } a = oldTarget; } final int npcId = ((NPC) a).getId(); return damageDealt / npcManager.getXpModifier(npcId); }
Example #26
Source File: PestControlPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Subscribe public void onNpcSpawned(NpcSpawned event) { final NPC npc = event.getNpc(); if (SPINNER_IDS.contains(npc.getId())) { spinners.add(npc); } }
Example #27
Source File: NpcStatusPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
@Subscribe private void onSpotAnimationChanged(SpotAnimationChanged event) { if ((event.getActor().getSpotAnimation() == GraphicID.SPLASH) && event.getActor() instanceof NPC) { for (MemorizedNPC mn : memorizedNPCs) { if (mn.getNpcIndex() != ((NPC) event.getActor()).getIndex()) { continue; } if (mn.getStatus() == MemorizedNPC.Status.OUT_OF_COMBAT || (mn.getStatus() == MemorizedNPC.Status.IN_COMBAT && mn.getCombatTimerEnd() - client.getTickCount() < 2) || event.getActor().getInteracting() == null) { mn.setStatus(MemorizedNPC.Status.FLINCHING); mn.setCombatTimerEnd(-1); if (config.isCustomAttSpeed()) { mn.setFlinchTimerEnd(client.getTickCount() + config.getCustomAttSpeed() / 2 + 2); } else { mn.setFlinchTimerEnd(client.getTickCount() + mn.getAttackSpeed() / 2 + 2); } } } } }
Example #28
Source File: NpcHighlightOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderHullOverlay(Graphics2D graphics, NPC npc, Color color) { Shape objectClickbox = npc.getConvexHull(); if (objectClickbox != null) { graphics.setColor(color); graphics.setStroke(new BasicStroke(2)); graphics.draw(objectClickbox); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20)); graphics.fill(objectClickbox); } }
Example #29
Source File: HintArrowOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private NPC getClosestNpc(List<NPC> npcList) { WorldPoint currentLocation = client.getLocalPlayer().getWorldLocation(); NPC closestNpc = null; int currentShortestDistance = 1337; int distanceToNpc; for (NPC npc : npcList) { if (closestNpc != null) { distanceToNpc = npc.getWorldLocation().distanceTo(currentLocation); if (distanceToNpc < currentShortestDistance) { closestNpc = npc; currentShortestDistance = distanceToNpc; } } else { closestNpc = npc; } } return closestNpc; }
Example #30
Source File: XpTrackerPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Subscribe public void onStatChanged(StatChanged statChanged) { final Skill skill = statChanged.getSkill(); final int currentXp = statChanged.getXp(); final int currentLevel = statChanged.getLevel(); final VarPlayer startGoal = startGoalVarpForSkill(skill); final VarPlayer endGoal = endGoalVarpForSkill(skill); final int startGoalXp = startGoal != null ? client.getVar(startGoal) : -1; final int endGoalXp = endGoal != null ? client.getVar(endGoal) : -1; if (initializeTracker) { // This is the XP sync on login, wait until after login to begin counting return; } if (xpTrackerConfig.hideMaxed() && currentLevel >= Experience.MAX_REAL_LEVEL) { return; } final XpStateSingle state = xpState.getSkill(skill); state.setActionType(XpActionType.EXPERIENCE); final Actor interacting = client.getLocalPlayer().getInteracting(); if (interacting instanceof NPC && COMBAT.contains(skill)) { final NPC npc = (NPC) interacting; xpState.updateNpcExperience(skill, npc, npcManager.getHealth(npc.getId())); } final XpUpdateResult updateResult = xpState.updateSkill(skill, currentXp, startGoalXp, endGoalXp); xpPanel.updateSkillExperience(updateResult == XpUpdateResult.UPDATED, xpPauseState.isPaused(skill), skill, xpState.getSkillSnapshot(skill)); // Also update the total experience xpState.updateSkill(Skill.OVERALL, client.getOverallExperience(), -1, -1); xpPanel.updateTotal(xpState.getTotalSnapshot()); }