runelite-client: update bank calculation and barrows calculation to use item mapping
This commit is contained in:
@@ -163,6 +163,25 @@ public class ItemManager
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look up an item's price from the price cache
|
||||||
|
*
|
||||||
|
* @param itemId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ItemPrice getCachedItemPrice(int itemId)
|
||||||
|
{
|
||||||
|
itemId = ItemMapping.mapFirst(itemId);
|
||||||
|
|
||||||
|
ItemPrice itemPrice = itemPriceCache.getIfPresent(itemId);
|
||||||
|
if (itemPrice != null && itemPrice != EMPTY && itemPrice != NONE)
|
||||||
|
{
|
||||||
|
return itemPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up bulk item prices asynchronously
|
* Look up bulk item prices asynchronously
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -33,11 +33,13 @@ import javax.inject.Inject;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.ItemComposition;
|
import net.runelite.api.ItemComposition;
|
||||||
|
import net.runelite.api.ItemID;
|
||||||
import static net.runelite.api.ItemID.COINS_995;
|
import static net.runelite.api.ItemID.COINS_995;
|
||||||
import static net.runelite.api.ItemID.PLATINUM_TOKEN;
|
import static net.runelite.api.ItemID.PLATINUM_TOKEN;
|
||||||
import net.runelite.api.queries.BankItemQuery;
|
import net.runelite.api.queries.BankItemQuery;
|
||||||
import net.runelite.api.widgets.WidgetItem;
|
import net.runelite.api.widgets.WidgetItem;
|
||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
|
import net.runelite.client.game.ItemMapping;
|
||||||
import net.runelite.client.util.QueryRunner;
|
import net.runelite.client.util.QueryRunner;
|
||||||
import net.runelite.http.api.item.ItemPrice;
|
import net.runelite.http.api.item.ItemPrice;
|
||||||
|
|
||||||
@@ -87,40 +89,49 @@ class BankCalculation
|
|||||||
gePrice = haPrice = 0;
|
gePrice = haPrice = 0;
|
||||||
finished = false;
|
finished = false;
|
||||||
|
|
||||||
List<ItemComposition> itemCompositions = new ArrayList<>();
|
|
||||||
Map<Integer, WidgetItem> itemMap = new HashMap<>();
|
|
||||||
List<Integer> itemIds = new ArrayList<>();
|
List<Integer> itemIds = new ArrayList<>();
|
||||||
|
|
||||||
// Generate our lists (and do some quick price additions)
|
// Generate our lists (and do some quick price additions)
|
||||||
for (WidgetItem widgetItem : widgetItems)
|
for (WidgetItem widgetItem : widgetItems)
|
||||||
{
|
{
|
||||||
if (widgetItem.getId() <= 0 || widgetItem.getQuantity() == 0)
|
int quantity = widgetItem.getQuantity();
|
||||||
|
|
||||||
|
if (widgetItem.getId() <= 0 || quantity == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widgetItem.getId() == COINS_995)
|
if (widgetItem.getId() == COINS_995)
|
||||||
{
|
{
|
||||||
gePrice += widgetItem.getQuantity();
|
gePrice += quantity;
|
||||||
haPrice += widgetItem.getQuantity();
|
haPrice += quantity;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widgetItem.getId() == PLATINUM_TOKEN)
|
if (widgetItem.getId() == PLATINUM_TOKEN)
|
||||||
{
|
{
|
||||||
gePrice += widgetItem.getQuantity() * 1000L;
|
gePrice += quantity * 1000L;
|
||||||
haPrice += widgetItem.getQuantity() * 1000L;
|
haPrice += quantity * 1000L;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ItemComposition itemComposition = itemManager.getItemComposition(widgetItem.getId());
|
final ItemComposition itemComposition = itemManager.getItemComposition(widgetItem.getId());
|
||||||
itemCompositions.add(itemComposition);
|
|
||||||
itemMap.put(widgetItem.getId(), widgetItem);
|
|
||||||
|
|
||||||
if (config.showGE())
|
if (config.showGE())
|
||||||
{
|
{
|
||||||
itemIds.add(widgetItem.getId());
|
itemIds.add(widgetItem.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.showHA())
|
||||||
|
{
|
||||||
|
int price = itemComposition.getPrice();
|
||||||
|
|
||||||
|
if (price > 0)
|
||||||
|
{
|
||||||
|
haPrice += (long) Math.round(price * HIGH_ALCHEMY_CONSTANT) *
|
||||||
|
(long) quantity;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now do the calculations
|
// Now do the calculations
|
||||||
@@ -145,14 +156,31 @@ class BankCalculation
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (ItemPrice itemPrice : itemPrices)
|
for (WidgetItem widgetItem : widgetItems)
|
||||||
{
|
{
|
||||||
if (itemPrice.getItem() == null)
|
int itemId = widgetItem.getId();
|
||||||
|
int quantity = widgetItem.getQuantity();
|
||||||
|
|
||||||
|
if (itemId <= 0 || quantity == 0
|
||||||
|
|| itemId == ItemID.COINS_995 || itemId == ItemID.PLATINUM_TOKEN)
|
||||||
{
|
{
|
||||||
continue; // cached no price
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
gePrice += (long) itemPrice.getPrice() * (long) itemMap.get(itemPrice.getItem().getId()).getQuantity();
|
long price = 0;
|
||||||
|
for (int mappedItemId : ItemMapping.map(itemId))
|
||||||
|
{
|
||||||
|
ItemPrice cachedItemPrice = itemManager.getCachedItemPrice(mappedItemId);
|
||||||
|
if (cachedItemPrice == null)
|
||||||
|
{
|
||||||
|
// this happens to items which have no ge price
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
price += cachedItemPrice.getPrice();
|
||||||
|
}
|
||||||
|
|
||||||
|
gePrice += price * quantity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex2)
|
catch (Exception ex2)
|
||||||
@@ -169,20 +197,6 @@ class BankCalculation
|
|||||||
{
|
{
|
||||||
finished = true;
|
finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.showHA())
|
|
||||||
{
|
|
||||||
for (ItemComposition itemComposition : itemCompositions)
|
|
||||||
{
|
|
||||||
int price = itemComposition.getPrice();
|
|
||||||
|
|
||||||
if (price > 0)
|
|
||||||
{
|
|
||||||
haPrice += (long) Math.round(price * HIGH_ALCHEMY_CONSTANT) *
|
|
||||||
(long) itemMap.get(itemComposition.getId()).getQuantity();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBankDifferent(WidgetItem[] widgetItems)
|
private boolean isBankDifferent(WidgetItem[] widgetItems)
|
||||||
|
|||||||
@@ -29,11 +29,10 @@ import com.google.common.eventbus.Subscribe;
|
|||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -207,23 +206,19 @@ public class BarrowsPlugin extends Plugin
|
|||||||
if (event.getGroupId() == WidgetID.BARROWS_REWARD_GROUP_ID && config.showChestValue())
|
if (event.getGroupId() == WidgetID.BARROWS_REWARD_GROUP_ID && config.showChestValue())
|
||||||
{
|
{
|
||||||
ItemContainer barrowsRewardContainer = client.getItemContainer(InventoryID.BARROWS_REWARD);
|
ItemContainer barrowsRewardContainer = client.getItemContainer(InventoryID.BARROWS_REWARD);
|
||||||
Map<Integer, Integer> itemMap = new HashMap<>();
|
Item[] items = barrowsRewardContainer.getItems();
|
||||||
chestPrice = 0;
|
chestPrice = 0;
|
||||||
|
|
||||||
for (Item item : barrowsRewardContainer.getItems())
|
for (Item item : items)
|
||||||
{
|
{
|
||||||
if (item.getId() != -1)
|
if (item.getId() == COINS_995)
|
||||||
{
|
{
|
||||||
if (item.getId() == COINS_995)
|
chestPrice += item.getQuantity();
|
||||||
{
|
|
||||||
chestPrice += item.getQuantity();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
itemMap.put(item.getId(), item.getQuantity());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(itemMap.keySet());
|
CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(
|
||||||
|
Arrays.stream(items).map(Item::getId).collect(Collectors.toList()));
|
||||||
future.whenComplete((ItemPrice[] itemPrices, Throwable ex) ->
|
future.whenComplete((ItemPrice[] itemPrices, Throwable ex) ->
|
||||||
{
|
{
|
||||||
if (ex != null)
|
if (ex != null)
|
||||||
@@ -242,14 +237,15 @@ public class BarrowsPlugin extends Plugin
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (ItemPrice itemPrice : itemPrices)
|
for (Item item : items)
|
||||||
{
|
{
|
||||||
if (itemPrice.getItem() == null)
|
ItemPrice cachedItemPrice = itemManager.getCachedItemPrice(item.getId());
|
||||||
|
if (cachedItemPrice == null)
|
||||||
{
|
{
|
||||||
continue; // cached no price
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
long itemStack = (long) itemPrice.getPrice() * (long) itemMap.get(itemPrice.getItem().getId());
|
long itemStack = (long) cachedItemPrice.getPrice() * (long) item.getQuantity();
|
||||||
chestPrice += itemStack;
|
chestPrice += itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user