25 lines
1.3 KiB
Java
25 lines
1.3 KiB
Java
package games.dmg.fantasystick.passive;
|
|
|
|
import games.dmg.fantasystick.progression.Stat;
|
|
import java.math.BigInteger;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
|
|
/** Immutable internal metadata for one character-owned automatic passive. */
|
|
public record PassiveDefinition(String id, String name, Map<Stat, BigInteger> requirements,
|
|
Set<String> prerequisites, BigInteger pointCost, List<String> description) {
|
|
public PassiveDefinition {
|
|
Objects.requireNonNull(id); Objects.requireNonNull(name); Objects.requireNonNull(requirements);
|
|
Objects.requireNonNull(prerequisites); Objects.requireNonNull(pointCost); Objects.requireNonNull(description);
|
|
requirements = Map.copyOf(requirements); prerequisites = Set.copyOf(prerequisites); description = List.copyOf(description);
|
|
if (!id.matches("[a-z][a-z0-9_]{0,63}") || name.isBlank() || !pointCost.equals(BigInteger.ONE)
|
|
|| requirements.entrySet().stream().anyMatch(entry -> entry.getValue().compareTo(BigInteger.TEN) < 0)
|
|
|| prerequisites.stream().anyMatch(value -> value.isBlank() || value.equals(id))
|
|
|| description.isEmpty() || description.stream().anyMatch(String::isBlank)) {
|
|
throw new IllegalArgumentException("Invalid passive definition");
|
|
}
|
|
}
|
|
}
|