Class Shop

java.lang.Object
privbot.hooks.Shop

public final class Shop extends Object
High-level shop interaction: open an NPC's shop, then sell items from inventory using the shop's widget actions (Sell 1 / Sell 5 / Sell 10 / Sell 50).

Selling is driven by the Widgets hook — it locates the requested action slot via getActions() on each shop-inventory child widget and dispatches the correct CC_OP packet. This keeps identifier math out of caller code and works across servers that re-order actions.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    OSRS/RSPS default: shop stock list (group 300, child 16).
    static final int
    OSRS/RSPS default: the shop's player-inventory container (group 301, child 0).
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    buy(String name, int quantity)
    Buys quantity of the named stock item from the open shop, using the buy quantities this server's shop offers (ShopInterface on Impact, Elorin and SpawnPK; the shop-stock widget's Buy 1/5/10/50 actions elsewhere).
    boolean
    True if the default shop widget is present and visible.
    boolean
    isOpen(int widgetId)
     
    boolean
    open(String npcName)
    Opens an NPC's shop using "Trade" as the default action.
    boolean
    open(String npcName, String action)
     
    boolean
    open(String npcName, String action, int widgetId, long timeoutMs)
    Interacts with the nearest NPC matching npcName using action, then waits up to timeoutMs for the shop widget to appear.
    int
    openAndSell(String npcName, String npcAction, int postOpenDelayTicks, List<String> names, boolean partialMatch, boolean sellAllExcept, String option, int widgetId)
    Opens the NPC's shop, waits postOpenDelayTicks game ticks, then sells items.
    boolean
    sell(String name, int quantity)
    Sells quantity of the named inventory item to the open shop, with the shop's Sell 1/5/10/50 actions.
    int
    sell(List<String> names, boolean partialMatch, boolean sellAllExcept, String option)
    Sells items from the open shop without any per-item delay.
    int
    sell(List<String> names, boolean partialMatch, boolean sellAllExcept, String option, int widgetId)
    sell(List, boolean, boolean, String) against a specific shop widget.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_SHOP_WIDGET_ID

      public static final int DEFAULT_SHOP_WIDGET_ID
      OSRS/RSPS default: the shop's player-inventory container (group 301, child 0).
      See Also:
    • DEFAULT_SHOP_STOCK_WIDGET_ID

      public static final int DEFAULT_SHOP_STOCK_WIDGET_ID
      OSRS/RSPS default: shop stock list (group 300, child 16).
      See Also:
  • Method Details

    • isOpen

      public boolean isOpen()
      True if the default shop widget is present and visible.
    • isOpen

      public boolean isOpen(int widgetId)
      Parameters:
      widgetId - the shop interface's widget id
      Returns:
      whether that widget is present and visible
    • open

      public boolean open(String npcName)
      Opens an NPC's shop using "Trade" as the default action.
    • open

      public boolean open(String npcName, String action)
      Parameters:
      npcName - the shopkeeper's name
      action - the menu action that opens the shop
      Returns:
      whether the shop opened within the default timeout
    • open

      public boolean open(String npcName, String action, int widgetId, long timeoutMs)
      Interacts with the nearest NPC matching npcName using action, then waits up to timeoutMs for the shop widget to appear. Returns true if the shop widget is visible at the end of the wait.

      No-op (returns true) if the shop is already open.

    • buy

      public boolean buy(String name, int quantity)
      Buys quantity of the named stock item from the open shop, using the buy quantities this server's shop offers (ShopInterface on Impact, Elorin and SpawnPK; the shop-stock widget's Buy 1/5/10/50 actions elsewhere).
    • sell

      public boolean sell(String name, int quantity)
      Sells quantity of the named inventory item to the open shop, with the shop's Sell 1/5/10/50 actions. Not supported on Impact, Elorin and SpawnPK yet.
    • sell

      public int sell(List<String> names, boolean partialMatch, boolean sellAllExcept, String option)
      Sells items from the open shop without any per-item delay. Matches item names against names (case-insensitive, optionally partial). When sellAllExcept is true, names is treated as a keep-list and everything else is sold.
      Parameters:
      option - widget action to invoke (e.g. "Sell 50", "Sell 10")
      Returns:
      number of items dispatched
    • sell

      public int sell(List<String> names, boolean partialMatch, boolean sellAllExcept, String option, int widgetId)
      sell(List, boolean, boolean, String) against a specific shop widget.
      Parameters:
      names - item names (a keep-list when sellAllExcept)
      partialMatch - match names as substrings
      sellAllExcept - sell everything not named
      option - the sell option (blank: Sell 50)
      widgetId - the shop interface's widget id
      Returns:
      number of items dispatched
    • openAndSell

      public int openAndSell(String npcName, String npcAction, int postOpenDelayTicks, List<String> names, boolean partialMatch, boolean sellAllExcept, String option, int widgetId)
      Opens the NPC's shop, waits postOpenDelayTicks game ticks, then sells items. Returns the number of items sold, or -1 if the shop failed to open.