Add item queries

This commit is contained in:
Devin
2017-10-12 22:11:46 -07:00
parent 58be3e8f4c
commit f2f60820ca
7 changed files with 351 additions and 25 deletions

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.api.queries;
import net.runelite.api.Client;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
public class BankItemQuery extends WidgetItemQuery
{
private static final int ITEM_EMPTY = 6512;
@Override
public WidgetItem[] result(Client client)
{
Collection<WidgetItem> widgetItems = getBankItems(client);
if (widgetItems != null)
{
return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new);
}
return new WidgetItem[0];
}
private Collection<WidgetItem> getBankItems(Client client)
{
Collection<WidgetItem> widgetItems = new ArrayList<>();
Widget bank = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
if (bank != null && !bank.isHidden())
{
Widget[] children = bank.getDynamicChildren();
for (int i = 0; i < children.length; i++)
{
if (children[i].getItemId() == ITEM_EMPTY)
{
continue;
}
// set bounds to same size as default inventory
Rectangle bounds = children[i].getBounds();
bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
// Index is set to 0 because the widget's index does not correlate to the order in the bank
widgetItems.add(new WidgetItem(children[i].getItemId(), children[i].getItemQuantity(), 0, bounds));
}
}
return widgetItems;
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.api.queries;
import net.runelite.api.Client;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
public class EquipmentItemQuery extends WidgetItemQuery
{
private static final WidgetInfo[] ALL_EQUIPMENT_WIDGET_INFOS = {
WidgetInfo.EQUIPMENT_HELMET,
WidgetInfo.EQUIPMENT_CAPE,
WidgetInfo.EQUIPMENT_AMULET,
WidgetInfo.EQUIPMENT_WEAPON,
WidgetInfo.EQUIPMENT_BODY,
WidgetInfo.EQUIPMENT_SHIELD,
WidgetInfo.EQUIPMENT_LEGS,
WidgetInfo.EQUIPMENT_GLOVES,
WidgetInfo.EQUIPMENT_BOOTS,
WidgetInfo.EQUIPMENT_RING,
WidgetInfo.EQUIPMENT_AMMO,
};
private Collection<WidgetInfo> slots;
public EquipmentItemQuery()
{
slots = new ArrayList<>();
}
public EquipmentItemQuery slotEquals(WidgetInfo... slotWidgetInfo)
{
slots.addAll(Arrays.asList(slotWidgetInfo));
return this;
}
@Override
public WidgetItem[] result(Client client)
{
Collection<WidgetItem> widgetItems = getEquippedItems(client);
if (widgetItems != null)
{
return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new);
}
return new WidgetItem[0];
}
private Collection<WidgetItem> getEquippedItems(Client client)
{
Collection<WidgetItem> widgetItems = new ArrayList<>();
Widget equipment = client.getWidget(WidgetInfo.EQUIPMENT);
if (equipment != null && !equipment.isHidden())
{
if (slots.isEmpty())
{
slots.addAll(Arrays.asList(ALL_EQUIPMENT_WIDGET_INFOS));
}
for (WidgetInfo slot : slots)
{
Widget widget = client.getWidget(slot).getChild(1);
// set bounds to same size as default inventory
Rectangle bounds = widget.getBounds();
bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
// Index is set to 0 because there is no set in stone order of equipment slots
widgetItems.add(new WidgetItem(widget.getItemId(), widget.getItemQuantity(), 0, bounds));
}
}
return widgetItems;
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.api.queries;
import net.runelite.api.Client;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
public class InventoryItemQuery extends WidgetItemQuery
{
private static final WidgetInfo[] INVENTORY_WIDGET_INFOS = {
WidgetInfo.DEPOSIT_BOX_INVENTORY_ITEMS_CONTAINER,
WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER,
WidgetInfo.SHOP_INVENTORY_ITEMS_CONTAINER,
WidgetInfo.INVENTORY
};
@Override
public WidgetItem[] result(Client client)
{
Collection<WidgetItem> widgetItems = getInventoryItems(client);
if (widgetItems != null)
{
return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new);
}
return new WidgetItem[0];
}
private Collection<WidgetItem> getInventoryItems(Client client)
{
Collection<WidgetItem> widgetItems = new ArrayList<>();
for (WidgetInfo widgetInfo : INVENTORY_WIDGET_INFOS)
{
Widget inventory = client.getWidget(widgetInfo);
if (inventory == null || inventory.isHidden())
{
continue;
}
if (widgetInfo == WidgetInfo.INVENTORY)
{
widgetItems.addAll(inventory.getWidgetItems());
break;
}
else
{
Widget[] children = inventory.getDynamicChildren();
for (int i = 0; i < children.length; i++)
{
// set bounds to same size as default inventory
Rectangle bounds = children[i].getBounds();
bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
widgetItems.add(new WidgetItem(children[i].getItemId(), children[i].getItemQuantity(), i, bounds));
}
break;
}
}
return widgetItems;
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.api.queries;
import net.runelite.api.Client;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
public class ShopItemQuery extends WidgetItemQuery
{
@Override
public WidgetItem[] result(Client client)
{
Collection<WidgetItem> widgetItems = getShopItems(client);
if (widgetItems != null)
{
return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new);
}
return new WidgetItem[0];
}
private Collection<WidgetItem> getShopItems(Client client)
{
Collection<WidgetItem> widgetItems = new ArrayList<>();
Widget shop = client.getWidget(WidgetInfo.SHOP_ITEMS_CONTAINER);
if (shop != null && !shop.isHidden())
{
Widget[] children = shop.getDynamicChildren();
for (int i = 1; i < children.length; i++)
{
// set bounds to same size as default inventory
Rectangle bounds = children[i].getBounds();
bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
widgetItems.add(new WidgetItem(children[i].getItemId(), children[i].getItemQuantity(), i - 1, bounds));
}
}
return widgetItems;
}
}

View File

@@ -26,21 +26,10 @@ package net.runelite.api.queries;
import net.runelite.api.Client;
import net.runelite.api.Query;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import java.util.Collection;
import java.util.Objects;
public class WidgetItemQuery extends Query<WidgetItem, WidgetItemQuery>
public abstract class WidgetItemQuery extends Query<WidgetItem, WidgetItemQuery>
{
private final WidgetInfo widgetInfo;
public WidgetItemQuery(WidgetInfo widgetInfo)
{
this.widgetInfo = widgetInfo;
}
public WidgetItemQuery idEquals(int... ids)
{
@@ -81,17 +70,5 @@ public class WidgetItemQuery extends Query<WidgetItem, WidgetItemQuery>
}
@Override
public WidgetItem[] result(Client client)
{
Widget widget = client.getWidget(widgetInfo);
if (widget != null)
{
Collection<WidgetItem> widgetItems = widget.getWidgetItems();
if (widgetItems != null)
{
return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new);
}
}
return new WidgetItem[0];
}
public abstract WidgetItem[] result(Client client);
}

View File

@@ -27,6 +27,8 @@ package net.runelite.api.widgets;
class WidgetID
{
static final int BANK_GROUP_ID = 12;
static final int BANK_INVENTORY_GROUP_ID = 15;
static final int DEPOSIT_BOX_GROUP_ID = 192;
static final int INVENTORY_GROUP_ID = 149;
static final int EQUIPMENT_GROUP_ID = 387;
static final int PESTRCONTROL_GROUP_ID = 408;
@@ -38,6 +40,8 @@ class WidgetID
static final int RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX_GROUP_ID = 161;
static final int RESIZABLE_VIEWPORT_BOTTOM_LINE_GROUP_ID = 164;
static final int PRAYER_GROUP_ID = 541;
static final int SHOP_GROUP_ID = 300;
static final int SHOP_INVENTORY_GROUP_ID = 301;
static class PestControl
{
@@ -70,6 +74,18 @@ class WidgetID
static class Bank
{
static final int ITEM_CONTAINER = 12;
static final int INVENTORY_ITEM_CONTAINER = 3;
}
static class DepositBox
{
static final int INVENTORY_ITEM_CONTAINER = 2;
}
static class Shop
{
static final int ITEMS_CONTAINER = 2;
static final int INVENTORY_ITEM_CONTAINER = 0;
}
static class Equipment

View File

@@ -64,6 +64,11 @@ public enum WidgetInfo
CLAN_CHAT_OWNER(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.OWNER),
BANK_ITEM_CONTAINER(WidgetID.BANK_GROUP_ID, WidgetID.Bank.ITEM_CONTAINER),
BANK_INVENTORY_ITEMS_CONTAINER(WidgetID.BANK_INVENTORY_GROUP_ID, WidgetID.Bank.INVENTORY_ITEM_CONTAINER),
DEPOSIT_BOX_INVENTORY_ITEMS_CONTAINER(WidgetID.DEPOSIT_BOX_GROUP_ID, WidgetID.DepositBox.INVENTORY_ITEM_CONTAINER),
SHOP_ITEMS_CONTAINER(WidgetID.SHOP_GROUP_ID, WidgetID.Shop.ITEMS_CONTAINER),
SHOP_INVENTORY_ITEMS_CONTAINER(WidgetID.SHOP_INVENTORY_GROUP_ID, WidgetID.Shop.INVENTORY_ITEM_CONTAINER),
MINIMAP_XP_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.XP_ORB),