entity hider: Don't hide NPCs which are alive at 0hp

This commit is contained in:
Jordan Atwood
2022-06-17 09:01:38 -07:00
committed by Adam
parent 68da7ce55f
commit 1979ca14a7
3 changed files with 69 additions and 29 deletions

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2022, Jordan Atwood <nightfirecat@nightfirec.at>
* 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();
}
}
}

View File

@@ -38,6 +38,7 @@ import net.runelite.client.callback.Hooks;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.ConfigChanged;
import net.runelite.client.game.NpcUtil;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; 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 // dead npcs can also be interacting so prioritize it over the interacting check
if (npc.isDead() && hideDeadNpcs) if (NpcUtil.isDying(npc) && hideDeadNpcs)
{ {
return false; return false;
} }

View File

@@ -55,7 +55,6 @@ import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry; import net.runelite.api.MenuEntry;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.NPCComposition; import net.runelite.api.NPCComposition;
import net.runelite.api.NpcID;
import net.runelite.api.ObjectComposition; import net.runelite.api.ObjectComposition;
import net.runelite.api.ParamID; import net.runelite.api.ParamID;
import net.runelite.api.events.ClientTick; 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.events.ConfigChanged;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
import net.runelite.client.game.ItemVariationMapping; import net.runelite.client.game.ItemVariationMapping;
import net.runelite.client.game.NpcUtil;
import net.runelite.client.menus.MenuManager; import net.runelite.client.menus.MenuManager;
import net.runelite.client.menus.WidgetMenuOption; import net.runelite.client.menus.WidgetMenuOption;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
@@ -1275,33 +1275,7 @@ public class MenuEntrySwapperPlugin extends Plugin
.filter(e -> .filter(e ->
{ {
final NPC npc = e.getNpc(); final NPC npc = e.getNpc();
if (npc == null) return npc == null || !NpcUtil.isDying(npc);
{
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();
}
}) })
.toArray(MenuEntry[]::new); .toArray(MenuEntry[]::new);
if (oldEntries.length != newEntries.length) if (oldEntries.length != newEntries.length)