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

The following examples show how to use net.runelite.api.NPC#getName() . 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: NpcIndicatorsPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onNpcDefinitionChanged(NpcDefinitionChanged event)
{
	NPC npc = event.getNpc();
	highlightNpcIfMatch(npc);

	MemorizedNpc mn = memorizedNpcs.get(npc.getIndex());
	if (mn != null)
	{
		String npcName = npc.getName();
		if (npcName != null)
		{
			mn.getNpcNames().add(npcName);
		}
	}
}
 
Example 2
Source File: LootTrackerPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Subscribe
public void onNpcLootReceived(final NpcLootReceived npcLootReceived)
{
	final NPC npc = npcLootReceived.getNpc();
	final Collection<ItemStack> items = npcLootReceived.getItems();
	final String name = npc.getName();
	final int combat = npc.getCombatLevel();

	addLoot(name, combat, LootRecordType.NPC, items);

	if (config.npcKillChatMessage())
	{
		final String prefix = VOWELS.contains(Character.toLowerCase(name.charAt(0)))
			? "an"
			: "a";

		lootReceivedChatMessage(items, prefix + ' ' + name);
	}
}
 
Example 3
Source File: TargetWeaknessOverlay.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 4
Source File: TargetWeaknessOverlay.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
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 5
Source File: NpcStatusPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onNpcSpawned(NpcSpawned npcSpawned)
{
	final NPC npc = npcSpawned.getNpc();
	final String npcName = npc.getName();

	if (npcName == null || !Arrays.asList(npc.getDefinition().getActions()).contains("Attack"))
	{
		return;
	}
	int AttackSpeed = npcManager.getAttackSpeed(npc.getId());
	if (AttackSpeed == 0)
	{
		AttackSpeed = 4;
	}
	memorizedNPCs.add(new MemorizedNPC(npc, AttackSpeed, npc.getWorldArea()));
}
 
Example 6
Source File: TargetClickboxOverlay.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (config.highlightTargets())
	{
		Set<NPC> targets = plugin.getHighlightedTargets();
		for (NPC target : targets)
		{
			if (target == null || target.getName() == null)
			{
				continue;
			}

			Color coloration = config.getTargetColor();

			if (plugin.isSuperior(target.getName()))
			{
				coloration = config.getSuperiorColor();
			}

			renderNpcOverlay(graphics, target, coloration);
		}
	}

	return null;
}
 
Example 7
Source File: ClueScrollPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void checkClueNPCs(ClueScroll clue, final NPC... npcs)
{
	if (!(clue instanceof NpcClueScroll))
	{
		return;
	}

	final NpcClueScroll npcClueScroll = (NpcClueScroll) clue;

	if (npcClueScroll.getNpcs() == null || npcClueScroll.getNpcs().length == 0)
	{
		return;
	}

	for (NPC npc : npcs)
	{
		if (npc == null || npc.getName() == null)
		{
			continue;
		}

		for (String npcName : npcClueScroll.getNpcs())
		{
			if (!Objects.equals(npc.getName(), npcName))
			{
				continue;
			}

			npcsToMark.add(npc);
		}
	}

	if (!npcsToMark.isEmpty() && config.displayHintArrows())
	{
		// Always set hint arrow to first seen NPC
		client.setHintArrow(npcsToMark.get(0));
	}
}
 
Example 8
Source File: MemorizedNPC.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
MemorizedNPC(final NPC npc, final int attackSpeed, final WorldArea worldArea)
{
	this.npc = npc;
	this.npcIndex = npc.getIndex();
	this.npcName = npc.getName();
	this.attackSpeed = attackSpeed;
	this.combatTimerEnd = -1;
	this.flinchTimerEnd = -1;
	this.timeLeft = 0;
	this.status = Status.OUT_OF_COMBAT;
	this.lastnpcarea = worldArea;
	this.lastinteracted = null;
}
 
Example 9
Source File: NpcIndicatorsPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuOptionClicked(MenuOptionClicked click)
{
	if (click.getMenuOpcode() != MenuOpcode.RUNELITE ||
		!(click.getOption().equals(TAG) || click.getOption().equals(UNTAG)))
	{
		return;
	}

	final int id = click.getIdentifier();
	final boolean removed = npcTags.remove(id);
	final NPC[] cachedNPCs = client.getCachedNPCs();
	final NPC npc = cachedNPCs[id];

	if (npc == null || npc.getName() == null)
	{
		return;
	}

	if (removed)
	{
		MemorizedNpc mn = memorizedNpcs.get(npc.getIndex());
		if (mn != null && isNpcMemorizationUnnecessary(mn))
		{
			memorizedNpcs.remove(npc.getIndex());
			rebuildAllNpcs();
		}
	}
	else
	{
		npcTags.add(id);
		rebuildAllNpcs();
	}

	click.consume();
}
 
Example 10
Source File: NpcIndicatorsPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
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 11
Source File: SlayerPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean isTarget(NPC npc)
{
	if (targetNames.isEmpty())
	{
		return false;
	}

	String name = npc.getName();
	if (name == null)
	{
		return false;
	}

	name = name.toLowerCase();

	for (String target : targetNames)
	{
		if (name.contains(target))
		{
			NPCComposition composition = npc.getTransformedComposition();

			if (composition != null)
			{
				List<String> actions = Arrays.asList(composition.getActions());
				if (actions.contains("Attack") || actions.contains("Pick")) //Pick action is for zygomite-fungi
				{
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 12
Source File: ClueScrollPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void checkClueNPCs(ClueScroll clue, final NPC... npcs)
{
	if (!(clue instanceof NpcClueScroll))
	{
		return;
	}

	final NpcClueScroll npcClueScroll = (NpcClueScroll) clue;

	if (npcClueScroll.getNpcs() == null || npcClueScroll.getNpcs().length == 0)
	{
		return;
	}

	for (NPC npc : npcs)
	{
		if (npc == null || npc.getName() == null)
		{
			continue;
		}

		for (String npcName : npcClueScroll.getNpcs())
		{
			if (!Objects.equals(npc.getName(), npcName))
			{
				continue;
			}

			npcsToMark.add(npc);
		}
	}

	if (!npcsToMark.isEmpty() && config.displayHintArrows())
	{
		// Always set hint arrow to first seen NPC
		client.setHintArrow(npcsToMark.get(0));
	}
}
 
Example 13
Source File: NpcIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked click)
{
	if (click.getMenuAction() != MenuAction.RUNELITE ||
		!(click.getMenuOption().equals(TAG) || click.getMenuOption().equals(UNTAG)))
	{
		return;
	}

	final int id = click.getId();
	final boolean removed = npcTags.remove(id);
	final NPC[] cachedNPCs = client.getCachedNPCs();
	final NPC npc = cachedNPCs[id];

	if (npc == null || npc.getName() == null)
	{
		return;
	}

	if (removed)
	{
		highlightedNpcs.remove(npc);
		memorizedNpcs.remove(npc.getIndex());
	}
	else
	{
		if (!client.isInInstancedRegion())
		{
			memorizeNpc(npc);
			npcTags.add(id);
		}
		highlightedNpcs.add(npc);
	}

	click.consume();
}
 
Example 14
Source File: NpcIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onNpcSpawned(NpcSpawned npcSpawned)
{
	final NPC npc = npcSpawned.getNpc();
	final String npcName = npc.getName();

	if (npcName == null)
	{
		return;
	}

	if (npcTags.contains(npc.getIndex()))
	{
		memorizeNpc(npc);
		highlightedNpcs.add(npc);
		spawnedNpcsThisTick.add(npc);
		return;
	}

	for (String highlight : highlights)
	{
		if (WildcardMatcher.matches(highlight, npcName))
		{
			highlightedNpcs.add(npc);
			if (!client.isInInstancedRegion())
			{
				memorizeNpc(npc);
				spawnedNpcsThisTick.add(npc);
			}
			break;
		}
	}
}
 
Example 15
Source File: MemorizedNpc.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
MemorizedNpc(NPC npc)
{
	this.npcName = npc.getName();
	this.npcIndex = npc.getIndex();
	this.possibleRespawnLocations = new ArrayList<>();
	this.respawnTime = -1;
	this.diedOnTick = -1;

	final NPCComposition composition = npc.getTransformedComposition();

	if (composition != null)
	{
		this.npcSize = composition.getSize();
	}
}
 
Example 16
Source File: TargetMinimapOverlay.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (!config.highlightTargets())
	{
		return null;
	}

	Set<NPC> targets = plugin.getHighlightedTargets();
	for (NPC target : targets)
	{
		if (target == null || target.getName() == null)
		{
			continue;
		}

		Color coloration = config.getTargetColor();

		if (plugin.isSuperior(target.getName()))
		{
			coloration = config.getSuperiorColor();
		}

		renderTargetOverlay(graphics, target, target.getName(), coloration);
	}

	return null;
}
 
Example 17
Source File: NpcHighlightOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (plugin.getGame() == null)
	{
		return null;
	}

	HashMap highlightedNpcList = plugin.getHighlightedNpcList();

	for (NPC npc : client.getNpcs())
	{
		if (!highlightedNpcList.containsKey(npc.getId()))
		{
			continue;
		}

		NpcHighlightContext npcHighlightContext = plugin.getHighlightedNpcList().get(npc.getId());

		String name = npcHighlightContext.isShowNpcName() ? npc.getName() : null;
		Color color = npcHighlightContext.getColor();
		NpcHighlightStyle highlightStyle = npcHighlightContext.getNpcRenderStyle();

		switch (highlightStyle)
		{
			case HULL:
			{
				renderHullOverlay(graphics, npc, color);
				break;
			}
			case TILE:
			{
				renderTileOverlay(graphics, npc, color);
				break;
			}
			case BOTH:
			{
				renderHullOverlay(graphics, npc, color);
				renderTileOverlay(graphics, npc, color);
				break;
			}
		}

		if (name != null)
		{
			renderTextOverlay(graphics, npc, name, color);
		}
	}

	return null;
}
 
Example 18
Source File: NPCPresence.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
static NPCPresence buildPresence(NPC npc)
{
	return new NPCPresence(npc.getName(), npc.getCombatLevel());
}
 
Example 19
Source File: NpcIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void rebuildAllNpcs()
{
	highlightedNpcs.clear();

	if (client.getGameState() != GameState.LOGGED_IN &&
		client.getGameState() != GameState.LOADING)
	{
		// NPCs are still in the client after logging out,
		// but we don't want to highlight those.
		return;
	}

	outer:
	for (NPC npc : client.getNpcs())
	{
		final String npcName = npc.getName();

		if (npcName == null)
		{
			continue;
		}

		if (npcTags.contains(npc.getIndex()))
		{
			highlightedNpcs.add(npc);
			continue;
		}

		for (String highlight : highlights)
		{
			if (WildcardMatcher.matches(highlight, npcName))
			{
				if (!client.isInInstancedRegion())
				{
					memorizeNpc(npc);
				}
				highlightedNpcs.add(npc);
				continue outer;
			}
		}

		// NPC is not highlighted
		memorizedNpcs.remove(npc.getIndex());
	}
}