| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package org.leumasjaffe.charsheet.model.magic.dimension;
- import static org.leumasjaffe.charsheet.config.Constants.K_DURATION;
- import static org.leumasjaffe.charsheet.config.Constants.DurationMeasurement.*;
- import org.leumasjaffe.charsheet.config.Config;
- import org.leumasjaffe.charsheet.util.StringHelper;
- import com.fasterxml.jackson.annotation.JsonCreator;
- import com.fasterxml.jackson.annotation.JsonProperty;
- import lombok.AccessLevel;
- import lombok.AllArgsConstructor;
- import lombok.NonNull;
- import lombok.RequiredArgsConstructor;
- import lombok.experimental.FieldDefaults;
- public interface Duration {
- @AllArgsConstructor
- public static enum Measure {
- round(1), minute(10), hour(600), day(14400);
- int rounds;
- }
-
- @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
- public static final class __Pair {
- int[] value;
- Measure measure;
-
- private __Pair(Measure def, int... times) {
- value = new int[times.length];
- final int div;
- if (Config.get(K_DURATION, NATURAL) == ROUNDS) {
- div = def.rounds;
- measure = Measure.round;
- } else {
- div = 1;
- measure = def;
- }
- for (int i = 0; i < times.length; ++i) {
- value[i] = times[i] / div;
- }
- }
- }
- public default String getResolved(int level) { return toString(); }
- @JsonCreator
- public static Duration create(String name) {
- return new Basic(name);
- }
-
- @JsonCreator
- public static Duration create(@JsonProperty("unit") Measure meas,
- @JsonProperty("duration") int min,
- @JsonProperty("per") int per,
- @JsonProperty("step") int step) {
- return new WithLevelGrowth(meas, min, per, step);
- }
-
- @RequiredArgsConstructor
- @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
- public static class Basic implements Duration {
- @NonNull String name;
-
- public String toString() {
- return name;
- }
- }
-
- @RequiredArgsConstructor
- @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
- public static class WithLevelGrowth implements Duration {
- @NonNull Measure measure;
- int length, per, step;
-
- @Override
- public String getResolved(int level) {
- final __Pair p = new __Pair(measure, length + (per * (level / step)));
- return StringHelper.format("{} {}{0>1?s:}", p.value[0], p.measure);
- }
-
- public String toString() {
- final __Pair p = new __Pair(measure, length, per);
- final StringBuilder str = new StringBuilder(StringHelper.format("{} {3}{0>1?s:} + {} {}{1>1?s:}/{?level:{} levels}",
- p.value[0], p.value[1], p.measure, step));
- return str.toString();
- }
- }
- }
|