Repository navigation
Status Effects
There are various status effects that can be applied to the player such as speed or health effects. This can take effect from attacks from enemies (such as a poison arrow) or from items being equipped or used (such as a regeneration potion).
To use an effect, add the relative component to the entity before creation and use the applyEffect method to apply the new effect.
applyEffect(Integer time, Integer healthChange)Health effects are used to make a numerical change to the entity's current health. This can be done over time by providing an integer to the time argument. This will be the number of updates the effect will take to apply the full amount of health change specified in the healthChange argument. Providing a positive healthChange value will increase the entity's health, while a negative value will decrease its health. Giving a time of 0 will apply the healthChange value instantly.
This can be used for:
- Regeneration potions (
time > 0,healthChange > 0) - Instant health potions or food (
time = 0,healthChange > 0) - Poison potions or attacks (
time > 0,healthChange < 0)
entity.addComponent(new HealthEffectComponent());
entity.create();
effect.getComponent(HealthEffectComponent).applyEffect(5, 50);(providing time = 5 and healthChange = 50) will increase the entity's health by 50 points over 5 update cycles: 10 hp per update for 5 updates.
Tests were created to ensure the following:
- Poison gets applied over time
- Regen gets applied over time
- Each tick applies the correct
healthChangevalue - Instant application occurs when a
timevalue of 0 is given - The component gets disabled once the full
healthChangevalue gets applied - The constructor throws an error when a negative value for
timeis given
applyEffect(Integer time, Float speedMultiplier) {}Speed effects apply a multiplier to the entity's current speed for the given amount of time (in number of updates). Providing a speedMultiplier of 0 will freeze the entity. A speedMultiplier > 1 will increase the entity's speed (speeding up). A speedMultiplier < 1 will decrease the entity's speed (slowing down). Giving a time value of 0 will apply the healthChange value instantly.
This can be used for:
- Speed potions (
speedMultiplier > 1) - Slowing attacks (
0 < speedMultiplier < 1) - Freezing attacks (
speedMultiplier = 0)
entity.addComponent(new SpeedEffectComponent());
entity.create();
effect.getComponent(SpeedEffectComponent).applyEffect(5, 0.5);(providing time = 5 and speedMultiplier = 0.5) will halve (slow down) the entity's speed for 5 update cycles.
Tests were created to ensure the following:
- The constructor throws an error when a negative
timeorspeedMultipliervalue is given - The constructor allows a value of 0 for
speedMultiplier - addSpeedModifier is called on creation of the component
- The component is disabled when remaining time is 0
- Speed should not revert until exactly after the timer expires
- The modifier gets removed on early dispose
- Pause, slow, and speed up values can all be added properly
Tests were created to ensure the following:
- Defaults to no modifiers
- Can apply a single or stacked modifiers
- A pause value (0) should dominate the other modifiers
- Reverts to default after removing modifiers
- Removing a modifier only removes a specific key
- Adding the same key twice overwrites the current value instead of stacking multiple with the same key