View Javadoc
1   /*
2    * Copyright (c) 2023 Kaiserpfalz EDV-Service, Roland T. Lichti.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
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   * Damage -- The damage of an {@link Attack}.
32   *
33   * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
34   * @since 0.3.0  2021-05-23
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  }