diff --git a/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java new file mode 100644 index 0000000000..e60408e5c0 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, Devin French + * 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 widgetItems = getBankItems(client); + if (widgetItems != null) + { + return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new); + } + return new WidgetItem[0]; + } + + private Collection getBankItems(Client client) + { + Collection 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; + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java new file mode 100644 index 0000000000..70cf2058e4 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2017, Devin French + * 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 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 widgetItems = getEquippedItems(client); + if (widgetItems != null) + { + return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new); + } + return new WidgetItem[0]; + } + + private Collection getEquippedItems(Client client) + { + Collection 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; + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/InventoryItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/InventoryItemQuery.java new file mode 100644 index 0000000000..da2c80d516 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/queries/InventoryItemQuery.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017, Devin French + * 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 widgetItems = getInventoryItems(client); + if (widgetItems != null) + { + return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new); + } + return new WidgetItem[0]; + } + + private Collection getInventoryItems(Client client) + { + Collection 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; + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java new file mode 100644 index 0000000000..52847b268b --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017, Devin French + * 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 widgetItems = getShopItems(client); + if (widgetItems != null) + { + return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new); + } + return new WidgetItem[0]; + } + + private Collection getShopItems(Client client) + { + Collection 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; + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java index 8ee9c9e5f7..9a71a9bf3c 100644 --- a/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java +++ b/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java @@ -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 +public abstract class WidgetItemQuery extends Query { - 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 } @Override - public WidgetItem[] result(Client client) - { - Widget widget = client.getWidget(widgetInfo); - if (widget != null) - { - Collection 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); } diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java index ac1a189167..c3ddc4f573 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java @@ -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 diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java index 5246261639..e60c93de07 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java @@ -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),