Whale Watchers plugin (#12)

Whale Watchers plugin
This commit is contained in:
Kyleeld
2019-04-20 06:38:08 +01:00
committed by Tyler Bochard
parent 4f4c8c0be9
commit 3f72947945
6 changed files with 410 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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 = "<font color=\"aqua\">!Whale Watchers</font>", 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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}