FreezeTimers Added Functionality (#204)
This commit is contained in:
@@ -7,26 +7,70 @@ import net.runelite.client.config.ConfigItem;
|
||||
@ConfigGroup("freezetimers")
|
||||
public interface FreezeTimersConfig extends Config
|
||||
{
|
||||
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showOverlay",
|
||||
name = "Show Players",
|
||||
description = "Configure if the player overlay should be shown",
|
||||
position = 1
|
||||
keyName = "showOverlay",
|
||||
name = "Show Players",
|
||||
description = "Configure if the player overlay should be shown",
|
||||
position = 1
|
||||
)
|
||||
default boolean showPlayers()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showNpcs",
|
||||
name = "Show NPCs",
|
||||
description = "Configure if the npc overlay should be shown",
|
||||
position = 2
|
||||
keyName = "showNpcs",
|
||||
name = "Show NPCs",
|
||||
description = "Configure if the npc overlay should be shown",
|
||||
position = 2
|
||||
)
|
||||
default boolean showNpcs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "FreezeTimers",
|
||||
name = "Show Freeze Timers",
|
||||
description = "Toggle overlay for Freeze timers",
|
||||
position = 3
|
||||
)
|
||||
default boolean FreezeTimers()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "TB",
|
||||
name = "Show TB Timers",
|
||||
description = "Toggle overlay for TB timers",
|
||||
position = 4
|
||||
)
|
||||
default boolean TB()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "Veng",
|
||||
name = "Show Veng Timers",
|
||||
description = "Toggle overlay for Veng timers",
|
||||
position = 5
|
||||
)
|
||||
default boolean Veng()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "noImage",
|
||||
name = "Text Timers",
|
||||
description = "Remove Images from Timers",
|
||||
position = 6
|
||||
)
|
||||
default boolean noImage()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
package net.runelite.client.plugins.freezetimers;
|
||||
|
||||
import java.awt.Color;
|
||||
import static java.awt.Color.RED;
|
||||
import static java.awt.Color.WHITE;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GraphicID;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
@@ -13,28 +22,21 @@ import net.runelite.client.ui.overlay.OverlayPriority;
|
||||
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import static java.awt.Color.RED;
|
||||
import static java.awt.Color.WHITE;
|
||||
import static java.awt.Color.green;
|
||||
|
||||
public class FreezeTimersOverlay extends Overlay
|
||||
{
|
||||
|
||||
@Inject
|
||||
private Timers timers;
|
||||
|
||||
|
||||
private final FreezeTimersConfig config;
|
||||
private final Client client;
|
||||
private final Font timerFont = FontManager.getRunescapeBoldFont().deriveFont(14.0f);
|
||||
private final BufferedImage FREEZE_IMAGE = ImageUtil.getResourceStreamFromClass(getClass(), "freeze.png");
|
||||
private final BufferedImage TB_IMAGE = ImageUtil.getResourceStreamFromClass(getClass(), "teleblock.png");
|
||||
private final BufferedImage VENG_IMAGE = ImageUtil.getResourceStreamFromClass(getClass(), "veng.png");
|
||||
|
||||
@Inject
|
||||
private Timers timers;
|
||||
private boolean lock;
|
||||
private long finishedAtTest;
|
||||
private Actor player;
|
||||
|
||||
@Inject
|
||||
public FreezeTimersOverlay(FreezeTimersConfig config, Client client)
|
||||
{
|
||||
@@ -44,7 +46,7 @@ public class FreezeTimersOverlay extends Overlay
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
setLayer(OverlayLayer.UNDER_WIDGETS);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
@@ -58,30 +60,30 @@ public class FreezeTimersOverlay extends Overlay
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void renderOverlayFor(Graphics2D g, Actor actor)
|
||||
{
|
||||
if (timers.areAllTimersZero(actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int overlaysDrawn = 0;
|
||||
|
||||
if (drawFreezeOverlay(g, actor, overlaysDrawn))
|
||||
|
||||
if (drawFreezeOverlay(g, actor, overlaysDrawn) && config.FreezeTimers())
|
||||
{
|
||||
overlaysDrawn++;
|
||||
}
|
||||
if (drawTBOverlay(g, actor, overlaysDrawn))
|
||||
if (drawTBOverlay(g, actor, overlaysDrawn) && config.TB())
|
||||
{
|
||||
overlaysDrawn++;
|
||||
}
|
||||
if (drawVengOverlay(g, actor, overlaysDrawn))
|
||||
if (drawVengOverlay(g, actor, overlaysDrawn) && config.Veng())
|
||||
{
|
||||
overlaysDrawn++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean drawFreezeOverlay(Graphics2D g, Actor actor, int overlaysDrawn)
|
||||
{
|
||||
long currentTick = System.currentTimeMillis();
|
||||
@@ -90,13 +92,24 @@ public class FreezeTimersOverlay extends Overlay
|
||||
return false;
|
||||
}
|
||||
long finishedAt = timers.getTimerEnd(actor, TimerType.FREEZE);
|
||||
|
||||
|
||||
String text = processTickCounter(finishedAt);
|
||||
|
||||
renderActorText(g, actor, text, overlaysDrawn, FREEZE_IMAGE);
|
||||
Point poi = actor.getCanvasTextLocation(g, text, 0);
|
||||
int xpoi = poi.getX();
|
||||
int ypoi = poi.getY();
|
||||
Point FixedPoint = new Point(xpoi, ypoi);
|
||||
|
||||
if (config.noImage())
|
||||
{
|
||||
renderTextLocation(g, text, 11, Font.BOLD, Color.WHITE, FixedPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderActorText(g, actor, text, overlaysDrawn, FREEZE_IMAGE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean drawTBOverlay(Graphics2D g, Actor actor, int overlaysDrawn)
|
||||
{
|
||||
long currentTick = System.currentTimeMillis();
|
||||
@@ -105,13 +118,31 @@ public class FreezeTimersOverlay extends Overlay
|
||||
return false;
|
||||
}
|
||||
long finishedAt = timers.getTimerEnd(actor, TimerType.TELEBLOCK);
|
||||
|
||||
|
||||
String text = processTickCounter(finishedAt);
|
||||
|
||||
renderActorText(g, actor, text, overlaysDrawn, TB_IMAGE);
|
||||
Point poi = actor.getCanvasTextLocation(g, text, 0);
|
||||
int xpoi = poi.getX() + 20;
|
||||
int ypoi = poi.getY();
|
||||
Point FixedPoint = new Point(xpoi, ypoi);
|
||||
|
||||
if (config.noImage())
|
||||
{
|
||||
if (timers.getTimerEnd(actor, TimerType.FREEZE) <= currentTick)
|
||||
{
|
||||
renderTextLocation(g, text, 11, Font.BOLD, Color.CYAN, poi);
|
||||
}
|
||||
if (timers.getTimerEnd(actor, TimerType.FREEZE) >= currentTick)
|
||||
{
|
||||
renderTextLocation(g, " | " + text, 11, Font.BOLD, Color.CYAN, FixedPoint);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
renderActorText(g, actor, text, overlaysDrawn, TB_IMAGE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean drawVengOverlay(Graphics2D g, Actor actor, int overlaysDrawn)
|
||||
{
|
||||
long currentTick = System.currentTimeMillis();
|
||||
@@ -120,25 +151,42 @@ public class FreezeTimersOverlay extends Overlay
|
||||
return false;
|
||||
}
|
||||
long finishedAt = timers.getTimerEnd(actor, TimerType.VENG);
|
||||
|
||||
|
||||
String text = processTickCounter(finishedAt);
|
||||
|
||||
renderActorText(g, actor, text, overlaysDrawn, VENG_IMAGE);
|
||||
Point poi = actor.getCanvasTextLocation(g, text, 0);
|
||||
int xpoi = poi.getX() - 20;
|
||||
int ypoi = poi.getY();
|
||||
Point FixedPoint = new Point(xpoi, ypoi);
|
||||
if (config.noImage())
|
||||
{
|
||||
if (timers.getTimerEnd(actor, TimerType.FREEZE) <= currentTick)
|
||||
{
|
||||
renderTextLocation(g, text, 11, Font.BOLD, Color.RED, poi);
|
||||
}
|
||||
if (timers.getTimerEnd(actor, TimerType.FREEZE) >= currentTick)
|
||||
{
|
||||
renderTextLocation(g, text + " | ", 11, Font.BOLD, Color.RED, FixedPoint);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
renderActorText(g, actor, text, overlaysDrawn, VENG_IMAGE);
|
||||
}
|
||||
if (actor.getGraphic() == GraphicID.VENGEANCE || actor.getGraphic() == GraphicID.VENGEANCE_OTHER)
|
||||
{
|
||||
|
||||
|
||||
g.setColor(RED);
|
||||
Polygon poly = actor.getCanvasTilePoly();
|
||||
if (poly != null)
|
||||
{
|
||||
OverlayUtil.renderPolygon(g, poly, RED);
|
||||
}
|
||||
OverlayUtil.renderTextLocation(g, new Point((int)poly.getBounds2D().getCenterX(),
|
||||
(int)poly.getBounds2D().getCenterY()), actor.getName(), RED);
|
||||
OverlayUtil.renderTextLocation(g, new Point((int) poly.getBounds2D().getCenterX(),
|
||||
(int) poly.getBounds2D().getCenterY()), actor.getName(), RED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void renderActorText(Graphics2D g, Actor actor, String text, int overlaysDrawn, BufferedImage image)
|
||||
{
|
||||
int yOffset = (overlaysDrawn * 18);
|
||||
@@ -147,9 +195,25 @@ public class FreezeTimersOverlay extends Overlay
|
||||
Rectangle rect = actor.getConvexHull().getBounds();
|
||||
int xOffset = (int) rect.getWidth();
|
||||
OverlayUtil.renderActorTextAndImage(g, actor, text, Color.WHITE, image, yOffset,
|
||||
xOffset);
|
||||
xOffset);
|
||||
}
|
||||
|
||||
|
||||
private void renderTextLocation(Graphics2D graphics, String txtString, int fontSize, int fontStyle, Color fontColor, Point canvasPoint)
|
||||
{
|
||||
graphics.setFont(new Font("Arial", fontStyle, fontSize));
|
||||
if (canvasPoint != null)
|
||||
{
|
||||
final Point canvasCenterPoint = new Point(
|
||||
canvasPoint.getX(),
|
||||
canvasPoint.getY());
|
||||
final Point canvasCenterPoint_shadow = new Point(
|
||||
canvasPoint.getX() + 1,
|
||||
canvasPoint.getY() + 1);
|
||||
OverlayUtil.renderTextLocation(graphics, canvasCenterPoint_shadow, txtString, Color.BLACK);
|
||||
OverlayUtil.renderTextLocation(graphics, canvasCenterPoint, txtString, fontColor);
|
||||
}
|
||||
}
|
||||
|
||||
private String processTickCounter(long finishedAt)
|
||||
{
|
||||
long currentTick = System.currentTimeMillis();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.runelite.client.plugins.freezetimers;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.GraphicChanged;
|
||||
@@ -8,52 +9,49 @@ import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.plugins.PluginManager;
|
||||
import net.runelite.client.plugins.PluginType;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Freeze Timers",
|
||||
description = "Shows a freeze timer overlay on players",
|
||||
tags = {"freeze", "timers", "barrage", "teleblock", "pklite"},
|
||||
type = PluginType.PVP
|
||||
name = "Freeze Timers",
|
||||
description = "Shows a freeze timer overlay on players",
|
||||
tags = {"freeze", "timers", "barrage", "teleblock", "pklite"},
|
||||
type = PluginType.PVP
|
||||
)
|
||||
public class FreezeTimersPlugin extends Plugin
|
||||
{
|
||||
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
|
||||
@Inject
|
||||
private Timers timers;
|
||||
|
||||
|
||||
@Inject
|
||||
private PrayerTracker prayerTracker;
|
||||
|
||||
|
||||
@Inject
|
||||
private FreezeTimersOverlay overlay;
|
||||
|
||||
|
||||
public void startUp()
|
||||
{
|
||||
overlayManager.add(overlay);
|
||||
}
|
||||
|
||||
|
||||
public void shutDown()
|
||||
{
|
||||
overlayManager.remove(overlay);
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
public FreezeTimersConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
return configManager.getConfig(FreezeTimersConfig.class);
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onGraphicChanged(GraphicChanged graphicChanged)
|
||||
{
|
||||
@@ -73,15 +71,19 @@ public class FreezeTimersPlugin extends Plugin
|
||||
{
|
||||
length /= 2;
|
||||
}
|
||||
if (timers.getTimerEnd(graphicChanged.getActor(), effect.getType()) > System.currentTimeMillis())
|
||||
{
|
||||
return;
|
||||
}
|
||||
timers.setTimerEnd(graphicChanged.getActor(), effect.getType(),
|
||||
System.currentTimeMillis() + length);
|
||||
System.currentTimeMillis() + length);
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onGameTick(GameTick tickEvent)
|
||||
{
|
||||
timers.gameTick();
|
||||
prayerTracker.gameTick();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public enum PlayerSpellEffect
|
||||
{
|
||||
BIND("Bind", 181,5000, true, 0, TimerType.FREEZE),
|
||||
BIND("Bind", 181, 5000, true, 0, TimerType.FREEZE),
|
||||
SNARE("Snare", 180, 10000, true, 1, TimerType.FREEZE),
|
||||
ENTANGLE("Entangle", 179, 15000, true, 2, TimerType.FREEZE),
|
||||
RUSH("Ice Rush", 361, 5000, false, 3, TimerType.FREEZE),
|
||||
@@ -17,7 +17,7 @@ public enum PlayerSpellEffect
|
||||
VENG("Vengeance", 726, 30000, false, 8, TimerType.VENG),
|
||||
VENG_OTHER("Vengeance Other", 725, 30000, false, 9, TimerType.VENG),
|
||||
NONE("Nothing", -69, 420, true, 9999, TimerType.THIS_SHIT_BROKE);
|
||||
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
@Getter
|
||||
@@ -30,7 +30,7 @@ public enum PlayerSpellEffect
|
||||
private final int spriteIdx;
|
||||
@Getter
|
||||
private final TimerType type;
|
||||
|
||||
|
||||
public static PlayerSpellEffect getFromSpotAnim(int spotAnim)
|
||||
{
|
||||
for(PlayerSpellEffect effect : values())
|
||||
@@ -40,5 +40,5 @@ public enum PlayerSpellEffect
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
package net.runelite.client.plugins.freezetimers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
public class PrayerTracker
|
||||
{
|
||||
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
|
||||
private HashMap<Actor, HashMap<String, Integer>> lastTick = new HashMap<>();
|
||||
private HashMap<Actor, HashMap<String, Integer>> newTick = new HashMap<>();
|
||||
|
||||
|
||||
public void gameTick()
|
||||
{
|
||||
lastTick.clear();
|
||||
@@ -35,7 +34,7 @@ public class PrayerTracker
|
||||
processActor(npc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processActor(Actor actor)
|
||||
{
|
||||
if (!newTick.containsKey(actor))
|
||||
@@ -43,20 +42,23 @@ public class PrayerTracker
|
||||
newTick.put(actor, new HashMap<>());
|
||||
}
|
||||
if (actor instanceof Player)
|
||||
if(actor instanceof Player) {
|
||||
{
|
||||
if (actor instanceof Player)
|
||||
{
|
||||
newTick.get(actor).put("PrayerIcon", ((Player) actor).getOverheadIcon() == null ? -1 : ((Player) actor).getOverheadIcon().ordinal());
|
||||
}
|
||||
}
|
||||
newTick.get(actor).put("SpotAnim", actor.getGraphic());
|
||||
}
|
||||
|
||||
|
||||
public int getPrayerIconLastTick(Actor p)
|
||||
{
|
||||
return lastTick.getOrDefault(p, new HashMap<>()).getOrDefault("PrayerIcon", -1337);
|
||||
}
|
||||
|
||||
|
||||
public int getSpotanimLastTick(Actor p)
|
||||
{
|
||||
return lastTick.getOrDefault(p, new HashMap<>()).getOrDefault("SpotAnim", -1337);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ public enum TimerType
|
||||
FREEZE,
|
||||
VENG,
|
||||
TELEBLOCK,
|
||||
THIS_SHIT_BROKE;
|
||||
THIS_SHIT_BROKE
|
||||
}
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
package net.runelite.client.plugins.freezetimers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
public class Timers
|
||||
{
|
||||
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
|
||||
private HashMap<Actor, HashMap<TimerType, Long>> timerMap = new HashMap<>();
|
||||
|
||||
|
||||
public void gameTick()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setTimerEnd(Actor actor, TimerType type, long n)
|
||||
{
|
||||
if (!timerMap.containsKey(actor))
|
||||
@@ -32,16 +30,16 @@ public class Timers
|
||||
}
|
||||
timerMap.get(actor).put(type, n);
|
||||
}
|
||||
|
||||
|
||||
public long getTimerEnd(Actor actor, TimerType type)
|
||||
{
|
||||
if (!timerMap.containsKey(actor))
|
||||
{
|
||||
timerMap.put(actor, new HashMap<>());
|
||||
}
|
||||
return timerMap.get(actor).getOrDefault(type, (long)0);
|
||||
return timerMap.get(actor).getOrDefault(type, (long) 0);
|
||||
}
|
||||
|
||||
|
||||
public boolean areAllTimersZero(Actor actor)
|
||||
{
|
||||
for (TimerType type : TimerType.values())
|
||||
@@ -53,5 +51,5 @@ public class Timers
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user