Merge pull request #12975 from akhtar-u/grounditems
grounditems: add despawn timer for items placed on tables
This commit is contained in:
@@ -75,6 +75,7 @@ public class GroundItemsOverlay extends Overlay
|
||||
private static final Duration DESPAWN_TIME_INSTANCE = Duration.ofMinutes(30);
|
||||
private static final Duration DESPAWN_TIME_LOOT = Duration.ofMinutes(2);
|
||||
private static final Duration DESPAWN_TIME_DROP = Duration.ofMinutes(3);
|
||||
private static final Duration DESPAWN_TIME_TABLE = Duration.ofMinutes(10);
|
||||
private static final int KRAKEN_REGION = 9116;
|
||||
private static final int KBD_NMZ_REGION = 9033;
|
||||
private static final int ZILYANA_REGION = 11602;
|
||||
@@ -397,8 +398,11 @@ public class GroundItemsOverlay extends Overlay
|
||||
|
||||
private Instant calculateDespawnTime(GroundItem groundItem)
|
||||
{
|
||||
// We can only accurately guess despawn times for our own pvm loot and dropped items
|
||||
if (groundItem.getLootType() != LootType.PVM && groundItem.getLootType() != LootType.DROPPED)
|
||||
// We can only accurately guess despawn times for our own pvm loot, dropped items,
|
||||
// and items we placed on tables
|
||||
if (groundItem.getLootType() != LootType.PVM
|
||||
&& groundItem.getLootType() != LootType.DROPPED
|
||||
&& groundItem.getLootType() != LootType.TABLE)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -461,9 +465,18 @@ public class GroundItemsOverlay extends Overlay
|
||||
}
|
||||
else
|
||||
{
|
||||
despawnTime = spawnTime.plus(groundItem.getLootType() == LootType.DROPPED
|
||||
? DESPAWN_TIME_DROP
|
||||
: DESPAWN_TIME_LOOT);
|
||||
switch (groundItem.getLootType())
|
||||
{
|
||||
case DROPPED:
|
||||
despawnTime = spawnTime.plus(DESPAWN_TIME_DROP);
|
||||
break;
|
||||
case TABLE:
|
||||
despawnTime = spawnTime.plus(DESPAWN_TIME_TABLE);
|
||||
break;
|
||||
default:
|
||||
despawnTime = spawnTime.plus(DESPAWN_TIME_LOOT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (now.isBefore(spawnTime) || now.isAfter(despawnTime))
|
||||
@@ -477,8 +490,11 @@ public class GroundItemsOverlay extends Overlay
|
||||
|
||||
private Color getItemTimerColor(GroundItem groundItem)
|
||||
{
|
||||
// We can only accurately guess despawn times for our own pvm loot and dropped items
|
||||
if (groundItem.getLootType() != LootType.PVM && groundItem.getLootType() != LootType.DROPPED)
|
||||
// We can only accurately guess despawn times for our own pvm loot, dropped items,
|
||||
// and items we placed on tables
|
||||
if (groundItem.getLootType() != LootType.PVM
|
||||
&& groundItem.getLootType() != LootType.DROPPED
|
||||
&& groundItem.getLootType() != LootType.TABLE)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,10 @@ import lombok.Setter;
|
||||
import lombok.Value;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.InventoryID;
|
||||
import net.runelite.api.Item;
|
||||
import net.runelite.api.ItemComposition;
|
||||
import net.runelite.api.ItemContainer;
|
||||
import net.runelite.api.ItemID;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
@@ -180,6 +183,7 @@ public class GroundItemsPlugin extends Plugin
|
||||
private LoadingCache<NamedQuantity, Boolean> highlightedItems;
|
||||
private LoadingCache<NamedQuantity, Boolean> hiddenItems;
|
||||
private final Queue<Integer> droppedItemQueue = EvictingQueue.create(16); // recently dropped items
|
||||
private int lastUsedItem;
|
||||
|
||||
@Provides
|
||||
GroundItemsConfig provideConfig(ConfigManager configManager)
|
||||
@@ -194,6 +198,7 @@ public class GroundItemsPlugin extends Plugin
|
||||
mouseManager.registerMouseListener(inputListener);
|
||||
keyManager.registerKeyListener(inputListener);
|
||||
executor.execute(this::reset);
|
||||
lastUsedItem = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -384,6 +389,7 @@ public class GroundItemsPlugin extends Plugin
|
||||
final int realItemId = itemComposition.getNote() != -1 ? itemComposition.getLinkedNoteId() : itemId;
|
||||
final int alchPrice = itemComposition.getHaPrice();
|
||||
final boolean dropped = tile.getWorldLocation().equals(client.getLocalPlayer().getWorldLocation()) && droppedItemQueue.remove(itemId);
|
||||
final boolean table = itemId == lastUsedItem && tile.getItemLayer().getHeight() > 0;
|
||||
|
||||
final GroundItem groundItem = GroundItem.builder()
|
||||
.id(itemId)
|
||||
@@ -394,12 +400,11 @@ public class GroundItemsPlugin extends Plugin
|
||||
.haPrice(alchPrice)
|
||||
.height(tile.getItemLayer().getHeight())
|
||||
.tradeable(itemComposition.isTradeable())
|
||||
.lootType(dropped ? LootType.DROPPED : LootType.UNKNOWN)
|
||||
.lootType(dropped ? LootType.DROPPED : (table ? LootType.TABLE : LootType.UNKNOWN))
|
||||
.spawnTime(Instant.now())
|
||||
.stackable(itemComposition.isStackable())
|
||||
.build();
|
||||
|
||||
|
||||
// Update item price in case it is coins
|
||||
if (realItemId == COINS)
|
||||
{
|
||||
@@ -687,5 +692,21 @@ public class GroundItemsPlugin extends Plugin
|
||||
// item spawns that are drops
|
||||
droppedItemQueue.add(itemId);
|
||||
}
|
||||
else if (menuOptionClicked.getMenuAction() == MenuAction.ITEM_USE_ON_GAME_OBJECT)
|
||||
{
|
||||
final ItemContainer inventory = client.getItemContainer(InventoryID.INVENTORY);
|
||||
if (inventory == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Item clickedItem = inventory.getItem(menuOptionClicked.getSelectedItemIndex());
|
||||
if (clickedItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastUsedItem = clickedItem.getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.runelite.client.plugins.grounditems;
|
||||
enum LootType
|
||||
{
|
||||
UNKNOWN,
|
||||
TABLE,
|
||||
DROPPED,
|
||||
PVP,
|
||||
PVM;
|
||||
|
||||
Reference in New Issue
Block a user