From 3f729479457a9a47efd7a597302136422affa523 Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Sat, 20 Apr 2019 06:38:08 +0100 Subject: [PATCH] Whale Watchers plugin (#12) Whale Watchers plugin --- whalewatchers/WhaleWatchersConfig.java | 34 +++ whalewatchers/WhaleWatchersGloryOverlay.java | 48 +++++ whalewatchers/WhaleWatchersOverlay.java | 51 +++++ whalewatchers/WhaleWatchersPlugin.java | 194 ++++++++++++++++++ whalewatchers/WhaleWatchersProtOverlay.java | 44 ++++ .../WhaleWatchersSmiteableOverlay.java | 39 ++++ 6 files changed, 410 insertions(+) create mode 100644 whalewatchers/WhaleWatchersConfig.java create mode 100644 whalewatchers/WhaleWatchersGloryOverlay.java create mode 100644 whalewatchers/WhaleWatchersOverlay.java create mode 100644 whalewatchers/WhaleWatchersPlugin.java create mode 100644 whalewatchers/WhaleWatchersProtOverlay.java create mode 100644 whalewatchers/WhaleWatchersSmiteableOverlay.java diff --git a/whalewatchers/WhaleWatchersConfig.java b/whalewatchers/WhaleWatchersConfig.java new file mode 100644 index 0000000000..75436c045c --- /dev/null +++ b/whalewatchers/WhaleWatchersConfig.java @@ -0,0 +1,34 @@ +package net.runelite.client.plugins.whalewatchers; + +import java.awt.*; +import net.runelite.client.config.*; + +@ConfigGroup("WhaleWatchers") +public interface WhaleWatchersConfig extends Config +{ + @ConfigItem(position = 1, keyName = "protectItemWarning", name = "Protect Item Warning", description = "Warns you when you are skulled and don't have protect item turned on.") + default boolean protectItemWarning() { + return false; + } + + @ConfigItem(position = 2, keyName = "showDamageCounter", name = "Damage Counter", description = "Shows damage you've done and damage your opponent has done to you while in a fight") + default boolean showDamageCounter() { + return true; + } + + @Alpha + @ConfigItem(position = 3, keyName = "damageBackgroundColor", name = "Counter Background Color", description = "The background color for the damage counter overlay") + default Color damageBackgroundColor() { + return Color.darkGray; + } + + @ConfigItem(position = 4, keyName = "smiteableWarning", name = "Smite Warning", description = "Displays a warning overlay when your prayer is at a smiteable level") + default boolean smiteableWarning() { + return true; + } + + @ConfigItem(position = 5, keyName = "gloryWarning", name = "Glory Warning", description = "Displays a warning box while you are wearing an uncharged glory") + default boolean gloryWarning() { + return true; + } +} diff --git a/whalewatchers/WhaleWatchersGloryOverlay.java b/whalewatchers/WhaleWatchersGloryOverlay.java new file mode 100644 index 0000000000..dd30579485 --- /dev/null +++ b/whalewatchers/WhaleWatchersGloryOverlay.java @@ -0,0 +1,48 @@ +package net.runelite.client.plugins.whalewatchers; + +import net.runelite.api.*; +import javax.inject.*; +import net.runelite.client.ui.overlay.*; +import net.runelite.api.kit.*; +import java.awt.*; +import net.runelite.client.ui.overlay.components.*; +import java.awt.image.*; +import net.runelite.client.game.*; + +public class WhaleWatchersGloryOverlay extends Overlay +{ + private Client client; + private final WhaleWatchersConfig config; + private WhaleWatchersPlugin plugin; + private PanelComponent panelComponent; + @Inject + private ItemManager itemManager; + + @Inject + public WhaleWatchersGloryOverlay(final WhaleWatchersConfig config, final Client client, final WhaleWatchersPlugin plugin) { + this.client = client; + this.config = config; + this.plugin = plugin; + this.setLayer(OverlayLayer.ABOVE_WIDGETS); + this.setPriority(OverlayPriority.HIGH); + this.setPosition(OverlayPosition.DETACHED); + this.panelComponent = new PanelComponent(); + } + + @Override + public Dimension render(final Graphics2D graphics) { + this.panelComponent.getChildren().clear(); + int amuletID = 0; + try { + amuletID = this.client.getLocalPlayer().getPlayerComposition().getEquipmentId(KitType.AMULET); + } + catch (NullPointerException ex) {} + if (this.config.gloryWarning() && amuletID == 1704) { + this.panelComponent.setBackgroundColor(Color.lightGray); + final AsyncBufferedImage gloryImage = this.itemManager.getImage(1704); + this.panelComponent.getChildren().add(TitleComponent.builder().text("Uncharged Glory").color(Color.BLACK).build()); + this.panelComponent.getChildren().add(new ImageComponent(gloryImage)); + } + return this.panelComponent.render(graphics); + } +} diff --git a/whalewatchers/WhaleWatchersOverlay.java b/whalewatchers/WhaleWatchersOverlay.java new file mode 100644 index 0000000000..2365bbfe38 --- /dev/null +++ b/whalewatchers/WhaleWatchersOverlay.java @@ -0,0 +1,51 @@ +package net.runelite.client.plugins.whalewatchers; + +import net.runelite.api.*; +import net.runelite.client.ui.overlay.*; +import javax.inject.*; +import net.runelite.client.ui.overlay.components.*; +import java.awt.*; + +public class WhaleWatchersOverlay extends Overlay +{ + private Client client; + private final WhaleWatchersConfig config; + private WhaleWatchersPlugin plugin; + private PanelComponent panelComponent; + private String lastOpponent; + + @Inject + public WhaleWatchersOverlay(final WhaleWatchersConfig config, final Client client, final WhaleWatchersPlugin plugin) { + this.lastOpponent = "-"; + this.client = client; + this.config = config; + this.plugin = plugin; + this.setLayer(OverlayLayer.ABOVE_WIDGETS); + this.setPriority(OverlayPriority.HIGH); + this.setPosition(OverlayPosition.DETACHED); + this.panelComponent = new PanelComponent(); + } + + @Override + public Dimension render(final Graphics2D graphics) { + this.panelComponent.getChildren().clear(); + if (this.plugin.inCombat && this.config.showDamageCounter()) { + this.panelComponent.setBackgroundColor(this.config.damageBackgroundColor()); + final String opp = (this.client.getLocalPlayer().getInteracting() != null) ? this.client.getLocalPlayer().getInteracting().getName() : this.lastOpponent; + if (this.client.getLocalPlayer().getInteracting() != null) { + this.lastOpponent = this.client.getLocalPlayer().getInteracting().getName(); + } + final String opponent = "Fight vs " + opp; + final String damageTaken = "Damage Taken: " + this.plugin.damageTaken; + final String damageDealt = "Damage Dealt: " + this.plugin.damageDone; + this.panelComponent.getChildren().add(TitleComponent.builder().text(opponent).color(Color.BLACK).build()); + this.panelComponent.getChildren().add(TitleComponent.builder().text(damageDealt).color(Color.BLACK).build()); + this.panelComponent.getChildren().add(TitleComponent.builder().text(damageTaken).color(Color.BLACK).build()); + this.panelComponent.setPreferredSize(new Dimension(graphics.getFontMetrics().stringWidth(damageDealt) + graphics.getFontMetrics().stringWidth(opponent) + 10, 0)); + } + else { + this.panelComponent.getChildren().clear(); + } + return this.panelComponent.render(graphics); + } +} diff --git a/whalewatchers/WhaleWatchersPlugin.java b/whalewatchers/WhaleWatchersPlugin.java new file mode 100644 index 0000000000..3d6fc5fe97 --- /dev/null +++ b/whalewatchers/WhaleWatchersPlugin.java @@ -0,0 +1,194 @@ +package net.runelite.client.plugins.whalewatchers; + + +import org.jetbrains.annotations.*; +import net.runelite.client.plugins.*; +import net.runelite.client.game.*; +import net.runelite.client.config.*; +import com.google.inject.*; +import net.runelite.client.ui.overlay.*; +import net.runelite.client.eventbus.*; +import net.runelite.api.kit.*; +import org.apache.commons.lang3.*; +import net.runelite.api.*; +import net.runelite.api.events.*; +import java.util.*; + +@PluginDescriptor(name = "!Whale Watchers", description = "A Plugin to save help whales in the wild", tags = { "whale watchers", "whale", "protect item", "warning", "pklite" }, enabledByDefault = true, hidden = false, developerPlugin = false, loadWhenOutdated = false) +public class WhaleWatchersPlugin extends Plugin +{ + @Inject + private Client client; + @Inject + private WhaleWatchersConfig config; + @Inject + private WhaleWatchersOverlay overlay; + @Inject + private WhaleWatchersProtOverlay whaleWatchersProtOverlay; + @Inject + private WhaleWatchersSmiteableOverlay whaleWatchersSmiteableOverlay; + @Inject + private WhaleWatchersGloryOverlay whaleWatchersGloryOverlay; + @Inject + private OverlayManager overlayManager; + @Inject + private ItemManager itemManager; + public boolean enableOverlay; + private int lastXP; + public int damageDone; + public int damageTaken; + public boolean inCombat; + private int tickCountdown; + private boolean displaySmiteOverlay; + private boolean displayGloryOverlay; + + public WhaleWatchersPlugin() { + this.enableOverlay = false; + this.lastXP = 0; + this.damageDone = 0; + this.damageTaken = 0; + this.inCombat = false; + this.tickCountdown = 0; + } + + @Provides + WhaleWatchersConfig getConfig(final ConfigManager configManager) { + return configManager.getConfig(WhaleWatchersConfig.class); + } + + @Override + protected void startUp() throws Exception { + this.overlayManager.add(this.overlay); + this.overlayManager.add(this.whaleWatchersProtOverlay); + this.overlayManager.add(this.whaleWatchersSmiteableOverlay); + this.overlayManager.add(this.whaleWatchersGloryOverlay); + } + + @Override + protected void shutDown() throws Exception { + this.overlayManager.remove(this.overlay); + this.overlayManager.remove(this.whaleWatchersProtOverlay); + this.overlayManager.remove(this.whaleWatchersSmiteableOverlay); + this.overlayManager.remove(this.whaleWatchersGloryOverlay); + } + + @Subscribe + public void onHitsplatApplied(final HitsplatApplied event) { + if (this.config.showDamageCounter()) { + if (!(event.getActor() == this.client.getLocalPlayer() | event.getActor() == this.client.getLocalPlayer().getInteracting())) { + return; + } + if (this.isAttackingPlayer(this.client) || this.inCombat) { + this.inCombat = true; + if (event.getActor() == this.client.getLocalPlayer()) { + this.damageTaken += event.getHitsplat().getAmount(); + } + if (event.getActor() == this.client.getLocalPlayer().getInteracting()) { + this.damageDone += event.getHitsplat().getAmount(); + } + } + } + } + + @Subscribe + public void onItemContainerChanged(final ItemContainerChanged event) { + if (this.config.gloryWarning() && event.getItemContainer().equals(InventoryID.EQUIPMENT)) { + final int amuletID = ObjectUtils.defaultIfNull(this.client.getLocalPlayer().getPlayerComposition().getEquipmentId(KitType.AMULET), 0); + if (amuletID == 1704) { + this.displayGloryOverlay = true; + } + else { + this.displayGloryOverlay = false; + } + } + else { + this.displayGloryOverlay = false; + } + } + + @Subscribe + public void onExperienceChanged(final ExperienceChanged event) { + final Skill skill = event.getSkill(); + final Player player = this.client.getLocalPlayer(); + if (skill.equals(Skill.HITPOINTS) && player.getInteracting() instanceof Player) { + this.lastXP = this.client.getSkillExperience(skill); + } + } + + @Subscribe + public void onMenuOptionClicked(final MenuOptionClicked event) { + if (this.config.showDamageCounter() && event.getMenuAction().equals(MenuAction.SPELL_CAST_ON_PLAYER)) { + this.inCombat = true; + } + } + + @Subscribe + public void onVarbitChanged(final VarbitChanged event) { + if (this.config.showDamageCounter() && this.client.getVar(VarPlayer.ATTACKING_PLAYER) == -1 && this.inCombat) { + this.tickCountdown = 10; + } + if (this.config.protectItemWarning()) { + try { + if (this.client.getLocalPlayer().getSkullIcon() == SkullIcon.SKULL) { + if ((this.client.getVar(Varbits.PRAYER_PROTECT_ITEM) == 0 && this.client.getVar(Varbits.IN_WILDERNESS) == 1) || this.client.getWorldType().contains(WorldType.PVP)) { + this.enableOverlay = true; + } + if (this.client.getVar(Varbits.PRAYER_PROTECT_ITEM) == 1 || this.client.getVar(Varbits.IN_WILDERNESS) == 0 || this.client.getWorldType().contains(WorldType.PVP_HIGH_RISK) || this.client.getWorld() == 365) { + this.enableOverlay = false; + } + } + else { + this.enableOverlay = false; + } + } + catch (NullPointerException ex) {} + } + } + + @Subscribe + public void onGameTick(final GameTick event) { + if (this.tickCountdown > 0 && this.tickCountdown < 11) { + --this.tickCountdown; + if (this.tickCountdown == 1 && !this.isAttackingPlayer(this.client)) { + this.inCombat = false; + this.damageDone = 0; + this.damageTaken = 0; + return; + } + } + if (this.config.smiteableWarning() && (this.client.getVar(Varbits.IN_WILDERNESS) == 1 || WorldType.isPvpWorld(this.client.getWorldType()))) { + if (this.client.getLocalPlayer().getSkullIcon() != null && this.client.getLocalPlayer().getSkullIcon().equals(SkullIcon.SKULL)) { + final int currentHealth = this.client.getLocalPlayer().getHealth(); + final int currentPrayer = this.client.getBoostedSkillLevel(Skill.PRAYER); + if (currentPrayer <= Math.ceil(currentHealth / 4)) { + this.displaySmiteOverlay = true; + } + else { + this.displaySmiteOverlay = false; + } + } + else { + this.displaySmiteOverlay = false; + } + } + else { + this.displaySmiteOverlay = false; + } + } + + public boolean isAttackingPlayer(@NotNull final Client c) { + if (this.client.getVar(Varbits.IN_WILDERNESS) == 1 && this.client.getLocalPlayer().getInteracting() != null) { + return true; + } + final int varp = c.getVar(VarPlayer.ATTACKING_PLAYER); + return varp != -1; + } + + public boolean isDisplaySmiteOverlay() { + return this.displaySmiteOverlay; + } + + public boolean isDisplayGloryOverlay() { + return this.displayGloryOverlay; + } +} diff --git a/whalewatchers/WhaleWatchersProtOverlay.java b/whalewatchers/WhaleWatchersProtOverlay.java new file mode 100644 index 0000000000..5c8fa24b84 --- /dev/null +++ b/whalewatchers/WhaleWatchersProtOverlay.java @@ -0,0 +1,44 @@ +package net.runelite.client.plugins.whalewatchers; + +import javax.inject.*; + +import net.runelite.api.Point; +import net.runelite.client.ui.*; +import net.runelite.api.*; +import net.runelite.client.ui.overlay.*; +import java.awt.*; + +public class WhaleWatchersProtOverlay extends Overlay +{ + private Client client; + private final WhaleWatchersConfig config; + private WhaleWatchersPlugin plugin; + + @Inject + public WhaleWatchersProtOverlay(final WhaleWatchersConfig config, final Client client, final WhaleWatchersPlugin plugin) { + this.client = client; + this.config = config; + this.plugin = plugin; + this.setLayer(OverlayLayer.ABOVE_WIDGETS); + this.setPriority(OverlayPriority.HIGH); + this.setPosition(OverlayPosition.DYNAMIC); + } + + @Override + public Dimension render(final Graphics2D graphics) { + if (this.plugin.enableOverlay && this.config.protectItemWarning()) { + final Rectangle rectangle = new Rectangle(); + rectangle.setBounds(this.client.getCanvas().getBounds()); + rectangle.setLocation(this.client.getCanvas().getLocation()); + final Stroke oldStroke = graphics.getStroke(); + graphics.setStroke(new BasicStroke(10.0f)); + graphics.setColor(Color.RED); + graphics.draw(rectangle); + final Font font = FontManager.getRunescapeBoldFont().deriveFont(1, 72.0f); + graphics.setFont(font); + OverlayUtil.renderTextLocation(graphics, new Point((int)rectangle.getCenterX() - 50, font.getSize()), "Protect item prayer disabled!!!", Color.red); + graphics.setStroke(oldStroke); + } + return null; + } +} diff --git a/whalewatchers/WhaleWatchersSmiteableOverlay.java b/whalewatchers/WhaleWatchersSmiteableOverlay.java new file mode 100644 index 0000000000..683841d246 --- /dev/null +++ b/whalewatchers/WhaleWatchersSmiteableOverlay.java @@ -0,0 +1,39 @@ +package net.runelite.client.plugins.whalewatchers; + +import net.runelite.api.*; +import net.runelite.client.ui.overlay.*; +import javax.inject.*; +import java.awt.*; +import net.runelite.client.ui.overlay.components.*; + +public class WhaleWatchersSmiteableOverlay extends Overlay +{ + private Client client; + private WhaleWatchersPlugin plugin; + private PanelComponent panelComponent; + + @Inject + public WhaleWatchersSmiteableOverlay(final WhaleWatchersPlugin plugin) { + this.plugin = plugin; + this.setLayer(OverlayLayer.ABOVE_WIDGETS); + this.setPriority(OverlayPriority.HIGH); + this.setPosition(OverlayPosition.BOTTOM_RIGHT); + this.panelComponent = new PanelComponent(); + } + + @Override + public Dimension render(final Graphics2D graphics) { + final String subText = "You could be smited in 1 tick"; + this.panelComponent.getChildren().clear(); + if (this.plugin.isDisplaySmiteOverlay()) { + this.panelComponent.setBackgroundColor(Color.WHITE); + this.panelComponent.getChildren().add(TitleComponent.builder().text("LOW PRAYER WARNING").color(Color.BLACK).build()); + this.panelComponent.getChildren().add(TitleComponent.builder().text(subText).color(Color.BLACK).build()); + this.panelComponent.setPreferredSize(new Dimension(graphics.getFontMetrics().stringWidth(subText) + 20, 0)); + } + else { + this.panelComponent.getChildren().clear(); + } + return this.panelComponent.render(graphics); + } +}