use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.
the class ItemManager method getItemPriceAsync.
/**
* Look up an item's price asynchronously.
*
* @param itemId item id
* @return the price, or null if the price is not yet loaded
*/
public ItemPrice getItemPriceAsync(int itemId) {
ItemPrice itemPrice = itemPriceCache.getIfPresent(itemId);
if (itemPrice != null && itemPrice != EMPTY) {
return itemPrice == NONE ? null : itemPrice;
}
itemPriceCache.refresh(itemId);
return null;
}
use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.
the class ItemManager method getItemPrice.
/**
* Look up an item's price synchronously
*
* @param itemId item id
* @return item price
* @throws IOException
*/
public ItemPrice getItemPrice(int itemId) throws IOException {
ItemPrice itemPrice = itemPriceCache.getIfPresent(itemId);
if (itemPrice != null && itemPrice != EMPTY) {
return itemPrice == NONE ? null : itemPrice;
}
itemPrice = itemClient.lookupItemPrice(itemId);
if (itemPrice == null) {
itemPriceCache.put(itemId, NONE);
return null;
}
itemPriceCache.put(itemId, itemPrice);
return itemPrice;
}
use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.
the class ItemController method prices.
@RequestMapping("/price")
public ItemPrice[] prices(@RequestParam("id") int[] itemIds) {
if (itemIds.length > MAX_BATCH_LOOKUP) {
itemIds = Arrays.copyOf(itemIds, MAX_BATCH_LOOKUP);
}
List<ItemPrice> itemPrices = new ArrayList<>(itemIds.length);
for (int itemId : itemIds) {
ItemEntry item = itemService.getItem(itemId);
PriceEntry priceEntry = itemService.getPrice(itemId, null);
if (item == null || priceEntry == null) {
continue;
}
ItemPrice itemPrice = new ItemPrice();
itemPrice.setItem(item.toItem());
itemPrice.setPrice(priceEntry.getPrice());
itemPrice.setTime(priceEntry.getTime());
itemPrices.add(itemPrice);
}
return itemPrices.toArray(new ItemPrice[itemPrices.size()]);
}
use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.
the class GroundItemsPlugin method buildGroundItem.
@Nullable
private GroundItem buildGroundItem(final Tile tile, final Item item) {
// Collect the data for the item
final int itemId = item.getId();
final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
final int realItemId = itemComposition.getNote() != -1 ? itemComposition.getLinkedNoteId() : itemId;
final int alchPrice = Math.round(itemComposition.getPrice() * HIGH_ALCHEMY_CONSTANT);
final String name = itemComposition.getName();
final boolean hidden = isHidden(name);
if (!isHotKeyPressed() && hidden) {
return null;
}
final boolean highlighted = isHighlighted(name);
if (config.showHighlightedOnly() && !isHotKeyPressed() && !highlighted) {
return null;
}
final GroundItem groundItem = GroundItem.builder().id(itemId).location(tile.getWorldLocation()).itemId(realItemId).quantity(item.getQuantity()).name(itemComposition.getName()).haPrice(alchPrice * item.getQuantity()).build();
// Set the correct item price
if (realItemId == COINS) {
groundItem.setHaPrice(item.getQuantity());
groundItem.setGePrice(item.getQuantity());
} else {
final ItemPrice itemPrice = itemManager.getItemPriceAsync(realItemId);
groundItem.setGePrice(itemPrice != null ? itemPrice.getPrice() * item.getQuantity() : 0);
}
return groundItem;
}
use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.
the class GroundItemsPlugin method onMenuEntryAdded.
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event) {
if ((config.highlightMenuOption() || config.highlightMenuItemName()) && event.getOption().equals("Take") && event.getType() == MenuAction.GROUND_ITEM_THIRD_OPTION.getId()) {
int itemId = event.getIdentifier();
ItemComposition itemComposition = client.getItemDefinition(itemId);
if (isHidden(itemComposition.getName())) {
return;
}
Region region = client.getRegion();
Tile tile = region.getTiles()[client.getPlane()][event.getActionParam0()][event.getActionParam1()];
ItemLayer itemLayer = tile.getItemLayer();
if (itemLayer == null) {
return;
}
MenuEntry[] menuEntries = client.getMenuEntries();
MenuEntry lastEntry = menuEntries[menuEntries.length - 1];
int quantity = 1;
Node current = itemLayer.getBottom();
while (current instanceof Item) {
Item item = (Item) current;
if (item.getId() == itemId) {
quantity = item.getQuantity();
}
current = current.getNext();
}
ItemPrice itemPrice = getItemPrice(itemComposition);
int price = itemPrice == null ? itemComposition.getPrice() : itemPrice.getPrice();
int cost = quantity * price;
Color color = overlay.getCostColor(cost, isHighlighted(itemComposition.getName()), isHidden(itemComposition.getName()));
if (!color.equals(config.defaultColor())) {
String hexColor = Integer.toHexString(color.getRGB() & 0xFFFFFF);
String colTag = "<col=" + hexColor + ">";
if (config.highlightMenuOption()) {
lastEntry.setOption(colTag + "Take");
}
if (config.highlightMenuItemName()) {
String target = lastEntry.getTarget().substring(lastEntry.getTarget().indexOf(">") + 1);
lastEntry.setTarget(colTag + target);
}
}
if (config.showMenuItemQuantities() && itemComposition.isStackable() && quantity > 1) {
lastEntry.setTarget(lastEntry.getTarget() + " (" + quantity + ")");
}
client.setMenuEntries(menuEntries);
}
}
Aggregations