From 14e6ff1806ffc830980e3de2a6bfdaf14c29b44b Mon Sep 17 00:00:00 2001 From: Lucwousin Date: Sat, 22 Jun 2019 23:28:29 +0200 Subject: [PATCH] Cleanup inferno plugin (functionality should be the same) (#700) * Cleanup inferno plugin (functionality should be the same) * Cleanup inferno plugin (functionality should be the same) --- .../client/plugins/inferno/InfernoConfig.java | 2 +- .../client/plugins/inferno/InfernoPlugin.java | 916 +++++++++--------- .../inferno/InfernoWaveDisplayMode.java | 3 +- .../plugins/inferno/InfernoWaveMappings.java | 242 ++--- .../plugins/inferno/InfernoWaveOverlay.java | 92 +- 5 files changed, 658 insertions(+), 597 deletions(-) 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 index 6330d38ca7..bd7c2b045e 100644 --- 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 @@ -56,7 +56,7 @@ public interface InfernoConfig extends Config @ConfigItem( position = 2, - keyName = "Wave Display", + keyName = "waveDisplay", name = "Wave display", description = "Shows monsters that will spawn on the selected wave(s)." ) 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 index c43f2eaa03..8a8549c4d5 100644 --- 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 @@ -1,439 +1,477 @@ -/* - * 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 com.google.inject.Provides; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.Nullable; -import javax.inject.Inject; -import lombok.AccessLevel; -import lombok.Getter; -import net.runelite.api.Actor; -import net.runelite.api.ChatMessageType; -import net.runelite.api.Client; -import net.runelite.api.GameState; -import net.runelite.api.HeadIcon; -import net.runelite.api.NPC; -import net.runelite.api.NpcID; -import net.runelite.api.events.AnimationChanged; -import net.runelite.api.events.ChatMessage; -import net.runelite.api.events.GameStateChanged; -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.plugins.PluginType; -import net.runelite.client.ui.overlay.OverlayManager; -import org.apache.commons.lang3.ArrayUtils; - -@PluginDescriptor( - name = "Inferno", - description = "Inferno helper", - tags = {"combat", "overlay", "pve", "pvm"}, - type = PluginType.PVM -) -public class InfernoPlugin extends Plugin - { - - @Inject - private Client client; - - @Inject - private OverlayManager overlayManager; - - @Inject - private InfernoOverlay infernoOverlay; - - @Inject - private InfernoWaveOverlay waveOverlay; - - @Inject - private InfernoJadOverlay jadOverlay; - - @Inject - private InfernoInfobox infernoInfobox; - - @Inject - private InfernoNibblerOverlay nibblerOverlay; - - @Inject - private InfernoConfig config; - - @Getter - private int currentWave = -1; - - @Getter - private Map monsters; - - @Getter - private Map> monsterCurrentAttackMap; - - @Getter - private List nibblers; - - @Getter - private InfernoNPC[] priorityNPC; - - - @Getter(AccessLevel.PACKAGE) - @Nullable - private InfernoJadAttack attack; - - private NPC jad; - private static final int INFERNO_REGION = 9043; - private int currentWaveNumber; - private int nextWaveNumber; - private Map monster; - private Map waves; - private List waveMonsters; - - public InfernoPlugin() - { - waveMonsters = new ArrayList(); - } - - @Provides - InfernoConfig provideConfig(ConfigManager configManager) - { - return configManager.getConfig(InfernoConfig.class); - } - - @Override - protected void startUp() throws Exception - { - overlayManager.add(infernoOverlay); - overlayManager.add(infernoInfobox); - overlayManager.add(nibblerOverlay); - overlayManager.add(waveOverlay); - overlayManager.add(jadOverlay); - monster = InfernoWaveMappings.npcNameMapping(); - waves = InfernoWaveMappings.waveMapping(); - monsters = new HashMap<>(); - monsterCurrentAttackMap = new HashMap<>(6); - for (int i = 1; i <= 6; i++) - { - monsterCurrentAttackMap.put(i, new ArrayList<>()); - } - nibblers = new ArrayList<>(); - priorityNPC = new InfernoNPC[4]; - } - - @Override - protected void shutDown() throws Exception - { - overlayManager.remove(infernoInfobox); - overlayManager.remove(infernoOverlay); - overlayManager.remove(nibblerOverlay); - overlayManager.remove(waveOverlay); - overlayManager.remove(jadOverlay); - jad = null; - attack = null; - monster = null; - monsters = null; - waves = null; - currentWaveNumber = -1; - nextWaveNumber = -1; - } - - @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) - { - nibblers.add(npc); - } - - final int id = event.getNpc().getId(); - - if (id == NpcID.JALTOKJAD || id == NpcID.JALTOKJAD_7704) - { - jad = event.getNpc(); - } - final Actor actor = event.getActor(); - if (actor != null) - { - waveMonsters.add(actor); - } - } - - @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) - { - nibblers.remove(npc); - } - - if (jad == event.getNpc()) - { - jad = null; - attack = null; - } - final Actor actor = event.getActor(); - if (actor != null) - { - waveMonsters.remove(actor); - } - } - - @Subscribe - public void onGameStateChanged(GameStateChanged event) - { - if (event.getGameState() != GameState.LOGGED_IN) - { - return; - } - - if (!inInferno()) - { - currentWave = -1; - } - } - - @Subscribe - public void onChatMessage(ChatMessage event) - { - - if (event.getType() != ChatMessageType.GAMEMESSAGE || !inInferno()) - { - return; - } - String message = event.getMessage(); - if (event.getMessage().contains("Wave:")) - { - message = message.substring(message.indexOf(": ") + 2); - currentWaveNumber = Integer.parseInt(message.substring(0, message.indexOf("<"))); - nextWaveNumber = ((currentWaveNumber < 69) ? (currentWaveNumber + 1) : -1); - } - - } - - @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(); - } - - @Subscribe - public void onAnimationChanged(final AnimationChanged event) - { - if (event.getActor() != jad) - { - return; - } - - if (jad.getAnimation() == InfernoJadAttack.MAGIC.getAnimation()) - { - attack = InfernoJadAttack.MAGIC; - } - else if (jad.getAnimation() == InfernoJadAttack.RANGE.getAnimation()) - { - attack = InfernoJadAttack.RANGE; - } - } - - 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; - } - - boolean inInferno() - { - return ArrayUtils.contains(client.getMapRegions(), INFERNO_REGION); - } - - public boolean isNotFinalWave() - { - return currentWaveNumber <= 68; - } - - @Nullable - InfernoJadAttack getAttack() - { - return attack; - } - - int getCurrentWaveNumber() - { - return currentWaveNumber; - } - - int getNextWaveNumber() - { - return nextWaveNumber; - } - - Map getMonster() - { - return monster; - } - - Map getWaves() - { - return waves; - } - - List getWaveMonsters() - { - return waveMonsters; - } - - } +/* + * 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 com.google.inject.Provides; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; +import javax.inject.Inject; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.Actor; +import net.runelite.api.ChatMessageType; +import net.runelite.api.Client; +import net.runelite.api.GameState; +import net.runelite.api.HeadIcon; +import net.runelite.api.NPC; +import net.runelite.api.NpcID; +import net.runelite.api.events.AnimationChanged; +import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.ConfigChanged; +import net.runelite.api.events.GameStateChanged; +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.plugins.PluginType; +import net.runelite.client.ui.overlay.OverlayManager; +import org.apache.commons.lang3.ArrayUtils; + +@PluginDescriptor( + name = "Inferno", + description = "Inferno helper", + tags = {"combat", "overlay", "pve", "pvm"}, + type = PluginType.PVM +) +@Slf4j +public class InfernoPlugin extends Plugin +{ + private static final int INFERNO_REGION = 9043; + + @Inject + private Client client; + + @Inject + private OverlayManager overlayManager; + + @Inject + private InfernoOverlay infernoOverlay; + + @Inject + private InfernoWaveOverlay waveOverlay; + + @Inject + private InfernoJadOverlay jadOverlay; + + @Inject + private InfernoInfobox infernoInfobox; + + @Inject + private InfernoNibblerOverlay nibblerOverlay; + + @Inject + private InfernoConfig config; + + @Getter + private int currentWave = -1; + + @Getter + private Map monsters; + + @Getter + private Map> monsterCurrentAttackMap; + + @Getter + private List nibblers; + + @Getter + private InfernoNPC[] priorityNPC; + + + @Getter(AccessLevel.PACKAGE) + @Nullable + private InfernoJadAttack attack; + + private NPC jad; + + @Getter(AccessLevel.PACKAGE) + private int currentWaveNumber; + + private List waveMonsters; + + public InfernoPlugin() + { + waveMonsters = new ArrayList<>(); + } + + @Provides + InfernoConfig provideConfig(ConfigManager configManager) + { + return configManager.getConfig(InfernoConfig.class); + } + + @Override + protected void startUp() throws Exception + { + waveOverlay.setDisplayMode(config.waveDisplay()); + + if (isInInferno()) + { + overlayManager.add(infernoOverlay); + overlayManager.add(infernoInfobox); + overlayManager.add(nibblerOverlay); + + if (config.waveDisplay() != InfernoWaveDisplayMode.NONE) + { + overlayManager.add(waveOverlay); + } + + overlayManager.add(jadOverlay); + } + + waveOverlay.setWaveHeaderColor(config.getWaveOverlayHeaderColor()); + waveOverlay.setWaveTextColor(config.getWaveTextColor()); + + monsters = new HashMap<>(); + monsterCurrentAttackMap = new HashMap<>(6); + + for (int i = 1; i <= 6; i++) + { + monsterCurrentAttackMap.put(i, new ArrayList<>()); + } + + nibblers = new ArrayList<>(); + priorityNPC = new InfernoNPC[4]; + } + + @Override + protected void shutDown() throws Exception + { + overlayManager.remove(infernoInfobox); + overlayManager.remove(infernoOverlay); + overlayManager.remove(nibblerOverlay); + overlayManager.remove(waveOverlay); + overlayManager.remove(jadOverlay); + jad = null; + attack = null; + monsters = null; + currentWaveNumber = -1; + } + @Subscribe + private void onConfigChanged(ConfigChanged event) + { + if (!"inferno".equals(event.getGroup())) + { + return; + } + + if (event.getKey().endsWith("color")) + { + waveOverlay.setWaveHeaderColor(config.getWaveOverlayHeaderColor()); + waveOverlay.setWaveTextColor(config.getWaveTextColor()); + } + else if ("waveDisplay".equals(event.getKey())) + { + overlayManager.remove(waveOverlay); + + waveOverlay.setDisplayMode(config.waveDisplay()); + + if (isInInferno() && config.waveDisplay() != InfernoWaveDisplayMode.NONE) + { + overlayManager.add(waveOverlay); + } + } + } + + @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)); + log.debug(String.valueOf(monsters.size())); + } + + if (npc.getId() == NpcID.JALNIB) + { + nibblers.add(npc); + } + + final int id = event.getNpc().getId(); + + if (id == NpcID.JALTOKJAD || id == NpcID.JALTOKJAD_7704) + { + jad = event.getNpc(); + } + + final Actor actor = event.getActor(); + + if (actor != null) + { + waveMonsters.add(actor); + } + } + + @Subscribe + public void onNpcDespawned(NpcDespawned event) + { + if (client.getMapRegions()[0] != 9043) return; + + NPC npc = event.getNpc(); + if (monsters.containsKey(npc)) + { + monsters.remove(npc); + log.debug(String.valueOf(monsters.size())); + } + + if (npc.getId() == NpcID.JALNIB) + { + nibblers.remove(npc); + } + + if (jad == event.getNpc()) + { + jad = null; + attack = null; + } + final Actor actor = event.getActor(); + if (actor != null) + { + waveMonsters.remove(actor); + } + } + + @Subscribe + public void onGameStateChanged(GameStateChanged event) + { + if (event.getGameState() != GameState.LOGGED_IN) + { + return; + } + + if (!isInInferno()) + { + currentWaveNumber = -1; + overlayManager.remove(infernoInfobox); + overlayManager.remove(infernoOverlay); + overlayManager.remove(nibblerOverlay); + overlayManager.remove(waveOverlay); + overlayManager.remove(jadOverlay); + } + else if (currentWaveNumber == -1) + { + currentWaveNumber = 1; + overlayManager.add(infernoOverlay); + overlayManager.add(infernoInfobox); + overlayManager.add(nibblerOverlay); + + if (config.waveDisplay() != InfernoWaveDisplayMode.NONE) + { + overlayManager.add(waveOverlay); + } + + overlayManager.add(jadOverlay); + } + } + + @Subscribe + public void onChatMessage(ChatMessage event) + { + if (!isInInferno() || event.getType() != ChatMessageType.GAMEMESSAGE) + { + return; + } + + String message = event.getMessage(); + + if (event.getMessage().contains("Wave:")) + { + message = message.substring(message.indexOf(": ") + 2); + currentWaveNumber = Integer.parseInt(message.substring(0, message.indexOf("<"))); + } + } + + @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(); + } + + @Subscribe + public void onAnimationChanged(final AnimationChanged event) + { + if (event.getActor() != jad) + { + return; + } + + if (jad.getAnimation() == InfernoJadAttack.MAGIC.getAnimation()) + { + attack = InfernoJadAttack.MAGIC; + } + else if (jad.getAnimation() == InfernoJadAttack.RANGE.getAnimation()) + { + attack = InfernoJadAttack.RANGE; + } + } + + 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; + + log.debug("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; + } + } + + private boolean isValidInfernoMob(NPC npc) + { + // we only want the bat, blob, melee, ranger and mager + return npc.getId() == NpcID.JALMEJRAH || + npc.getId() == NpcID.JALAK || + npc.getId() == NpcID.JALIMKOT || + npc.getId() == NpcID.JALXIL || + npc.getId() == NpcID.JALZEK; + } + + private boolean isInInferno() + { + return ArrayUtils.contains(client.getMapRegions(), INFERNO_REGION); + } + + boolean isNotFinalWave() + { + return currentWaveNumber <= 68; + } + + List getWaveMonsters() + { + return waveMonsters; + } + + int getNextWaveNumber() + { + return currentWaveNumber == -1 || currentWaveNumber == 69 ? -1 : currentWaveNumber + 1; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveDisplayMode.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveDisplayMode.java index 628c4e814c..96c7d12001 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveDisplayMode.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveDisplayMode.java @@ -31,7 +31,8 @@ public enum InfernoWaveDisplayMode { CURRENT("Current wave"), NEXT("Next wave"), - BOTH("Both"); + BOTH("Both"), + NONE("None"); private final String name; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveMappings.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveMappings.java index 068ed55d1f..0e87b0c13b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveMappings.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveMappings.java @@ -26,121 +26,143 @@ */ package net.runelite.client.plugins.inferno; -import java.util.HashMap; -import java.util.Map; +import com.google.common.collect.ImmutableMap; +import java.awt.Color; +import lombok.Getter; +import net.runelite.client.ui.overlay.components.PanelComponent; +import net.runelite.client.ui.overlay.components.TitleComponent; -public class InfernoWaveMappings +class InfernoWaveMappings +{ + @Getter + private static final ImmutableMap waveMapping; + + @Getter + private static final ImmutableMap npcNameMapping; + + static { - static Map waveMapping() + ImmutableMap.Builder waveMapBuilder = new ImmutableMap.Builder<>(); + + waveMapBuilder.put(1, new int[]{32, 32, 32, 85}); + waveMapBuilder.put(2, new int[]{32, 32, 32, 85, 85}); + waveMapBuilder.put(3, new int[]{32, 32, 32, 32, 32, 32}); + waveMapBuilder.put(4, new int[]{32, 32, 32, 165}); + waveMapBuilder.put(5, new int[]{32, 32, 32, 85, 165}); + waveMapBuilder.put(6, new int[]{32, 32, 32, 85, 85, 165}); + waveMapBuilder.put(7, new int[]{32, 32, 32, 165, 165}); + waveMapBuilder.put(8, new int[]{32, 32, 32, 32, 32, 32}); + waveMapBuilder.put(9, new int[]{32, 32, 32, 240}); + waveMapBuilder.put(10, new int[]{32, 32, 32, 85, 240}); + waveMapBuilder.put(11, new int[]{32, 32, 32, 85, 85, 240}); + waveMapBuilder.put(12, new int[]{32, 32, 32, 165, 240}); + waveMapBuilder.put(13, new int[]{32, 32, 32, 85, 165, 240}); + waveMapBuilder.put(14, new int[]{32, 32, 32, 85, 85, 165, 240}); + waveMapBuilder.put(15, new int[]{32, 32, 32, 165, 165, 240}); + waveMapBuilder.put(16, new int[]{32, 32, 32, 240, 240}); + waveMapBuilder.put(17, new int[]{32, 32, 32, 32, 32, 32}); + waveMapBuilder.put(18, new int[]{32, 32, 32, 370}); + waveMapBuilder.put(19, new int[]{32, 32, 32, 85, 370}); + waveMapBuilder.put(20, new int[]{32, 32, 32, 85, 85, 370}); + waveMapBuilder.put(21, new int[]{32, 32, 32, 165, 370}); + waveMapBuilder.put(22, new int[]{32, 32, 32, 85, 165, 370}); + waveMapBuilder.put(23, new int[]{32, 32, 32, 85, 85, 165, 370}); + waveMapBuilder.put(24, new int[]{32, 32, 32, 165, 165, 370}); + waveMapBuilder.put(25, new int[]{32, 32, 32, 240, 370}); + waveMapBuilder.put(26, new int[]{32, 32, 32, 85, 240, 370}); + waveMapBuilder.put(27, new int[]{32, 32, 32, 85, 85, 240, 370}); + waveMapBuilder.put(28, new int[]{32, 32, 32, 165, 240, 370}); + waveMapBuilder.put(29, new int[]{32, 32, 32, 85, 165, 240, 370}); + waveMapBuilder.put(30, new int[]{32, 32, 32, 85, 85, 165, 240, 370}); + waveMapBuilder.put(31, new int[]{32, 32, 32, 165, 165, 240, 370}); + waveMapBuilder.put(32, new int[]{32, 32, 32, 240, 240, 370}); + waveMapBuilder.put(33, new int[]{32, 32, 32, 370, 370}); + waveMapBuilder.put(34, new int[]{32, 32, 32, 32, 32, 32}); + waveMapBuilder.put(35, new int[]{32, 32, 32, 490}); + waveMapBuilder.put(36, new int[]{32, 32, 32, 85, 490}); + waveMapBuilder.put(37, new int[]{32, 32, 32, 85, 85, 490}); + waveMapBuilder.put(38, new int[]{32, 32, 32, 165, 490}); + waveMapBuilder.put(39, new int[]{32, 32, 32, 85, 165, 490}); + waveMapBuilder.put(40, new int[]{32, 32, 32, 85, 85, 165, 490}); + waveMapBuilder.put(41, new int[]{32, 32, 32, 165, 165, 490}); + waveMapBuilder.put(42, new int[]{32, 32, 32, 240, 490}); + waveMapBuilder.put(43, new int[]{32, 32, 32, 85, 240, 490}); + waveMapBuilder.put(44, new int[]{32, 32, 32, 85, 85, 240, 490}); + waveMapBuilder.put(45, new int[]{32, 32, 32, 165, 240, 490 }); + waveMapBuilder.put(46, new int[]{32, 32, 32, 85, 165, 240, 490}); + waveMapBuilder.put(47, new int[]{32, 32, 32, 85, 85, 165, 240, 490}); + waveMapBuilder.put(48, new int[]{32, 32, 32, 165, 165, 240, 490}); + waveMapBuilder.put(49, new int[]{32, 32, 32, 240, 240, 490}); + waveMapBuilder.put(50, new int[]{32, 32, 32, 370, 490}); + waveMapBuilder.put(51, new int[]{32, 32, 32, 85, 370, 490}); + waveMapBuilder.put(52, new int[]{32, 32, 32, 85, 85, 370, 490}); + waveMapBuilder.put(53, new int[]{32, 32, 32, 165, 370, 490}); + waveMapBuilder.put(54, new int[]{32, 32, 32, 85, 165, 370, 490}); + waveMapBuilder.put(55, new int[]{32, 32, 32, 85, 85, 165, 370, 490}); + waveMapBuilder.put(56, new int[]{32, 32, 32, 165, 165, 370, 490}); + waveMapBuilder.put(57, new int[]{32, 32, 32, 240, 370, 490}); + waveMapBuilder.put(58, new int[]{32, 32, 32, 85, 240, 370, 490}); + waveMapBuilder.put(59, new int[]{32, 32, 32, 85, 85, 240, 370, 490}); + waveMapBuilder.put(60, new int[]{32, 32, 32, 165, 240, 370, 490}); + waveMapBuilder.put(61, new int[]{32, 32, 32, 85, 165, 240, 370, 490}); + waveMapBuilder.put(62, new int[]{32, 32, 32, 85, 85, 165, 240, 370, 490}); + waveMapBuilder.put(63, new int[]{32, 32, 32, 165, 165, 240, 370, 490}); + waveMapBuilder.put(64, new int[]{32, 32, 32, 85, 240, 240, 370, 490}); + waveMapBuilder.put(65, new int[]{32, 32, 32, 85, 370, 370, 490}); + waveMapBuilder.put(66, new int[]{32, 32, 32, 85, 490, 490}); + waveMapBuilder.put(67, new int[]{900}); + waveMapBuilder.put(68, new int[]{900, 900, 900}); + waveMapBuilder.put(69, new int[]{1400}); + + waveMapping = waveMapBuilder.build(); + + ImmutableMap.Builder nameMapBuilder = new ImmutableMap.Builder<>(); + + nameMapBuilder.put(32, "Jal-Nib - Level 32"); + nameMapBuilder.put(85, "Jal-MejRah - Level 85"); + nameMapBuilder.put(165, "Jal-Ak - Level 165"); + nameMapBuilder.put(240, "Jal-ImKot - Level 240"); + nameMapBuilder.put(370, "Jal-Xil - Level 370"); + nameMapBuilder.put(490, "Jal-Zek - Level 490"); + nameMapBuilder.put(900, "JalTok-Jad - Level 900"); + nameMapBuilder.put(1400, "TzKal-Zuk - Level 1400"); + + npcNameMapping = nameMapBuilder.build(); + } + + static void addWaveComponent(PanelComponent panelComponent, String header, int wave, Color titleColor, Color color) + { + int[] monsters = waveMapping.get(wave); + + if (monsters == null) { - return new HashMap() + return; + } + + panelComponent.getChildren() + .add(TitleComponent.builder() + .text(header) + .color(titleColor) + .build() + ); + + + for (int i = 0; i < monsters.length; i++) + { + int monsterType = monsters[i]; + int count = 1; + + for (; i < monsters.length - 1 && monsters[i + 1] == monsterType; i++) { - { - put(1, new int[]{32, 32, 32, 85}); - put(2, new int[]{32, 32, 32, 85, 85}); - put(3, new int[]{32, 32, 32, 32, 32, 32}); - put(4, new int[]{32, 32, 32, 165}); - put(5, new int[]{32, 32, 32, 85, 165}); - put(6, new int[]{32, 32, 32, 85, 85, 165}); - put(7, new int[]{32, 32, 32, 165, 165}); - put(8, new int[]{32, 32, 32, 32, 32, 32}); - put(9, new int[]{32, 32, 32, 240}); - put(10, new int[]{32, 32, 32, 85, 240}); - put(11, new int[]{32, 32, 32, 85, 85, 240}); - put(12, new int[]{32, 32, 32, 165, 240}); - put(13, new int[]{32, 32, 32, 85, 165, 240}); - put(14, new int[]{32, 32, 32, 85, 85, 165, 240}); - put(15, new int[]{32, 32, 32, 165, 165, 240}); - put(16, new int[]{32, 32, 32, 240, 240}); - put(17, new int[]{32, 32, 32, 32, 32, 32}); - put(18, new int[]{32, 32, 32, 370}); - put(19, new int[]{32, 32, 32, 85, 370}); - put(20, new int[]{32, 32, 32, 85, 85, 370}); - put(21, new int[]{32, 32, 32, 165, 370}); - put(22, new int[]{32, 32, 32, 85, 165, 370}); - put(23, new int[]{32, 32, 32, 85, 85, 165, 370}); - put(24, new int[]{32, 32, 32, 165, 165, 370}); - put(25, new int[]{32, 32, 32, 240, 370}); - put(26, new int[]{32, 32, 32, 85, 240, 370}); - put(27, new int[]{32, 32, 32, 85, 85, 240, 370}); - put(28, new int[]{32, 32, 32, 165, 240, 370}); - put(29, new int[]{32, 32, 32, 85, 165, 240, 370}); - put(30, new int[]{32, 32, 32, 85, 85, 165, 240, 370}); - put(31, new int[]{32, 32, 32, 165, 165, 240, 370}); - put(32, new int[]{32, 32, 32, 240, 240, 370}); - put(33, new int[]{32, 32, 32, 370, 370}); - put(34, new int[]{32, 32, 32, 32, 32, 32}); - put(35, new int[]{32, 32, 32, 490}); - put(36, new int[]{32, 32, 32, 85, 490}); - put(37, new int[]{32, 32, 32, 85, 85, 490}); - put(38, new int[]{32, 32, 32, 165, 490}); - put(39, new int[]{32, 32, 32, 85, 165, 490}); - put(40, new int[]{32, 32, 32, 85, 85, 165, 490}); - put(41, new int[]{32, 32, 32, 165, 165, 490}); - put(42, new int[]{32, 32, 32, 240, 490}); - put(43, new int[]{32, 32, 32, 85, 240, 490}); - put(44, new int[]{32, 32, 32, 85, 85, 240, 490}); - put(45, new int[]{32, 32, 32, 165, 240, 490 }); - put(46, new int[]{32, 32, 32, 85, 165, 240, 490}); - put(47, new int[]{32, 32, 32, 85, 85, 165, 240, 490}); - put(48, new int[]{32, 32, 32, 165, 165, 240, 490}); - put(49, new int[]{32, 32, 32, 240, 240, 490}); - put(50, new int[]{32, 32, 32, 370, 490}); - put(51, new int[]{32, 32, 32, 85, 370, 490}); - put(52, new int[]{32, 32, 32, 85, 85, 370, 490}); - put(53, new int[]{32, 32, 32, 165, 370, 490}); - put(54, new int[]{32, 32, 32, 85, 165, 370, 490}); - put(55, new int[]{32, 32, 32, 85, 85, 165, 370, 490}); - put(56, new int[]{32, 32, 32, 165, 165, 370, 490}); - put(57, new int[]{32, 32, 32, 240, 370, 490}); - put(58, new int[]{32, 32, 32, 85, 240, 370, 490}); - put(59, new int[]{32, 32, 32, 85, 85, 240, 370, 490}); - put(60, new int[]{32, 32, 32, 165, 240, 370, 490}); - put(61, new int[]{32, 32, 32, 85, 165, 240, 370, 490}); - put(62, new int[]{32, 32, 32, 85, 85, 165, 240, 370, 490}); - put(63, new int[]{32, 32, 32, 165, 165, 240, 370, 490}); - put(64, new int[]{32, 32, 32, 85, 240, 240, 370, 490}); - put(65, new int[]{32, 32, 32, 85, 370, 370, 490}); - put(66, new int[]{32, 32, 32, 85, 490, 490}); - put(67, new int[]{900}); - put(68, new int[]{900, 900, 900}); - put(69, new int[]{1400}); + count++; + } - } - }; - } + TitleComponent.TitleComponentBuilder builder = TitleComponent.builder(); - static Map npcNameMapping() - { - return new HashMap() - { - { - put(32, "Jal-Nib - Level 32"); - put(85, " Jal-MejRah - Level 85"); - put(165, "Jal-Ak - Level 165"); - put(240, "Jal-ImKot - Level 240"); - put(370, "Jal-Xil - Level 370"); - put(490, "Jal-Zek - Level 490"); - put(900, "JalTok-Jad - Level 900"); - put(1400, "TzKal-Zuk - Level 1400"); - } - }; - } + builder.text(count + "x " + npcNameMapping.get(monsterType)); + builder.color(color); - static HashMap intArrayToHashmap(int inputArray[]) - { - HashMap elementCountMap = new HashMap(); - for (int i : inputArray) - { - if (elementCountMap.containsKey(i)) - { - elementCountMap.put(i, elementCountMap.get(i) + 1); - } - else - { - elementCountMap.put(i, 1); - } - } - return elementCountMap; + panelComponent.getChildren().add(builder.build()); } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveOverlay.java index f721682a01..88e3e32766 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveOverlay.java @@ -1,69 +1,69 @@ package net.runelite.client.plugins.inferno; -import java.util.HashMap; -import java.util.Map; +import java.awt.Color; import com.google.inject.Inject; -import net.runelite.client.ui.overlay.components.TitleComponent; +import lombok.Setter; +import static net.runelite.client.plugins.inferno.InfernoWaveMappings.addWaveComponent; import java.awt.Graphics2D; import net.runelite.client.ui.overlay.OverlayPriority; import net.runelite.client.ui.overlay.OverlayPosition; import java.awt.Dimension; import net.runelite.client.ui.overlay.components.PanelComponent; -import net.runelite.api.Client; import net.runelite.client.ui.overlay.Overlay; public class InfernoWaveOverlay extends Overlay { - private final Client client; private final InfernoPlugin plugin; - private final InfernoConfig config; - private PanelComponent panelComponent; + private final PanelComponent panelComponent; + + @Setter + private Color waveHeaderColor; + + @Setter + private Color waveTextColor; + + @Setter + private InfernoWaveDisplayMode displayMode; @Inject - InfernoWaveOverlay(final Client client, final InfernoPlugin plugin, final InfernoConfig config) - { - (this.panelComponent = new PanelComponent()).setPreferredSize(new Dimension(150, 0)); - this.setPosition(OverlayPosition.TOP_RIGHT); - this.setPriority(OverlayPriority.HIGH); - this.client = client; - this.plugin = plugin; - this.config = config; - } + InfernoWaveOverlay(final InfernoPlugin plugin) + { + this.panelComponent = new PanelComponent(); + this.setPosition(OverlayPosition.TOP_RIGHT); + this.setPriority(OverlayPriority.HIGH); + this.plugin = plugin; + + panelComponent.setPreferredSize(new Dimension(160, 0)); + } public Dimension render(final Graphics2D graphics) + { + panelComponent.getChildren().clear(); + + if (displayMode == InfernoWaveDisplayMode.CURRENT || + displayMode == InfernoWaveDisplayMode.BOTH) { - if (!plugin.inInferno() || plugin.getCurrentWaveNumber() == 0) - { - return null; - } - panelComponent.getChildren().clear(); - if (config.waveDisplay() == InfernoWaveDisplayMode.CURRENT - || config.waveDisplay() == InfernoWaveDisplayMode.BOTH) - { - renderWave("Current Wave (Wave " + plugin.getCurrentWaveNumber() + ")", plugin.getCurrentWaveNumber()); - } - if ((config.waveDisplay() == InfernoWaveDisplayMode.NEXT - || config.waveDisplay() == InfernoWaveDisplayMode.BOTH) - && plugin.isNotFinalWave()) - { - renderWave("Next Wave (Wave " + plugin.getNextWaveNumber() + ")", plugin.getCurrentWaveNumber()); - } - return panelComponent.render(graphics); + addWaveComponent( + panelComponent, + "Current Wave (Wave " + plugin.getCurrentWaveNumber() + ")", + plugin.getCurrentWaveNumber(), + waveHeaderColor, + waveTextColor + ); } - private void renderWave(final String header, final int waveNumber) + if (displayMode == InfernoWaveDisplayMode.NEXT || + displayMode == InfernoWaveDisplayMode.BOTH) { - panelComponent.getChildren().add(TitleComponent.builder().text(header).color(config.getWaveOverlayHeaderColor()).build()); - final HashMap waveMap = (HashMap) InfernoWaveMappings.intArrayToHashmap(plugin.getWaves().get(waveNumber)); - for (final Map.Entry entry : waveMap.entrySet()) - { - final int monsterID = entry.getKey(); - final int quantity = entry.getValue(); - if (quantity <= 0) - { - continue; - } - panelComponent.getChildren().add(TitleComponent.builder().text(quantity + "x " + plugin.getMonster().get(monsterID)).color(config.getWaveTextColor()).build()); - } + addWaveComponent( + panelComponent, + "Next Wave (Wave " + plugin.getNextWaveNumber() + ")", + plugin.getNextWaveNumber(), + waveHeaderColor, + waveTextColor + ); } + + return panelComponent.render(graphics); } +}