|
|
@@ -0,0 +1,39 @@
|
|
|
+package org.leumasjaffe.charsheet.model.magic;
|
|
|
+
|
|
|
+import org.leumasjaffe.charsheet.util.StringHelper;
|
|
|
+import org.leumasjaffe.format.Named;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.annotation.JsonCreator;
|
|
|
+
|
|
|
+import lombok.AccessLevel;
|
|
|
+import lombok.NonNull;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.experimental.FieldDefaults;
|
|
|
+import lombok.experimental.NonFinal;
|
|
|
+
|
|
|
+@RequiredArgsConstructor
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
+public class Duration {
|
|
|
+ @NonNull String format;
|
|
|
+ String resolved;
|
|
|
+ int count, perlevel;
|
|
|
+ @NonFinal int step = 1;
|
|
|
+
|
|
|
+ @JsonCreator
|
|
|
+ public Duration(final String descr) {
|
|
|
+ this.format = descr;
|
|
|
+ this.resolved = null;
|
|
|
+ this.count = this.perlevel = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getResolved(int level) {
|
|
|
+ final int result = count + perlevel * (level / step);
|
|
|
+ return resolved == null ? toString() :
|
|
|
+ StringHelper.format(resolved, new Named("atlevel", result));
|
|
|
+ }
|
|
|
+
|
|
|
+ public String toString() {
|
|
|
+ return StringHelper.format(format, new Named("count", count),
|
|
|
+ new Named("perlevel", perlevel), new Named("step", step));
|
|
|
+ }
|
|
|
+}
|