LATE is a library for managing lasting effects, not instant effects.
**Targets**: Targets of effects. For now, players and mobs can be targets of effects.
**Impacts**: An elementary impact on target. Different effects can result in the same impact. In that case, their parameters and intensities are properly mixed to result in a single impact.
**Effects**: Combination of impacts, conditions and target. Many effects at once can be affected to a target, with different conditions (duration, area, equipment).
Conditions are only for stopping effect. LATE does not automatically start effects where condition are fulfilled. This would be far too difficult to continuously check for every possibility. Effect creation has to be triggered explicitely. Some helpers exist to start effects automatically on certain events.
# Effects management
Active effects are represented by Effect objects. Effect objects are created by calling `late.new_effect` method. Effects can also be automatically affected when using some items and blocks. In that case, they are defined in item or node definition.
## Effect phases
Effects have a cycle of life involving four phases:
### raise
Effect starts in this phase.
It stops after `raise` seconds or if effect conditions are no longer fulfilled.
Intensity of effect grows from 0 to 1 during this phase.
### still
Once raise phase is completed, effects enters the *still* phase.
Intensity is full and the phases lasts until one of the conditions stops being fulfilled.
### fall
When conditions are no longer fulfilled, effect enters fall phase.
Returns an Effect object if creation succeded, `nil` otherwise.
Possible cause of failure :
* Target is not suitable (neither a player nor a mob);
*`definition.id` (optional) field contains a value that is already in use for the target (check first with `late.get_effect_by_id` if you are using ids);
#### start
```lua
function Effect:start()
```
Starts an effect or restart it.
If conditions are not fulfilled, it will fall in *fall* phase again during next step. So `start`/`restart` should be called only if condition are fulfilled again.
#### restart
```lua
function Effect:restart()
```
Same as `start`.
#### stop
```lua
function Effect:stop()
```
Stops an effect. Actually set it in *fall* phase, regardless of conditions.
function late.register_condition_type(name, definition)
```
Registers a condition type.
Conditions are checked each step to determine if the effect should last or stop.
Registering new condition types allows to extend the available types of conditions.
`name`: Name of the condition type.
`definition`: Definition table of the condition type.
### Condition definition table
`definition` table may contain following fields:
*`check` = function(data, target, effect) A function called to check is a condition is fulfilled. Should return true if condition still fulfilled, false otherwise. This function is not called at each step, only when engine needs it. Function parameters:
*`data`: effect data
*`target`: target affected,
*`effect`: Effect object instance.
*`step` = function(data, target, effect) A function called at each step. Could be useful to prepare condition checking. Same parameters as `check` function.
In following helpers, valint stands for a pair of value / intensity.
Each effect corresponding to an impact gives one or more parameters to the impact and an effect intensity.
The impact is responsible of computing a single values from these parameters and intensity. LATE provides helpers to perform common combination operations.
## get_valints
```lua
function late.get_valints(params, index)
```
Returns extacts value/intensity pairs from impact params table.
Impact params table contains params given by effects definition, plus an *intensity* field reflecting the corresponding effect intensity.
`params`: the impact.params field
`index`: index of the params field to be extracted