InventoryItem Documentation¶
Overview¶
The InventoryItem class represents an item within a player’s inventory or bank storage in the HighSpell game. It encapsulates properties such as the item’s definition, quantity, and IOU (placeholder) status, providing methods for manipulating and serializing item data. This class is integral to the game’s inventory system, used by classes like MainPlayer to manage player possessions.
Usefulness for botting¶
An InventoryItem holds some important information about the items you have available to your character. But most importantly they're passed whole to functions that act on items.
Key Properties¶
The InventoryItem class defines properties, accessed via getters and setters:
_def: The item’s definition, lazily loaded viaItemDefs.getDefById(this._id)when accessed (getter only)._amount: The quantity of the item (getter and setter)._isIOU: A boolean indicating if the item is an IOU (placeholder, e.g., for items promised but not yet delivered) (getter and setter)._id: The item’s unique identifier, used to fetch its definition (not directly accessible via getter/setter).
Constructor¶
- Signature:
constructor(e, t, i) - Parameters:
e: The item’s ID (_id), used to retrieve its definition.t: The item’s quantity (_amount).i: The IOU status (_isIOU), indicating if the item is a placeholder.
- Initializes
_id,_amount, and_isIOUwith the provided values. - Does not immediately load
_def, deferring it to theDefgetter for lazy initialization.
Methods¶
updateAmount(e):- Adjusts
_amountby addinge(can be positive or negative). - Ensures
_amountdoes not go below 0. - Returns the updated
_amount. doesMatch(e, t):- Checks if the item matches the given ID (
e) and IOU status (t). - Returns
trueif both the item’sDef.IDand_isIOUmatch the provided values. clone():- Creates a new
InventoryIteminstance with the sameDef.ID,_amount, and_isIOU. - Useful for duplicating items without modifying the original.
toSocketArray():- Serializes the item into an array format for network transmission:
[Def.ID, _amount, _isIOU ? 1 : 0]. toJson():- Serializes the item into a JSON object:
{ id: Def.ID, amt: _amount, isIOU: _isIOU }. toString():- Returns a string representation of the item:
"[ ID: <Def.ID>, Name: <Def.Name>, Amount: _amount, IsIOU: _isIOU ]". - Uses
-1and empty string ifDefis not loaded. static fromPacketArray(e):- Creates an
InventoryItemfrom a network packet array. - Expects an array of length 2 (
[id, amount]) or 3 ([id, amount, isIOU]), whereisIOUis1fortrueor0forfalse. - Returns
nullif the array is invalid. static fromJson(e):- Creates an
InventoryItemfrom a JSON object withid,amt, andisIOUproperties. - Returns
nullif the input is invalid. destroy():- Cleans up the item by nullifying
_amountand_isIOU. - Does not nullify
_idor_def, as_defis lazily loaded and_idis immutable.
Technical Observations¶
- Lazy Loading: The
_defproperty is lazily loaded to optimize performance, only fetching the definition when accessed. - Serialization: Supports both array-based (
toSocketArray) and JSON (toJson) serialization, likely for network communication and local storage, respectively.
Ethical and Legal Notes¶
Per the HighSpell Botting Resources ethos: - This documentation is for educational purposes, analyzing observable game client behavior. - Using this information to create bots violates HighSpell’s terms of service, risking account bans.