Class GearSetup
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne wanted item.static enumWhether a setup describes worn equipment or carried supplies.static enumWhat a carried item is for. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GearSetupcaptureCarried(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).static GearSetupcaptureWorn(ItemContainerSnapshot equipment) Captures what is worn, by slot, at the quantity worn now.entries()booleanstatic GearSetupinthashCode()booleanisEmpty()kind()static StringtoJson()The JSON form with the server it belongs to recorded as"server".toString()
-
Constructor Details
-
GearSetup
- Parameters:
kind- worn or carriedentries- the wanted items, in the order a diff reports them (copied; no nulls)
-
-
Method Details
-
kind
- Returns:
- worn or carried
-
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
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
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
- Returns:
- this setup as JSON text that
fromJson(String)reads back to an equal setup
-
toJson
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 andfromJson(String)ignores it.- Parameters:
server- the server's slug (for example"elorin"), or null to record none- Returns:
- the JSON text
-
fromJson
- Parameters:
json- text written bytoJson()- Returns:
- the setup
- Throws:
IllegalArgumentException- when the text is not a setup (never returns a partial setup)
-
serverOf
- Parameters:
json- text written bytoJson(String)- Returns:
- the server recorded in it, or null when it records none or is not readable JSON
-
equals
-
hashCode
-
toString
-