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.JsonIgnore;
21  import com.fasterxml.jackson.annotation.JsonValue;
22  import de.kaiserpfalzedv.rpg.core.Books.Publication;
23  import de.kaiserpfalzedv.rpg.torg.model.MapperEnum;
24  import lombok.Getter;
25  import lombok.ToString;
26  import lombok.extern.slf4j.Slf4j;
27  
28  import jakarta.validation.constraints.NotNull;
29  import java.util.HashMap;
30  import java.util.Optional;
31  import java.util.Set;
32  
33  import static de.kaiserpfalzedv.rpg.torg.data.Publications.CORE_RULES;
34  
35  /**
36   * Realm -- The realms of the possibility wars with their axioms.
37   *
38   * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
39   * @since 1.2.0  2021-03-26
40   */
41  @Getter
42  @ToString
43  @Slf4j
44  public enum Cosm implements MapperEnum<Cosm> {
45      AYSLE("Aysle", "Aysle", 24, 16, 18, 14, Type.MAIN, CORE_RULES),
46      CORE_EARTH("Core Earth", "Core Earth", 9, 23, 10, 23, Type.MAIN, CORE_RULES),
47      CYBERPAPACY("Cyberpapacy", "Cyberpapacy", 14, 18, 16, 26, Type.MAIN, CORE_RULES),
48      LIVING_LAND("Living Land", "Living Land", 1, 7, 24, 6, Type.MAIN, CORE_RULES),
49      NILE_EMPIRE("Nile Empire", "Nile Empire", 14, 20, 18, 20, Type.MAIN, CORE_RULES),
50      ORRORSH("Orrorsh", "Orrorsh", 16, 18, 16, 18, Type.MAIN, CORE_RULES),
51      PAN_PACIFICA("Pan-Pacifica", "Pan-Pacifica", 4, 24, 8, 24, Type.MAIN, CORE_RULES),
52      THARKOLD("Tharkold", "Tharkold", 12, 25, 4, 25, Type.MAIN, CORE_RULES),
53  
54      AKASHA("akasha", "Akasha", 1, 26, 1, 28, Type.MINOR, null),
55      UKHAAN("ukhaan", "Ukhaan", 8, 27, 5, 27, Type.MINOR, null),
56  
57      AYSLE_THARKOLD("aysleTharkold", "Aysle/Tharkold", 24, 25, 18, 25, Type.UNKNOWN, null),
58      ELFAME("elfame", "Elfame", 24, 11, 18, 14, Type.UNKNOWN, null),
59      FAIRY_TALE_AYSLE("fairyTaleAysle", "Fairy Tale Aysle", 24, 16, 18, 14, Type.UNKNOWN, null),
60      MECHOPOTAMIA("mechopotamia", "Mechopotamia", 9, 9, 12, 8, Type.UNKNOWN, null),
61      THE_DEAD_WORLD("theDeadWorld", "The Dead World", 3, 7, 4, 8, Type.UNKNOWN, null),
62      TOMBSPACE("tombSpace", "Tomb Space", 0, 0, 0, 0, Type.UNKNOWN, null),
63      WALDECK("waldeck", "Waldeck", 14, 11, 2, 12, Type.UNKNOWN, null);
64  
65      public enum Type {
66          MAIN,
67          MINOR,
68          UNKNOWN
69      }
70  
71  
72      private final String foundry;
73  
74      @JsonValue
75      private final String roll20;
76      @ToString.Exclude
77      private final Publication publication;
78      @ToString.Exclude
79      private final Type type;
80      @ToString.Exclude
81      private final HashMap<Axiom.AxiomName, Axiom> axioms = new HashMap<>();
82      @ToString.Exclude
83      private final String[] laws;
84  
85  
86      Cosm(
87              @NotNull final String foundry,
88              @NotNull final String roll20,
89              @NotNull final int magic,
90              @NotNull final int social,
91              @NotNull final int spirit,
92              @NotNull final int tech,
93              @NotNull final Type cosmType,
94              @NotNull final Publication publication,
95              String... laws
96      ) {
97          axioms.put(Axiom.AxiomName.Magic, Axiom.builder().name(Axiom.AxiomName.Magic).value(tech).build());
98          axioms.put(Axiom.AxiomName.Social, Axiom.builder().name(Axiom.AxiomName.Social).value(social).build());
99          axioms.put(Axiom.AxiomName.Spirit, Axiom.builder().name(Axiom.AxiomName.Spirit).value(spirit).build());
100         axioms.put(Axiom.AxiomName.Tech, Axiom.builder().name(Axiom.AxiomName.Tech).value(tech).build());
101 
102         this.foundry = foundry;
103         this.roll20 = roll20;
104         this.publication = publication;
105         this.type = cosmType;
106         this.laws = laws;
107     }
108 
109     @JsonIgnore
110     public int[] axioms() {
111         return new int[]{
112                 getMagic(),
113                 getSocial(),
114                 getSpirit(),
115                 getTech()
116         };
117     }
118 
119     @JsonIgnore
120     public int getMagic() {
121         return axioms.get(Axiom.AxiomName.Magic).getValue();
122     }
123 
124     @JsonIgnore
125     public int getSocial() {
126         return axioms.get(Axiom.AxiomName.Social).getValue();
127     }
128 
129     @JsonIgnore
130     public int getSpirit() {
131         return axioms.get(Axiom.AxiomName.Spirit).getValue();
132     }
133 
134     @JsonIgnore
135     public int getTech() {
136         return axioms.get(Axiom.AxiomName.Tech).getValue();
137     }
138 
139 
140     public static Optional<Cosm> mapFoundry(final String name) {
141         return Cosm.CORE_EARTH.mapFromFoundry(name);
142     }
143 
144     @Override
145     public Optional<Cosm> mapFromFoundry(@NotNull final String name) {
146         log.trace("Mapping cosm. name='{}'", name);
147 
148         if ("(None)".equals(name) || "Universal".equals(name)) {
149             return Optional.empty();
150         }
151 
152         return allCosms().stream()
153                         .filter(e -> e.foundry.equals(name)).distinct()
154                         .findFirst();
155     }
156 
157     @Override
158     public Optional<Cosm> mapFromRoll20(@NotNull final String name) {
159         return allCosms().stream()
160                         .filter(e -> e.roll20.equals(name)).distinct()
161                         .findFirst();
162     }
163 
164 
165     public Set<Cosm> allCosms() {
166         return Set.of(
167                 AYSLE,
168                 CORE_EARTH,
169                 CYBERPAPACY,
170                 LIVING_LAND,
171                 NILE_EMPIRE,
172                 ORRORSH,
173                 PAN_PACIFICA,
174                 THARKOLD,
175 
176                 AKASHA,
177                 UKHAAN,
178 
179                 AYSLE_THARKOLD,
180                 ELFAME,
181                 FAIRY_TALE_AYSLE,
182                 MECHOPOTAMIA,
183                 THE_DEAD_WORLD,
184                 TOMBSPACE,
185                 WALDECK
186         );
187     }
188 }