com.softwaremagico.tm.character.CharacterDefinitionStep Maven / Gradle / Ivy
package com.softwaremagico.tm.character;
/*-
* #%L
* Think Machine 4E (Rules)
* %%
* Copyright (C) 2017 - 2024 Softwaremagico
* %%
* This software is designed by Jorge Hortelano Otero. Jorge Hortelano Otero
* Valencia (Spain).
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; If not, see .
* #L%
*/
import com.fasterxml.jackson.annotation.JsonProperty;
import com.softwaremagico.tm.Element;
import com.softwaremagico.tm.character.capabilities.CapabilityOptions;
import com.softwaremagico.tm.character.characteristics.CharacteristicOption;
import com.softwaremagico.tm.character.equipment.Equipment;
import com.softwaremagico.tm.character.equipment.EquipmentOptions;
import com.softwaremagico.tm.character.perks.PerkOptions;
import com.softwaremagico.tm.character.skills.SkillOption;
import com.softwaremagico.tm.exceptions.InvalidXmlElementException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
public class CharacterDefinitionStep> extends Element {
private static final int TOTAL_CHARACTERISTICS_OPTIONS = 0;
private static final int TOTAL_SKILL_OPTIONS = 0;
@JsonProperty("capabilities")
private List capabilityOptions;
@JsonProperty("characteristics")
private List characteristicOptions;
@JsonProperty("skills")
private List skillOptions;
@JsonProperty("perks")
private List perksOptions;
@JsonProperty("materialAwards")
private List materialAwards;
public List getCapabilityOptions() {
return capabilityOptions;
}
public void setCapabilityOptions(List capabilityOptions) {
this.capabilityOptions = capabilityOptions;
}
public List getCharacteristicOptions() {
return Objects.requireNonNullElseGet(characteristicOptions, ArrayList::new);
}
public void setCharacteristicOptions(List characteristicOptions) {
this.characteristicOptions = characteristicOptions;
}
public List getSkillOptions() {
return Objects.requireNonNullElseGet(skillOptions, ArrayList::new);
}
public void setSkillOptions(List skillOptions) {
this.skillOptions = skillOptions;
}
public List getPerksOptions() {
return perksOptions;
}
public void setPerksOptions(List perksOptions) {
this.perksOptions = perksOptions;
}
public int getCharacteristicsTotalPoints() {
return TOTAL_CHARACTERISTICS_OPTIONS;
}
public int getSkillsTotalPoints() {
return TOTAL_SKILL_OPTIONS;
}
public Set> getMaterialAwards(Collection selectedMaterialAwards) {
return getMaterialAwards().stream().map(m -> m.getItems(selectedMaterialAwards)).flatMap(Collection::stream)
.collect(Collectors.toSet());
}
public List getMaterialAwards() {
if (materialAwards == null) {
return new ArrayList<>();
}
return materialAwards;
}
public void setMaterialAwards(List materialAwards) {
this.materialAwards = materialAwards;
}
@Override
public void validate() throws InvalidXmlElementException {
super.validate();
int totalCharacteristicsPoints = 0;
for (CharacteristicOption characteristicOption : getCharacteristicOptions()) {
totalCharacteristicsPoints += characteristicOption.getTotalOptions() * characteristicOption.getCharacteristics().get(0).getBonus();
}
if (totalCharacteristicsPoints > getCharacteristicsTotalPoints()) {
throw new InvalidXmlElementException("Element '" + getId() + "' has more than '" + getCharacteristicsTotalPoints() + "' characteristics options. "
+ "Currently has '" + totalCharacteristicsPoints + "' characteristic points.");
}
int totalSkillPoints = 0;
for (SkillOption skillOption : getSkillOptions()) {
totalSkillPoints += skillOption.getTotalOptions() * skillOption.getSkills().get(0).getBonus();
}
if (totalSkillPoints > getSkillsTotalPoints()) {
throw new InvalidXmlElementException("Element '" + getId() + "' has more than " + getSkillsTotalPoints() + " skill options. "
+ "Currently has '" + totalSkillPoints + "' skill points.");
}
}
}