summaryrefslogtreecommitdiff
path: root/src/main/java/space/m0e/quga/oop/lab56maven/handlers/DwarfHandler.java
diff options
context:
space:
mode:
authorAndriy Cherniy <qugalet@m0e.space>2024-06-17 05:10:58 +0300
committerAndriy Cherniy <qugalet@m0e.space>2024-06-17 05:10:58 +0300
commit943bc45a13256d57c82ed58f22aa2cb802292744 (patch)
treeada8c6d5eefa3e4034504bfcc5eb03ab84597ebe /src/main/java/space/m0e/quga/oop/lab56maven/handlers/DwarfHandler.java
parent3401d742ca53dce6bb1464cc12f94d107cfc285d (diff)
downloadoop-kursach-master.tar.gz
oop-kursach-master.zip
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEADmaster
Diffstat (limited to 'src/main/java/space/m0e/quga/oop/lab56maven/handlers/DwarfHandler.java')
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/handlers/DwarfHandler.java42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/handlers/DwarfHandler.java b/src/main/java/space/m0e/quga/oop/lab56maven/handlers/DwarfHandler.java
index 7ba5466..1e6b0c7 100644
--- a/src/main/java/space/m0e/quga/oop/lab56maven/handlers/DwarfHandler.java
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/handlers/DwarfHandler.java
@@ -10,9 +10,10 @@ 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.micro.Dwarf;
+import space.m0e.quga.oop.lab56maven.entities.micro.Nobel;
-import java.util.Objects;
import java.util.Random;
+import java.util.concurrent.atomic.AtomicBoolean;
public class DwarfHandler implements EventHandler<ActionEvent> {
public Dwarf getDwarf() {
@@ -25,10 +26,6 @@ public class DwarfHandler implements EventHandler<ActionEvent> {
private int timer = 0;
- public Decision getDecision() {
- return decision;
- }
-
public void setDecision(Decision decision) {
this.decision = decision;
}
@@ -78,30 +75,47 @@ public class DwarfHandler implements EventHandler<ActionEvent> {
}
} else {
if (decision == null) {
- String decisionName = availableDecisions[new Random().nextInt(availableDecisions.length)];
- while (Objects.equals(lastDecision, decisionName)) {
- decisionName = availableDecisions[new Random().nextInt(availableDecisions.length)];
- }
- lastDecision = decisionName;
+ Fortress fortress = dwarf.getFortress();
+ String decisionName = fortress.getAvailableDecisions().get(new Random().nextInt(fortress.getAvailableDecisions().size()));
+// while (Objects.equals(lastDecision, decisionName)) {
+// decisionName = availableDecisions[new Random().nextInt(availableDecisions.length)];
+// }
+// lastDecision = decisionName;
switch (decisionName) {
case "GoToWorkstation" -> {
if (dwarf.getAge() > 12 && dwarf.getAge() < 70 && dwarf.getAbility() != Ability.COMMUNICATION ) {
- decision = new GoToWorkstationDecision(new Random().nextInt(timer + 200, timer + 500), dwarf);
+ decision = new GoToWorkstationDecision(new Random().nextInt(timer + 5, timer + 50), dwarf);
}
}
case "GoToDwarvesContainer" -> {
if (dwarf.getFortress().contains(dwarf))
break;
- decision = new GoToDwarvesContainerDecision(new Random().nextInt(timer + 200, timer + 500), dwarf);
+ decision = new GoToDwarvesContainerDecision(new Random().nextInt(timer + 5, timer + 50), dwarf);
}
case "GoToThroneRoom" -> {
if (dwarf.getAge() > 35 && dwarf.getAge() < 70) {
- decision = new GoToThroneRoomDecision(new Random().nextInt(timer + 200, timer + 500), dwarf);
+// if (!dwarf.getFortress().getDwarves().stream().anyMatch(dwarf1 -> {
+// DwarfHandler dwarfHandler = (DwarfHandler) dwarf1.getHandler();
+// return dwarfHandler.decision.getClass().getSimpleName().equals("GoToThroneRoomDecision");
+// }))
+ AtomicBoolean isThroneEmpty = new AtomicBoolean(false);
+ dwarf.getFortress().getDwarves().stream().forEach(dwarf1 -> {
+ if (dwarf1 instanceof Nobel) {
+ return;
+ }
+
+ DwarfHandler dwarfHandler = (DwarfHandler) dwarf1.getHandler();
+ if (dwarfHandler.decision != null && dwarfHandler.decision.getClass().getSimpleName().equals("GoToThroneRoomDecision")) {
+ isThroneEmpty.set(true);
+ }
+ });
+ if (!isThroneEmpty.get()) {
+ decision = new GoToThroneRoomDecision(new Random().nextInt(timer + 5, timer + 50), dwarf);
+ }
}
}
case "GoTrading" -> {
if (dwarf.getAbility() == Ability.COMMUNICATION) {
- Fortress fortress = dwarf.getFortress();
Item itemToTrade;
int amountToTrade;
if (fortress.getWoodCount() > 0 && fortress.getWoodCount() >= fortress.getStoneCount()) {