package org.leumasjaffe.charsheet.model; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.function.Function; import org.leumasjaffe.charsheet.model.observable.IntValue; import org.leumasjaffe.observer.Observable; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.FieldDefaults; @Data @AllArgsConstructor @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true) public class Ability { public static final Map> fields; static { Map> tmp = new HashMap<>(); tmp.put("STR", Ability::getStr); tmp.put("DEX", Ability::getDex); tmp.put("CON", Ability::getCon); tmp.put("INT", Ability::getInt); tmp.put("WIS", Ability::getWis); tmp.put("CHA", Ability::getCha); fields = Collections.unmodifiableMap(tmp); } @Data @AllArgsConstructor @EqualsAndHashCode(callSuper=false) @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true) public static class Scores extends Observable.Instance { IntValue base, temp; @JsonCreator public Scores() { this.base = new IntValue(-1); this.temp = new IntValue(-1); } public int baseScore() { return base.value(); } public int score() { return temp.value() == -1 ? base.value() : temp.value(); } public int baseModifier() { return Ability.modifier(baseScore()); } public int modifier() { return Ability.modifier(score()); } } Scores str, dex, con, wis, cha; @JsonProperty(value="int") Scores Int; public Ability() { this.str = new Scores(); this.dex = new Scores(); this.con = new Scores(); this.Int = new Scores(); this.wis = new Scores(); this.cha = new Scores(); } public static int modifier(int val) { return val == -1 ? 0 : val / 2 - 5; } }