ItemManager Documentation¶
Overview¶
The ItemManager class is a singleton in the HighSpell game responsible for managing player interactions with inventory items, including selecting, using, equipping, and performing actions like dropping or trading. It coordinates item-related actions, emits network packets for server-side validation, and handles UI interactions such as confirmation dialogs and text input menus. This class is central to the game’s inventory and item interaction system, working closely with classes like MainPlayer and TargetActionManager.
Usefulness for Botting¶
The ItemManager class provides access to the currently selected item (CurrentSelectedItem), item action states (IsAwaitingItemAction), and methods for invoking actions like use, equip, or drop. It exposes methods to emit network packets for item actions (emitInventoryItemActionPacket, emitUseItemOnItemActionPacket), enabling bots to automate inventory interactions, such as equipping items, combining items, or dropping items, based on their definitions and slots. The class’s integration with MenuTypesEnum and ItemActionEnum allows precise targeting of inventory or bank items.
Key Features¶
- Singleton Pattern: Ensures a single instance via the
Instancegetter. - Item Selection: Manages the currently selected item and its UI state.
- Action Handling: Processes item actions (e.g., equip, use, drop) with server communication.
- UI Integration: Coordinates confirmation dialogs and text input menus for item actions.
- Event System: Uses listeners to notify other systems of changes in item action states.
Key Properties¶
_itemManager(static): The singleton instance ofItemManager._currentSelectedItem: The currently selected item, stored as anAVobject (menu type, item, control, slot)._shouldWithdrawBankItemsAsIOU: A boolean indicating whether bank items should be withdrawn as IOUs (getter and setter)._isAwaitingItemAction: A boolean indicating if an item action is pending server response (getter and setter, triggers_onIsAwaitingItemActionChangedEventListener)._onIsAwaitingItemActionChangedEventListener: AListenersobject for notifying changes in_isAwaitingItemAction._didLoad: A boolean tracking whether the manager has loaded item and shop definitions.
Constructor¶
- Signature:
constructor() - Binds callback methods (
_handleSelectAnItemOptionMenuCallback,_handleCreateItemsTextInputMenuSubmitted,_handleConfirmInventoryActionResult). - Initializes
_didLoadtofalse,_currentSelectedItemtonull,_shouldWithdrawBankItemsAsIOUtofalse,_isAwaitingItemActiontofalse, and_onIsAwaitingItemActionChangedEventListeneras a newListenersobject.
Static Methods¶
Instance(getter):- Returns the singleton instance, creating a new
ItemManagerif_itemManageris undefined.
Instance Methods¶
loadAsync(e, t, i):- Parameters:
e: Unused (likely a context or callback).t: Path or identifier for item definition data.i: Path or identifier for shop definition data.
-
Functionality:
- Warns if already loaded (
_didLoadistrue). - Sets
_didLoadtotrue. - Asynchronously loads item definitions (
ItemDefs.loadFromJSON) and shop definitions (ShopDefs.loadFromJSON) usingAssetManager.getDefinitionData. - Returns a
Promisefor asynchronous execution.
- Warns if already loaded (
-
invokeInventoryAction(e, t, i, n): - Parameters:
e: Menu type (e.g.,MenuTypesEnum.Inventory).t: Action type (e.g.,ItemActionEnum.use).i: Inventory slot index.n: TheInventoryItemobject.
-
Functionality:
- Exits if
_isAwaitingItemActionistrue. - If an item is selected and the action is valid, performs an item-on-item action or unselects the item.
- Handles actions based on
t: use: Selects the item for further interaction.create: Emits acreateCreateItemActionpacket.equip: Checks requirements via_hasRequirementsToEquipItemand emits an action packet.discard: Shows a confirmation dialog before emitting the action.- Other actions (e.g.,
offer,drop,eat): Emits an action packet directly.
- Exits if
-
emitCreateItemActionPacket(e, t, i): -
Emits a
createCreateItemActionpacket viaSocketManagerwith menu type, item ID, and amount. SeeMenuTypesEnum. -
emitUseItemOnItemActionPacket(e, t, i, n, r, s, a): -
Sets
_isAwaitingItemActiontotrueand emits acreateUseItemOnItemActionpacket with menu type, slots, item details, and quantity. -
emitInventoryItemActionPacket(e, t, i, n, r, s): -
Sets
_isAwaitingItemActiontotrueand emits acreateInvokeInventoryItemActionActionpacket with action, menu type, slot, item ID, amount, and IOU status. -
emitReorganizeInventorySlotsPacket(e, t, i, n, r, s, a, o): -
Sets
_isAwaitingItemActiontotrueand emits acreateReorganizeInventorySlotsActionpacket for inventory slot reorganization. -
selectItem(e, t, i): -
Selects an item from the inventory UI, creating an
AVobject and marking the item’s UI control as selected. -
unselectItem(): -
Unselects the current item, clearing its UI state and destroying the
AVobject. -
_handleItemOnItemAction(e, t, i, n, r, s, a): -
Handles combining two items, checking if the action is valid via
SP.get. Shows a selection menu or text input for quantity if needed, or emits auseItemOnItempacket. -
_handleSelectAnItemOptionMenuCallback(e, t): -
Processes the selection of an item combination result and calls
_handleItemOnItemAction. -
_handleCreateItemsTextInputMenuSubmitted(e, t): -
Parses the quantity input and emits a
useItemOnItempacket if valid. -
_canPlayerCreateItem(e, t, i): -
Checks if the player can create an item based on skill requirements (e.g.,
CraftingHandler,PotionMakingHandler). -
useItemOnEntity(e, t): -
Uses an item on an entity via
TargetActionManager.handleItemOnEntityActionand unselects the item. -
_hasRequirementsToEquipItem(e, t): -
Verifies if the player meets the skill requirements to equip an item, showing a chat message if requirements are unmet.
-
handleLookedAtItem(e, t): -
Handles the
look_ataction for specific item types (e.g., treasure maps), showing a UI menu. -
_confirmInventoryActionBeforeInvoking(e, t, i, n, r, s, a, o, l, h): -
Shows a confirmation dialog for actions like
discardusingScreenMaskController. -
_handleConfirmInventoryActionResult(e, t): -
Processes confirmation dialog results, emitting an action packet if confirmed.
-
reset(): - Clears
_currentSelectedItem,_shouldWithdrawBankItemsAsIOU,_isAwaitingItemAction, and reinitializes_onIsAwaitingItemActionChangedEventListener.
Technical Observations¶
- Dependencies: Integrates with UI controllers (
GameMenuBarController,ChatMenuController,ScreenMaskController), network systems (SocketManager), and skill/item handlers. - Singleton Pattern: Ensures a single instance for global item management.
- Event-Driven Design: Uses
_onIsAwaitingItemActionChangedEventListenerfor state changes and callbacks for UI interactions. - Network Integration: Emits packets for all actions, ensuring server-side validation.
- Asynchronous Loading: Uses
loadAsyncto load item and shop definitions, suggesting networked or asset-based initialization.
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.