spec-counter: use npc index instead of id for tracking

This commit is contained in:
Hexagon
2022-06-19 09:00:22 -03:00
committed by GitHub
parent 2e3d6e27fe
commit cc61a00950
4 changed files with 19 additions and 100 deletions

View File

@@ -1,71 +0,0 @@
/*
* Copyright (c) 2018, Raqes <j.raqes@gmail.com>
* 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.specialcounter;
import com.google.common.collect.Sets;
import java.util.Set;
import lombok.Getter;
import lombok.ToString;
import net.runelite.api.NpcID;
@Getter
@ToString
enum Boss
{
ABYSSAL_SIRE(NpcID.ABYSSAL_SIRE, NpcID.ABYSSAL_SIRE_5887, NpcID.ABYSSAL_SIRE_5888, NpcID.ABYSSAL_SIRE_5889, NpcID.ABYSSAL_SIRE_5890, NpcID.ABYSSAL_SIRE_5891, NpcID.ABYSSAL_SIRE_5908),
CALLISTO(NpcID.CALLISTO, NpcID.CALLISTO_6609),
CERBERUS(NpcID.CERBERUS, NpcID.CERBERUS_5863, NpcID.CERBERUS_5866),
CHAOS_ELEMENTAL(NpcID.CHAOS_ELEMENTAL, NpcID.CHAOS_ELEMENTAL_6505),
CORPOREAL_BEAST(NpcID.CORPOREAL_BEAST),
GENERAL_GRAARDOR(NpcID.GENERAL_GRAARDOR, NpcID.GENERAL_GRAARDOR_6494),
GIANT_MOLE(NpcID.GIANT_MOLE, NpcID.GIANT_MOLE_6499),
KALPHITE_QUEEN(NpcID.KALPHITE_QUEEN, NpcID.KALPHITE_QUEEN_963, NpcID.KALPHITE_QUEEN_965, NpcID.KALPHITE_QUEEN_4303, NpcID.KALPHITE_QUEEN_4304, NpcID.KALPHITE_QUEEN_6500, NpcID.KALPHITE_QUEEN_6501),
KING_BLACK_DRAGON(NpcID.KING_BLACK_DRAGON, NpcID.KING_BLACK_DRAGON_2642, NpcID.KING_BLACK_DRAGON_6502),
KRIL_TSUROTH(NpcID.KRIL_TSUTSAROTH, NpcID.KRIL_TSUTSAROTH_6495),
VENETENATIS(NpcID.VENENATIS, NpcID.VENENATIS_6610),
VETION(NpcID.VETION, NpcID.VETION_REBORN),
ALCHEMICAL_HYDRA(NpcID.ALCHEMICAL_HYDRA, NpcID.ALCHEMICAL_HYDRA_8616, NpcID.ALCHEMICAL_HYDRA_8617, NpcID.ALCHEMICAL_HYDRA_8618, NpcID.ALCHEMICAL_HYDRA_8619, NpcID.ALCHEMICAL_HYDRA_8620, NpcID.ALCHEMICAL_HYDRA_8621, NpcID.ALCHEMICAL_HYDRA_8622, NpcID.ALCHEMICAL_HYDRA_8634);
private final Set<Integer> ids;
Boss(Integer... ids)
{
this.ids = Sets.newHashSet(ids);
}
static Boss getBoss(int id)
{
for (Boss boss : values())
{
if (boss.ids.contains(id))
{
return boss;
}
}
return null;
}
}

View File

@@ -101,7 +101,7 @@ public class SpecialCounterPlugin extends Plugin
private boolean wasInInstance;
private SpecialWeapon specialWeapon;
private final Set<Integer> interactedNpcIds = new HashSet<>();
private final Set<Integer> interactedNpcIndexes = new HashSet<>();
private final SpecialCounter[] specialCounter = new SpecialCounter[SpecialWeapon.values().length];
@Getter(AccessLevel.PACKAGE)
@@ -156,7 +156,7 @@ public class SpecialCounterPlugin extends Plugin
specialPercentage = -1;
lastSpecTarget = null;
lastSpecTick = -1;
interactedNpcIds.clear();
interactedNpcIndexes.clear();
}
@Override
@@ -275,6 +275,7 @@ public class SpecialCounterPlugin extends Plugin
NPC npc = (NPC) target;
int interactingId = npc.getId();
int npcIndex = npc.getIndex();
if (IGNORED_NPCS.contains(interactingId))
{
@@ -282,10 +283,10 @@ public class SpecialCounterPlugin extends Plugin
}
// If this is a new NPC reset the counters
if (!interactedNpcIds.contains(interactingId))
if (!interactedNpcIndexes.contains(npcIndex))
{
removeCounters();
addInteracting(interactingId);
interactedNpcIndexes.add(npcIndex);
}
if (wasSpec && specialWeapon != null && hitsplat.getAmount() > 0)
@@ -300,7 +301,7 @@ public class SpecialCounterPlugin extends Plugin
if (!party.getMembers().isEmpty())
{
final SpecialCounterUpdate specialCounterUpdate = new SpecialCounterUpdate(interactingId, specialWeapon, hit, client.getWorld(), localPlayerId);
final SpecialCounterUpdate specialCounterUpdate = new SpecialCounterUpdate(npcIndex, specialWeapon, hit, client.getWorld(), localPlayerId);
specialCounterUpdate.setMemberId(party.getLocalMember().getMemberId());
party.send(specialCounterUpdate);
}
@@ -309,18 +310,6 @@ public class SpecialCounterPlugin extends Plugin
}
}
private void addInteracting(int npcId)
{
interactedNpcIds.add(npcId);
// Add alternate forms of bosses
final Boss boss = Boss.getBoss(npcId);
if (boss != null)
{
interactedNpcIds.addAll(boss.getIds());
}
}
@Subscribe
public void onNpcDespawned(NpcDespawned npcDespawned)
{
@@ -331,7 +320,7 @@ public class SpecialCounterPlugin extends Plugin
lastSpecTarget = null;
}
if (actor.isDead() && interactedNpcIds.contains(actor.getId()))
if (actor.isDead() && interactedNpcIndexes.contains(actor.getIndex()))
{
removeCounters();
}
@@ -340,7 +329,8 @@ public class SpecialCounterPlugin extends Plugin
@Subscribe
public void onSpecialCounterUpdate(SpecialCounterUpdate event)
{
if (party.getLocalMember().getMemberId().equals(event.getMemberId()))
if (party.getLocalMember().getMemberId().equals(event.getMemberId())
|| event.getWorld() != client.getWorld())
{
return;
}
@@ -354,13 +344,13 @@ public class SpecialCounterPlugin extends Plugin
clientThread.invoke(() ->
{
// If not interacting with any npcs currently, add to interacting list
if (interactedNpcIds.isEmpty())
if (interactedNpcIndexes.isEmpty())
{
addInteracting(event.getNpcId());
interactedNpcIndexes.add(event.getNpcIndex());
}
// Otherwise we only add the count if it is against a npc we are already tracking
if (interactedNpcIds.contains(event.getNpcId()))
if (interactedNpcIndexes.contains(event.getNpcIndex()))
{
if (config.infobox())
{
@@ -368,10 +358,7 @@ public class SpecialCounterPlugin extends Plugin
}
}
if (event.getWorld() == client.getWorld())
{
playerInfoDrops.add(createSpecInfoDrop(event.getWeapon(), event.getHit(), event.getPlayerId()));
}
playerInfoDrops.add(createSpecInfoDrop(event.getWeapon(), event.getHit(), event.getPlayerId()));
});
}
@@ -453,7 +440,7 @@ public class SpecialCounterPlugin extends Plugin
private void removeCounters()
{
interactedNpcIds.clear();
interactedNpcIndexes.clear();
for (int i = 0; i < specialCounter.length; ++i)
{

View File

@@ -32,7 +32,7 @@ import net.runelite.client.party.messages.PartyMemberMessage;
@EqualsAndHashCode(callSuper = true)
public class SpecialCounterUpdate extends PartyMemberMessage
{
private final int npcId;
private final int npcIndex;
private final SpecialWeapon weapon;
private final int hit;
private final int world;

View File

@@ -238,7 +238,10 @@ public class SpecialCounterPluginTest
{
NPC targetA = mock(NPC.class);
NPC targetB = mock(NPC.class);
when(targetB.getId()).thenReturn(1); // a different npc type
// a different npc type
when(targetB.getId()).thenReturn(1);
when(targetB.getIndex()).thenReturn(1);
Player player = mock(Player.class);
when(client.getLocalPlayer()).thenReturn(player);