1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.kaiserpfalzedv.rpg.torg.model.core;
19
20 import com.fasterxml.jackson.annotation.JsonInclude;
21 import de.kaiserpfalzedv.rpg.torg.model.MapperEnum;
22 import lombok.*;
23 import lombok.extern.jackson.Jacksonized;
24 import lombok.extern.slf4j.Slf4j;
25 import org.eclipse.microprofile.openapi.annotations.media.Schema;
26
27 import java.util.Optional;
28 import java.util.Set;
29
30
31
32
33
34
35
36 @Jacksonized
37 @Builder(toBuilder = true)
38 @AllArgsConstructor
39 @Getter
40 @ToString
41 @EqualsAndHashCode
42 @JsonInclude(JsonInclude.Include.NON_ABSENT)
43 @Schema(description = "Type of damage and the value")
44 @Slf4j
45 public class Damage {
46
47 @AllArgsConstructor
48 @Getter
49 public enum DamageType implements MapperEnum<DamageType> {
50 fixed("flat", "fixed"),
51 cha("charismaPlus", "cha"),
52 dex("dexterityPlus", "dex"),
53 min("mindPlus", "min"),
54 spi("spiritPlus", "spi"),
55 str("strengthPlus", "str");
56
57 private final String foundry;
58 private final String roll20;
59
60 public static Optional<DamageType> mapFoundry(final String name) {
61 return fixed.mapFromFoundry(name);
62 }
63
64 @Override
65 public Optional<DamageType> mapFromFoundry(final String name) {
66 log.trace("Mapping damage type. name='{}'", name);
67
68 if (name == null || "null".equals(name)) {
69 return Optional.empty();
70 }
71
72 return all().stream()
73 .filter(e -> e.foundry.equals(name)).distinct()
74 .findFirst();
75 }
76
77 @Override
78 public Optional<DamageType> mapFromRoll20(String name) {
79 return all().stream()
80 .filter(e -> e.roll20.equals(name)).distinct()
81 .findFirst();
82 }
83
84 public Set<DamageType> all() {
85 return Set.of(fixed, cha, dex, min, spi, str);
86 }
87 }
88
89 @Schema(description = "Type of the damage. Either 'fixed' or the base attribute.", defaultValue = "fixed")
90 @Builder.Default
91 private final DamageType type = DamageType.fixed;
92
93 @Schema(description = "The adds for damage calculated. Will be ignored when type is 'fixed'.")
94 private final Integer adds;
95
96 @Schema(description = "The total value of damage or the adds for the damage (to be added to the attribute specified in type.")
97 private final Integer value;
98 }