Refactor NpcIndicators functions
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.npchighlight;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
@@ -77,12 +76,4 @@ class MemorizedNpc
|
||||
this.npcSize = composition.getSize();
|
||||
}
|
||||
}
|
||||
|
||||
public double getSecondsFromRespawn(int tickCount, Instant lastTickUpdate)
|
||||
{
|
||||
final Instant now = Instant.now();
|
||||
final double baseTick = NpcIndicatorsPlugin.ESTIMATED_TICK_LENGTH * (diedOnTick + respawnTime - tickCount);
|
||||
final double sinceLast = (now.toEpochMilli() - lastTickUpdate.toEpochMilli()) / 1000.0;
|
||||
return Math.max(0.0, baseTick - sinceLast);
|
||||
}
|
||||
}
|
||||
@@ -74,10 +74,15 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
{
|
||||
private static final int MAX_ACTOR_VIEW_RANGE = 15;
|
||||
|
||||
public static final NumberFormat TIME_LEFT_FORMATTER = DecimalFormat.getInstance(Locale.US);
|
||||
|
||||
// Estimated time of a game tick in seconds
|
||||
public static final double ESTIMATED_TICK_LENGTH = 0.6;
|
||||
private static final double ESTIMATED_TICK_LENGTH = 0.6;
|
||||
|
||||
private static final NumberFormat TIME_LEFT_FORMATTER = DecimalFormat.getInstance(Locale.getDefault());
|
||||
|
||||
static
|
||||
{
|
||||
((DecimalFormat)TIME_LEFT_FORMATTER).applyPattern("#0.0");
|
||||
}
|
||||
|
||||
// Option added to NPC menu
|
||||
private static final String TAG = "Tag";
|
||||
@@ -88,11 +93,6 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
// Regex for splitting the hidden items in the config.
|
||||
private static final Splitter COMMA_SPLITTER = Splitter.on(",").omitEmptyStrings().trimResults();
|
||||
|
||||
static
|
||||
{
|
||||
((DecimalFormat)TIME_LEFT_FORMATTER).applyPattern("#0.0");
|
||||
}
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@@ -417,6 +417,16 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
return new WorldPoint(currWP.getX() - dx, currWP.getY() - dy, currWP.getPlane());
|
||||
}
|
||||
|
||||
public double getTimeLeftForNpc(MemorizedNpc npc)
|
||||
{
|
||||
final Instant now = Instant.now();
|
||||
final double baseTick = NpcIndicatorsPlugin.ESTIMATED_TICK_LENGTH * (
|
||||
npc.getDiedOnTick() + npc.getRespawnTime() - client.getTickCount()
|
||||
);
|
||||
final double sinceLast = (now.toEpochMilli() - lastTickUpdate.toEpochMilli()) / 1000.0;
|
||||
return Math.max(0.0, baseTick - sinceLast);
|
||||
}
|
||||
|
||||
private void memorizeNpc(NPC npc)
|
||||
{
|
||||
final int npcIndex = npc.getIndex();
|
||||
@@ -503,6 +513,11 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public String formatTime(double time)
|
||||
{
|
||||
return TIME_LEFT_FORMATTER.format(time);
|
||||
}
|
||||
|
||||
private void checkNotifyNpcs()
|
||||
{
|
||||
if (!config.getNotifyOnRespawn())
|
||||
@@ -511,14 +526,13 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
}
|
||||
|
||||
final double notifyDelay = ((double)config.getNotifyOnRespawnDelay()) / 1000;
|
||||
final int tickCount = client.getTickCount();
|
||||
final String notifyDelayStr = notifyDelay > 0
|
||||
? " is less than " + TIME_LEFT_FORMATTER.format(notifyDelay) + " seconds from respawn"
|
||||
? " is less than " + formatTime(notifyDelay) + " seconds from respawn"
|
||||
: " respawned.";
|
||||
|
||||
for (MemorizedNpc npc : pendingNotificationNpcs)
|
||||
{
|
||||
if (npc.getSecondsFromRespawn(tickCount, lastTickUpdate) <= notifyDelay)
|
||||
if (getTimeLeftForNpc(npc) <= notifyDelay)
|
||||
{
|
||||
pendingNotificationNpcs.remove(npc);
|
||||
notifier.notify(npc.getNpcName() + notifyDelayStr);
|
||||
|
||||
@@ -107,10 +107,7 @@ public class NpcSceneOverlay extends Overlay
|
||||
OverlayUtil.renderPolygon(graphics, poly, color);
|
||||
}
|
||||
|
||||
final String timeLeftStr = NpcIndicatorsPlugin.TIME_LEFT_FORMATTER.format(npc.getSecondsFromRespawn(
|
||||
client.getTickCount(),
|
||||
plugin.getLastTickUpdate()
|
||||
));
|
||||
final String timeLeftStr = plugin.formatTime(plugin.getTimeLeftForNpc(npc));
|
||||
|
||||
final int textWidth = graphics.getFontMetrics().stringWidth(timeLeftStr);
|
||||
final int textHeight = graphics.getFontMetrics().getAscent();
|
||||
|
||||
Reference in New Issue
Block a user