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;
}
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);
}
}
}
}
}
Aggregations