Entity Documentation¶
Overview¶
The Entity class serves as the base class for all entities in the HighSpell game, providing a foundation for objects like players, NPCs, and world objects (e.g., WorldEntity). It encapsulates core properties such as identity, position, state, and appearance, along with event listeners for lifecycle events. This class is extended by more specific classes like WorldEntity to add specialized behavior.
Usefulness for botting¶
A Entity is the basis that holds most of the information useful in dervied classes, such as EntityId for NPCs and EntityTypeId for World Objects.
Key Properties¶
The Entity class defines properties, primarily accessed via getters, with one setter for state changes:
_entityId: A unique identifier for the entity._entityTypeId: An identifier for the entity’s type (e.g., specific to a class or category)._entityType: The entity’s type, likely an enum or constant defining its category._nameLowerCase: The entity’s name in lowercase, derived from the provided name._name: The entity’s capitalized name, formatted usingHighSpellUtil.simpleCapitalization._description: A textual description of the entity._appearance: An object managing the entity’s visual representation (e.g., 3D model or sprite)._currentMapLevel: The entity’s current map level (getter and setter)._currentGamePosition: ACoordinate3Dobject representing the entity’s 3D position (x, y, z)._currentState: The entity’s current state (e.g.,IdleState.Idle), with a setter that triggers state change events._actions: An array of possible actions the entity can perform (e.g.,TargetAction.inspect)._onAppearListener: AListenersobject for handling appearance events._onDisappearListener: AListenersobject for handling disappearance events._onMoveListener: AListenersobject for handling movement events._onSwitchedStateListener: AListenersobject for handling state changes._isDestroyed: A boolean indicating if the entity has been destroyed.
Constructor MIGHT BE INCORRECT¶
- Signature:
constructor(entityId, entityTypeId, entityType, name, description, appearance, currentMapLevel, positionX, positionY, positionZ, actions) - Parameters:
entityId: Unique identifier for the entity (_entityId).entityTypeId: Identifier for the entity type (_entityTypeId).entityType: Type of the entity, likely an enum or constant (_entityType).name: Display name, used to set_nameand_nameLowerCase.description: Descriptive text for the entity (_description).appearance: Visual or rendering properties (_appearance).currentMapLevel: Current map level the entity is on (_currentMapLevel).positionX, positionY, positionZ: X, Y, Z coordinates for_currentGamePosition.actions: List of possible actions the entity can perform (_actions).
- Initializes properties, sets
_currentStatetoIdleState.Idle, and createsListenersobjects for events. - Derives
_nameLowerCasefromname(lowercase) and_nameusingHighSpellUtil.simpleCapitalization. - Creates a
Coordinate3Dobject for_currentGamePositionusingpositionX,positionY, andpositionZ. - Ensures
_actionsis an array, initializing it to an empty array ifnullorundefined. - Sets
_isDestroyedtofalse.
State Management¶
CurrentState(getter/setter):- Getter: Returns the current state.
- Setter: Updates
_currentStateand triggers_onSwitchedStateListenerwith anEntityStateChangeEventcontaining the entity’s IDs, old state, and new state.
Lifecycle Methods¶
update(e):- An empty method intended to be overridden by subclasses for updating entity logic (e.g., based on a delta time
e). draw(e, t, i):- An empty method intended to be overridden by subclasses for rendering the entity.
beforeDestroy():- Invokes
_onDisappearListenerto notify listeners before destruction. destroy():- Cleans up the entity by:
- Destroying and nullifying all listeners (
_onAppearListener,_onDisappearListener,_onMoveListener,_onSwitchedStateListener). - Nullifying properties (
_entityId,_entityTypeId,_entityType,_name,_nameLowerCase,_description,_currentMapLevel,_currentGamePosition). - Clearing and nullifying
_actions. - Exiting and nullifying
_currentState. - Destroying and nullifying
_appearance. - Setting
_isDestroyedtotrue.
- Destroying and nullifying all listeners (
Event System¶
The class uses a Listeners system to manage events: - Listeners: _onAppearListener, _onDisappearListener, _onMoveListener, _onSwitchedStateListener allow external components to subscribe to entity events (e.g., appearing, moving, state changes). - State Change Event: The EntityStateChangeEvent includes the entity’s type ID, ID, and state transition details, enabling precise event handling.
Technical Observations¶
- Extensibility: The empty
updateanddrawmethods suggest the class is designed for inheritance, with subclasses likeWorldEntityadding specific behavior. - Event-Driven Design: The listener system supports a reactive architecture, allowing dynamic responses to entity changes.
- Destruction: The
destroymethod is thorough, nullifying all properties and cleaning up resources, likely to prevent memory leaks in a 3D rendering context (e.g., Babylon.js).
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.