use of net.runelite.api.ItemComposition in project runelite by runelite.
the class BankCalculation method calculate.
/**
* Calculate the bank based on the cache, price can be 0 if bank not active, or cache not set
*/
void calculate() {
Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
// Don't update on a search because rs seems to constantly update the title
if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden() || widgetBankTitleBar.getText().contains("Showing")) {
return;
}
WidgetItem[] widgetItems = new BankItemQuery().result(client);
if (widgetItems.length == 0 || !isBankDifferent(widgetItems)) {
return;
}
log.debug("Calculating new bank value...");
gePrice = haPrice = 0;
finished = false;
List<ItemComposition> itemCompositions = new ArrayList<>();
Map<Integer, WidgetItem> itemMap = new HashMap<>();
List<Integer> itemIds = new ArrayList<>();
// Generate our lists (and do some quick price additions)
for (WidgetItem widgetItem : widgetItems) {
if (widgetItem.getId() <= 0 || widgetItem.getQuantity() == 0) {
continue;
}
if (widgetItem.getId() == COINS_995) {
gePrice += widgetItem.getQuantity();
haPrice += widgetItem.getQuantity();
continue;
}
if (widgetItem.getId() == PLATINUM_TOKEN) {
gePrice += widgetItem.getQuantity() * 1000;
haPrice += widgetItem.getQuantity() * 1000;
continue;
}
ItemComposition itemComposition = itemManager.getItemComposition(widgetItem.getId());
itemCompositions.add(itemComposition);
itemMap.put(widgetItem.getId(), widgetItem);
if (config.showGE()) {
itemIds.add(widgetItem.getId());
}
}
// Now do the calculations
if (config.showGE() && !itemIds.isEmpty()) {
CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(itemIds);
future.whenComplete((ItemPrice[] itemPrices, Throwable ex) -> {
if (ex != null) {
log.debug("Error looking up item prices", ex);
return;
}
if (itemPrices == null) {
log.debug("Error looking up item prices");
return;
}
log.debug("Price lookup is complete. {} prices.", itemPrices.length);
try {
for (ItemPrice itemPrice : itemPrices) {
if (itemPrice.getItem() == null) {
// cached no price
continue;
}
gePrice += itemPrice.getPrice() * itemMap.get(itemPrice.getItem().getId()).getQuantity();
}
} catch (Exception ex2) {
log.warn("error calculating price", ex2);
} finally {
finished = true;
}
});
} else {
finished = true;
}
if (config.showHA()) {
for (ItemComposition itemComposition : itemCompositions) {
int price = itemComposition.getPrice();
if (price > 0) {
haPrice += Math.round(price * HIGH_ALCHEMY_CONSTANT) * itemMap.get(itemComposition.getId()).getQuantity();
}
}
}
}
use of net.runelite.api.ItemComposition in project runelite by runelite.
the class ItemPricesOverlay method getItemStackValueText.
private String getItemStackValueText(Item item) {
int id = item.getId();
int qty = item.getQuantity();
// Special case for coins and platinum tokens
if (id == ItemID.COINS_995) {
return StackFormatter.formatNumber(qty) + " gp";
} else if (id == ItemID.PLATINUM_TOKEN) {
return StackFormatter.formatNumber(qty * 1000) + " gp";
}
final ItemComposition itemDef = itemManager.getItemComposition(id);
// Only check prices for things with store prices
if (itemDef.getPrice() <= 0) {
return null;
}
int gePrice = 0;
int haPrice = 0;
if (config.showGEPrice()) {
final ItemPrice price = itemManager.getItemPriceAsync(id);
if (price != null) {
gePrice = price.getPrice();
}
}
if (config.showHAValue()) {
haPrice = Math.round(itemDef.getPrice() * HIGH_ALCHEMY_CONSTANT);
}
if (gePrice > 0 || haPrice > 0) {
return stackValueText(qty, gePrice, haPrice);
}
return null;
}
use of net.runelite.api.ItemComposition in project runelite by runelite.
the class MenuEntrySwapperPlugin method cycleItemShiftClickAction.
public void cycleItemShiftClickAction(WidgetItem item, int mouseClick) {
ItemComposition itemComposition = client.getItemDefinition(item.getId());
if (mouseClick == MouseEvent.BUTTON1) {
String[] actions = itemComposition.getInventoryActions();
int shiftClickActionIndex = itemComposition.getShiftClickActionIndex();
int nextActionIndex = getNextActionIndex(actions, shiftClickActionIndex);
setSwapConfig(item.getId(), nextActionIndex);
itemComposition.setShiftClickActionIndex(nextActionIndex);
} else if (mouseClick == MouseEvent.BUTTON3) {
unsetSwapConfig(item.getId());
itemComposition.resetShiftClickActionIndex();
}
}
use of net.runelite.api.ItemComposition in project runelite by runelite.
the class MenuEntrySwapperPlugin method onPostItemComposition.
@Subscribe
public void onPostItemComposition(PostItemComposition event) {
ItemComposition itemComposition = event.getItemComposition();
Integer option = getSwapConfig(itemComposition.getId());
if (option != null) {
itemComposition.setShiftClickActionIndex(option);
// Update our cached item composition too
ItemComposition ourItemComposition = itemManager.getItemComposition(itemComposition.getId());
ourItemComposition.setShiftClickActionIndex(option);
}
}
use of net.runelite.api.ItemComposition in project runelite by runelite.
the class ShiftClickConfigurationOverlay method render.
@Override
public Dimension render(Graphics2D graphics) {
if (!plugin.isConfiguringShiftClick() || client.isMenuOpen() || client.getWidget(WidgetInfo.INVENTORY).isHidden()) {
return null;
}
Font font = FontManager.getRunescapeSmallFont();
graphics.setFont(font);
net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
Point mousePoint = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY());
for (WidgetItem item : plugin.getInventoryItems()) {
final Rectangle bounds = item.getCanvasBounds();
if (!bounds.contains(mousePoint)) {
continue;
}
ItemComposition itemComposition = client.getItemDefinition(item.getId());
String[] actions = itemComposition.getInventoryActions();
int index = itemComposition.getShiftClickActionIndex();
if (index >= 0 && actions[index] == null) {
continue;
}
String action = index == -1 ? "Use" : actions[index];
int textWidth = graphics.getFontMetrics().stringWidth(action);
int textLocationX = (int) (bounds.x + bounds.getWidth() / 2 - textWidth / 2);
int textLocationY = bounds.y + 28;
final TextComponent textComponent = new TextComponent();
textComponent.setPosition(new Point(textLocationX, textLocationY));
textComponent.setText(action);
textComponent.render(graphics);
}
return null;
}
Aggregations