com.softwaremagico.tm.random.profiles.RandomProfile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of think-machine-random Show documentation
Show all versions of think-machine-random Show documentation
Think Machine - A Fading Suns character generator (random character creation)
package com.softwaremagico.tm.random.profiles;
/*-
* #%L
* Think Machine (Core)
* %%
* Copyright (C) 2017 - 2018 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 java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import com.softwaremagico.tm.Element;
import com.softwaremagico.tm.InvalidXmlElementException;
import com.softwaremagico.tm.character.benefices.AvailableBenefice;
import com.softwaremagico.tm.character.benefices.BeneficeDefinition;
import com.softwaremagico.tm.character.blessings.Blessing;
import com.softwaremagico.tm.character.characteristics.Characteristic;
import com.softwaremagico.tm.character.characteristics.CharacteristicName;
import com.softwaremagico.tm.character.equipment.armours.Armour;
import com.softwaremagico.tm.character.equipment.shields.Shield;
import com.softwaremagico.tm.character.equipment.weapons.Weapon;
import com.softwaremagico.tm.character.skills.AvailableSkill;
import com.softwaremagico.tm.json.ExcludeFromJson;
import com.softwaremagico.tm.random.selectors.IRandomPreference;
public class RandomProfile extends Element implements IRandomProfile {
private final Set randomPreferences;
private final Set characteristicsMinimumValues;
private final Set requiredSkills;
private final Set suggestedSkills;
private final Set suggestedBenefices;
private final Set mandatoryBenefices;
private final Set mandatoryWeapons;
private final Set mandatoryArmours;
private final Set mandatoryShields;
@ExcludeFromJson
public boolean parentMerged = false;
public RandomProfile(String id, String name, String language, String moduleName,
Set randomPreferences, Set characteristicsMinimumValues,
Set requiredSkills, Set suggestedSkills,
Set mandatoryBenefices, Set suggestedBenefices,
Set mandatoryWeapons, Set mandatoryArmours, Set mandatoryShields) {
super(id, name, language, moduleName);
this.randomPreferences = randomPreferences;
this.characteristicsMinimumValues = characteristicsMinimumValues;
this.requiredSkills = requiredSkills;
this.suggestedSkills = suggestedSkills;
this.suggestedBenefices = suggestedBenefices;
this.mandatoryBenefices = mandatoryBenefices;
this.mandatoryWeapons = mandatoryWeapons;
this.mandatoryArmours = mandatoryArmours;
this.mandatoryShields = mandatoryShields;
}
public RandomProfile(String id, String name, String language, String moduleName) {
this(id, name, language, moduleName, new HashSet(), new HashSet(),
new HashSet(), new HashSet(), new HashSet(),
new HashSet(), new HashSet(), new HashSet(), new HashSet());
}
@Override
public void setParent(IRandomProfile parentProfile) throws InvalidXmlElementException {
if (!parentMerged && parentProfile != null) {
// Merge preferences. This has preference over parent profile.
final RandomProfile mergedProfile = ProfileMerger.merge(parentProfile.getLanguage(),
parentProfile.getModuleName(), parentProfile, this);
randomPreferences.clear();
randomPreferences.addAll(mergedProfile.getPreferences());
characteristicsMinimumValues.clear();
characteristicsMinimumValues.addAll(mergedProfile.getCharacteristicsMinimumValues());
parentMerged = true;
}
}
@Override
public Set getCharacteristicsMinimumValues() {
return characteristicsMinimumValues;
}
@Override
public Characteristic getCharacteristicMinimumValues(CharacteristicName characteristicName) {
for (final Characteristic characteristic : getCharacteristicsMinimumValues()) {
if (Objects
.equals(characteristic.getCharacteristicDefinition().getCharacteristicName(), characteristicName)) {
return characteristic;
}
}
return null;
}
@Override
public Map getSkillsMinimumValues() {
return new HashMap<>();
}
@Override
public Set getBlessings() {
return new HashSet<>();
}
@Override
public Set getBenefices() {
return new HashSet<>();
}
@Override
public int getExperiencePoints() {
return 0;
}
@Override
public Set getPreferences() {
return randomPreferences;
}
public boolean isParentMerged() {
return parentMerged;
}
public void setParentMerged(boolean parentMerged) {
this.parentMerged = parentMerged;
}
@Override
public Set getRequiredSkills() {
return requiredSkills;
}
@Override
public Set getSuggestedSkills() {
return suggestedSkills;
}
@Override
public Set getSuggestedBenefices() {
return suggestedBenefices;
}
@Override
public Set getMandatoryBenefices() {
return mandatoryBenefices;
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
@Override
public Set getMandatoryWeapons() {
return mandatoryWeapons;
}
@Override
public Set getMandatoryArmours() {
return mandatoryArmours;
}
@Override
public Set getMandatoryShields() {
return mandatoryShields;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy