use of pcgen.base.util.HashMapToList in project pcgen by PCGen.
the class PCGVer2Parser method resolveLanguages.
private void resolveLanguages() {
CNAbility langbonus = thePC.getBonusLanguageAbility();
int currentBonusLang = thePC.getDetailedAssociationCount(langbonus);
boolean foundLang = currentBonusLang > 0;
Set<Language> foundLanguages = new HashSet<>(thePC.getLanguageSet());
//Captures Auto (AUTO:LANG) and Persistent choices (ADD ex ability and CHOOSE)
cachedLanguages.removeAll(foundLanguages);
HashMapToList<Language, Object> langSources = new HashMapToList<>();
Map<Object, Integer> actorLimit = new IdentityHashMap<>();
Map<PersistentTransitionChoice, CDOMObject> ptcSources = new IdentityHashMap<>();
List<? extends CDOMObject> abilities = thePC.getCDOMObjectList();
for (CDOMObject a : abilities) {
List<PersistentTransitionChoice<?>> addList = a.getListFor(ListKey.ADD);
if (addList != null) {
for (PersistentTransitionChoice<?> ptc : addList) {
SelectableSet<?> ss = ptc.getChoices();
if (ss.getName().equals("LANGUAGE") && LANGUAGE_CLASS.equals(ss.getChoiceClass())) {
Collection<Language> selected = (Collection<Language>) ss.getSet(thePC);
for (Language l : selected) {
if (cachedLanguages.contains(l)) {
String source = SourceFormat.getFormattedString(a, Globals.getSourceDisplay(), true);
int choiceCount = ptc.getCount().resolve(thePC, source).intValue();
if (choiceCount > 0) {
langSources.addToListFor(l, ptc);
ptcSources.put(ptc, a);
actorLimit.put(ptc, choiceCount);
}
}
}
}
}
}
}
if (!foundLang) {
Set<Language> bonusAllowed = thePC.getLanguageBonusSelectionList();
int count = thePC.getBonusLanguageCount();
int choiceCount = count - currentBonusLang;
if (choiceCount > 0) {
for (Language l : bonusAllowed) {
if (cachedLanguages.contains(l)) {
langSources.addToListFor(l, langbonus);
actorLimit.put(langbonus, choiceCount);
}
}
}
}
//Try to match them up as best as possible (this matches things with only one possible location...)
boolean acted = !cachedLanguages.isEmpty();
while (acted) {
acted = false;
for (Language l : langSources.getKeySet()) {
List<Object> actors = langSources.getListFor(l);
if ((actors != null) && (actors.size() == 1)) {
Object actor = actors.get(0);
acted = true;
processRemoval(langbonus, langSources, actorLimit, ptcSources, l, actor);
}
}
if (!acted && !langSources.isEmpty() && !actorLimit.isEmpty()) {
//pick one
Language l = langSources.getKeySet().iterator().next();
Object source = langSources.getListFor(l).get(0);
processRemoval(langbonus, langSources, actorLimit, ptcSources, l, source);
acted = true;
}
}
for (Language l : cachedLanguages) {
warnings.add("Unable to find source: " + "Character no longer speaks language: " + l.getDisplayName());
}
}
use of pcgen.base.util.HashMapToList in project pcgen by PCGen.
the class VisionLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
AssociatedChanges<CDOMReference<Vision>> changes = context.getListContext().getChangesInList(getTokenName(), obj, Vision.VISIONLIST);
List<String> list = new ArrayList<>();
Collection<CDOMReference<Vision>> removedItems = changes.getRemoved();
if (changes.includesGlobalClear()) {
if (removedItems != null && !removedItems.isEmpty()) {
context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
return null;
}
list.add(Constants.LST_DOT_CLEAR);
} else if (removedItems != null && !removedItems.isEmpty()) {
list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
}
MapToList<CDOMReference<Vision>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl != null && !mtl.isEmpty()) {
MapToList<Set<Prerequisite>, Vision> m = new HashMapToList<>();
for (CDOMReference<Vision> ab : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
m.addAllToListFor(new HashSet<>(assoc.getPrerequisiteList()), ab.getContainedObjects());
}
}
Set<String> set = new TreeSet<>();
for (Set<Prerequisite> prereqs : m.getKeySet()) {
StringBuilder sb = new StringBuilder(StringUtil.join(m.getListFor(prereqs), Constants.PIPE));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
set.add(sb.toString());
}
list.addAll(set);
}
if (list.isEmpty()) {
return null;
}
return list.toArray(new String[list.size()]);
}
use of pcgen.base.util.HashMapToList in project pcgen by PCGen.
the class AbilityAutoListToken method getAbilityList.
/**
* @see pcgen.io.exporttoken.AbilityListToken#getAbilityList(pcgen.core.PlayerCharacter, pcgen.core.AbilityCategory)
*/
@Override
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
for (AbilityCategory aCat : allCats) {
if (AbilityCategory.ANY.equals(aCategory) || aCat.getParentCategory().equals(aCategory)) {
for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.AUTOMATIC)) {
listOfAbilities.addToListFor(cna.getAbility(), cna);
}
}
}
return listOfAbilities;
}
use of pcgen.base.util.HashMapToList in project pcgen by PCGen.
the class AbilityAutoToken method getAbilityList.
/**
* @see pcgen.io.exporttoken.AbilityToken#getAbilityList(pcgen.core.PlayerCharacter, pcgen.core.AbilityCategory)
*/
@Override
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
for (AbilityCategory aCat : allCats) {
if (AbilityCategory.ANY.equals(aCategory) || aCat.getParentCategory().equals(aCategory)) {
for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.AUTOMATIC)) {
listOfAbilities.addToListFor(cna.getAbility(), cna);
}
}
}
return listOfAbilities;
}
Aggregations