speccounter: use hitsplats for determining spec hit

This commit is contained in:
Adam
2020-03-05 09:08:03 -05:00
parent 183761cafb
commit 8674a4f998
2 changed files with 41 additions and 109 deletions

View File

@@ -34,25 +34,23 @@ import net.runelite.api.NpcID;
@ToString @ToString
enum Boss enum Boss
{ {
ABYSSAL_SIRE(1.25d, 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), 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(1.225d, NpcID.CALLISTO, NpcID.CALLISTO_6609), CALLISTO(NpcID.CALLISTO, NpcID.CALLISTO_6609),
CERBERUS(1.15d, NpcID.CERBERUS, NpcID.CERBERUS_5863, NpcID.CERBERUS_5866), CERBERUS(NpcID.CERBERUS, NpcID.CERBERUS_5863, NpcID.CERBERUS_5866),
CHAOS_ELEMENTAL(1.075d, NpcID.CHAOS_ELEMENTAL, NpcID.CHAOS_ELEMENTAL_6505), CHAOS_ELEMENTAL(NpcID.CHAOS_ELEMENTAL, NpcID.CHAOS_ELEMENTAL_6505),
CORPOREAL_BEAST(1.55d, NpcID.CORPOREAL_BEAST), CORPOREAL_BEAST(NpcID.CORPOREAL_BEAST),
GENERAL_GRAARDOR(1.325d, NpcID.GENERAL_GRAARDOR, NpcID.GENERAL_GRAARDOR_6494), GENERAL_GRAARDOR(NpcID.GENERAL_GRAARDOR, NpcID.GENERAL_GRAARDOR_6494),
GIANT_MOLE(1.075d, NpcID.GIANT_MOLE, NpcID.GIANT_MOLE_6499), GIANT_MOLE(NpcID.GIANT_MOLE, NpcID.GIANT_MOLE_6499),
KALPHITE_QUEEN(1.05d, 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), 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(1.075d, NpcID.KING_BLACK_DRAGON, NpcID.KING_BLACK_DRAGON_2642, NpcID.KING_BLACK_DRAGON_6502), KING_BLACK_DRAGON(NpcID.KING_BLACK_DRAGON, NpcID.KING_BLACK_DRAGON_2642, NpcID.KING_BLACK_DRAGON_6502),
KRIL_TSUROTH(1.375d, NpcID.KRIL_TSUTSAROTH, NpcID.KRIL_TSUTSAROTH_6495), KRIL_TSUROTH(NpcID.KRIL_TSUTSAROTH, NpcID.KRIL_TSUTSAROTH_6495),
VENETENATIS(1.4d, NpcID.VENENATIS, NpcID.VENENATIS_6610), VENETENATIS(NpcID.VENENATIS, NpcID.VENENATIS_6610),
VETION(1.225d, NpcID.VETION, NpcID.VETION_REBORN); VETION(NpcID.VETION, NpcID.VETION_REBORN);
private final Set<Integer> ids; private final Set<Integer> ids;
private final double modifier; // Some NPCs have a modifier to the experience a player receives.
Boss(double modifier, Integer... ids) Boss(Integer... ids)
{ {
this.modifier = modifier;
this.ids = Sets.newHashSet(ids); this.ids = Sets.newHashSet(ids);
} }

View File

@@ -32,19 +32,15 @@ import net.runelite.api.Actor;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.EquipmentInventorySlot; import net.runelite.api.EquipmentInventorySlot;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.api.Hitsplat;
import net.runelite.api.InventoryID; import net.runelite.api.InventoryID;
import net.runelite.api.Item; import net.runelite.api.Item;
import net.runelite.api.ItemContainer; import net.runelite.api.ItemContainer;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.Player;
import net.runelite.api.Skill;
import net.runelite.api.VarPlayer; import net.runelite.api.VarPlayer;
import net.runelite.api.events.FakeXpDrop;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick; import net.runelite.api.events.HitsplatApplied;
import net.runelite.api.events.NpcDespawned; import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.StatChanged;
import net.runelite.api.events.VarbitChanged; import net.runelite.api.events.VarbitChanged;
import net.runelite.client.callback.ClientThread; import net.runelite.client.callback.ClientThread;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
@@ -54,7 +50,6 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.ws.PartyService; import net.runelite.client.ws.PartyService;
import net.runelite.client.ws.WSClient; import net.runelite.client.ws.WSClient;
import org.apache.commons.lang3.ArrayUtils;
@PluginDescriptor( @PluginDescriptor(
name = "Special Attack Counter", name = "Special Attack Counter",
@@ -66,10 +61,7 @@ public class SpecialCounterPlugin extends Plugin
{ {
private int currentWorld = -1; private int currentWorld = -1;
private int specialPercentage = -1; private int specialPercentage = -1;
private int specialHitpointsExperience = -1;
private int specialHitpointsGained = -1;
private boolean specialUsed; private boolean specialUsed;
private double modifier = 1d;
private SpecialWeapon specialWeapon; private SpecialWeapon specialWeapon;
private final Set<Integer> interactedNpcIds = new HashSet<>(); private final Set<Integer> interactedNpcIds = new HashSet<>();
@@ -137,105 +129,57 @@ public class SpecialCounterPlugin extends Plugin
this.specialPercentage = specialPercentage; this.specialPercentage = specialPercentage;
this.specialWeapon = usedSpecialWeapon(); this.specialWeapon = usedSpecialWeapon();
checkInteracting();
specialUsed = true; specialUsed = true;
specialHitpointsExperience = client.getSkillExperience(Skill.HITPOINTS);
specialHitpointsGained = -1;
} }
@Subscribe @Subscribe
public void onStatChanged(StatChanged statChanged) public void onHitsplatApplied(HitsplatApplied hitsplatApplied)
{ {
if (specialUsed && statChanged.getSkill() == Skill.HITPOINTS) Actor target = hitsplatApplied.getActor();
{ Hitsplat hitsplat = hitsplatApplied.getHitsplat();
specialHitpointsGained = statChanged.getXp() - specialHitpointsExperience; if (hitsplat.getHitsplatType() != Hitsplat.HitsplatType.DAMAGE_ME || !(target instanceof NPC))
}
}
@Subscribe
public void onFakeXpDrop(FakeXpDrop fakeXpDrop)
{
if (specialUsed && fakeXpDrop.getSkill() == Skill.HITPOINTS)
{
specialHitpointsGained = fakeXpDrop.getXp();
}
}
@Subscribe
private void onGameTick(GameTick tick)
{
if (client.getGameState() != GameState.LOGGED_IN)
{ {
return; return;
} }
int interactingId = checkInteracting(); NPC npc = (NPC) target;
if (interactingId > -1 && specialUsed) int interactingId = npc.getId();
{
int deltaExperience = specialHitpointsGained;
// If this is a new NPC reset the counters
if (!interactedNpcIds.contains(interactingId))
{
removeCounters();
addInteracting(interactingId);
}
if (specialUsed)
{
specialUsed = false; specialUsed = false;
if (deltaExperience > 0) if (specialWeapon != null)
{ {
if (specialWeapon != null) int hit = getHit(specialWeapon, hitsplat);
updateCounter(specialWeapon, null, hit);
if (!party.getMembers().isEmpty())
{ {
int hit = getHit(specialWeapon, deltaExperience); final SpecialCounterUpdate specialCounterUpdate = new SpecialCounterUpdate(interactingId, specialWeapon, hit);
specialCounterUpdate.setMemberId(party.getLocalMember().getMemberId());
updateCounter(specialWeapon, null, hit); wsClient.send(specialCounterUpdate);
if (!party.getMembers().isEmpty())
{
final SpecialCounterUpdate specialCounterUpdate = new SpecialCounterUpdate(interactingId, specialWeapon, hit);
specialCounterUpdate.setMemberId(party.getLocalMember().getMemberId());
wsClient.send(specialCounterUpdate);
}
} }
} }
} }
} }
private int checkInteracting()
{
Player localPlayer = client.getLocalPlayer();
Actor interacting = localPlayer.getInteracting();
if (interacting instanceof NPC)
{
NPC npc = (NPC) interacting;
NPCComposition composition = npc.getComposition();
int interactingId = npc.getId();
if (!ArrayUtils.contains(composition.getActions(), "Attack"))
{
// Skip over non attackable npcs so that eg. talking to bankers doesn't reset
// the counters.
return -1;
}
if (!interactedNpcIds.contains(interactingId))
{
removeCounters();
addInteracting(interactingId);
}
return interactingId;
}
return -1;
}
private void addInteracting(int npcId) private void addInteracting(int npcId)
{ {
modifier = 1d;
interactedNpcIds.add(npcId); interactedNpcIds.add(npcId);
// Add alternate forms of bosses // Add alternate forms of bosses
final Boss boss = Boss.getBoss(npcId); final Boss boss = Boss.getBoss(npcId);
if (boss != null) if (boss != null)
{ {
modifier = boss.getModifier();
interactedNpcIds.addAll(boss.getIds()); interactedNpcIds.addAll(boss.getIds());
} }
} }
@@ -356,18 +300,8 @@ public class SpecialCounterPlugin extends Plugin
} }
} }
private int getHit(SpecialWeapon specialWeapon, int deltaExperience) private int getHit(SpecialWeapon specialWeapon, Hitsplat hitsplat)
{ {
double modifierBase = 1d / modifier; return specialWeapon.isDamage() ? hitsplat.getAmount() : 1;
double damageOutput = (deltaExperience * modifierBase) / 1.3333d;
if (!specialWeapon.isDamage())
{
return 1;
}
else
{
return (int) Math.round(damageOutput);
}
} }
} }