|
@@ -1,19 +1,12 @@
|
|
|
package in.ocsf.frei.geld.core.model;/* kpmy 15.11.2017 */
|
|
|
|
|
|
-import org.apache.commons.lang3.Range;
|
|
|
-import org.apache.commons.lang3.tuple.MutablePair;
|
|
|
+import in.ocsf.frei.geld.core.model.aspects.*;
|
|
|
import org.bson.types.ObjectId;
|
|
|
import org.springframework.data.annotation.Id;
|
|
|
import org.springframework.data.annotation.Version;
|
|
|
import org.springframework.data.mongodb.core.mapping.DBRef;
|
|
|
import org.springframework.data.mongodb.core.mapping.Document;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.function.BiConsumer;
|
|
|
-import java.util.function.Consumer;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
@Document(collection = "dwarf")
|
|
|
public class Dwarf {
|
|
|
|
|
@@ -43,14 +36,48 @@ public class Dwarf {
|
|
|
|
|
|
private VisionAspect vision;
|
|
|
|
|
|
+ private TaskAspect tasks;
|
|
|
+
|
|
|
+ private ManagerAspect manager;
|
|
|
+
|
|
|
+ private DecisionAspect decision;
|
|
|
+
|
|
|
+ private RunnerAspect runner;
|
|
|
+
|
|
|
@DBRef
|
|
|
private World world;
|
|
|
|
|
|
public Dwarf() {
|
|
|
- energy = new EnergyAspect();
|
|
|
- activity = new ActivityAspect();
|
|
|
- feelings = new FeelingsAspect();
|
|
|
- vision = new VisionAspect();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Dwarf getInstance(World world) {
|
|
|
+ Dwarf ret = new Dwarf();
|
|
|
+ ret.world = world;
|
|
|
+ ret.energy = EnergyAspect.getInstance();
|
|
|
+ ret.activity = ActivityAspect.getInstance();
|
|
|
+ ret.feelings = FeelingsAspect.getInstance();
|
|
|
+ ret.vision = VisionAspect.getInstance();
|
|
|
+ ret.tasks = TaskAspect.getInstance();
|
|
|
+ ret.manager = ManagerAspect.getInstance();
|
|
|
+ ret.decision = DecisionAspect.getInstance();
|
|
|
+ ret.runner = RunnerAspect.getInstance();
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ManagerAspect getManager() {
|
|
|
+ return manager;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setManager(ManagerAspect manager) {
|
|
|
+ this.manager = manager;
|
|
|
+ }
|
|
|
+
|
|
|
+ public TaskAspect getTasks() {
|
|
|
+ return tasks;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTasks(TaskAspect tasks) {
|
|
|
+ this.tasks = tasks;
|
|
|
}
|
|
|
|
|
|
public VisionAspect getVision() {
|
|
@@ -101,8 +128,8 @@ public class Dwarf {
|
|
|
this.death = death;
|
|
|
}
|
|
|
|
|
|
- public ObjectId getId() {
|
|
|
- return id;
|
|
|
+ public String getId() {
|
|
|
+ return id.toHexString();
|
|
|
}
|
|
|
|
|
|
public void setId(ObjectId id) {
|
|
@@ -149,136 +176,19 @@ public class Dwarf {
|
|
|
this.hour = hour;
|
|
|
}
|
|
|
|
|
|
- public static class ActivityAspect implements DwarfAspect {
|
|
|
-
|
|
|
- private boolean active;
|
|
|
-
|
|
|
- public ActivityAspect() {
|
|
|
- this.active = true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiConsumer<DwarfContext, Dwarf> perform() {
|
|
|
- return (ctx, dwarf) -> {
|
|
|
- if (ctx.getConsequences().contains(SimpleConsequence.SLEEP)) {
|
|
|
- active = false;
|
|
|
- ctx.getConsequences().remove(SimpleConsequence.SLEEP);
|
|
|
- } else if (ctx.getConsequences().contains(SimpleConsequence.AWAKE)) {
|
|
|
- active = true;
|
|
|
- ctx.getConsequences().remove(SimpleConsequence.AWAKE);
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isActive() {
|
|
|
- return active;
|
|
|
- }
|
|
|
-
|
|
|
- public void setActive(boolean active) {
|
|
|
- this.active = active;
|
|
|
- }
|
|
|
+ public DecisionAspect getDecision() {
|
|
|
+ return decision;
|
|
|
}
|
|
|
|
|
|
- public static class EnergyAspect implements DwarfAspect {
|
|
|
-
|
|
|
- private static final Range<Double> sleepRange = Range.between(LiveCycle.DAYLY_ENERGY * 2 / 3, LiveCycle.DAYLY_ENERGY);
|
|
|
-
|
|
|
- private Double energy;
|
|
|
- private Double loss;
|
|
|
-
|
|
|
- public EnergyAspect() {
|
|
|
- this.energy = LiveCycle.TOTAL_ENERGY;
|
|
|
- this.loss = 0.0;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getEnergy() {
|
|
|
- return energy;
|
|
|
- }
|
|
|
-
|
|
|
- public void setEnergy(Double energy) {
|
|
|
- this.energy = energy;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiConsumer<DwarfContext, Dwarf> perform() {
|
|
|
- return (context, dwarf) -> {
|
|
|
- double deltaLoss = (LiveCycle.DAYLY_ENERGY / LiveCycle.HOURS);
|
|
|
- this.energy = this.energy - deltaLoss;
|
|
|
- this.loss = this.loss + deltaLoss;
|
|
|
- if (this.energy <= 0) {
|
|
|
- context.addSimpleConsequence(this, SimpleConsequence.DEATH);
|
|
|
- } else if (sleepRange.contains(this.loss)) {
|
|
|
- context.addSimpleConsequence(this, SimpleConsequence.SLEEP);
|
|
|
- } else if (sleepRange.isBefore(this.loss)) {
|
|
|
- this.loss = deltaLoss;
|
|
|
- context.addSimpleConsequence(this, SimpleConsequence.AWAKE);
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
+ public void setDecision(DecisionAspect decision) {
|
|
|
+ this.decision = decision;
|
|
|
}
|
|
|
|
|
|
- public static class FeelingsAspect implements DwarfAspect {
|
|
|
-
|
|
|
- private double hunger;
|
|
|
-
|
|
|
- public FeelingsAspect() {
|
|
|
- this.hunger = 0.0;
|
|
|
- }
|
|
|
-
|
|
|
- public double getHunger() {
|
|
|
- return hunger;
|
|
|
- }
|
|
|
-
|
|
|
- public void setHunger(double hunger) {
|
|
|
- this.hunger = hunger;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiConsumer<DwarfContext, Dwarf> perform() {
|
|
|
- return (ctx, d) -> {
|
|
|
- this.hunger = (Math.min(LiveCycle.DAYLY_ENERGY, LiveCycle.TOTAL_ENERGY - d.getEnergy().getEnergy()) / LiveCycle.DAYLY_ENERGY) * 100;
|
|
|
- };
|
|
|
- }
|
|
|
+ public RunnerAspect getRunner() {
|
|
|
+ return runner;
|
|
|
}
|
|
|
|
|
|
- public static class VisionAspect implements DwarfDefaultAspect {
|
|
|
-
|
|
|
- private Map<String, MutablePair<WorldObjectType, Object>> frame;
|
|
|
-
|
|
|
- @DBRef
|
|
|
- private World.DwarfPoint self;
|
|
|
-
|
|
|
- public VisionAspect() {
|
|
|
- frame = new HashMap<>();
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, MutablePair<WorldObjectType, Object>> getFrame() {
|
|
|
- return frame;
|
|
|
- }
|
|
|
-
|
|
|
- public void setFrame(Map<String, MutablePair<WorldObjectType, Object>> frame) {
|
|
|
- this.frame = frame;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Consumer<Dwarf> skip() {
|
|
|
- return (d) -> frame = new HashMap<>();
|
|
|
- }
|
|
|
-
|
|
|
- public World.DwarfPoint getSelf() {
|
|
|
- return self;
|
|
|
- }
|
|
|
-
|
|
|
- public void setSelf(World.DwarfPoint self) {
|
|
|
- this.self = self;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiConsumer<DwarfContext, Dwarf> perform() {
|
|
|
- return (ctx, dwarf) -> {
|
|
|
- self = ctx.getDwarfPosition(dwarf);
|
|
|
- frame = ctx.getAllAround(self).stream().filter(s -> !s.getPoint().equals(self.getPoint())).collect(Collectors.toMap(s -> s.getPoint().toString(), World.Something::getRef, (same, key) -> same));
|
|
|
- };
|
|
|
- }
|
|
|
+ public void setRunner(RunnerAspect runner) {
|
|
|
+ this.runner = runner;
|
|
|
}
|
|
|
}
|