Class ShopInterface

java.lang.Object
privbot.hooks.shop.ShopInterface

public final class ShopInterface extends Object
Finds the open shop's stock and buys from it; ctx.shop uses it on Impact, Elorin and SpawnPK.

A shop is a container, not a tree of slot widgets. These clients have no widget per stock item carrying a "Buy 10" action, as an OSRS client does: the stock is one container, the same kind that holds the inventory and the worn equipment.

The buy options exist only in the slot's right-click menu (Buy-1, Buy-5, Buy-10, Buy-X, Value), and each quantity is its own action, so the quantities this class offers are exactly the ones PrivBot knows how to send on this server. Nothing is guessed: any other quantity is simply not offered. A buy is sent exactly as the player's own click on that slot and quantity.

  • Constructor Summary

    Constructors
    Constructor
    Description
    ShopInterface(net.runelite.api.Client client, Widgets widgets)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    buy(ShopSlot slot, int remaining)
    Clicks the best available buy option for remaining units.
    The purchase quantities PrivBot can send on this server, largest first.
    boolean
    buyX(ShopSlot slot)
    Opens the Buy X amount prompt on a stock slot.
    The stock scan, as a copy: the one openState() just made when asked within CACHE_TTL_MS of it, so a caller that checks the state and then reads the stock scans once.
    currentStock() limited to the containers the client confirms are drawn (the client reports them drawn): what the shop learner records, so a live-but-hidden panel is never learned as stock.
    void
    Prints every item-bearing container the client holds.
    findStockSlot(String itemName, boolean partialMatch)
    Finds the stock slot holding itemName.
    boolean
    True when PrivBot can open the shop's Buy X amount prompt on this server.
    void
    Drops the cached scan so the next query reads the shop again.
    boolean
    Strict gate for "should I (re)open the shop?": stale contents are not enough.
    boolean
    True when a stock container with at least one item is live — i.e.
    Three-valued "is the shop on screen?" — TRUE drawn, FALSE definitely not, null unanswerable.
    int
    Remaining shop stock for a slot, or 0 when unreadable.

    Methods inherited from class java.lang.Object

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

    • ShopInterface

      public ShopInterface(net.runelite.api.Client client, Widgets widgets)
  • Method Details

    • invalidate

      public void invalidate()
      Drops the cached scan so the next query reads the shop again.
    • isOpen

      public boolean isOpen()
      True when a stock container with at least one item is live — i.e. a shop is on screen.
    • isDefinitelyOpen

      public boolean isDefinitelyOpen()
      Strict gate for "should I (re)open the shop?": stale contents are not enough.

      A closed shop still reads as stocked. On Elorin a shop keeps its items after the interface closes, as the bank and the trade screens do. Gating the trade-open on isOpen() would therefore skip the NPC click for anyone who had opened that shop earlier in the session, and every buy would go to a shop that is not on screen, which the server ignores.

      Answers true only when the client confirms the shop is drawn, so when that cannot be told the caller re-opens rather than assuming: a redundant trade click costs one tick, a skipped one costs the whole action.

    • openState

      public Boolean openState()
      Three-valued "is the shop on screen?" — TRUE drawn, FALSE definitely not, null unanswerable.

      The two-valued form folds "cannot tell" into "closed", which is right for deciding whether to CLICK the NPC and wrong for deciding whether to BUY. On Elorin the answer is always null: a buy gated on isDefinitelyOpen() would never happen.

      Callers must decide what null means for them. Opening treats it as "open anyway" (a redundant trade click costs a tick). Buying treats it as "try, and let the inventory delta be the proof" — the same rule the bank withdraw already follows, for the same reason.

    • currentStock

      public List<ShopSlot> currentStock()
      The stock scan, as a copy: the one openState() just made when asked within CACHE_TTL_MS of it, so a caller that checks the state and then reads the stock scans once.
    • drawnStock

      public List<ShopSlot> drawnStock()
      currentStock() limited to the containers the client confirms are drawn (the client reports them drawn): what the shop learner records, so a live-but-hidden panel is never learned as stock. Empty when nothing is confirmed drawn or the adapter cannot answer.
    • findStockSlot

      public ShopSlot findStockSlot(String itemName, boolean partialMatch)
      Finds the stock slot holding itemName.
      Parameters:
      partialMatch - when true, a slot matches if its item name contains itemName
      Returns:
      the slot, or null when the shop does not stock it
    • stockOf

      public int stockOf(ShopSlot slot)
      Remaining shop stock for a slot, or 0 when unreadable.
    • buyOptions

      public List<ShopOption> buyOptions()
      The purchase quantities PrivBot can send on this server, largest first.
    • buy

      public boolean buy(ShopSlot slot, int remaining)
      Clicks the best available buy option for remaining units.
      Returns:
      false when no quantity can be sent on this server, or dispatch failed
    • hasBuyX

      public boolean hasBuyX()
      True when PrivBot can open the shop's Buy X amount prompt on this server.

      Buy-X buys any quantity in one dispatch instead of chunking into the 1/5/10 options, so 400 of something is one click and three keystrokes rather than forty clicks.

    • buyX

      public boolean buyX(ShopSlot slot)
      Opens the Buy X amount prompt on a stock slot.

      Dispatch only. The prompt then wants the amount typed and Enter, which is keyboard input and belongs with the keyboard helper in the caller — this class stays free of AWT, and the caller is where the game's listener-bearing canvas is already resolved.

      Returns:
      false when Buy X cannot be sent on this server, or dispatch was not possible
    • dumpDiagnostics

      public void dumpDiagnostics()
      Prints every item-bearing container the client holds. Called when no shop is detected, so the real structure is visible in the console instead of a silent no-op: if the stock container sits below MIN_SHOP_SLOTS or is the INVENTORY_SLOTS panel, it shows up here and can be named with -Dprivbot.shop.containerWidget=<id>.