mlm plugin: fix ore counter to not count already collected ore
This commit is contained in:
@@ -26,11 +26,15 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.motherlode;
|
||||
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.Multisets;
|
||||
import com.google.inject.Provides;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
@@ -135,6 +139,7 @@ public class MotherlodePlugin extends Plugin
|
||||
@Inject
|
||||
private MotherlodeSession session;
|
||||
private boolean shouldUpdateOres;
|
||||
private Multiset<Integer> inventorySnapshot;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Set<WallObject> veins = new HashSet<>();
|
||||
@@ -193,7 +198,19 @@ public class MotherlodePlugin extends Plugin
|
||||
{
|
||||
int lastSackValue = curSackSize;
|
||||
refreshSackValues();
|
||||
shouldUpdateOres = curSackSize != lastSackValue;
|
||||
shouldUpdateOres = curSackSize < lastSackValue;
|
||||
if (shouldUpdateOres)
|
||||
{
|
||||
// Take a snapshot of the inventory before the new ore is added.
|
||||
ItemContainer itemContainer = client.getItemContainer(InventoryID.INVENTORY);
|
||||
if (itemContainer != null)
|
||||
{
|
||||
inventorySnapshot = HashMultiset.create();
|
||||
Arrays.stream(itemContainer.getItems())
|
||||
.filter(item -> MLM_ORE_TYPES.contains(item.getId()))
|
||||
.forEach(item -> inventorySnapshot.add(item.getId(), item.getQuantity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,21 +393,23 @@ public class MotherlodePlugin extends Plugin
|
||||
{
|
||||
final ItemContainer container = event.getItemContainer();
|
||||
|
||||
if (!inMlm || container != client.getItemContainer(InventoryID.INVENTORY) || !shouldUpdateOres)
|
||||
if (!inMlm || !shouldUpdateOres || inventorySnapshot == null || container != client.getItemContainer(InventoryID.INVENTORY))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Item[] inv = container.getItems();
|
||||
// Build set of current inventory
|
||||
Multiset<Integer> current = HashMultiset.create();
|
||||
Arrays.stream(container.getItems())
|
||||
.filter(item -> MLM_ORE_TYPES.contains(item.getId()))
|
||||
.forEach(item -> current.add(item.getId(), item.getQuantity()));
|
||||
|
||||
for (Item item : inv)
|
||||
{
|
||||
if (MLM_ORE_TYPES.contains(item.getId()))
|
||||
{
|
||||
session.updateOreFound(item);
|
||||
}
|
||||
}
|
||||
// Take the difference
|
||||
Multiset<Integer> delta = Multisets.difference(current, inventorySnapshot);
|
||||
|
||||
// Update the session
|
||||
delta.forEachEntry(session::updateOreFound);
|
||||
inventorySnapshot = null;
|
||||
shouldUpdateOres = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import javax.inject.Singleton;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Item;
|
||||
import net.runelite.api.ItemID;
|
||||
|
||||
@Slf4j
|
||||
@@ -107,27 +106,27 @@ public class MotherlodeSession
|
||||
}
|
||||
}
|
||||
|
||||
void updateOreFound(Item ore)
|
||||
void updateOreFound(int item, int count)
|
||||
{
|
||||
switch (ore.getId())
|
||||
switch (item)
|
||||
{
|
||||
case ItemID.GOLDEN_NUGGET:
|
||||
nuggetsFound += ore.getQuantity();
|
||||
nuggetsFound += count;
|
||||
break;
|
||||
case ItemID.COAL:
|
||||
coalFound++;
|
||||
coalFound += count;
|
||||
break;
|
||||
case ItemID.GOLD_ORE:
|
||||
goldFound++;
|
||||
goldFound += count;
|
||||
break;
|
||||
case ItemID.MITHRIL_ORE:
|
||||
mithrilFound++;
|
||||
mithrilFound += count;
|
||||
break;
|
||||
case ItemID.ADAMANTITE_ORE:
|
||||
adamantiteFound++;
|
||||
adamantiteFound += count;
|
||||
break;
|
||||
case ItemID.RUNITE_ORE:
|
||||
runiteFound++;
|
||||
runiteFound += count;
|
||||
break;
|
||||
default:
|
||||
log.debug("Invalid ore specified. The ore count will not be updated.");
|
||||
|
||||
Reference in New Issue
Block a user