examine plugin: split item/quantity lookup from item price lookup

This commit is contained in:
Adam
2019-01-20 15:47:46 -05:00
parent b4de93d722
commit 5508812678
2 changed files with 84 additions and 88 deletions

View File

@@ -103,17 +103,35 @@ public class ExaminePlugin extends Plugin
} }
ExamineType type; ExamineType type;
int id; int id, quantity = -1;
switch (event.getMenuAction()) switch (event.getMenuAction())
{ {
case EXAMINE_ITEM: case EXAMINE_ITEM:
{
type = ExamineType.ITEM; type = ExamineType.ITEM;
id = event.getId(); id = event.getId();
int widgetId = event.getWidgetId();
int widgetGroup = TO_GROUP(widgetId);
int widgetChild = TO_CHILD(widgetId);
Widget widget = client.getWidget(widgetGroup, widgetChild);
WidgetItem widgetItem = widget.getWidgetItem(event.getActionParam());
quantity = widgetItem != null ? widgetItem.getQuantity() : 1;
break; break;
}
case EXAMINE_ITEM_BANK_EQ: case EXAMINE_ITEM_BANK_EQ:
{
type = ExamineType.ITEM_BANK_EQ; type = ExamineType.ITEM_BANK_EQ;
id = event.getId(); int[] qi = findItemFromWidget(event.getWidgetId(), event.getActionParam());
if (qi == null)
{
log.debug("Examine for item with unknown widget: {}", event);
return;
}
quantity = qi[0];
id = qi[1];
break; break;
}
case EXAMINE_OBJECT: case EXAMINE_OBJECT:
type = ExamineType.OBJECT; type = ExamineType.OBJECT;
id = event.getId(); id = event.getId();
@@ -127,10 +145,9 @@ public class ExaminePlugin extends Plugin
} }
PendingExamine pendingExamine = new PendingExamine(); PendingExamine pendingExamine = new PendingExamine();
pendingExamine.setWidgetId(event.getWidgetId());
pendingExamine.setActionParam(event.getActionParam());
pendingExamine.setType(type); pendingExamine.setType(type);
pendingExamine.setId(id); pendingExamine.setId(id);
pendingExamine.setQuantity(quantity);
pendingExamine.setCreated(Instant.now()); pendingExamine.setCreated(Instant.now());
pending.push(pendingExamine); pending.push(pendingExamine);
} }
@@ -174,7 +191,20 @@ public class ExaminePlugin extends Plugin
log.debug("Got examine for {} {}: {}", pendingExamine.getType(), pendingExamine.getId(), event.getMessage()); log.debug("Got examine for {} {}: {}", pendingExamine.getType(), pendingExamine.getId(), event.getMessage());
findExamineItem(pendingExamine); // If it is an item, show the price of it
if (pendingExamine.getType() == ExamineType.ITEM || pendingExamine.getType() == ExamineType.ITEM_BANK_EQ)
{
final int itemId = pendingExamine.getId();
final int itemQuantity = pendingExamine.getQuantity();
final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
if (itemComposition != null)
{
final int id = itemManager.canonicalize(itemComposition.getId());
executor.submit(() -> getItemPrice(id, itemComposition, itemQuantity));
}
}
CacheKey key = new CacheKey(type, pendingExamine.getId()); CacheKey key = new CacheKey(type, pendingExamine.getId());
Boolean cached = cache.getIfPresent(key); Boolean cached = cache.getIfPresent(key);
if (cached != null) if (cached != null)
@@ -186,113 +216,80 @@ public class ExaminePlugin extends Plugin
submitExamine(pendingExamine, event.getMessage()); submitExamine(pendingExamine, event.getMessage());
} }
private void findExamineItem(PendingExamine pendingExamine) private int[] findItemFromWidget(int widgetId, int actionParam)
{ {
int quantity = 1;
int itemId = -1;
// Get widget
int widgetId = pendingExamine.getWidgetId();
int widgetGroup = TO_GROUP(widgetId); int widgetGroup = TO_GROUP(widgetId);
int widgetChild = TO_CHILD(widgetId); int widgetChild = TO_CHILD(widgetId);
Widget widget = client.getWidget(widgetGroup, widgetChild); Widget widget = client.getWidget(widgetGroup, widgetChild);
if (widget == null) if (widget == null)
{ {
return; return null;
} }
if (pendingExamine.getType() == ExamineType.ITEM) if (WidgetInfo.EQUIPMENT.getGroupId() == widgetGroup)
{ {
WidgetItem widgetItem = widget.getWidgetItem(pendingExamine.getActionParam()); Widget widgetItem = widget.getChild(1);
quantity = widgetItem != null ? widgetItem.getQuantity() : 1; if (widgetItem != null)
itemId = pendingExamine.getId(); {
return new int[]{widgetItem.getItemQuantity(), widgetItem.getItemId()};
}
} }
else if (pendingExamine.getType() == ExamineType.ITEM_BANK_EQ) else if (WidgetInfo.SMITHING_INVENTORY_ITEMS_CONTAINER.getGroupId() == widgetGroup)
{ {
if (WidgetInfo.EQUIPMENT.getGroupId() == widgetGroup) Widget widgetItem = widget.getChild(2);
if (widgetItem != null)
{ {
Widget widgetItem = widget.getChild(1); return new int[]{widgetItem.getItemQuantity(), widgetItem.getItemId()};
if (widgetItem != null)
{
quantity = widgetItem.getItemQuantity();
itemId = widgetItem.getItemId();
}
} }
else if (WidgetInfo.SMITHING_INVENTORY_ITEMS_CONTAINER.getGroupId() == widgetGroup) }
else if (WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER.getGroupId() == widgetGroup
|| WidgetInfo.RUNE_POUCH_ITEM_CONTAINER.getGroupId() == widgetGroup)
{
Widget widgetItem = widget.getChild(actionParam);
if (widgetItem != null)
{ {
Widget widgetItem = widget.getChild(2); return new int[]{widgetItem.getItemQuantity(), widgetItem.getItemId()};
if (widgetItem != null)
{
quantity = widgetItem.getItemQuantity();
itemId = widgetItem.getItemId();
}
} }
else if (WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER.getGroupId() == widgetGroup }
|| WidgetInfo.RUNE_POUCH_ITEM_CONTAINER.getGroupId() == widgetGroup) else if (WidgetInfo.BANK_ITEM_CONTAINER.getGroupId() == widgetGroup)
{
Widget[] children = widget.getDynamicChildren();
if (actionParam < children.length)
{ {
Widget widgetItem = widget.getChild(pendingExamine.getActionParam()); Widget widgetItem = children[actionParam];
if (widgetItem != null) return new int[]{widgetItem.getItemQuantity(), widgetItem.getItemId()};
{
quantity = widgetItem.getItemQuantity();
itemId = widgetItem.getItemId();
}
} }
else if (WidgetInfo.BANK_ITEM_CONTAINER.getGroupId() == widgetGroup) }
else if (WidgetInfo.SHOP_ITEMS_CONTAINER.getGroupId() == widgetGroup)
{
Widget[] children = widget.getDynamicChildren();
if (actionParam < children.length)
{ {
Widget[] children = widget.getDynamicChildren(); Widget widgetItem = children[actionParam];
if (pendingExamine.getActionParam() < children.length) return new int[]{1, widgetItem.getItemId()};
{
Widget widgetItem = children[pendingExamine.getActionParam()];
quantity = widgetItem.getItemQuantity();
itemId = widgetItem.getItemId();
}
} }
else if (WidgetInfo.SHOP_ITEMS_CONTAINER.getGroupId() == widgetGroup) }
else if (WidgetInfo.CLUE_SCROLL_REWARD_ITEM_CONTAINER.getGroupId() == widgetGroup)
{
Widget[] children = widget.getDynamicChildren();
if (actionParam < children.length)
{ {
Widget[] children = widget.getDynamicChildren(); Widget widgetItem = children[actionParam];
if (pendingExamine.getActionParam() < children.length) return new int[]{widgetItem.getItemQuantity(), widgetItem.getItemId()};
{
Widget widgetItem = children[pendingExamine.getActionParam()];
quantity = 1;
itemId = widgetItem.getItemId();
}
} }
else if (WidgetInfo.CLUE_SCROLL_REWARD_ITEM_CONTAINER.getGroupId() == widgetGroup) }
else if (WidgetInfo.LOOTING_BAG_CONTAINER.getGroupId() == widgetGroup)
{
Widget[] children = widget.getDynamicChildren();
if (actionParam < children.length)
{ {
Widget[] children = widget.getDynamicChildren(); Widget widgetItem = children[actionParam];
if (pendingExamine.getActionParam() < children.length) return new int[]{widgetItem.getItemQuantity(), widgetItem.getItemId()};
{
Widget widgetItem = children[pendingExamine.getActionParam()];
quantity = widgetItem.getItemQuantity();
itemId = widgetItem.getItemId();
}
}
else if (WidgetInfo.LOOTING_BAG_CONTAINER.getGroupId() == widgetGroup)
{
Widget[] children = widget.getDynamicChildren();
if (pendingExamine.getActionParam() < children.length)
{
Widget widgetItem = children[pendingExamine.getActionParam()];
quantity = widgetItem.getItemQuantity();
itemId = widgetItem.getItemId();
}
} }
} }
if (itemId == -1) return null;
{
return;
}
final int itemQuantity = quantity;
final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
if (itemComposition != null)
{
final int id = itemManager.canonicalize(itemComposition.getId());
executor.submit(() -> getItemPrice(id, itemComposition, itemQuantity));
}
} }
private void getItemPrice(int id, ItemComposition itemComposition, int quantity) private void getItemPrice(int id, ItemComposition itemComposition, int quantity)

View File

@@ -32,7 +32,6 @@ class PendingExamine
{ {
private ExamineType type; private ExamineType type;
private int id; private int id;
private int widgetId; private int quantity;
private int actionParam;
private Instant created; private Instant created;
} }