Search in sources :

Example 21 with HashMapToList

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());
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) Language(pcgen.core.Language) CDOMObject(pcgen.cdom.base.CDOMObject) Collection(java.util.Collection) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) HashSet(java.util.HashSet)

Example 22 with HashMapToList

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()]);
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) HashMapToList(pcgen.base.util.HashMapToList) Vision(pcgen.core.Vision) TreeSet(java.util.TreeSet) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 23 with HashMapToList

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;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Example 24 with HashMapToList

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;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Aggregations

HashMapToList (pcgen.base.util.HashMapToList)24 CNAbility (pcgen.cdom.content.CNAbility)15 Ability (pcgen.core.Ability)14 AbilityCategory (pcgen.core.AbilityCategory)14 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)5 CDOMReference (pcgen.cdom.base.CDOMReference)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 CDOMObject (pcgen.cdom.base.CDOMObject)2 CategorizedCDOMReference (pcgen.cdom.reference.CategorizedCDOMReference)2 Qualifier (pcgen.cdom.reference.Qualifier)2 QualifiedObject (pcgen.core.QualifiedObject)2 StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1