From cdee2b1b0f83baa1a98f9a6ed65d67f2b92c9abb Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Mon, 10 Jun 2019 15:15:22 +0100 Subject: [PATCH 01/10] wave display --- .../client/plugins/inferno/InfernoConfig.java | 11 ++ .../plugins/inferno/InfernoOverlay.java | 1 - .../client/plugins/inferno/InfernoPlugin.java | 103 +++++++++++++- .../inferno/InfernoWaveDisplayMode.java | 43 ++++++ .../plugins/inferno/InfernoWaveMonster.java | 50 +++++++ .../plugins/inferno/InfernoWaveOverlay.java | 127 ++++++++++++++++++ 6 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveDisplayMode.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveMonster.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveOverlay.java 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 d6cd48ccce..1d25deef3e 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 @@ -52,4 +52,15 @@ public interface InfernoConfig extends Config { return false; } + + @ConfigItem( + position = 2, + keyName = "Wave Display", + name = "Wave display", + description = "Shows monsters that will spawn on the selected wave(s)." + ) + default InfernoWaveDisplayMode waveDisplay() + { + return InfernoWaveDisplayMode.BOTH; + } } 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 index dde2a01a9f..0175e1f751 100644 --- 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 @@ -36,7 +36,6 @@ 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; 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 599203359c..690fbdd347 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 @@ -26,15 +26,22 @@ package net.runelite.client.plugins.inferno; import com.google.inject.Provides; import java.util.ArrayList; +import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.inject.Inject; import lombok.Getter; +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.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; @@ -53,6 +60,10 @@ import net.runelite.client.ui.overlay.OverlayManager; ) public class InfernoPlugin extends Plugin { + + private static final Pattern WAVE_PATTERN = Pattern.compile(".*Wave: (\\d+).*"); + private static final int MAX_MONSTERS_OF_TYPE_PER_WAVE = 6; + static final int MAX_WAVE = 69; @Inject private Client client; @@ -62,6 +73,9 @@ public class InfernoPlugin extends Plugin @Inject private InfernoOverlay infernoOverlay; + + @Inject + private InfernoWaveOverlay waveOverlay; @Inject private InfernoInfobox infernoInfobox; @@ -71,6 +85,12 @@ public class InfernoPlugin extends Plugin @Inject private InfernoConfig config; + + @Getter + static final List> WAVES = new ArrayList<>(); + + @Getter + private int currentWave = -1; @Getter private Map monsters; @@ -83,6 +103,46 @@ public class InfernoPlugin extends Plugin @Getter private InfernoNPC[] priorityNPC; + + static + { + final InfernoWaveMonster[] waveMonsters = InfernoWaveMonster.values(); + + // Add wave 1, future waves are derived from its contents + final EnumMap waveOne = new EnumMap<>(InfernoWaveMonster.class); + waveOne.put(waveMonsters[0], 1); + WAVES.add(waveOne); + + for (int wave = 1; wave < MAX_WAVE; wave++) + { + final EnumMap prevWave = WAVES.get(wave - 1).clone(); + int maxMonsterOrdinal = -1; + + for (int i = 0; i < waveMonsters.length; i++) + { + final int ordinalMonsterQuantity = prevWave.getOrDefault(waveMonsters[i], 0); + + if (ordinalMonsterQuantity == MAX_MONSTERS_OF_TYPE_PER_WAVE) + { + maxMonsterOrdinal = i; + break; + } + } + + if (maxMonsterOrdinal >= 0) + { + prevWave.remove(waveMonsters[maxMonsterOrdinal]); + } + + final int addedMonsterOrdinal = maxMonsterOrdinal >= 0 ? maxMonsterOrdinal + 1 : 0; + final InfernoWaveMonster addedMonster = waveMonsters[addedMonsterOrdinal]; + final int addedMonsterQuantity = prevWave.getOrDefault(addedMonster, 0); + + prevWave.put(addedMonster, addedMonsterQuantity + 1); + + WAVES.add(prevWave); + } + } @Provides InfernoConfig provideConfig(ConfigManager configManager) @@ -96,6 +156,7 @@ public class InfernoPlugin extends Plugin overlayManager.add(infernoOverlay); overlayManager.add(infernoInfobox); overlayManager.add(nibblerOverlay); + overlayManager.add(waveOverlay); monsters = new HashMap<>(); monsterCurrentAttackMap = new HashMap<>(6); for (int i = 1; i <= 6; i++) @@ -112,6 +173,7 @@ public class InfernoPlugin extends Plugin overlayManager.remove(infernoInfobox); overlayManager.remove(infernoOverlay); overlayManager.remove(nibblerOverlay); + overlayManager.remove(waveOverlay); } @Subscribe @@ -148,6 +210,35 @@ public class InfernoPlugin extends Plugin nibblers.remove(npc); } } + + @Subscribe + public void onGameStateChanged(GameStateChanged event) + { + if (event.getGameState() != GameState.LOGGED_IN) + { + return; + } + + if (!inInferno()) + { + currentWave = -1; + } + } + + @Subscribe + public void onChatMessage(ChatMessage event) + { + final Matcher waveMatcher = WAVE_PATTERN.matcher(event.getMessage()); + + if (event.getType() != ChatMessageType.GAMEMESSAGE + || !inInferno() + || !waveMatcher.matches()) + { + return; + } + + currentWave = Integer.parseInt(waveMatcher.group(1)); + } @Subscribe public void onGameTick(GameTick event) @@ -271,5 +362,15 @@ public class InfernoPlugin extends Plugin return false; } + + boolean inInferno() + { + if (client.getMapRegions()[0] = 9043) return;; + } -} + static String formatMonsterQuantity(final InfernoWaveMonster monster, final int quantity) + { + return String.format("%dx %s", quantity, monster); + } + +} \ No newline at end of file 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 new file mode 100644 index 0000000000..628c4e814c --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveDisplayMode.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018, Jordan Atwood + * 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 lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum InfernoWaveDisplayMode +{ + CURRENT("Current wave"), + NEXT("Next wave"), + BOTH("Both"); + + private final String name; + + @Override + public String toString() + { + return name; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveMonster.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveMonster.java new file mode 100644 index 0000000000..3c93005f37 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveMonster.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018, Jordan Atwood + * 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 lombok.AllArgsConstructor; + +@AllArgsConstructor +enum InfernoWaveMonster +{ + + JAL_NIB("Jal-Nib", 32), + JAL_MEJRAH("Jal-MejRah", 85), + JAL_AK("Jal-Ak", 165), + JAL_IMKOT("Jal-ImKot", 240), + JAL_XIL("Jal-XIL", 370), + JAL_ZEK("Jal-Zek", 490), + JALTOK_JAD("JalTok-Jad", 900), + TZKAL_ZUK("TzKal-Zuk", 1400); + + private final String name; + private final int level; + + @Override + public String toString() + { + return String.format("%s - Level %s", name, level); + } +} 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 new file mode 100644 index 0000000000..1b367ea577 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoWaveOverlay.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2018, Jordan Atwood + * 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 java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import javax.inject.Inject; +import net.runelite.client.ui.ColorScheme; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.PanelComponent; +import net.runelite.client.ui.overlay.components.TitleComponent; +import net.runelite.client.ui.overlay.components.table.TableComponent; + +class WaveOverlay extends Overlay +{ + private static final Color HEADER_COLOR = ColorScheme.BRAND_ORANGE; + + private final InfernoConfig config; + private final InfernoPlugin plugin; + + private final PanelComponent panelComponent = new PanelComponent(); + + @Inject + private WaveOverlay(InfernoConfig config, InfernoPlugin plugin) + { + setPosition(OverlayPosition.TOP_RIGHT); + this.config = config; + this.plugin = plugin; + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (!plugin.inInferno() + || plugin.getCurrentWave() < 0) + { + return null; + } + + panelComponent.getChildren().clear(); + + final int currentWave = plugin.getCurrentWave(); + final int waveIndex = currentWave - 1; + + if (config.waveDisplay() == WaveDisplayMode.CURRENT + || config.waveDisplay() == WaveDisplayMode.BOTH) + { + final Map waveContents = InfernoPlugin.getWAVES().get(waveIndex); + + addWaveInfo("Wave " + plugin.getCurrentWave(), waveContents); + } + + if ((config.waveDisplay() == WaveDisplayMode.NEXT + || config.waveDisplay() == WaveDisplayMode.BOTH) + && currentWave != InfernoPlugin.MAX_WAVE) + { + final Map waveContents = InfernoPlugin.getWAVES().get(waveIndex + 1); + + addWaveInfo("Next wave", waveContents); + } + + return panelComponent.render(graphics); + } + + private void addWaveInfo(final String headerText, final Map waveContents) + { + panelComponent.getChildren().add(TitleComponent.builder() + .text(headerText) + .color(HEADER_COLOR) + .build()); + + TableComponent tableComponent = new TableComponent(); + + for (String line : buildWaveLines(waveContents)) + { + tableComponent.addRow(line); + } + + panelComponent.getChildren().add(tableComponent); + } + + private static Collection buildWaveLines(final Map wave) + { + final List> monsters = new ArrayList<>(wave.entrySet()); + monsters.sort(Map.Entry.comparingByKey()); + final List outputLines = new ArrayList<>(); + + for (Map.Entry monsterEntry : monsters) + { + final WaveMonster monster = monsterEntry.getKey(); + final int quantity = monsterEntry.getValue(); + final String line = InfernoPlugin.formatMonsterQuantity(monster, quantity); + + outputLines.add(line); + } + + return outputLines; + } +} From 8f7b855741cef570bee9dbe9e0b2252f699e5f6e Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Mon, 10 Jun 2019 15:19:52 +0100 Subject: [PATCH 02/10] Update InfernoWaveOverlay.java --- .../net/runelite/client/plugins/inferno/InfernoWaveOverlay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1b367ea577..17fb055d32 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 @@ -39,7 +39,7 @@ import net.runelite.client.ui.overlay.components.PanelComponent; import net.runelite.client.ui.overlay.components.TitleComponent; import net.runelite.client.ui.overlay.components.table.TableComponent; -class WaveOverlay extends Overlay +class InfernoWaveOverlay extends Overlay { private static final Color HEADER_COLOR = ColorScheme.BRAND_ORANGE; From 6ffc049e0af2bea95455219baa9c2871923129bb Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Mon, 10 Jun 2019 15:23:43 +0100 Subject: [PATCH 03/10] Update InfernoWaveOverlay.java --- .../net/runelite/client/plugins/inferno/InfernoWaveOverlay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 17fb055d32..fdeb425f51 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 @@ -49,7 +49,7 @@ class InfernoWaveOverlay extends Overlay private final PanelComponent panelComponent = new PanelComponent(); @Inject - private WaveOverlay(InfernoConfig config, InfernoPlugin plugin) + private InfernoWaveOverlay(InfernoConfig config, InfernoPlugin plugin) { setPosition(OverlayPosition.TOP_RIGHT); this.config = config; From 3a69b8f37cddc00f035b45ef6d6be342940fa4ac Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Mon, 10 Jun 2019 15:30:25 +0100 Subject: [PATCH 04/10] Update InfernoWaveOverlay.java --- .../plugins/inferno/InfernoWaveOverlay.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 fdeb425f51..32fb60d2f4 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 @@ -70,19 +70,19 @@ class InfernoWaveOverlay extends Overlay final int currentWave = plugin.getCurrentWave(); final int waveIndex = currentWave - 1; - if (config.waveDisplay() == WaveDisplayMode.CURRENT - || config.waveDisplay() == WaveDisplayMode.BOTH) + if (config.waveDisplay() == InfernoWaveDisplayMode.CURRENT + || config.waveDisplay() == InfernoWaveDisplayMode.BOTH) { - final Map waveContents = InfernoPlugin.getWAVES().get(waveIndex); + final Map waveContents = InfernoPlugin.getWAVES().get(waveIndex); addWaveInfo("Wave " + plugin.getCurrentWave(), waveContents); } - if ((config.waveDisplay() == WaveDisplayMode.NEXT - || config.waveDisplay() == WaveDisplayMode.BOTH) + if ((config.waveDisplay() == InfernoWaveDisplayMode.NEXT + || config.waveDisplay() == InfernoWaveDisplayMode.BOTH) && currentWave != InfernoPlugin.MAX_WAVE) { - final Map waveContents = InfernoPlugin.getWAVES().get(waveIndex + 1); + final Map waveContents = InfernoPlugin.getWAVES().get(waveIndex + 1); addWaveInfo("Next wave", waveContents); } @@ -90,7 +90,7 @@ class InfernoWaveOverlay extends Overlay return panelComponent.render(graphics); } - private void addWaveInfo(final String headerText, final Map waveContents) + private void addWaveInfo(final String headerText, final Map waveContents) { panelComponent.getChildren().add(TitleComponent.builder() .text(headerText) @@ -107,15 +107,15 @@ class InfernoWaveOverlay extends Overlay panelComponent.getChildren().add(tableComponent); } - private static Collection buildWaveLines(final Map wave) + private static Collection buildWaveLines(final Map wave) { - final List> monsters = new ArrayList<>(wave.entrySet()); + final List> monsters = new ArrayList<>(wave.entrySet()); monsters.sort(Map.Entry.comparingByKey()); final List outputLines = new ArrayList<>(); - for (Map.Entry monsterEntry : monsters) + for (Map.Entry monsterEntry : monsters) { - final WaveMonster monster = monsterEntry.getKey(); + final InfernoWaveMonster monster = monsterEntry.getKey(); final int quantity = monsterEntry.getValue(); final String line = InfernoPlugin.formatMonsterQuantity(monster, quantity); From 2c72126a9ed46b0428bffbbaebe09ab639b51ca6 Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Mon, 10 Jun 2019 15:38:16 +0100 Subject: [PATCH 05/10] Update InfernoPlugin.java --- .../net/runelite/client/plugins/inferno/InfernoPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 690fbdd347..9d9a783601 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 @@ -365,7 +365,7 @@ public class InfernoPlugin extends Plugin boolean inInferno() { - if (client.getMapRegions()[0] = 9043) return;; + if (client.getMapRegions()[0] = 9043) return; } static String formatMonsterQuantity(final InfernoWaveMonster monster, final int quantity) @@ -373,4 +373,4 @@ public class InfernoPlugin extends Plugin return String.format("%dx %s", quantity, monster); } -} \ No newline at end of file +} From fed0c9c91126150b3b7e37f0ae5146c7d2459417 Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Mon, 10 Jun 2019 15:41:23 +0100 Subject: [PATCH 06/10] Update InfernoPlugin.java --- .../net/runelite/client/plugins/inferno/InfernoPlugin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 9d9a783601..2160ec049a 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 @@ -51,6 +51,7 @@ 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", @@ -63,6 +64,7 @@ public class InfernoPlugin extends Plugin private static final Pattern WAVE_PATTERN = Pattern.compile(".*Wave: (\\d+).*"); private static final int MAX_MONSTERS_OF_TYPE_PER_WAVE = 6; + private static final int INFERNO_REGION = 9043; static final int MAX_WAVE = 69; @Inject @@ -365,7 +367,7 @@ public class InfernoPlugin extends Plugin boolean inInferno() { - if (client.getMapRegions()[0] = 9043) return; + return ArrayUtils.contains(client.getMapRegions(), INFERNO_REGION); } static String formatMonsterQuantity(final InfernoWaveMonster monster, final int quantity) From 3b3ebce7f416eb367eaad9724c5b8c64f974cb9b Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Tue, 11 Jun 2019 21:15:44 +0100 Subject: [PATCH 07/10] yad supp0rt --- .../plugins/inferno/InfernoJadAttack.java | 53 ++ .../plugins/inferno/InfernoJadOverlay.java | 87 ++ .../client/plugins/inferno/InfernoPlugin.java | 805 ++++++++++-------- 3 files changed, 567 insertions(+), 378 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadAttack.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadOverlay.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadAttack.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadAttack.java new file mode 100644 index 0000000000..3ca1dee8b0 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadAttack.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, Devin French + * 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.api.AnimationID; +import net.runelite.api.Prayer; + +public enum InfernoJadAttack +{ + MAGIC(AnimationID.JALTOK_JAD_MAGE_ATTACK, Prayer.PROTECT_FROM_MAGIC), + RANGE(AnimationID.JALTOK_JAD_RANGE_ATTACK, Prayer.PROTECT_FROM_MISSILES); + + private final int animation; + private final Prayer prayer; + + InfernoJadAttack(int animation, Prayer prayer) + { + this.animation = animation; + this.prayer = prayer; + } + + public int getAnimation() + { + return animation; + } + + public Prayer getPrayer() + { + return prayer; + } +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadOverlay.java new file mode 100644 index 0000000000..d6a07c5523 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadOverlay.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017, Devin French + * 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 java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.api.SpriteID; +import net.runelite.client.game.SpriteManager; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.OverlayPriority; +import net.runelite.client.ui.overlay.components.ComponentConstants; +import net.runelite.client.ui.overlay.components.ImageComponent; +import net.runelite.client.ui.overlay.components.PanelComponent; + +public class InfernoJadOverlay extends Overlay +{ + private static final Color NOT_ACTIVATED_BACKGROUND_COLOR = new Color(150, 0, 0, 150); + + private final Client client; + private final InfernoPlugin plugin; + private final SpriteManager spriteManager; + private final PanelComponent imagePanelComponent = new PanelComponent(); + + @Inject + private InfernoJadOverlay(Client client, InfernoPlugin plugin, SpriteManager spriteManager) + { + setPosition(OverlayPosition.BOTTOM_RIGHT); + setPriority(OverlayPriority.HIGH); + this.client = client; + this.plugin = plugin; + this.spriteManager = spriteManager; + } + + @Override + public Dimension render(Graphics2D graphics) + { + final InfernoJadAttack attack = plugin.getAttack(); + + if (attack == null) + { + return null; + } + + final BufferedImage prayerImage = getPrayerImage(attack); + + imagePanelComponent.getChildren().clear(); + imagePanelComponent.getChildren().add(new ImageComponent(prayerImage)); + imagePanelComponent.setBackgroundColor(client.isPrayerActive(attack.getPrayer()) + ? ComponentConstants.STANDARD_BACKGROUND_COLOR + : NOT_ACTIVATED_BACKGROUND_COLOR); + + return imagePanelComponent.render(graphics); + } + + private BufferedImage getPrayerImage(InfernoJadAttack attack) + { + final int prayerSpriteID = attack == InfernoJadAttack.MAGIC ? SpriteID.PRAYER_PROTECT_FROM_MAGIC : SpriteID.PRAYER_PROTECT_FROM_MISSILES; + return spriteManager.getSprite(prayerSpriteID, 0); + } +} \ No newline at end of file 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 2160ec049a..fd48d077b7 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,378 +1,427 @@ -/* - * 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.EnumMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import javax.inject.Inject; -import lombok.Getter; -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.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 -{ - - private static final Pattern WAVE_PATTERN = Pattern.compile(".*Wave: (\\d+).*"); - private static final int MAX_MONSTERS_OF_TYPE_PER_WAVE = 6; - private static final int INFERNO_REGION = 9043; - static final int MAX_WAVE = 69; - - @Inject - private Client client; - - @Inject - private OverlayManager overlayManager; - - @Inject - private InfernoOverlay infernoOverlay; - - @Inject - private InfernoWaveOverlay waveOverlay; - - @Inject - private InfernoInfobox infernoInfobox; - - @Inject - private InfernoNibblerOverlay nibblerOverlay; - - @Inject - private InfernoConfig config; - - @Getter - static final List> WAVES = new ArrayList<>(); - - @Getter - private int currentWave = -1; - - @Getter - private Map monsters; - - @Getter - private Map> monsterCurrentAttackMap; - - @Getter - private List nibblers; - - @Getter - private InfernoNPC[] priorityNPC; - - static - { - final InfernoWaveMonster[] waveMonsters = InfernoWaveMonster.values(); - - // Add wave 1, future waves are derived from its contents - final EnumMap waveOne = new EnumMap<>(InfernoWaveMonster.class); - waveOne.put(waveMonsters[0], 1); - WAVES.add(waveOne); - - for (int wave = 1; wave < MAX_WAVE; wave++) - { - final EnumMap prevWave = WAVES.get(wave - 1).clone(); - int maxMonsterOrdinal = -1; - - for (int i = 0; i < waveMonsters.length; i++) - { - final int ordinalMonsterQuantity = prevWave.getOrDefault(waveMonsters[i], 0); - - if (ordinalMonsterQuantity == MAX_MONSTERS_OF_TYPE_PER_WAVE) - { - maxMonsterOrdinal = i; - break; - } - } - - if (maxMonsterOrdinal >= 0) - { - prevWave.remove(waveMonsters[maxMonsterOrdinal]); - } - - final int addedMonsterOrdinal = maxMonsterOrdinal >= 0 ? maxMonsterOrdinal + 1 : 0; - final InfernoWaveMonster addedMonster = waveMonsters[addedMonsterOrdinal]; - final int addedMonsterQuantity = prevWave.getOrDefault(addedMonster, 0); - - prevWave.put(addedMonster, addedMonsterQuantity + 1); - - WAVES.add(prevWave); - } - } - - @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); - 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); - } - - @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); - } - } - - @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); - } - } - - @Subscribe - public void onGameStateChanged(GameStateChanged event) - { - if (event.getGameState() != GameState.LOGGED_IN) - { - return; - } - - if (!inInferno()) - { - currentWave = -1; - } - } - - @Subscribe - public void onChatMessage(ChatMessage event) - { - final Matcher waveMatcher = WAVE_PATTERN.matcher(event.getMessage()); - - if (event.getType() != ChatMessageType.GAMEMESSAGE - || !inInferno() - || !waveMatcher.matches()) - { - return; - } - - currentWave = Integer.parseInt(waveMatcher.group(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(); - } - - 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); - } - - static String formatMonsterQuantity(final InfernoWaveMonster monster, final int quantity) - { - return String.format("%dx %s", quantity, monster); - } - -} +/* + * 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.EnumMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.annotation.Nullable; +import javax.inject.Inject; +import lombok.AccessLevel; +import lombok.Getter; +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 +{ + + private static final Pattern WAVE_PATTERN = Pattern.compile(".*Wave: (\\d+).*"); + private static final int MAX_MONSTERS_OF_TYPE_PER_WAVE = 6; + private static final int INFERNO_REGION = 9043; + static final int MAX_WAVE = 69; + + @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 + static final List> WAVES = new ArrayList<>(); + + @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; + + + static + { + final InfernoWaveMonster[] waveMonsters = InfernoWaveMonster.values(); + + // Add wave 1, future waves are derived from its contents + final EnumMap waveOne = new EnumMap<>(InfernoWaveMonster.class); + waveOne.put(waveMonsters[0], 1); + WAVES.add(waveOne); + + for (int wave = 1; wave < MAX_WAVE; wave++) + { + final EnumMap prevWave = WAVES.get(wave - 1).clone(); + int maxMonsterOrdinal = -1; + + for (int i = 0; i < waveMonsters.length; i++) + { + final int ordinalMonsterQuantity = prevWave.getOrDefault(waveMonsters[i], 0); + + if (ordinalMonsterQuantity == MAX_MONSTERS_OF_TYPE_PER_WAVE) + { + maxMonsterOrdinal = i; + break; + } + } + + if (maxMonsterOrdinal >= 0) + { + prevWave.remove(waveMonsters[maxMonsterOrdinal]); + } + + final int addedMonsterOrdinal = maxMonsterOrdinal >= 0 ? maxMonsterOrdinal + 1 : 0; + final InfernoWaveMonster addedMonster = waveMonsters[addedMonsterOrdinal]; + final int addedMonsterQuantity = prevWave.getOrDefault(addedMonster, 0); + + prevWave.put(addedMonster, addedMonsterQuantity + 1); + + WAVES.add(prevWave); + } + } + + @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); + 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; + } + + @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(); + } + } + + @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; + } + } + + @Subscribe + public void onGameStateChanged(GameStateChanged event) + { + if (event.getGameState() != GameState.LOGGED_IN) + { + return; + } + + if (!inInferno()) + { + currentWave = -1; + } + } + + @Subscribe + public void onChatMessage(ChatMessage event) + { + final Matcher waveMatcher = WAVE_PATTERN.matcher(event.getMessage()); + + if (event.getType() != ChatMessageType.GAMEMESSAGE + || !inInferno() + || !waveMatcher.matches()) + { + return; + } + + currentWave = Integer.parseInt(waveMatcher.group(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); + } + + static String formatMonsterQuantity(final InfernoWaveMonster monster, final int quantity) + { + return String.format("%dx %s", quantity, monster); + } + +} \ No newline at end of file From f84d5b856869a24b91671b4fbe65b75117897214 Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Tue, 11 Jun 2019 22:02:08 +0100 Subject: [PATCH 08/10] yad fix --- .../plugins/inferno/InfernoJadOverlay.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadOverlay.java index d6a07c5523..43252b4c95 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadOverlay.java @@ -6,10 +6,10 @@ * 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. + * 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 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 @@ -29,6 +29,7 @@ import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import javax.inject.Inject; + import net.runelite.api.Client; import net.runelite.api.SpriteID; import net.runelite.client.game.SpriteManager; @@ -40,48 +41,47 @@ import net.runelite.client.ui.overlay.components.ImageComponent; import net.runelite.client.ui.overlay.components.PanelComponent; public class InfernoJadOverlay extends Overlay -{ - private static final Color NOT_ACTIVATED_BACKGROUND_COLOR = new Color(150, 0, 0, 150); + { + private static final Color NOT_ACTIVATED_BACKGROUND_COLOR = new Color(150, 0, 0, 150); + private final Client client; + private final InfernoPlugin plugin; + private final SpriteManager spriteManager; + private final PanelComponent imagePanelComponent = new PanelComponent(); - private final Client client; - private final InfernoPlugin plugin; - private final SpriteManager spriteManager; - private final PanelComponent imagePanelComponent = new PanelComponent(); + @Inject + private InfernoJadOverlay(Client client, InfernoPlugin plugin, SpriteManager spriteManager) + { + setPosition(OverlayPosition.BOTTOM_RIGHT); + setPriority(OverlayPriority.HIGH); + this.client = client; + this.plugin = plugin; + this.spriteManager = spriteManager; + } - @Inject - private InfernoJadOverlay(Client client, InfernoPlugin plugin, SpriteManager spriteManager) - { - setPosition(OverlayPosition.BOTTOM_RIGHT); - setPriority(OverlayPriority.HIGH); - this.client = client; - this.plugin = plugin; - this.spriteManager = spriteManager; - } + @Override + public Dimension render(Graphics2D graphics) + { + final InfernoJadAttack attack = plugin.getAttack(); - @Override - public Dimension render(Graphics2D graphics) - { - final InfernoJadAttack attack = plugin.getAttack(); + if (attack == null) + { + return null; + } - if (attack == null) - { - return null; - } + final BufferedImage prayerImage = getPrayerImage(attack); - final BufferedImage prayerImage = getPrayerImage(attack); + imagePanelComponent.getChildren().clear(); + imagePanelComponent.getChildren().add(new ImageComponent(prayerImage)); + imagePanelComponent.setBackgroundColor(client.isPrayerActive(attack.getPrayer()) + ? ComponentConstants.STANDARD_BACKGROUND_COLOR + : NOT_ACTIVATED_BACKGROUND_COLOR); - imagePanelComponent.getChildren().clear(); - imagePanelComponent.getChildren().add(new ImageComponent(prayerImage)); - imagePanelComponent.setBackgroundColor(client.isPrayerActive(attack.getPrayer()) - ? ComponentConstants.STANDARD_BACKGROUND_COLOR - : NOT_ACTIVATED_BACKGROUND_COLOR); + return imagePanelComponent.render(graphics); + } - return imagePanelComponent.render(graphics); - } - - private BufferedImage getPrayerImage(InfernoJadAttack attack) - { - final int prayerSpriteID = attack == InfernoJadAttack.MAGIC ? SpriteID.PRAYER_PROTECT_FROM_MAGIC : SpriteID.PRAYER_PROTECT_FROM_MISSILES; - return spriteManager.getSprite(prayerSpriteID, 0); - } -} \ No newline at end of file + private BufferedImage getPrayerImage(InfernoJadAttack attack) + { + final int prayerSpriteID = attack == InfernoJadAttack.MAGIC ? SpriteID.PRAYER_PROTECT_FROM_MAGIC : SpriteID.PRAYER_PROTECT_FROM_MISSILES; + return spriteManager.getSprite(prayerSpriteID, 0); + } + } From 74957017ba665bc57c2bbe2ff06370a88ae549c5 Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Tue, 11 Jun 2019 22:02:33 +0100 Subject: [PATCH 09/10] yad fix --- .../plugins/inferno/InfernoJadAttack.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadAttack.java b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadAttack.java index 3ca1dee8b0..28ae29c1cd 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadAttack.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inferno/InfernoJadAttack.java @@ -6,10 +6,10 @@ * 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. + * 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 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 @@ -28,26 +28,26 @@ import net.runelite.api.AnimationID; import net.runelite.api.Prayer; public enum InfernoJadAttack -{ - MAGIC(AnimationID.JALTOK_JAD_MAGE_ATTACK, Prayer.PROTECT_FROM_MAGIC), - RANGE(AnimationID.JALTOK_JAD_RANGE_ATTACK, Prayer.PROTECT_FROM_MISSILES); + { + MAGIC(AnimationID.JALTOK_JAD_MAGE_ATTACK, Prayer.PROTECT_FROM_MAGIC), + RANGE(AnimationID.JALTOK_JAD_RANGE_ATTACK, Prayer.PROTECT_FROM_MISSILES); - private final int animation; - private final Prayer prayer; + private final int animation; + private final Prayer prayer; - InfernoJadAttack(int animation, Prayer prayer) - { - this.animation = animation; - this.prayer = prayer; - } + InfernoJadAttack(int animation, Prayer prayer) + { + this.animation = animation; + this.prayer = prayer; + } - public int getAnimation() - { - return animation; - } + public int getAnimation() + { + return animation; + } - public Prayer getPrayer() - { - return prayer; - } -} \ No newline at end of file + public Prayer getPrayer() + { + return prayer; + } + } From f1027795978d9d82f0a691489388a8022593e4ac Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Tue, 11 Jun 2019 22:09:49 +0100 Subject: [PATCH 10/10] Update AnimationID.java --- .../main/java/net/runelite/api/AnimationID.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/runelite-api/src/main/java/net/runelite/api/AnimationID.java b/runelite-api/src/main/java/net/runelite/api/AnimationID.java index 39353a15f4..7d8c4f52f4 100644 --- a/runelite-api/src/main/java/net/runelite/api/AnimationID.java +++ b/runelite-api/src/main/java/net/runelite/api/AnimationID.java @@ -251,4 +251,21 @@ public final class AnimationID public static final int HYDRA_RANGED_4 = 8255; public static final int HYDRA_4_1 = 8257; public static final int HYDRA_4_2 = 8258; + + // INFERNO animations + public static final int JAL_NIB = 7574; + public static final int JAL_MEJRAH = 7578; + public static final int JAL_AK_RANGE_ATTACK = 7581; + public static final int JAL_AK_MELEE_ATTACK = 7582; + public static final int JAL_AK_MAGIC_ATTACK = 7583; + public static final int JAL_IMKOT = 7597; + public static final int JAL_XIL_MELEE_ATTACK = 7604; + public static final int JAL_XIL_RANGE_ATTACK = 7605; + public static final int JAL_ZEK_MAGE_ATTACK = 7610; + public static final int JAL_ZEK_MELEE_ATTACK = 7612; + public static final int JALTOK_JAD_MELEE_ATTACK = 7590; + public static final int JALTOK_JAD_MAGE_ATTACK = 7592; + public static final int JALTOK_JAD_RANGE_ATTACK = 7593; + public static final int TZKAL_ZUK = 7566; + public static final int JAL_MEJJAK = 2858; }