Class GearSetup

java.lang.Object
privbot.mechanics.GearSetup

public final class GearSetup extends Object
An immutable description of the gear a fight needs, the same on every server: what is worn, or what is carried.

Capture one from the player's real containers (captureWorn(privbot.hooks.container.ItemContainerSnapshot), captureCarried(privbot.hooks.container.ItemContainerSnapshot)), save it with toJson(), and compare it with what the player has now through SetupDiff. Worn entries are requirements by slot. Carried entries are by item id; a drink also carries a dose family, so another dose of the same potion counts toward it.

What a capture proves: the snapshot it was made from was readable at that moment. Unreadable looks like: a null return (an unavailable container, a slot outside the container, two items in one slot, a repeated item id with a different identity, or a stack total that overflows). A readable but empty container captures as an empty setup; that is a real observation, not an error.

Thread rule: pure data. Nothing here reads the client; build the snapshot with ctx.inventory or ctx.equipment on the worker thread and pass it in.

  • Constructor Details

    • GearSetup

      public GearSetup(GearSetup.Kind kind, List<GearSetup.Entry> entries)
      Parameters:
      kind - worn or carried
      entries - the wanted items, in the order a diff reports them (copied; no nulls)
  • Method Details

    • kind

      public GearSetup.Kind kind()
      Returns:
      worn or carried
    • entries

      public List<GearSetup.Entry> entries()
      Returns:
      the wanted items in order (unmodifiable)
    • isEmpty

      public boolean isEmpty()
      Returns:
      true when the setup wants nothing; such a setup is trivially satisfied, so it is no target
    • captureWorn

      public static GearSetup captureWorn(ItemContainerSnapshot equipment)
      Captures what is worn, by slot, at the quantity worn now. A stack (quantity above 1) has minimum 1.
      Parameters:
      equipment - the equipment snapshot
      Returns:
      the setup, or null when the snapshot is unavailable or invalid (see the class comment)
    • captureCarried

      public static GearSetup captureCarried(ItemContainerSnapshot inventory)
      Captures what is carried: a stack split over several slots is merged into one entry per item id (it keeps the first slot it was seen in). The role is read from the item's actions and name: food carries "Eat" (rock cakes do not count), drinks carry "Drink" and are a prayer restore, a combat boost or another consumable, and arrows, bolts, runes and the like are ammunition. Food and drinks may drop to 0 (GearSetup.Entry.minimum()), ammunition needs 1, everything else needs the quantity captured.
      Parameters:
      inventory - the inventory snapshot
      Returns:
      the setup, or null when the snapshot is unavailable or invalid (see the class comment)
    • toJson

      public String toJson()
      Returns:
      this setup as JSON text that fromJson(String) reads back to an equal setup
    • toJson

      public String toJson(String server)
      The JSON form with the server it belongs to recorded as "server". Item ids differ between servers, so a saved setup is only meaningful on the server it was captured on; serverOf(String) reads the tag back and fromJson(String) ignores it.
      Parameters:
      server - the server's slug (for example "elorin"), or null to record none
      Returns:
      the JSON text
    • fromJson

      public static GearSetup fromJson(String json)
      Parameters:
      json - text written by toJson()
      Returns:
      the setup
      Throws:
      IllegalArgumentException - when the text is not a setup (never returns a partial setup)
    • serverOf

      public static String serverOf(String json)
      Parameters:
      json - text written by toJson(String)
      Returns:
      the server recorded in it, or null when it records none or is not readable JSON
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object