-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVet.java
More file actions
83 lines (67 loc) · 3.19 KB
/
Vet.java
File metadata and controls
83 lines (67 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import processing.core.PImage;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
public class Vet extends ActivityEntity implements Move, PathingStrategy {
public Vet(String id, Point position, double animationPeriod, double actionPeriod, List<PImage> images) {
super(id, position, animationPeriod, actionPeriod, images);
}
@Override
public boolean moveTo(WorldModel world, Entity target, EventScheduler scheduler) {
if (this.getPosition().adjacent(target.getPosition())) {
world.removeEntity(scheduler, target);
return true;
} else {
Point nextPos = this.nextPosition(world, target.getPosition());
if (!this.getPosition().equals(nextPos)) {
world.moveEntity(scheduler, this, nextPos);
}
return false;
}
}
@Override
public Point nextPosition(WorldModel world, Point destPos) {
Predicate<Point> canPassThrough = p -> world.withinBounds(p)
&& (world.getOccupant(p).isEmpty() || world.getOccupant(getPosition()).get().getClass().equals(House.class));
BiPredicate<Point, Point> withinReach = Point::adjacent;
PathingStrategy strategy = new AStarPathingStrategy();
List<Point> path = strategy.computePath(
getPosition(),
destPos,
canPassThrough,
withinReach,
PathingStrategy.CARDINAL_NEIGHBORS
);
if (path == null || path.isEmpty()) {
return getPosition();
}
return path.getFirst();
}
@Override
public void executeActivity(WorldModel world, ImageStore imageStore, EventScheduler scheduler) {
Optional<Entity> vetTarget = world.findNearest(getPosition(), new ArrayList<>(List.of(Steak.class, Bacon.class)));
if (vetTarget.isPresent()) {
Point tgtPos = vetTarget.get().getPosition();
if (this.moveTo(world, vetTarget.get(), scheduler)) {
if (vetTarget.get() instanceof Steak) {
BabyCow babyCow = Factory.createBabyCow(WorldLoader.BABY_COW_KEY + "_" + vetTarget.get().getId(), tgtPos, imageStore.getImageList(WorldLoader.BABY_COW_KEY));
world.tryAddEntity(babyCow);
babyCow.scheduleActions(scheduler, world, imageStore);
} else {
BabyPig babyPig = Factory.createBabyPig(WorldLoader.BABY_PIG_KEY + "_" + vetTarget.get().getId(), tgtPos, imageStore.getImageList(WorldLoader.BABY_PIG_KEY));
world.tryAddEntity(babyPig);
babyPig.scheduleActions(scheduler, world, imageStore);
}
}
}
scheduler.scheduleEvent(this, Factory.createActivityAction(this, world, imageStore), getActionPeriod());
}
@Override
public List<Point> computePath(Point start, Point end, Predicate<Point> canPassThrough, BiPredicate<Point, Point> withinReach, Function<Point, Stream<Point>> potentialNeighbors) {
return null;
}
}