prayer: display prayer time remaining in prayer orb

This commit is contained in:
dekvall
2019-08-06 02:11:43 +02:00
committed by Adam
parent 12c969cc0a
commit 2d01dc21bd
5 changed files with 95 additions and 48 deletions

View File

@@ -324,6 +324,7 @@ public class WidgetID
static final int HEALTH_ORB = 2; static final int HEALTH_ORB = 2;
static final int PRAYER_ORB = 12; static final int PRAYER_ORB = 12;
static final int QUICK_PRAYER_ORB = 14; // Has the "Quick-prayers" name 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 RUN_ORB = 20;
static final int TOGGLE_RUN_ORB = 22; // Has the "Toggle run" name static final int TOGGLE_RUN_ORB = 22; // Has the "Toggle run" name
static final int RUN_ORB_TEXT = 23; static final int RUN_ORB_TEXT = 23;

View File

@@ -165,6 +165,7 @@ public enum WidgetInfo
MINIMAP_XP_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.XP_ORB), MINIMAP_XP_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.XP_ORB),
MINIMAP_PRAYER_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.PRAYER_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_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_RUN_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.RUN_ORB),
MINIMAP_TOGGLE_RUN_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.TOGGLE_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), MINIMAP_RUN_ORB_TEXT(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.RUN_ORB_TEXT),

View File

@@ -129,4 +129,15 @@ public interface PrayerConfig extends Config
{ {
return false; 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;
}
} }

View File

@@ -37,7 +37,6 @@ import lombok.Setter;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Constants; import net.runelite.api.Constants;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.api.Prayer;
import net.runelite.api.Skill; import net.runelite.api.Skill;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo; 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.Tooltip;
import net.runelite.client.ui.overlay.tooltip.TooltipManager; import net.runelite.client.ui.overlay.tooltip.TooltipManager;
import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ColorUtil;
import org.apache.commons.lang3.StringUtils;
class PrayerDoseOverlay extends Overlay class PrayerDoseOverlay extends Overlay
{ {
@@ -57,13 +55,12 @@ class PrayerDoseOverlay extends Overlay
private static final Color END_COLOR = new Color(0, 92, 92); private static final Color END_COLOR = new Color(0, 92, 92);
private final Client client; private final Client client;
private final PrayerPlugin plugin;
private final PrayerConfig config; private final PrayerConfig config;
private final TooltipManager tooltipManager; private final TooltipManager tooltipManager;
private Instant startOfLastTick = Instant.now(); private Instant startOfLastTick = Instant.now();
private boolean trackTick = true; private boolean trackTick = true;
@Setter(AccessLevel.PACKAGE)
private int prayerBonus;
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
private boolean hasPrayerRestore; private boolean hasPrayerRestore;
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
@@ -72,10 +69,11 @@ class PrayerDoseOverlay extends Overlay
private boolean hasHolyWrench; private boolean hasHolyWrench;
@Inject @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.client = client;
this.tooltipManager = tooltipManager; this.tooltipManager = tooltipManager;
this.plugin = plugin;
this.config = config; this.config = config;
setPosition(OverlayPosition.DYNAMIC); setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS); setLayer(OverlayLayer.ABOVE_WIDGETS);
@@ -114,11 +112,19 @@ class PrayerDoseOverlay extends Overlay
if (config.showPrayerStatistics() && bounds.contains(mousePosition.getX(), mousePosition.getY())) if (config.showPrayerStatistics() && bounds.contains(mousePosition.getX(), mousePosition.getY()))
{ {
final String tooltip = "Time Remaining: " + getEstimatedTimeRemaining() + final StringBuilder sb = new StringBuilder();
"</br>" +
"Prayer Bonus: " + prayerBonus;
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) if (!config.showPrayerDoseIndicator() || !hasPrayerRestore)
@@ -163,42 +169,4 @@ class PrayerDoseOverlay extends Overlay
return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight()); 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");
}
} }

View File

@@ -28,6 +28,8 @@ package net.runelite.client.plugins.prayer;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
@@ -38,8 +40,11 @@ import net.runelite.api.Item;
import net.runelite.api.ItemContainer; import net.runelite.api.ItemContainer;
import net.runelite.api.Prayer; import net.runelite.api.Prayer;
import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.ConfigChanged;
import net.runelite.api.Skill;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
import net.runelite.api.events.ItemContainerChanged; 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.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
@@ -64,6 +69,9 @@ public class PrayerPlugin extends Plugin
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private boolean prayersActive = false; private boolean prayersActive = false;
@Getter(AccessLevel.PACKAGE)
private int prayerBonus;
@Inject @Inject
private Client client; private Client client;
@@ -150,7 +158,7 @@ public class PrayerPlugin extends Plugin
if (equipment != null) if (equipment != null)
{ {
doseOverlay.setPrayerBonus(checkContainerForPrayer(equipment.getItems())); prayerBonus = checkContainerForPrayer(equipment.getItems());
} }
} }
@@ -176,6 +184,11 @@ public class PrayerPlugin extends Plugin
barOverlay.onTick(); barOverlay.onTick();
} }
if (config.replaceOrbText() && isAnyPrayerActive())
{
setPrayerOrbText(getEstimatedTimeRemaining(true));
}
if (!config.prayerIndicator()) if (!config.prayerIndicator())
{ {
return; return;
@@ -304,4 +317,57 @@ public class PrayerPlugin extends Plugin
infoBoxManager.removeIf(entry -> entry instanceof PrayerCounter infoBoxManager.removeIf(entry -> entry instanceof PrayerCounter
&& ((PrayerCounter) entry).getPrayerType().isOverhead()); && ((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"));
}
}
} }