From 1979ca14a7c53e1f793cbde9cefb66d64907865d Mon Sep 17 00:00:00 2001 From: Jordan Atwood Date: Fri, 17 Jun 2022 09:01:38 -0700 Subject: [PATCH] entity hider: Don't hide NPCs which are alive at 0hp --- .../net/runelite/client/game/NpcUtil.java | 65 +++++++++++++++++++ .../entityhider/EntityHiderPlugin.java | 3 +- .../MenuEntrySwapperPlugin.java | 30 +-------- 3 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/game/NpcUtil.java diff --git a/runelite-client/src/main/java/net/runelite/client/game/NpcUtil.java b/runelite-client/src/main/java/net/runelite/client/game/NpcUtil.java new file mode 100644 index 0000000000..a39757ce95 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/game/NpcUtil.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022, 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 HOLDER 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.game; + +import net.runelite.api.NPC; +import net.runelite.api.NpcID; + +public class NpcUtil +{ + /** + * Returns whether an NPC is dying and can no longer be interacted with, or if it is still alive or in some special + * state where it can be 0hp without dying. (For example, Gargoyles and other slayer monsters with item weaknesses + * are not killed by reaching 0hp, so would not be dead based on that alone.) + * + * @param npc NPC to check whether it is dying + * @return {@code true} if the NPC is dying + */ + public static boolean isDying(final NPC npc) + { + final int id = npc.getId(); + switch (id) + { + // These NPCs hit 0hp but don't actually die + case NpcID.GARGOYLE: + case NpcID.GARGOYLE_413: + case NpcID.GARGOYLE_1543: + case NpcID.ZYGOMITE: + case NpcID.ZYGOMITE_1024: + case NpcID.ANCIENT_ZYGOMITE: + case NpcID.ROCKSLUG: + case NpcID.ROCKSLUG_422: + case NpcID.DESERT_LIZARD: + case NpcID.DESERT_LIZARD_460: + case NpcID.DESERT_LIZARD_461: + case NpcID.ICE_DEMON: + case NpcID.ICE_DEMON_7585: + return false; + default: + return npc.isDead(); + } + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderPlugin.java index ee63182d03..a3932376e3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderPlugin.java @@ -38,6 +38,7 @@ import net.runelite.client.callback.Hooks; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.events.ConfigChanged; +import net.runelite.client.game.NpcUtil; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; @@ -190,7 +191,7 @@ public class EntityHiderPlugin extends Plugin } // dead npcs can also be interacting so prioritize it over the interacting check - if (npc.isDead() && hideDeadNpcs) + if (NpcUtil.isDying(npc) && hideDeadNpcs) { return false; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java index 51485ea6fa..3c11c50207 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java @@ -55,7 +55,6 @@ import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.NPC; import net.runelite.api.NPCComposition; -import net.runelite.api.NpcID; import net.runelite.api.ObjectComposition; import net.runelite.api.ParamID; import net.runelite.api.events.ClientTick; @@ -73,6 +72,7 @@ import net.runelite.client.eventbus.Subscribe; import net.runelite.client.events.ConfigChanged; import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemVariationMapping; +import net.runelite.client.game.NpcUtil; import net.runelite.client.menus.MenuManager; import net.runelite.client.menus.WidgetMenuOption; import net.runelite.client.plugins.Plugin; @@ -1275,33 +1275,7 @@ public class MenuEntrySwapperPlugin extends Plugin .filter(e -> { final NPC npc = e.getNpc(); - if (npc == null) - { - return true; - } - - final int id = npc.getId(); - switch (id) - { - // These NPCs hit 0hp but don't actually die - case NpcID.GARGOYLE: - case NpcID.GARGOYLE_413: - case NpcID.GARGOYLE_1543: - case NpcID.ZYGOMITE: - case NpcID.ZYGOMITE_1024: - case NpcID.ANCIENT_ZYGOMITE: - case NpcID.ROCKSLUG: - case NpcID.ROCKSLUG_422: - case NpcID.DESERT_LIZARD: - case NpcID.DESERT_LIZARD_460: - case NpcID.DESERT_LIZARD_461: - case NpcID.ICE_DEMON: - case NpcID.ICE_DEMON_7585: - return true; - default: - return !npc.isDead(); - - } + return npc == null || !NpcUtil.isDying(npc); }) .toArray(MenuEntry[]::new); if (oldEntries.length != newEntries.length)