Search in sources :

Example 16 with CDOMList

use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.

the class AbstractSpellListToken method getMap.

/**
	 * Gets the map.
	 *
	 * @param context the context
	 * @param obj the obj
	 * @param changedLists the changed lists
	 * @param knownSpells Should this scan be for known spells
	 * @return the map
	 */
protected TripleKeyMapToList<String, Integer, CDOMReference<? extends CDOMList<?>>, CDOMReference<Spell>> getMap(LoadContext context, CDOMObject obj, Collection<CDOMReference<? extends CDOMList<?>>> changedLists, boolean knownSpells) {
    TripleKeyMapToList<String, Integer, CDOMReference<? extends CDOMList<?>>, CDOMReference<Spell>> map = new TripleKeyMapToList<>();
    for (CDOMReference listRef : changedLists) {
        AssociatedChanges<CDOMReference<Spell>> changes = context.getListContext().getChangesInList(getTokenName(), obj, listRef);
        Collection<?> removedItems = changes.getRemoved();
        if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
            context.addWriteMessage(getTokenName() + " does not support .CLEAR");
            return null;
        }
        MapToList<CDOMReference<Spell>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
        if (mtl == null || mtl.isEmpty()) {
            // TODO Error message - unexpected?
            continue;
        }
        for (CDOMReference<Spell> added : mtl.getKeySet()) {
            for (AssociatedPrereqObject assoc : mtl.getListFor(added)) {
                Integer lvl = assoc.getAssociation(AssociationKey.SPELL_LEVEL);
                String prereqString = getPrerequisiteString(context, assoc.getPrerequisiteList());
                Boolean known = assoc.getAssociation(AssociationKey.KNOWN);
                boolean isKnown = known != null && known.booleanValue();
                if (knownSpells == isKnown) {
                    map.addToListFor(prereqString, lvl, listRef, added);
                }
            }
        }
    }
    return map;
}
Also used : Spell(pcgen.core.spell.Spell) TripleKeyMapToList(pcgen.base.util.TripleKeyMapToList) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 17 with CDOMList

use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.

the class MasterAvailableSpellFacet method initialize.

/**
	 * Initializes the global lists of ClassSkillLists. This method only needs
	 * to be called once for each set of sources that are loaded.
	 */
@Override
public synchronized void initialize(LoadContext lc) {
    DataSetID dsID = lc.getDataSetID();
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    List<CDOMReference<CDOMList<Spell>>> useLists = new ArrayList<>();
    for (CDOMReference ref : masterLists.getActiveLists()) {
        Collection<CDOMList<Spell>> lists = ref.getContainedObjects();
        for (CDOMList<Spell> list : lists) {
            if ((list instanceof ClassSpellList) || (list instanceof DomainSpellList)) {
                useLists.add(ref);
                break;
            }
        }
    }
    for (CDOMReference<CDOMList<Spell>> ref : useLists) {
        for (Spell spell : masterLists.getObjects(ref)) {
            Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, spell);
            for (AssociatedPrereqObject apo : assoc) {
                int lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
                for (CDOMList<Spell> list : ref.getContainedObjects()) {
                    AvailableSpell as = new AvailableSpell(list, spell, lvl);
                    if (apo.hasPrerequisites()) {
                        as.addAllPrerequisites(apo.getPrerequisiteList());
                    }
                    add(dsID, as);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ClassSpellList(pcgen.cdom.list.ClassSpellList) DataSetID(pcgen.cdom.enumeration.DataSetID) AvailableSpell(pcgen.cdom.helper.AvailableSpell) Spell(pcgen.core.spell.Spell) DomainSpellList(pcgen.cdom.list.DomainSpellList) AvailableSpell(pcgen.cdom.helper.AvailableSpell) MasterListInterface(pcgen.cdom.base.MasterListInterface) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

CDOMList (pcgen.cdom.base.CDOMList)17 CDOMReference (pcgen.cdom.base.CDOMReference)10 Spell (pcgen.core.spell.Spell)10 ArrayList (java.util.ArrayList)6 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)6 TreeSet (java.util.TreeSet)4 DomainSpellList (pcgen.cdom.list.DomainSpellList)4 HashSet (java.util.HashSet)3 TripleKeyMapToList (pcgen.base.util.TripleKeyMapToList)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 ClassSpellList (pcgen.cdom.list.ClassSpellList)3 PCClass (pcgen.core.PCClass)3 CharacterSpell (pcgen.core.character.CharacterSpell)3 Set (java.util.Set)2 StringTokenizer (java.util.StringTokenizer)2 Test (org.junit.Test)2 MasterListInterface (pcgen.cdom.base.MasterListInterface)2 CharID (pcgen.cdom.enumeration.CharID)2 AvailableSpell (pcgen.cdom.helper.AvailableSpell)2 Prerequisite (pcgen.core.prereq.Prerequisite)2