Root - UQdeco2800/2022-studio-2 GitHub Wiki
Root Code
Root length
The root skill greatly reduces enemy movement speed for a period of 5 seconds. After 5 seconds, the effect wears off and the enemy returns to normal.
Applying root effect to enemy
If the root skill is currently equipped by the player, an event listener will trigger when the player attacks an enemy (the listener calls hitRoot() seen below). If the player has activated the skill and the event has been triggered, then the rooted condition will be applied to the attacked enemy. If the player has not activated the skill, nothing will happen on event trigger.
public void hitRoot(Entity target) {
if (!this.rootApplied) {
return;
}
this.enemy = target;
changeSpeed(target, ROOT_LENGTH, true);
}
Changing enemy movement speed
The below function is called when either applying or removing the root effect from an enemy. Slowing movement is achieved by assigning a new chase task to the enemy with a higher priority and a lower speed value. Original movement is restored by disposing and removing the new chase task.
private void changeSpeed(Entity target, long slowLength, boolean slow) {
if (slow) {
target.getComponent(AITaskComponent.class).addTask
(new ChaseTask(playerEntity, 11, 5f, 6f, 1f));
this.rooted = true;
this.rootApplied = false;
} else {
target.getComponent(AITaskComponent.class).dispose();
target.getComponent(AITaskComponent.class).getPriorityTasks().remove
(target.getComponent(AITaskComponent.class).getPriorityTasks().size() - 1);
}
this.slowEnd = System.currentTimeMillis() + slowLength;
}