Refactor FollowEntityAI

This commit is contained in:
2021-11-28 16:04:18 +01:00
parent f576d8fc1b
commit 225dd84b21

View File

@@ -9,7 +9,6 @@ import com.bartlomiejpluta.base.util.path.MovementPath;
import com.bartlomiejpluta.base.util.path.PathExecutor;
import com.bartlomiejpluta.base.util.pathfinder.PathFinder;
import lombok.NonNull;
import lombok.Setter;
public abstract class FollowEntityAI<N extends NPC, T extends Entity> implements AI {
@@ -18,12 +17,6 @@ public abstract class FollowEntityAI<N extends NPC, T extends Entity> implements
private final N npc;
private final T target;
@Setter
private AI idleAI;
@Setter
private int range = 20;
private MovementPath<N> path = null;
protected FollowEntityAI(@NonNull PathFinder finder, @NonNull N npc, @NonNull T target) {
@@ -54,9 +47,9 @@ public abstract class FollowEntityAI<N extends NPC, T extends Entity> implements
if (distance == 1) {
npc.setFaceDirection(npc.getDirectionTowards(target));
interact(npc, target);
} else if (distance < range) {
follow(npc, target);
interact(npc, target, layer, dt);
} else if (sees(npc, target, layer, distance)) {
follow(npc, target, layer, dt);
if (path == null) {
path = finder.findPath(layer, npc, target.getCoordinates());
@@ -65,18 +58,16 @@ public abstract class FollowEntityAI<N extends NPC, T extends Entity> implements
executor.execute(layer, dt);
} else {
idle(npc, target);
if (idleAI != null) {
idleAI.nextActivity(layer, dt);
}
idle(npc, target, layer, dt);
}
}
}
protected abstract void interact(N npc, T target);
protected abstract boolean sees(N npc, T target, ObjectLayer layer, int distance);
protected abstract void follow(N npc, T target);
protected abstract void interact(N npc, T target, ObjectLayer layer, float dt);
protected abstract void idle(N npc, T target);
protected abstract void follow(N npc, T target, ObjectLayer layer, float dt);
protected abstract void idle(N npc, T target, ObjectLayer layer, float dt);
}