|
@@ -6,6 +6,8 @@ import in.ocsf.frei.geld.core.model.LiveCycle;
|
|
|
import in.ocsf.frei.geld.core.model.SimpleEvent;
|
|
|
import org.apache.commons.lang3.Range;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
|
public class EnergyAspect implements DwarfAspect {
|
|
@@ -13,8 +15,11 @@ public 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;
|
|
|
|
|
|
+ private Map<String, Double> mood;
|
|
|
+
|
|
|
public EnergyAspect() {
|
|
|
}
|
|
|
|
|
@@ -22,6 +27,7 @@ public class EnergyAspect implements DwarfAspect {
|
|
|
EnergyAspect ret = new EnergyAspect();
|
|
|
ret.energy = LiveCycle.TOTAL_ENERGY;
|
|
|
ret.loss = 0.0;
|
|
|
+ ret.mood = new HashMap<>();
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -33,6 +39,22 @@ public class EnergyAspect implements DwarfAspect {
|
|
|
this.energy = energy;
|
|
|
}
|
|
|
|
|
|
+ public Double getLoss() {
|
|
|
+ return loss;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setLoss(Double loss) {
|
|
|
+ this.loss = loss;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Double> getMood() {
|
|
|
+ return mood;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMood(Map<String, Double> mood) {
|
|
|
+ this.mood = mood;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public BiConsumer<DwarfContext, Dwarf> perform() {
|
|
|
return (context, dwarf) -> {
|
|
@@ -50,7 +72,27 @@ public class EnergyAspect implements DwarfAspect {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ public void addMood(String type, Double value) {
|
|
|
+ this.mood.put(type, Math.min(1.0, Math.max(value, -1.0)));
|
|
|
+ }
|
|
|
+
|
|
|
public void addFood() {
|
|
|
- this.energy += 2500;
|
|
|
+ this.energy = Math.min(LiveCycle.TOTAL_ENERGY, this.energy + 2500);
|
|
|
+ this.addMood(DwarfTask.EAT.name(), DwarfTask.EAT.getValue().getImaginary());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void doRest(Integer hours) {
|
|
|
+ Double hourPart = DwarfTask.REST.getValue().getImaginary() / LiveCycle.HOURS;
|
|
|
+ addMood(DwarfTask.REST.name(), Math.min(DwarfTask.REST.getValue().getImaginary(), hourPart * hours));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void doSuccess(Integer hours) {
|
|
|
+ Double prev = this.mood.getOrDefault("OK", 0.0);
|
|
|
+ addMood("OK", prev + hours.doubleValue() / 10.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void doError(Integer hours) {
|
|
|
+ Double prev = this.mood.getOrDefault("OK", 0.0);
|
|
|
+ addMood("OK", prev - hours.doubleValue() / 10.0);
|
|
|
}
|
|
|
}
|