Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/com/duckblade/osrs/sailing/SailingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,31 @@ default boolean navigationOverlaySpeed()
return true;
}

@ConfigItem(
keyName = "lowBoatHPNotify",
name = "Notify on Low Boat HP",
description = "Notify when your boat's hitpoints drop below the threshold.",
section = SECTION_NAVIGATION,
position = 13
)
default Notification lowBoatHPNotification()
{
return Notification.OFF;
}

@ConfigItem(
keyName = "lowBoatHPThreshold",
name = "Low HP Threshold",
description = "The hitpoint threshold at which to notify you.",
section = SECTION_NAVIGATION,
position = 14
)
@Range(min = 1)
default int lowBoatHPThreshold()
{
return 50;
}

@ConfigItem(
keyName = "highlightTrimmableSails",
name = "Highlight Trimmable Sails",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.duckblade.osrs.sailing.features.navigation;

import com.duckblade.osrs.sailing.SailingConfig;
import com.duckblade.osrs.sailing.features.util.SailingUtil;
import com.duckblade.osrs.sailing.module.PluginLifecycleComponent;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.RequiredArgsConstructor;
import net.runelite.api.Client;
import net.runelite.api.events.GameTick;
import net.runelite.api.gameval.VarbitID;
import net.runelite.client.Notifier;
import net.runelite.client.config.Notification;
import net.runelite.client.eventbus.Subscribe;

@Singleton
@RequiredArgsConstructor(onConstructor_ = @Inject)
public class LowHPNotification implements PluginLifecycleComponent
{

private final Client client;
private final Notifier notifier;

private Notification notification;
private int threshold;

private boolean hasNotified = false;

@Override
public boolean isEnabled(SailingConfig config)
{
notification = config.lowBoatHPNotification();
threshold = config.lowBoatHPThreshold();
return notification.isEnabled();
}

@Override
public void shutDown()
{
hasNotified = false;
}

@Subscribe
public void onGameTick(GameTick e)
{
if (!SailingUtil.isSailing(client))
{
hasNotified = false;
return;
}

int currentHP = getBoatHP();

if (currentHP < 0)
{
hasNotified = false;
return;
}

if (currentHP < threshold)
{
if (!hasNotified)
{
notifier.notify(notification, "Your boat's hitpoints are low!");
hasNotified = true;
}
}
else
{
hasNotified = false;
}
}

private int getBoatHP()
{
int hp = client.getVarbitValue(VarbitID.SAILING_SIDEPANEL_BOAT_HP);
if (hp >= 0)
{
return hp;
}

return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.duckblade.osrs.sailing.features.mes.HideStopNavigatingDuringTrials;
import com.duckblade.osrs.sailing.features.mes.PrioritizeCargoHold;
import com.duckblade.osrs.sailing.features.navigation.LightningCloudsOverlay;
import com.duckblade.osrs.sailing.features.navigation.LowHPNotification;
import com.duckblade.osrs.sailing.features.navigation.NavigationOverlay;
import com.duckblade.osrs.sailing.features.navigation.RapidsOverlay;
import com.duckblade.osrs.sailing.features.navigation.TrueTileIndicator;
Expand Down Expand Up @@ -87,6 +88,7 @@ Set<PluginLifecycleComponent> lifecycleComponents(
LightningCloudsOverlay lightningCloudsOverlay,
LostCargoHighlighter lostCargoHighlighter,
LostShipment lostShipment,
LowHPNotification lowHPNotification,
LuffOverlay luffOverlay,
CrystalExtractorHighlight crystalExtractorHighlight,
MermaidTaskSolver mermaidTaskSolver,
Expand Down Expand Up @@ -130,6 +132,7 @@ Set<PluginLifecycleComponent> lifecycleComponents(
.add(lightningCloudsOverlay)
.add(lostCargoHighlighter)
.add(lostShipment)
.add(lowHPNotification)
.add(luffOverlay)
.add(crystalExtractorHighlight)
.add(mermaidTaskSolver)
Expand Down