Java Code Examples for net.runelite.api.NPC#getDefinition()

The following examples show how to use net.runelite.api.NPC#getDefinition() . 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: DevToolsOverlay.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void renderNpcs(Graphics2D graphics)
{
	List<NPC> npcs = client.getNpcs();
	for (NPC npc : npcs)
	{
		NPCDefinition composition = npc.getDefinition();
		Color color = composition.getCombatLevel() > 1 ? YELLOW : ORANGE;
		if (composition.getConfigs() != null)
		{
			NPCDefinition 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.getSpotAnimation() + ")  (IDX: " + npc.getIndex() + ")";

		OverlayUtil.renderActorOverlay(graphics, npc, text, color);
	}
}
 
Example 2
Source File: StatusBarsPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void hideStatusBar()
{
	final Actor interacting = client.getLocalPlayer().getInteracting();
	final boolean isNpc = interacting instanceof NPC;
	final int combatTimeout = config.hideStatusBarDelay();

	if (isNpc)
	{
		final NPC npc = (NPC) interacting;
		final NPCDefinition npcComposition = npc.getDefinition();
		final List<String> npcMenuActions = Arrays.asList(npcComposition.getActions());
		if (npcMenuActions.contains("Attack") && config.toggleRestorationBars())
		{
			updateLastCombatAction();
			overlayManager.add(overlay);
		}
	}
	else if (lastCombatAction == null || Duration.between(getLastCombatAction(), Instant.now()).getSeconds() > combatTimeout)
	{
		overlayManager.remove(overlay);
	}
}
 
Example 3
Source File: ImplingsOverlay.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
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 4
Source File: IdleNotifierPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
void onInteractingChanged(InteractingChanged event)
{
	final Actor source = event.getSource();
	if (source != client.getLocalPlayer())
	{
		return;
	}

	final Actor target = event.getTarget();

	// Reset last interact
	if (target != null)
	{
		lastInteract = null;
	}
	else
	{
		lastInteracting = Instant.now();
	}

	final boolean isNpc = target instanceof NPC;

	// If this is not NPC, do not process as we are not interested in other entities
	if (!isNpc)
	{
		return;
	}

	final NPC npc = (NPC) target;
	final NPCDefinition npcComposition = npc.getDefinition();
	final List<String> npcMenuActions = Arrays.asList(npcComposition.getActions());

	if (npcMenuActions.contains("Attack"))
	{
		// Player is most likely in combat with attack-able NPC
		resetTimers();
		lastInteract = target;
		lastInteracting = Instant.now();
		lastInteractWasCombat = true;
	}
	else if (target.getName() != null && target.getName().contains(FISHING_SPOT))
	{
		// Player is fishing
		resetTimers();
		lastInteract = target;
		lastInteracting = Instant.now();
		lastInteractWasCombat = false;
	}
}
 
Example 5
Source File: AgilityOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation();
	Point mousePosition = client.getMouseCanvasPosition();
	final List<Tile> marksOfGrace = plugin.getMarksOfGrace();
	final Tile stickTile = plugin.getStickTile();
	plugin.getObstacles().forEach((object, obstacle) ->
	{
		if (Obstacles.SHORTCUT_OBSTACLE_IDS.containsKey(object.getId()) && !config.highlightShortcuts() ||
			Obstacles.TRAP_OBSTACLE_IDS.contains(object.getId()) && !config.showTrapOverlay() ||
			Obstacles.COURSE_OBSTACLE_IDS.contains(object.getId()) && !config.showCourseClickboxes())
		{
			return;
		}

		Tile tile = obstacle.getTile();

		if (tile.getPlane() == client.getPlane() && checkDistance(object.getLocalLocation(), playerLocation))
		{
			// This assumes that the obstacle is not clickable.
			if (Obstacles.TRAP_OBSTACLE_IDS.contains(object.getId()))
			{
				Polygon polygon = object.getCanvasTilePoly();
				if (polygon != null)
				{
					OverlayUtil.renderPolygon(graphics, polygon, config.getTrapColor());
				}
				return;
			}
			Shape objectClickbox = object.getClickbox();
			if (objectClickbox != null)
			{
				AgilityShortcut agilityShortcut = obstacle.getShortcut();
				Color configColor = agilityShortcut == null || agilityShortcut.getLevel() <= plugin.getAgilityLevel() ? config.getOverlayColor() : SHORTCUT_HIGH_LEVEL_COLOR;
				if (config.highlightMarks() && !marksOfGrace.isEmpty())
				{
					configColor = config.getMarkColor();
				}
				if (config.highlightPortals() && Obstacles.PORTAL_OBSTACLE_IDS.contains(object.getId()))
				{
					configColor = config.getPortalsColor();
				}

				OverlayUtil.renderClickBox(graphics, mousePosition, objectClickbox, configColor);
			}
		}

	});

	if (config.highlightMarks() && !marksOfGrace.isEmpty())
	{
		for (Tile markOfGraceTile : marksOfGrace)
		{
			highlightTile(graphics, playerLocation, markOfGraceTile, config.getMarkColor());
		}
	}
	
	if (stickTile != null && config.highlightStick())
	{
		highlightTile(graphics, playerLocation, stickTile, config.stickHighlightColor());
	}

	Set<NPC> npcs = plugin.getNpcs();
	if (!npcs.isEmpty() && config.highlightSepulchreNpcs())
	{
		Color color = config.sepulchreHighlightColor();
		for (NPC npc : npcs)
		{
			NPCDefinition npcDefinition = npc.getDefinition();
			int size = npcDefinition.getSize();
			LocalPoint lp = npc.getLocalLocation();

			Polygon tilePoly = Perspective.getCanvasTileAreaPoly(client, lp, size);
			if (tilePoly != null)
			{
				OverlayUtil.renderPolygon(graphics, tilePoly, color);
			}
		}
	}

	return null;
}