From a877c5800546b5c28727224e114f058d473d7894 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 13 Mar 2022 15:29:24 -0400 Subject: [PATCH] loot tracker: support opening multiple imp jars in 1 tick This tracks the number of removed jars to determine how many were opened. This only works when opening multiple of the same type of jar. Co-authored-by: Shawn Shadrix --- .../plugins/loottracker/LootReceived.java | 1 + .../plugins/loottracker/LootTrackerPanel.java | 4 +-- .../loottracker/LootTrackerPlugin.java | 29 ++++++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootReceived.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootReceived.java index bba5363988..2d95de301a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootReceived.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootReceived.java @@ -41,4 +41,5 @@ public class LootReceived private int combatLevel; private LootRecordType type; private Collection items; + private int amount; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java index 11dfb21abf..9ac6ac53ce 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java @@ -400,7 +400,7 @@ class LootTrackerPanel extends PluginPanel * Creates a subtitle, adds a new entry and then passes off to the render methods, that will decide * how to display this new data. */ - void add(final String eventName, final LootRecordType type, final int actorLevel, LootTrackerItem[] items) + void add(final String eventName, final LootRecordType type, final int actorLevel, LootTrackerItem[] items, int kills) { final String subTitle; if (type == LootRecordType.PICKPOCKET) @@ -411,7 +411,7 @@ class LootTrackerPanel extends PluginPanel { subTitle = actorLevel > -1 ? "(lvl-" + actorLevel + ")" : ""; } - final LootTrackerRecord record = new LootTrackerRecord(eventName, subTitle, type, items, 1); + final LootTrackerRecord record = new LootTrackerRecord(eventName, subTitle, type, items, kills); sessionRecords.add(record); if (hideIgnoredItems && plugin.isEventIgnored(eventName)) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java index 1d1ca945bd..6c3678bbcc 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java @@ -571,9 +571,14 @@ public class LootTrackerPlugin extends Plugin } void addLoot(@NonNull String name, int combatLevel, LootRecordType type, Object metadata, Collection items) + { + addLoot(name, combatLevel, type, metadata, items, 1); + } + + void addLoot(@NonNull String name, int combatLevel, LootRecordType type, Object metadata, Collection items, int amount) { final LootTrackerItem[] entries = buildEntries(stack(items)); - SwingUtilities.invokeLater(() -> panel.add(name, type, combatLevel, entries)); + SwingUtilities.invokeLater(() -> panel.add(name, type, combatLevel, entries, amount)); LootRecord lootRecord = new LootRecord(name, type, metadata, toGameItems(items), Instant.now(), getLootWorldId()); synchronized (queuedLoots) @@ -581,7 +586,7 @@ public class LootTrackerPlugin extends Plugin queuedLoots.add(lootRecord); } - eventBus.post(new LootReceived(name, combatLevel, type, items)); + eventBus.post(new LootReceived(name, combatLevel, type, items, amount)); } private Integer getLootWorldId() @@ -885,6 +890,7 @@ public class LootTrackerPlugin extends Plugin final Collection groundItems = lootManager.getItemSpawns(playerLocation); final Multiset diff = Multisets.difference(currentInventory, inventorySnapshot); + final Multiset diffr = Multisets.difference(inventorySnapshot, currentInventory); final List items = diff.entrySet().stream() .map(e -> new ItemStack(e.getElement(), e.getCount(), client.getLocalPlayer().getLocalLocation())) @@ -894,7 +900,7 @@ public class LootTrackerPlugin extends Plugin if (inventorySnapshotCb != null) { - inventorySnapshotCb.accept(items, groundItems); + inventorySnapshotCb.accept(items, groundItems, diffr); } inventoryId = null; @@ -957,8 +963,15 @@ public class LootTrackerPlugin extends Plugin } else if (event.getMenuOption().equals("Loot") && IMPLING_JARS.contains(event.getId())) { - String name = itemManager.getItemComposition(event.getId()).getName(); - onInvChange(collectInvItems(LootRecordType.EVENT, name)); + onInvChange(((invItems, groundItems, removedItems) -> + { + int cnt = removedItems.count(event.getId()); + if (cnt > 0) + { + String name = itemManager.getItemComposition(event.getId()).getName(); + addLoot(name, -1, LootRecordType.EVENT, null, invItems, cnt); + } + })); } } } @@ -1064,7 +1077,7 @@ public class LootTrackerPlugin extends Plugin @FunctionalInterface interface InvChangeCallback { - void accept(Collection invItems, Collection groundItems); + void accept(Collection invItems, Collection groundItems, Multiset removedItems); } private InvChangeCallback collectInvItems(LootRecordType type, String event) @@ -1074,7 +1087,7 @@ public class LootTrackerPlugin extends Plugin private InvChangeCallback collectInvItems(LootRecordType type, String event, Object metadata) { - return (invItems, groundItems) -> + return (invItems, groundItems, removedItems) -> addLoot(event, -1, type, metadata, invItems); } @@ -1085,7 +1098,7 @@ public class LootTrackerPlugin extends Plugin private InvChangeCallback collectInvAndGroundItems(LootRecordType type, String event, Object metadata) { - return (invItems, groundItems) -> + return (invItems, groundItems, removedItems) -> { List combined = new ArrayList<>(); combined.addAll(invItems);