diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoConfig.java new file mode 100644 index 0000000000..24132a037a --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoConfig.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019, Jacky + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.inferno; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup("inferno") +public interface InfernoConfig extends Config +{ + @ConfigItem( + position = 0, + keyName = "Nibber Overlay", + name = "Nibber Overlay", + description = "Shows if there are any nibbas left" + ) + default boolean displayNibbaOverlay() + { + return false; + } + + @ConfigItem( + position = 1, + keyName = "Prayer Helper", + name = "Prayer Helper", + description = "Tells you what to flick in how many ticks" + ) + default boolean showPrayerHelp() + { + return false; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoInfobox.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoInfobox.java new file mode 100644 index 0000000000..7edf69cced --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoInfobox.java @@ -0,0 +1,57 @@ +package net.runelite.client.plugins.inferno; + +import java.awt.Dimension; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.LineComponent; +import net.runelite.client.ui.overlay.components.PanelComponent; + +public class InfernoInfobox extends Overlay +{ + private final Client client; + private final InfernoPlugin plugin; + private final InfernoConfig config; + + private final PanelComponent panelComponent = new PanelComponent(); + + @Inject + public InfernoInfobox(Client client, InfernoConfig config, InfernoPlugin plugin) + { + this.client = client; + this.config = config; + this.plugin = plugin; + setPosition(OverlayPosition.TOP_LEFT); + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (!config.showPrayerHelp() || client.getMapRegions()[0] != 9043) return null; + + panelComponent.getChildren().clear(); + + for (int i = plugin.getPriorityNPC().length; i > 0; i--) + { + if (plugin.getPriorityNPC()[i-1] == null) + { + panelComponent.getChildren().add(LineComponent.builder() + .left(Integer.toString(i)) + .right("-") + .build()); + } + else + { + panelComponent.getChildren().add(LineComponent.builder() + .left(plugin.getPriorityNPC()[i-1].getName()) + .right(plugin.getPriorityNPC()[i-1].getAttackstyle().getName()) + .rightColor(plugin.getPriorityNPC()[i-1].getAttackstyle().getColor()) + .build()); + } + } + + return panelComponent.render(graphics); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoNPC.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoNPC.java new file mode 100644 index 0000000000..250f63d244 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoNPC.java @@ -0,0 +1,161 @@ +package net.runelite.client.plugins.inferno; + +import java.awt.Color; +import lombok.Getter; +import lombok.Setter; +import net.runelite.api.NPC; +import net.runelite.api.NpcID; + +public class InfernoNPC +{ + public enum Attackstyle + { + MAGE("Mage", Color.CYAN), + RANGE("Range", Color.GREEN), + MELEE("Melee", Color.WHITE), + RANDOM("Random", Color.ORANGE); + + @Getter + private String name = ""; + + @Getter + private Color color; + + Attackstyle(String s, Color c) + { + this.name = s; + this.color = c; + } + } + + @Getter + private NPC npc; + + @Getter + private String name; + + @Getter + @Setter + private Attackstyle attackstyle; + + @Getter + private int attackTicks; + + @Getter + private int priority; + + @Getter + @Setter + private int ticksTillAttack = -1; + + @Getter + @Setter + private boolean attacking = false; + + @Getter + private int attackAnimation; + + @Getter + private boolean isMidAttack = false; + + @Getter + @Setter + private int distanceToPlayer = 0; + + @Getter + int textLocHeight; + + public InfernoNPC(NPC npc) + { + this.npc = npc; + textLocHeight = npc.getLogicalHeight() + 40; + switch (npc.getId()) + { + case NpcID.JALAKREKKET: + attackTicks = 4; + name = "lil mel"; + attackAnimation = 7582; + attackstyle = Attackstyle.MELEE; + priority = 7; + break; + + case NpcID.JALAKREKXIL: + attackTicks = 4; + name = "lil range"; + attackAnimation = 7583; + attackstyle = Attackstyle.RANGE; + priority = 6; + break; + + case NpcID.JALAKREKMEJ: + attackTicks = 4; + name = "lil mage"; + attackAnimation = 7581; + attackstyle = Attackstyle.MAGE; + priority = 5; + break; + + case NpcID.JALMEJRAH: + attackTicks = 3; + name = "bat"; + attackAnimation = 7578; + attackstyle = Attackstyle.RANGE; + priority = 4; + break; + + case NpcID.JALAK: + attackTicks = 6; + name = "blob"; + attackAnimation = 7583; // also 7581 + attackstyle = Attackstyle.RANDOM; + priority = 3; + break; + + case NpcID.JALIMKOT: + attackTicks = 4; + name = "meleer"; + attackAnimation = 7597; + attackstyle = Attackstyle.MELEE; + priority = 2; + break; + + case NpcID.JALXIL: + attackTicks = 4; + name = "ranger"; + attackAnimation = 7605; + attackstyle = Attackstyle.RANGE; + priority = 1; + break; + + case NpcID.JALZEK: + attackTicks = 4; + name = "mager"; + attackAnimation = 7610; + attackstyle = Attackstyle.MAGE; + priority = 0; + break; + + default: + attackTicks = 0; + } + } + + public String info() + { + String info = ""; + + if (attacking) + { + info += ticksTillAttack; + } + //info += " D: " + distanceToPlayer; + + return info; + } + + public void attacked() + { + ticksTillAttack = attackTicks; + attacking = true; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoNibberOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoNibberOverlay.java new file mode 100644 index 0000000000..e11dac5bfe --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoNibberOverlay.java @@ -0,0 +1,47 @@ +package net.runelite.client.plugins.inferno; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.LineComponent; +import net.runelite.client.ui.overlay.components.PanelComponent; + +public class InfernoNibberOverlay extends Overlay +{ + private final Client client; + private final InfernoPlugin plugin; + private final InfernoConfig config; + + private final PanelComponent panelComponent = new PanelComponent(); + + @Inject + public InfernoNibberOverlay(Client client, InfernoConfig config, InfernoPlugin plugin) + { + this.client = client; + this.config = config; + this.plugin = plugin; + setPosition(OverlayPosition.TOP_LEFT); + } + + + @Override + public Dimension render(Graphics2D graphics) + { + if (!config.displayNibbaOverlay() || plugin.getNibbers().size() == 0 || client.getMapRegions()[0] != 9043) + return null; + + panelComponent.getChildren().clear(); + + panelComponent.getChildren().add(LineComponent.builder() + .left("Nibbas Left: ") + .right(Integer.toString(plugin.getNibbers().size())) + .leftColor(Color.BLUE) + .build()); + + return panelComponent.render(graphics); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoOverlay.java new file mode 100644 index 0000000000..7901f5e321 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoOverlay.java @@ -0,0 +1,85 @@ +package net.runelite.client.plugins.inferno; + +import com.google.common.base.Strings; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.api.NPC; +import net.runelite.api.Perspective; +import net.runelite.api.Point; +import net.runelite.api.coords.LocalPoint; +import net.runelite.client.ui.overlay.Overlay; + +import net.runelite.client.ui.overlay.OverlayLayer; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.PanelComponent; + +public class InfernoOverlay extends Overlay +{ + private final Client client; + private final InfernoPlugin plugin; + private final InfernoConfig config; + private final PanelComponent panelComponent = new PanelComponent(); + + @Inject + public InfernoOverlay(Client client, InfernoConfig config, InfernoPlugin plugin) + { + setPosition(OverlayPosition.DYNAMIC); + setLayer(OverlayLayer.ABOVE_SCENE); + this.client = client; + this.config = config; + this.plugin = plugin; + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (!client.isInInstancedRegion() || client.getMapRegions()[0] != 9043) return null; + + for (InfernoNPC monster : plugin.getMonsters().values()) + { + NPC npc = monster.getNpc(); + //if (npc == null || !config.showPrayer()) return; + LocalPoint lp = npc.getLocalLocation(); + if (lp != null) + { + Point point = Perspective.localToCanvas(client, lp, client.getPlane(), npc.getLogicalHeight()); + if (point != null) + { + if (monster.getTicksTillAttack() == 1 || (monster.getName().equals("blob") && monster.getTicksTillAttack() <= 3)) + { + renderTextLocation(graphics, monster, monster.info(), Color.GREEN); + } + else + { + renderTextLocation(graphics, monster, monster.info(), Color.RED); + } + } + } + } + return null; + } + + // renders text location + public static void renderTextLocation(Graphics2D graphics, InfernoNPC actor, String text, Color color) + { + graphics.setFont(new Font("Arial", Font.BOLD, 15)); + Point textLocation = actor.getNpc().getCanvasTextLocation(graphics, text, actor.textLocHeight + 40); + if (Strings.isNullOrEmpty(text)) + { + return; + } + + int x = textLocation.getX(); + int y = textLocation.getY(); + + graphics.setColor(Color.BLACK); + graphics.drawString(text, x + 1, y + 1); + + graphics.setColor(color); + graphics.drawString(text, x, y); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoPlugin.java new file mode 100644 index 0000000000..548455749d --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoPlugin.java @@ -0,0 +1,249 @@ +package net.runelite.client.plugins.inferno; + +import com.google.inject.Provides; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.inject.Inject; +import lombok.Getter; +import net.runelite.api.Client; +import net.runelite.api.HeadIcon; +import net.runelite.api.NPC; +import net.runelite.api.NpcID; +import net.runelite.api.events.GameTick; +import net.runelite.api.events.NpcDespawned; +import net.runelite.api.events.NpcSpawned; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.ui.overlay.OverlayManager; + +@PluginDescriptor( + name = "Inferno", + description = "Inferno helper", + tags = {"combat", "overlay", "pve", "pvm"} +) +public class InfernoPlugin extends Plugin +{ + + @Inject + private Client client; + + @Inject + private OverlayManager overlayManager; + + @Inject + private InfernoOverlay infernoOverlay; + + @Inject + private InfernoInfobox infernoInfobox; + + @Inject + private InfernoNibberOverlay nibberOverlay; + + @Inject + private InfernoConfig config; + + @Getter + private Map monsters; + + @Getter + private Map> monsterCurrentAttackMap; + + @Getter + private List nibbers; + + @Getter + private InfernoNPC[] priorityNPC; + + @Provides + InfernoConfig provideConfig(ConfigManager configManager) + { + return configManager.getConfig(InfernoConfig.class); + } + + @Override + protected void startUp() throws Exception + { + overlayManager.add(infernoOverlay); + overlayManager.add(infernoInfobox); + overlayManager.add(nibberOverlay); + monsters = new HashMap<>(); + monsterCurrentAttackMap = new HashMap<>(6); + for (int i = 1; i <= 6; i++) + { + monsterCurrentAttackMap.put(i, new ArrayList<>()); + } + nibbers = new ArrayList<>(); + priorityNPC = new InfernoNPC[4]; + } + + @Override + protected void shutDown() throws Exception + { + overlayManager.remove(infernoInfobox); + overlayManager.remove(infernoOverlay); + overlayManager.remove(nibberOverlay); + } + + @Subscribe + public void onNpcSpawned(NpcSpawned event) + { + if (client.getMapRegions()[0] != 9043) return; + + NPC npc = event.getNpc(); + if (isValidInfernoMob(npc)) + { + monsters.put(npc, new InfernoNPC(npc)); + System.out.println(monsters.size()); + } + if (npc.getId() == NpcID.JALNIB) + { + nibbers.add(npc); + } + } + + @Subscribe + public void onNpcDespawned(NpcDespawned event) + { + if (client.getMapRegions()[0] != 9043) return; + + NPC npc = event.getNpc(); + if (monsters.containsKey(npc)) + { + monsters.remove(npc); + System.out.println(monsters.size()); + } + + if (npc.getId() == NpcID.JALNIB) + { + nibbers.remove(npc); + } + } + + @Subscribe + public void onGameTick(GameTick event) + { + if (client.getMapRegions()[0] != 9043) return; + + clearMapAndPriority(); + + for (InfernoNPC monster : monsters.values()) + { + calculateDistanceToPlayer(monster); + + NPC npc = monster.getNpc(); + + // if they are not attacking but are still attacking + if (monster.isAttacking()) + { + monster.setTicksTillAttack(monster.getTicksTillAttack() - 1); + + // sets the blobs attack style + if (monster.getName().equals("blob") && monster.getTicksTillAttack() == 3 && monster.getDistanceToPlayer() <= 15) + { + if (client.getLocalPlayer().getOverheadIcon() == null) + { + monster.setAttackstyle(InfernoNPC.Attackstyle.RANDOM); + } + else if (client.getLocalPlayer().getOverheadIcon().equals(HeadIcon.MAGIC)) + { + monster.setAttackstyle(InfernoNPC.Attackstyle.RANGE); + } + else if (client.getLocalPlayer().getOverheadIcon().equals(HeadIcon.RANGED)) + { + monster.setAttackstyle(InfernoNPC.Attackstyle.MAGE); + } + } + + // we know the monster is not attacking because it should have attacked and is idling + if (monster.getTicksTillAttack() == 0) + { + if (npc.getAnimation() == -1) + { + monster.setAttacking(false); + } + else + { + // want to reset the monsters attack back to attacking + monster.attacked(); + } + } + } + else + { + // they've just attacked + if (npc.getAnimation() == monster.getAttackAnimation() || npc.getAnimation() == 7581) // special case for blob + { + monster.attacked(); + } + } + + if (monster.getTicksTillAttack() >= 1) + { + monsterCurrentAttackMap.get(monster.getTicksTillAttack()).add(monster); + } + } + + calculatePriorityNPC(); + } + + private void calculatePriorityNPC() + { + for (int i = 0; i < priorityNPC.length; i++) + { + ArrayList monsters = monsterCurrentAttackMap.get(i+1); + + if (monsters.size() == 0) continue; + + int priority = monsters.get(0).getPriority(); + + InfernoNPC infernoNPC = monsters.get(0); + + for (InfernoNPC npc : monsters) + { + if (npc.getPriority() < priority) + { + priority = npc.getPriority(); + infernoNPC = npc; + } + } + priorityNPC[i] = infernoNPC; + System.out.println("i: " + i + " " + infernoNPC.getName()); + } + } + + // TODO: blob calculator + private void calculateDistanceToPlayer(InfernoNPC monster) + { + monster.setDistanceToPlayer(client.getLocalPlayer().getWorldLocation().distanceTo(monster.getNpc().getWorldArea())); + } + + private void clearMapAndPriority() + { + for (List l : monsterCurrentAttackMap.values()) + { + l.clear(); + } + + for (int i = 0; i < priorityNPC.length; i++) + { + priorityNPC[i] = null; + } + } + + public boolean isValidInfernoMob(NPC npc) + { + // we only want the bat, blob, melee, ranger and mager + if (npc.getId() == NpcID.JALMEJRAH || + npc.getId() == NpcID.JALAK || + npc.getId() == NpcID.JALIMKOT || + npc.getId() == NpcID.JALXIL || + npc.getId() == NpcID.JALZEK) return true; + + return false; + } + +}