prayer: display prayer time remaining in prayer orb
This commit is contained in:
@@ -324,6 +324,7 @@ public class WidgetID
|
||||
static final int HEALTH_ORB = 2;
|
||||
static final int PRAYER_ORB = 12;
|
||||
static final int QUICK_PRAYER_ORB = 14; // Has the "Quick-prayers" name
|
||||
static final int PRAYER_ORB_TEXT = 15;
|
||||
static final int RUN_ORB = 20;
|
||||
static final int TOGGLE_RUN_ORB = 22; // Has the "Toggle run" name
|
||||
static final int RUN_ORB_TEXT = 23;
|
||||
|
||||
@@ -165,6 +165,7 @@ public enum WidgetInfo
|
||||
MINIMAP_XP_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.XP_ORB),
|
||||
MINIMAP_PRAYER_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.PRAYER_ORB),
|
||||
MINIMAP_QUICK_PRAYER_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.QUICK_PRAYER_ORB),
|
||||
MINIMAP_PRAYER_ORB_TEXT(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.PRAYER_ORB_TEXT),
|
||||
MINIMAP_RUN_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.RUN_ORB),
|
||||
MINIMAP_TOGGLE_RUN_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.TOGGLE_RUN_ORB),
|
||||
MINIMAP_RUN_ORB_TEXT(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.RUN_ORB_TEXT),
|
||||
|
||||
@@ -129,4 +129,15 @@ public interface PrayerConfig extends Config
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 9,
|
||||
keyName = "replaceOrbText",
|
||||
name = "Replace orb text with prayer time left",
|
||||
description = "Show time remaining of current prayers in the prayer orb."
|
||||
)
|
||||
default boolean replaceOrbText()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ import lombok.Setter;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Constants;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.Prayer;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
@@ -47,7 +46,6 @@ import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
||||
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
class PrayerDoseOverlay extends Overlay
|
||||
{
|
||||
@@ -57,13 +55,12 @@ class PrayerDoseOverlay extends Overlay
|
||||
private static final Color END_COLOR = new Color(0, 92, 92);
|
||||
|
||||
private final Client client;
|
||||
private final PrayerPlugin plugin;
|
||||
private final PrayerConfig config;
|
||||
private final TooltipManager tooltipManager;
|
||||
private Instant startOfLastTick = Instant.now();
|
||||
private boolean trackTick = true;
|
||||
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private int prayerBonus;
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private boolean hasPrayerRestore;
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
@@ -72,10 +69,11 @@ class PrayerDoseOverlay extends Overlay
|
||||
private boolean hasHolyWrench;
|
||||
|
||||
@Inject
|
||||
private PrayerDoseOverlay(final Client client, final TooltipManager tooltipManager, final PrayerConfig config)
|
||||
private PrayerDoseOverlay(final Client client, final TooltipManager tooltipManager, final PrayerPlugin plugin, final PrayerConfig config)
|
||||
{
|
||||
this.client = client;
|
||||
this.tooltipManager = tooltipManager;
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
||||
@@ -114,11 +112,19 @@ class PrayerDoseOverlay extends Overlay
|
||||
|
||||
if (config.showPrayerStatistics() && bounds.contains(mousePosition.getX(), mousePosition.getY()))
|
||||
{
|
||||
final String tooltip = "Time Remaining: " + getEstimatedTimeRemaining() +
|
||||
"</br>" +
|
||||
"Prayer Bonus: " + prayerBonus;
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
tooltipManager.add(new Tooltip(tooltip));
|
||||
if (config.replaceOrbText())
|
||||
{
|
||||
sb.append("Prayer points remaining: ").append(client.getBoostedSkillLevel(Skill.PRAYER));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append("Time Remaining: ").append(plugin.getEstimatedTimeRemaining(false));
|
||||
}
|
||||
|
||||
sb.append("</br>").append("Prayer Bonus: ").append(plugin.getPrayerBonus());
|
||||
tooltipManager.add(new Tooltip(sb.toString()));
|
||||
}
|
||||
|
||||
if (!config.showPrayerDoseIndicator() || !hasPrayerRestore)
|
||||
@@ -163,42 +169,4 @@ class PrayerDoseOverlay extends Overlay
|
||||
return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight());
|
||||
}
|
||||
|
||||
private double getPrayerDrainRate(Client client)
|
||||
{
|
||||
double drainRate = 0.0;
|
||||
|
||||
for (Prayer prayer : Prayer.values())
|
||||
{
|
||||
if (client.isPrayerActive(prayer))
|
||||
{
|
||||
drainRate += prayer.getDrainRate();
|
||||
}
|
||||
}
|
||||
|
||||
return drainRate;
|
||||
}
|
||||
|
||||
private String getEstimatedTimeRemaining()
|
||||
{
|
||||
// Base data
|
||||
final double drainRate = getPrayerDrainRate(client);
|
||||
|
||||
if (drainRate == 0)
|
||||
{
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
final int currentPrayer = client.getBoostedSkillLevel(Skill.PRAYER);
|
||||
|
||||
// Calculate how many seconds each prayer points last so the prayer bonus can be applied
|
||||
final double secondsPerPoint = (60.0 / drainRate) * (1.0 + (prayerBonus / 30.0));
|
||||
|
||||
// Calculate the number of seconds left
|
||||
final double secondsLeft = (currentPrayer * secondsPerPoint);
|
||||
final int minutes = (int) Math.floor(secondsLeft / 60.0);
|
||||
final int seconds = (int) Math.floor(secondsLeft - (minutes * 60.0));
|
||||
|
||||
// Return the text
|
||||
return Integer.toString(minutes) + ":" + StringUtils.leftPad(Integer.toString(seconds), 2, "0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ package net.runelite.client.plugins.prayer;
|
||||
import com.google.inject.Provides;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
@@ -38,8 +40,11 @@ import net.runelite.api.Item;
|
||||
import net.runelite.api.ItemContainer;
|
||||
import net.runelite.api.Prayer;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
@@ -64,6 +69,9 @@ public class PrayerPlugin extends Plugin
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private boolean prayersActive = false;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private int prayerBonus;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@@ -150,7 +158,7 @@ public class PrayerPlugin extends Plugin
|
||||
|
||||
if (equipment != null)
|
||||
{
|
||||
doseOverlay.setPrayerBonus(checkContainerForPrayer(equipment.getItems()));
|
||||
prayerBonus = checkContainerForPrayer(equipment.getItems());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -176,6 +184,11 @@ public class PrayerPlugin extends Plugin
|
||||
barOverlay.onTick();
|
||||
}
|
||||
|
||||
if (config.replaceOrbText() && isAnyPrayerActive())
|
||||
{
|
||||
setPrayerOrbText(getEstimatedTimeRemaining(true));
|
||||
}
|
||||
|
||||
if (!config.prayerIndicator())
|
||||
{
|
||||
return;
|
||||
@@ -304,4 +317,57 @@ public class PrayerPlugin extends Plugin
|
||||
infoBoxManager.removeIf(entry -> entry instanceof PrayerCounter
|
||||
&& ((PrayerCounter) entry).getPrayerType().isOverhead());
|
||||
}
|
||||
|
||||
private void setPrayerOrbText(String text)
|
||||
{
|
||||
Widget prayerOrbText = client.getWidget(WidgetInfo.MINIMAP_PRAYER_ORB_TEXT);
|
||||
if (prayerOrbText != null)
|
||||
{
|
||||
prayerOrbText.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
private static double getPrayerDrainRate(Client client)
|
||||
{
|
||||
double drainRate = 0.0;
|
||||
|
||||
for (Prayer prayer : Prayer.values())
|
||||
{
|
||||
if (client.isPrayerActive(prayer))
|
||||
{
|
||||
drainRate += prayer.getDrainRate();
|
||||
}
|
||||
}
|
||||
|
||||
return drainRate;
|
||||
}
|
||||
|
||||
String getEstimatedTimeRemaining(boolean formatForOrb)
|
||||
{
|
||||
final double drainRate = getPrayerDrainRate(client);
|
||||
|
||||
if (drainRate == 0)
|
||||
{
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
final int currentPrayer = client.getBoostedSkillLevel(Skill.PRAYER);
|
||||
|
||||
// Calculate how many seconds each prayer points last so the prayer bonus can be applied
|
||||
final double secondsPerPoint = (60.0 / drainRate) * (1.0 + (prayerBonus / 30.0));
|
||||
|
||||
// Calculate the number of seconds left
|
||||
final double secondsLeft = (currentPrayer * secondsPerPoint);
|
||||
|
||||
LocalTime timeLeft = LocalTime.ofSecondOfDay((long) secondsLeft);
|
||||
|
||||
if (formatForOrb && timeLeft.getMinute() > 9)
|
||||
{
|
||||
return timeLeft.format(DateTimeFormatter.ofPattern("m")) + "m";
|
||||
}
|
||||
else
|
||||
{
|
||||
return timeLeft.format(DateTimeFormatter.ofPattern("m:ss"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user