diff --git a/src/main/java/com/duckblade/osrs/sailing/SailingConfig.java b/src/main/java/com/duckblade/osrs/sailing/SailingConfig.java index 4b328a38..25968c9f 100644 --- a/src/main/java/com/duckblade/osrs/sailing/SailingConfig.java +++ b/src/main/java/com/duckblade/osrs/sailing/SailingConfig.java @@ -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", diff --git a/src/main/java/com/duckblade/osrs/sailing/features/navigation/LowHPNotification.java b/src/main/java/com/duckblade/osrs/sailing/features/navigation/LowHPNotification.java new file mode 100644 index 00000000..cd421561 --- /dev/null +++ b/src/main/java/com/duckblade/osrs/sailing/features/navigation/LowHPNotification.java @@ -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; + } +} diff --git a/src/main/java/com/duckblade/osrs/sailing/module/SailingModule.java b/src/main/java/com/duckblade/osrs/sailing/module/SailingModule.java index ecb93950..76449dd8 100644 --- a/src/main/java/com/duckblade/osrs/sailing/module/SailingModule.java +++ b/src/main/java/com/duckblade/osrs/sailing/module/SailingModule.java @@ -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; @@ -87,6 +88,7 @@ Set lifecycleComponents( LightningCloudsOverlay lightningCloudsOverlay, LostCargoHighlighter lostCargoHighlighter, LostShipment lostShipment, + LowHPNotification lowHPNotification, LuffOverlay luffOverlay, CrystalExtractorHighlight crystalExtractorHighlight, MermaidTaskSolver mermaidTaskSolver, @@ -130,6 +132,7 @@ Set lifecycleComponents( .add(lightningCloudsOverlay) .add(lostCargoHighlighter) .add(lostShipment) + .add(lowHPNotification) .add(luffOverlay) .add(crystalExtractorHighlight) .add(mermaidTaskSolver)