Search in sources :

Example 6 with AssociationKey

use of pcgen.cdom.enumeration.AssociationKey in project pcgen by PCGen.

the class SpellsLst method processAdds.

private Collection<? extends String> processAdds(LoadContext context, MapToList<CDOMReference<Spell>, AssociatedPrereqObject> mtl) {
    TripleKeyMap<Set<Prerequisite>, Map<AssociationKey<?>, Object>, CDOMReference<Spell>, String> m = new TripleKeyMap<>();
    for (CDOMReference<Spell> lw : mtl.getKeySet()) {
        for (AssociatedPrereqObject assoc : mtl.getListFor(lw)) {
            Map<AssociationKey<?>, Object> am = new HashMap<>();
            String dc = null;
            for (AssociationKey<?> ak : assoc.getAssociationKeys()) {
                // else
                if (AssociationKey.DC_FORMULA.equals(ak)) {
                    dc = assoc.getAssociation(AssociationKey.DC_FORMULA);
                } else {
                    am.put(ak, assoc.getAssociation(ak));
                }
            }
            m.put(new HashSet<>(assoc.getPrerequisiteList()), am, lw, dc);
        }
    }
    Set<String> set = new TreeSet<>();
    for (Set<Prerequisite> prereqs : m.getKeySet()) {
        for (Map<AssociationKey<?>, Object> am : m.getSecondaryKeySet(prereqs)) {
            StringBuilder sb = new StringBuilder();
            sb.append(am.get(AssociationKey.SPELLBOOK));
            Formula times = AssociationKey.TIMES_PER_UNIT.cast(am.get(AssociationKey.TIMES_PER_UNIT));
            sb.append(Constants.PIPE).append("TIMES=").append(times);
            String timeunit = AssociationKey.TIME_UNIT.cast(am.get(AssociationKey.TIME_UNIT));
            if (timeunit != null) {
                sb.append(Constants.PIPE).append("TIMEUNIT=").append(timeunit);
            }
            String casterLvl = AssociationKey.CASTER_LEVEL.cast(am.get(AssociationKey.CASTER_LEVEL));
            if (casterLvl != null) {
                sb.append(Constants.PIPE).append("CASTERLEVEL=").append(casterLvl);
            }
            Set<String> spellSet = new TreeSet<>();
            for (CDOMReference<Spell> spell : m.getTertiaryKeySet(prereqs, am)) {
                String spellString = spell.getLSTformat(false);
                String dc = m.get(prereqs, am, spell);
                if (dc != null) {
                    spellString += Constants.COMMA + dc;
                }
                spellSet.add(spellString);
            }
            sb.append(Constants.PIPE);
            sb.append(StringUtil.join(spellSet, Constants.PIPE));
            if (prereqs != null && !prereqs.isEmpty()) {
                sb.append(Constants.PIPE);
                sb.append(getPrerequisiteString(context, prereqs));
            }
            set.add(sb.toString());
        }
    }
    return set;
}
Also used : AssociationKey(pcgen.cdom.enumeration.AssociationKey) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Spell(pcgen.core.spell.Spell) Formula(pcgen.base.formula.Formula) TripleKeyMap(pcgen.base.util.TripleKeyMap) TreeSet(java.util.TreeSet) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DoubleKeyMap(pcgen.base.util.DoubleKeyMap) TripleKeyMap(pcgen.base.util.TripleKeyMap) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)6 AssociationKey (pcgen.cdom.enumeration.AssociationKey)6 CDOMReference (pcgen.cdom.base.CDOMReference)5 CDOMObject (pcgen.cdom.base.CDOMObject)3 Formula (pcgen.base.formula.Formula)2 DoubleKeyMap (pcgen.base.util.DoubleKeyMap)2 Prerequisite (pcgen.core.prereq.Prerequisite)2 Spell (pcgen.core.spell.Spell)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ParsingSeparator (pcgen.base.text.ParsingSeparator)1 TripleKeyMap (pcgen.base.util.TripleKeyMap)1 MasterListInterface (pcgen.cdom.base.MasterListInterface)1 Ungranted (pcgen.cdom.base.Ungranted)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1