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

The following examples show how to use net.runelite.api.NPC#getWorldLocation() . 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: CombatCounter.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private int calculateDistance(Player p, NPC npc)
{
	int size = 1;
	NPCDefinition comp = npc.getTransformedDefinition();
	if (comp != null)
	{
		size = comp.getSize();
	}

	WorldPoint wpPlayer = p.getWorldLocation();
	WorldPoint wpNPC = npc.getWorldLocation();
	int distance = wpNPC.distanceTo(wpPlayer);

	if (size > 1)
	{
		for (int x = 0; x < size; x++)
		{
			for (int y = 0; y < size; y++)
			{
				WorldPoint wpNPCB = WorldPoint.fromRegion(wpNPC.getRegionID(), wpNPC.getRegionX() + x, wpNPC.getRegionY() + y, wpNPC.getPlane());
				int distB = wpNPCB.distanceTo(wpPlayer);
				if (distB >= 1 && distB < distance)
				{
					distance = distB;
				}
			}
		}
	}

	return distance;
}
 
Example 2
Source File: NpcIndicatorsPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private static WorldPoint getWorldLocationBehind(NPC npc)
{
	final int orientation = npc.getOrientation() / 256;
	int dx = 0, dy = 0;

	switch (orientation)
	{
		case 0: // South
			dy = -1;
			break;
		case 1: // Southwest
			dx = -1;
			dy = -1;
			break;
		case 2: // West
			dx = -1;
			break;
		case 3: // Northwest
			dx = -1;
			dy = 1;
			break;
		case 4: // North
			dy = 1;
			break;
		case 5: // Northeast
			dx = 1;
			dy = 1;
			break;
		case 6: // East
			dx = 1;
			break;
		case 7: // Southeast
			dx = 1;
			dy = -1;
			break;
	}

	final WorldPoint currWP = npc.getWorldLocation();
	return new WorldPoint(currWP.getX() - dx, currWP.getY() - dy, currWP.getPlane());
}
 
Example 3
Source File: LootManager.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private WorldPoint getAdjacentSquareLootTile(NPC npc)
{
	final NPCComposition composition = npc.getComposition();
	final WorldPoint worldLocation = npc.getWorldLocation();
	int x = worldLocation.getX();
	int y = worldLocation.getY();

	if (playerLocationLastTick.getX() < x)
	{
		x -= 1;
	}
	else
	{
		x += Math.min(playerLocationLastTick.getX() - x, composition.getSize());
	}

	if (playerLocationLastTick.getY() < y)
	{
		y -= 1;
	}
	else
	{
		y += Math.min(playerLocationLastTick.getY() - y, composition.getSize());
	}

	return new WorldPoint(x, y, worldLocation.getPlane());
}
 
Example 4
Source File: NpcIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static WorldPoint getWorldLocationBehind(NPC npc)
{
	final int orientation = npc.getOrientation() / 256;
	int dx = 0, dy = 0;

	switch (orientation)
	{
		case 0: // South
			dy = -1;
			break;
		case 1: // Southwest
			dx = -1;
			dy = -1;
			break;
		case 2: // West
			dx = -1;
			break;
		case 3: // Northwest
			dx = -1;
			dy = 1;
			break;
		case 4: // North
			dy = 1;
			break;
		case 5: // Northeast
			dx = 1;
			dy = 1;
			break;
		case 6: // East
			dx = 1;
			break;
		case 7: // Southeast
			dx = 1;
			dy = -1;
			break;
	}

	final WorldPoint currWP = npc.getWorldLocation();
	return new WorldPoint(currWP.getX() - dx, currWP.getY() - dy, currWP.getPlane());
}
 
Example 5
Source File: WikiPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
private void onMenuOptionClicked(MenuOptionClicked ev)
{
	if (ev.getMenuOpcode() == MenuOpcode.RUNELITE)
	{
		checkQuestClicked(ev);
	}

	if (!wikiSelected)
	{
		return;
	}

	onDeselect();
	client.setSpellSelected(false);
	ev.consume();

	String type;
	int id;
	String name;
	WorldPoint location;

	switch (ev.getMenuOpcode())
	{
		case RUNELITE:
		case CANCEL:
			return;
		case ITEM_USE_ON_WIDGET:
		case SPELL_CAST_ON_GROUND_ITEM:
		{
			type = "item";
			id = itemManager.canonicalize(ev.getIdentifier());
			name = itemManager.getItemDefinition(id).getName();
			location = null;
			break;
		}
		case SPELL_CAST_ON_NPC:
		{
			type = "npc";
			NPC npc = client.getCachedNPCs()[ev.getIdentifier()];
			NPCDefinition nc = npc.getTransformedDefinition();
			id = nc.getId();
			name = nc.getName();
			location = npc.getWorldLocation();
			break;
		}
		case SPELL_CAST_ON_GAME_OBJECT:
		{
			type = "object";
			ObjectDefinition lc = client.getObjectDefinition(ev.getIdentifier());
			if (lc.getImpostorIds() != null)
			{
				lc = lc.getImpostor();
			}
			id = lc.getId();
			name = lc.getName();
			location = WorldPoint.fromScene(client, ev.getParam0(), ev.getParam1(), client.getPlane());
			break;
		}
		case SPELL_CAST_ON_WIDGET:
		{
			Widget w = getWidget(ev.getParam1(), ev.getParam0());

			if (w.getType() == WidgetType.GRAPHIC && w.getItemId() != -1)
			{
				type = "item";
				id = itemManager.canonicalize(w.getItemId());
				name = itemManager.getItemDefinition(id).getName();
				location = null;
				break;
			}
		}
			// fallthrough
		default:
			log.info("Unknown menu option: {} {} {}", ev, ev.getMenuOpcode(), ev.getMenuOpcode() == MenuOpcode.CANCEL);
			return;
	}

	name = Text.removeTags(name);
	HttpUrl.Builder urlBuilder = WIKI_BASE.newBuilder();
	urlBuilder.addPathSegments("w/Special:Lookup")
		.addQueryParameter("type", type)
		.addQueryParameter("id", "" + id)
		.addQueryParameter("name", name)
		.addQueryParameter(UTM_SOURCE_KEY, UTM_SOURCE_VALUE);

	if (location != null)
	{
		urlBuilder.addQueryParameter("x", "" + location.getX())
			.addQueryParameter("y", "" + location.getY())
			.addQueryParameter("plane", "" + location.getPlane());
	}

	HttpUrl url = urlBuilder.build();

	LinkBrowser.browse(url.toString());
}
 
Example 6
Source File: TargetClickboxOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void renderNpcOverlay(Graphics2D graphics, NPC actor, Color color)
{
	switch (config.renderStyle())
	{
		case SOUTH_WEST_TILE:
			LocalPoint lp1 = LocalPoint.fromWorld(client, actor.getWorldLocation());

			if (lp1 == null)
			{
				return;
			}

			Polygon tilePoly1 = Perspective.getCanvasTilePoly(client, lp1);

			OverlayUtil.renderPolygon(graphics, tilePoly1, color);
			break;

		case TILE:
			int size = 1;
			NPCDefinition composition = actor.getTransformedDefinition();

			if (composition != null)
			{
				size = composition.getSize();
			}

			LocalPoint lp = actor.getLocalLocation();
			Polygon tilePoly = Perspective.getCanvasTileAreaPoly(client, lp, size);

			OverlayUtil.renderPolygon(graphics, tilePoly, color);
			break;

		case HULL:
			Shape objectClickbox = actor.getConvexHull();

			if (objectClickbox == null)
			{
				return;
			}

			OverlayUtil.renderPolygon(graphics, objectClickbox, color);
			break;
		case THIN_OUTLINE:
			modelOutliner.drawOutline(actor, 1, color);
			break;

		case OUTLINE:
			modelOutliner.drawOutline(actor, 2, color);
			break;

		case THIN_GLOW:
			modelOutliner.drawOutline(actor, 4, color, TRANSPARENT);
			break;

		case GLOW:
			modelOutliner.drawOutline(actor, 8, color, TRANSPARENT);
			break;
		case TRUE_LOCATIONS:
			size = 1;
			composition = actor.getTransformedDefinition();

			if (composition != null)
			{
				size = composition.getSize();
			}

			WorldPoint wp = actor.getWorldLocation();
			getSquare(wp, size).forEach(square ->
				drawTile(graphics, square, color, 1, 255, 50));
			break;
	}

	if (config.drawNames())
	{
		String npcName = Text.removeTags(actor.getName());
		Point textLocation = actor.getCanvasTextLocation(graphics, npcName, actor.getLogicalHeight() + 40);

		if (textLocation != null)
		{
			OverlayUtil.renderTextLocation(graphics, textLocation, npcName, color);
		}
	}
}
 
Example 7
Source File: CorpDamageOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	Widget damageWidget = client.getWidget(WidgetID.CORP_DAMAGE, 0);
	if (damageWidget != null)
	{
		damageWidget.setHidden(true);
	}

	NPC corp = corpPlugin.getCorp();
	if (corp == null)
	{
		return null;
	}

	int myDamage = client.getVar(Varbits.CORP_DAMAGE);
	int totalDamage = corpPlugin.getTotalDamage();
	int players = corpPlugin.getPlayers().size();

	// estimate how much damage is required for kill based on number of players
	int damageForKill = players != 0 ? totalDamage / players : 0;

	TableComponent tableComponent = new TableComponent();
	tableComponent.setColumnAlignments(TableAlignment.LEFT, TableAlignment.RIGHT);

	NPC core = corpPlugin.getCore();
	if (core != null)
	{
		WorldPoint corePoint = core.getWorldLocation();
		WorldPoint myPoint = client.getLocalPlayer().getWorldLocation();

		String text = null;

		if (core.getInteracting() == client.getLocalPlayer())
		{
			text = "The core is targeting you!";
		}
		else if (corePoint.distanceTo(myPoint) <= 1)
		{
			text = "Stay away from the core!";
		}

		if (text != null)
		{
			final FontMetrics fontMetrics = graphics.getFontMetrics();
			int textWidth = Math.max(ComponentConstants.STANDARD_WIDTH, fontMetrics.stringWidth(text));

			panelComponent.setPreferredSize(new Dimension(textWidth, 0));
			tableComponent.addRow(ColorUtil.prependColorTag(text, Color.RED), "");
		}
	}

	if (config.showDamage())
	{
		tableComponent.addRow("Your damage", ColorUtil.prependColorTag(Integer.toString(myDamage), damageForKill > 0 && myDamage >= damageForKill ? Color.GREEN : Color.RED));
		tableComponent.addRow("Total damage:", Integer.toString(totalDamage));
	}

	panelComponent.getChildren().add(tableComponent);
	return super.render(graphics);
}
 
Example 8
Source File: CorpDamageOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	Widget damageWidget = client.getWidget(WidgetID.CORP_DAMAGE, 0);
	if (damageWidget != null)
	{
		damageWidget.setHidden(true);
	}

	NPC corp = corpPlugin.getCorp();
	if (corp == null)
	{
		return null;
	}

	int myDamage = client.getVar(Varbits.CORP_DAMAGE);
	int totalDamage = corpPlugin.getTotalDamage();
	int players = corpPlugin.getPlayers().size();

	// estimate how much damage is required for kill based on number of players
	int damageForKill = players != 0 ? totalDamage / players : 0;

	NPC core = corpPlugin.getCore();
	if (core != null)
	{
		WorldPoint corePoint = core.getWorldLocation();
		WorldPoint myPoint = client.getLocalPlayer().getWorldLocation();

		String text = null;

		if (core.getInteracting() == client.getLocalPlayer())
		{
			text = "The core is targeting you!";
		}
		else if (corePoint.distanceTo(myPoint) <= 1)
		{
			text = "Stay away from the core!";
		}

		if (text != null)
		{
			final FontMetrics fontMetrics = graphics.getFontMetrics();
			int textWidth = Math.max(ComponentConstants.STANDARD_WIDTH, fontMetrics.stringWidth(text));

			panelComponent.setPreferredSize(new Dimension(textWidth, 0));
			panelComponent.getChildren().add(LineComponent.builder()
				.left(text)
				.leftColor(Color.RED)
				.build());
		}
	}

	if (config.showDamage())
	{
		panelComponent.getChildren().add(LineComponent.builder()
			.left("Your damage")
			.right(Integer.toString(myDamage))
			.rightColor(damageForKill > 0 && myDamage >= damageForKill ? Color.GREEN : Color.RED)
			.build());

		panelComponent.getChildren().add(LineComponent.builder()
			.left("Total damage")
			.right(Integer.toString(totalDamage))
			.build());
	}

	return super.render(graphics);
}