Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package api.sparklearts.astralinfusion.soul;
- import java.util.List;
- import java.util.ArrayList;
- public class SoulType {
- private static final List<SoulType> SOUL_TYPES = new ArrayList<>();
- private final String id;
- private final String displayName;
- private final SoulTypeRarities rarity;
- private final double corruption;
- private double strength;
- private SoulType(String id, String displayName, SoulTypeRarities rarity, double corruption, double strength) {
- this.id = id;
- this.displayName = displayName;
- this.rarity = rarity;
- this.corruption = corruption;
- this.strength = strength;
- }
- public static List<SoulType> getSoulTypes() { // Neue Getter-Methode
- return SOUL_TYPES;
- }
- public String getId() {
- return id;
- }
- public String getDisplayName() {
- return displayName;
- }
- public SoulTypeRarities getRarity() {
- return rarity;
- }
- public Double getCorruption() {
- return corruption;
- }
- public Double getStrength() {
- return strength;
- }
- public void setStrength(double newStrength) {
- this.strength = newStrength;
- }
- public void addStrength(double addStrength) {
- this.strength += addStrength;
- }
- public static SoulType register(String id, String displayName, SoulTypeRarities rarity, double corruption, double strength) throws IllegalArgumentException {
- double minCorruption = 0;
- double maxCorruption = 2;
- double minStrength = 0;
- double maxStrength = 5;
- if (corruption < minCorruption || corruption > maxCorruption) {
- throw new IllegalArgumentException("Corruption must be between " + minCorruption + " and " + maxCorruption + " .");
- }
- if (strength < minStrength || strength > maxStrength) {
- throw new IllegalArgumentException("Strength must be between " + minStrength + " and " + maxStrength + " .");
- }
- SoulType newType = new SoulType(id, displayName, rarity, corruption, strength);
- SOUL_TYPES.add(newType);
- for (SoulType soulType : SOUL_TYPES) {
- if (soulType.getId().equals(id)) {
- throw new IllegalArgumentException("SoulType with id '" + id + "' already exists.");
- }
- }
- return newType;
- }
- public static SoulType fromId(String id) {
- for (SoulType soulType : SOUL_TYPES) {
- if (soulType.getId().equals(id)) {
- return soulType;
- }
- }
- throw new IllegalArgumentException("SoulType with id '" + id + "' not found.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement