Show full price for stackable items when examined

This commit is contained in:
Tomas Slusny
2017-12-08 18:34:30 -05:00
committed by Adam
parent ea74c47d46
commit 49a11cab46
4 changed files with 88 additions and 57 deletions

View File

@@ -190,7 +190,7 @@ public class Hooks
} }
} }
public static void menuActionHook(int var0, int widgetId, int menuAction, int id, String menuOption, String menuTarget, int var6, int var7) public static void menuActionHook(int actionParam, int widgetId, int menuAction, int id, String menuOption, String menuTarget, int var6, int var7)
{ {
/* Along the way, the RuneScape client may change a menuAction by incrementing it with 2000. /* Along the way, the RuneScape client may change a menuAction by incrementing it with 2000.
* I have no idea why, but it does. Their code contains the same conditional statement. * I have no idea why, but it does. Their code contains the same conditional statement.
@@ -201,9 +201,10 @@ public class Hooks
} }
log.debug("Menu action clicked: {} ({}) on {} ({} widget: {})", log.debug("Menu action clicked: {} ({}) on {} ({} widget: {})",
menuOption, menuAction, menuTarget.isEmpty() ? "<nothing>" : menuTarget, id, var0, widgetId); menuOption, menuAction, menuTarget.isEmpty() ? "<nothing>" : menuTarget, id, actionParam, widgetId);
MenuOptionClicked menuOptionClicked = new MenuOptionClicked(); MenuOptionClicked menuOptionClicked = new MenuOptionClicked();
menuOptionClicked.setActionParam(actionParam);
menuOptionClicked.setMenuOption(menuOption); menuOptionClicked.setMenuOption(menuOption);
menuOptionClicked.setMenuTarget(menuTarget); menuOptionClicked.setMenuTarget(menuTarget);
menuOptionClicked.setMenuAction(MenuAction.of(menuAction)); menuOptionClicked.setMenuAction(MenuAction.of(menuAction));

View File

@@ -30,6 +30,7 @@ import net.runelite.api.MenuAction;
@Data @Data
public class MenuOptionClicked public class MenuOptionClicked
{ {
private int actionParam;
private String menuOption; private String menuOption;
private String menuTarget; private String menuTarget;
private MenuAction menuAction; private MenuAction menuAction;

View File

@@ -39,6 +39,10 @@ import net.runelite.api.ChatMessageType;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.api.ItemComposition; import net.runelite.api.ItemComposition;
import net.runelite.api.widgets.Widget;
import static net.runelite.api.widgets.WidgetInfo.TO_CHILD;
import static net.runelite.api.widgets.WidgetInfo.TO_GROUP;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.chat.ChatColor; import net.runelite.client.chat.ChatColor;
import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatColorType;
import net.runelite.client.chat.ChatMessageBuilder; import net.runelite.client.chat.ChatMessageBuilder;
@@ -151,7 +155,12 @@ public class ExaminePlugin extends Plugin
return; return;
} }
PendingExamine pendingExamine = new PendingExamine(type, id, Instant.now()); PendingExamine pendingExamine = new PendingExamine();
pendingExamine.setWidgetId(event.getWidgetId());
pendingExamine.setActionParam(event.getActionParam());
pendingExamine.setType(type);
pendingExamine.setId(id);
pendingExamine.setCreated(Instant.now());
pending.push(pendingExamine); pending.push(pendingExamine);
} }
@@ -193,7 +202,19 @@ public class ExaminePlugin extends Plugin
if (config.itemPrice() && pendingExamine.getType() == ExamineType.ITEM) if (config.itemPrice() && pendingExamine.getType() == ExamineType.ITEM)
{ {
executor.submit(() -> getItemPrice(pendingExamine)); // get quantity from widget
int widgetId = pendingExamine.getWidgetId();
Widget widget = client.getWidget(TO_GROUP(widgetId), TO_CHILD(widgetId));
WidgetItem widgetItem = widget != null ? widget.getWidgetItem(pendingExamine.getActionParam()) : null;
int quantity = widgetItem != null ? widgetItem.getQuantity() : 1;
ItemComposition itemComposition = itemManager.getItemComposition(pendingExamine.getId());
if (itemComposition != null)
{
executor.submit(() -> getItemPrice(itemComposition, quantity));
}
} }
CacheKey key = new CacheKey(type, pendingExamine.getId()); CacheKey key = new CacheKey(type, pendingExamine.getId());
@@ -207,40 +228,66 @@ public class ExaminePlugin extends Plugin
executor.submit(() -> submitExamine(pendingExamine, event.getMessage())); executor.submit(() -> submitExamine(pendingExamine, event.getMessage()));
} }
private void getItemPrice(PendingExamine examine) private void getItemPrice(ItemComposition itemComposition, int quantity)
{ {
// convert to unnoted id
final boolean note = itemComposition.getNote() != -1;
final int id = note ? itemComposition.getLinkedNoteId() : itemComposition.getId();
ItemPrice itemPrice;
try try
{ {
final ItemComposition itemComposition = itemManager.getItemComposition(examine.getId()); itemPrice = itemManager.getItemPrice(id);
if (itemComposition != null)
{
final int id = itemComposition.getNote() != -1 ? itemComposition.getLinkedNoteId() : itemComposition.getId();
final ItemPrice itemPrice = itemManager.getItemPrice(id);
final int gePrice = itemPrice == null ? 0 : itemPrice.getPrice();
final int alchPrice = Math.round(itemComposition.getPrice() * HIGH_ALCHEMY_CONSTANT);
final String message = new ChatMessageBuilder()
.append(ChatColorType.NORMAL)
.append("Price of ")
.append(ChatColorType.HIGHLIGHT)
.append(itemComposition.getName())
.append(ChatColorType.NORMAL)
.append(": GE average ")
.append(ChatColorType.HIGHLIGHT)
.append(String.valueOf(gePrice))
.append(ChatColorType.NORMAL)
.append(" HA value ")
.append(ChatColorType.HIGHLIGHT)
.append(String.valueOf(alchPrice))
.build();
chatMessageManager.queue(ChatMessageType.EXAMINE_ITEM, message);
}
} }
catch (IOException e) catch (IOException e)
{ {
log.warn("Error looking up item price", e); log.warn("Error looking up item price", e);
return;
}
int itemCompositionPrice = itemComposition.getPrice();
final int gePrice = itemPrice == null ? 0 : itemPrice.getPrice() * quantity;
final int alchPrice = itemCompositionPrice <= 0
? 0
: Math.round(itemCompositionPrice * HIGH_ALCHEMY_CONSTANT) * quantity;
if (gePrice > 0 || alchPrice > 0)
{
final ChatMessageBuilder message = new ChatMessageBuilder()
.append(ChatColorType.NORMAL)
.append("Price of ")
.append(ChatColorType.HIGHLIGHT);
if (quantity > 1)
{
message
.append(String.format("%,d", quantity))
.append(" x ");
}
message
.append(itemComposition.getName());
if (gePrice > 0)
{
message
.append(ChatColorType.NORMAL)
.append(": GE average ")
.append(ChatColorType.HIGHLIGHT)
.append(String.format("%,d", gePrice));
}
if (alchPrice > 0)
{
message
.append(ChatColorType.NORMAL)
.append(" HA value ")
.append(ChatColorType.HIGHLIGHT)
.append(String.format("%,d", alchPrice));
}
chatMessageManager.queue(ChatMessageType.EXAMINE_ITEM, message.build());
client.refreshChat();
} }
} }

View File

@@ -25,32 +25,14 @@
package net.runelite.client.plugins.examine; package net.runelite.client.plugins.examine;
import java.time.Instant; import java.time.Instant;
import lombok.Data;
public class PendingExamine @Data
class PendingExamine
{ {
private final ExamineType type; private ExamineType type;
private final int id; private int id;
private final Instant created; private int widgetId;
private int actionParam;
public PendingExamine(ExamineType type, int id, Instant created) private Instant created;
{
this.type = type;
this.id = id;
this.created = created;
}
public ExamineType getType()
{
return type;
}
public int getId()
{
return id;
}
public Instant getCreated()
{
return created;
}
} }