blob: 4eb83c2735746c55c3e6d406a1592e460b5b6ade (
plain) (
blame)
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
|
package space.m0e.quga.oop.lab56maven.decisions;
import javafx.application.Platform;
import space.m0e.quga.oop.lab56maven.entities.common.Coordinates;
import space.m0e.quga.oop.lab56maven.entities.common.Item;
import space.m0e.quga.oop.lab56maven.entities.macro.Fortress;
import space.m0e.quga.oop.lab56maven.entities.macro.Workstation;
import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf;
public class GoToDwarvesContainerDecision extends Decision {
private Dwarf dwarf;
public GoToDwarvesContainerDecision(int executeWhen, Dwarf dwarf) {
super(executeWhen);
this.dwarf = dwarf;
}
@Override
public void cycle() {
Fortress fortress = dwarf.getFortress();
Coordinates nearCoordinates = new Coordinates(fortress.getGroup().getBoundsInParent().getCenterX(), fortress.getGroup().getBoundsInParent().getCenterY());
dwarf.move(nearCoordinates);
if (nearCoordinates.isThere(dwarf)) {
dwarf.getItems().entrySet().forEach(item -> {
switch (item.getKey()) {
case WOOD -> {
fortress.setWoodCount(fortress.getWoodCount() + item.getValue());
item.setValue(0);
}
case STONE -> {
fortress.setStoneCount(fortress.getStoneCount() + item.getValue());
item.setValue(0);
}
}
});
Platform.runLater(dwarf::updateItemLabel);
fortress.addToContainer(dwarf);
setComplete(true);
}
}
}
|