HealthSystem Class
This system is reponsible for dealing damage, healing and checking if entities are dead. If an entity dies, the system will trigger an 'entityDied' event with the entity as an argument.
Constructor
HealthSystem
-
entitySystemManager
Parameters:
-
entitySystemManager
ManagerThe entity system manager whose entities this system will be working on.
Item Index
Methods
damageEntity
-
entity
-
damageAmount
-
damageType
Damages an entity if it has the health component. Additionally, if a spell effect component is present, all shield and resistance effects will be taken into account. When damaging an entity, first the damage is modified by resistance values, then damage is dealt to shield effects if present, then if there's any damage left to be dealt, it's dealt to health.
Parameters:
-
entity
EntityEntity that will be damaged.
-
damageAmount
Number -
damageType
StringThe type of damage dealt. This type can be 'c' for cyan, 'm' for magenta, 'y' for yellow and 'w' for white.
destroy
()
healEntity
-
entity
-
healAmount
Heals the specified entity by the given value. Doesn't heal past maximum health.
Parameters:
-
entity
EntityEntity that will be healed.
-
healAmount
Number
subscribe
-
event
-
callback
-
[subscriber]
Parameters:
-
event
StringName of the event being subscribed to.
-
callback
FunctionFunction that will be called back when the specified event is triggered.
-
[subscriber]
Object optionalAn optional parameter that specifies an object that's subscribing. When a function is subscribed with an object, that function will be called back with "this" set to the object.
trigger
-
event
-
[eventObject]
Triggers the event, calling all functions that subscribed to it.
Parameters:
-
event
StringThe event to be triggered.
-
[eventObject]
Object optionalAll functions that were subscribed to the specified event will be called with this as the argument.
unsubscribe
-
event
-
[callback]
-
[subscriber]
This is a multi-purpose method. See the example for all the ways it can be overloaded.
Parameters:
-
event
Object -
[callback]
Object optional -
[subscriber]
Object optional
Example:
//Unsubscribing all callbacks for a given event.
eventHandler.unsubscribe('eventName');
//Unsubscribing all callbacks subscribed by the object.
eventHandler.unsubscribe(object);
//Unsubscribing all callbacks an object made for the given event.
eventHandler.unsubscribe('eventName', object);
//Unsubscribing a callback that was subscribed with an object.
eventHandler.unsubscribe('eventName', callback, object);
//Unsubscribing a callback subscribed by itself.
eventHandler.unsubscribe('eventName', callback);
//The last method can't be used to unsubscribe callbacks which were subscribed with an object.