Search in sources :

Example 31 with AssociatedPrereqObject

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

the class DeityToken method getCollection.

@Override
public <R> Collection<R> getCollection(PlayerCharacter pc, Converter<Domain, R> c) {
    HashSet<R> returnSet = new HashSet<>();
    Deity deity = pc.getDisplay().getDeity();
    if (deity == null) {
        return returnSet;
    }
    CDOMReference<DomainList> list = Deity.DOMAINLIST;
    Collection<CDOMReference<Domain>> mods = deity.getListMods(list);
    for (CDOMReference<Domain> ref : mods) {
        Collection<AssociatedPrereqObject> assoc = deity.getListAssociations(list, ref);
        for (AssociatedPrereqObject apo : assoc) {
            if (PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, deity)) {
                returnSet.addAll(c.convert(ref));
                break;
            }
        }
    }
    return returnSet;
}
Also used : Deity(pcgen.core.Deity) DomainList(pcgen.cdom.list.DomainList) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) HashSet(java.util.HashSet) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 32 with AssociatedPrereqObject

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

the class VisionFacet method dataAdded.

/**
	 * Adds any granted Vision objects to this facet when a CDOMObject that
	 * grants Vision objects is added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which VisionFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    Collection<CDOMReference<Vision>> mods = cdo.getListMods(Vision.VISIONLIST);
    if (mods != null) {
        CharID id = dfce.getCharID();
        for (CDOMReference<Vision> ref : mods) {
            Collection<AssociatedPrereqObject> assoc = cdo.getListAssociations(Vision.VISIONLIST, ref);
            for (AssociatedPrereqObject apo : assoc) {
                List<Prerequisite> prereqs = apo.getPrerequisiteList();
                for (Vision v : ref.getContainedObjects()) {
                    add(id, new QualifiedObject<>(v, prereqs), cdo);
                }
            }
        }
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) Vision(pcgen.core.Vision) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 33 with AssociatedPrereqObject

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

the class ListChanges method getAddedAssociations.

@Override
public MapToList<CDOMReference<T>, AssociatedPrereqObject> getAddedAssociations() {
    Collection<CDOMReference<T>> mods = positive.getListMods(list);
    if (mods == null) {
        return null;
    }
    MapToList<CDOMReference<T>, AssociatedPrereqObject> owned = new TreeMapToList<>(ReferenceUtilities.REFERENCE_SORTER);
    for (CDOMReference<T> lw : mods) {
        Collection<AssociatedPrereqObject> assocs = positive.getListAssociations(list, lw);
        for (AssociatedPrereqObject assoc : assocs) {
            if (tokenName.equals(assoc.getAssociation(AssociationKey.TOKEN))) {
                owned.addToListFor(lw, assoc);
            }
        }
    }
    if (owned.isEmpty()) {
        return null;
    }
    return owned;
}
Also used : TreeMapToList(pcgen.base.util.TreeMapToList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 34 with AssociatedPrereqObject

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

the class AbstractListContext method add.

private <BT extends CDOMObject, L extends CDOMList<BT>> void add(CDOMObject owner, CDOMObject neg, CDOMReference<L> list) {
    ListCommitStrategy commit = getCommitStrategy();
    Collection<CDOMReference<BT>> mods = neg.getListMods(list);
    for (CDOMReference<BT> ref : mods) {
        for (AssociatedPrereqObject assoc : neg.getListAssociations(list, ref)) {
            String token = assoc.getAssociation(AssociationKey.TOKEN);
            AssociatedPrereqObject edge = commit.addToList(token, owner, list, ref);
            Collection<AssociationKey<?>> associationKeys = assoc.getAssociationKeys();
            for (AssociationKey<?> ak : associationKeys) {
                setAssoc(assoc, edge, ak);
            }
            edge.addAllPrerequisites(assoc.getPrerequisiteList());
        }
    }
}
Also used : AssociationKey(pcgen.cdom.enumeration.AssociationKey) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 35 with AssociatedPrereqObject

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

the class AbstractListContext method cloneInMasterLists.

/**
	 * Create a copy of any associations to the original object and link them 
	 * to the new object. This will scan lists such as ClassSpellLists and 
	 * DomainSpellLists which may link to the original object. For each 
	 * association found, a new association will be created linking to the new object 
	 * and the association will be added to the list.
	 * 
	 * @param <T>    The type of CDOMObject being copied (e.g. Spell, Domain etc)
	 * @param cdoOld The original object being copied. 
	 * @param cdoNew The new object to be linked in.
	 */
@SuppressWarnings("unchecked")
<T extends CDOMObject> void cloneInMasterLists(T cdoOld, T cdoNew) {
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    for (CDOMReference ref : masterLists.getActiveLists()) {
        Collection<AssociatedPrereqObject> assocs = masterLists.getAssociations(ref, cdoOld);
        if (assocs != null) {
            for (AssociatedPrereqObject apo : assocs) {
                //					Logging.debugPrint("Found assoc from " + ref + " to "
                //							+ apo.getAssociationKeys() + " / "
                //							+ apo.getAssociation(AssociationKey.OWNER));
                AssociatedPrereqObject newapo = getCommitStrategy().addToMasterList(apo.getAssociation(AssociationKey.TOKEN), cdoNew, ref, cdoNew);
                newapo.addAllPrerequisites(apo.getPrerequisiteList());
                for (AssociationKey assocKey : apo.getAssociationKeys()) {
                    if (assocKey != AssociationKey.TOKEN && assocKey != AssociationKey.OWNER) {
                        newapo.setAssociation(assocKey, apo.getAssociation(assocKey));
                    }
                }
            }
        }
    }
}
Also used : AssociationKey(pcgen.cdom.enumeration.AssociationKey) MasterListInterface(pcgen.cdom.base.MasterListInterface) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)50 CDOMReference (pcgen.cdom.base.CDOMReference)34 ArrayList (java.util.ArrayList)18 Prerequisite (pcgen.core.prereq.Prerequisite)18 Spell (pcgen.core.spell.Spell)14 StringTokenizer (java.util.StringTokenizer)11 TreeSet (java.util.TreeSet)10 Domain (pcgen.core.Domain)8 CDOMObject (pcgen.cdom.base.CDOMObject)7 ClassSpellList (pcgen.cdom.list.ClassSpellList)7 CDOMList (pcgen.cdom.base.CDOMList)6 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 HashSet (java.util.HashSet)5 MasterListInterface (pcgen.cdom.base.MasterListInterface)5 AssociationKey (pcgen.cdom.enumeration.AssociationKey)5 ClassSkillList (pcgen.cdom.list.ClassSkillList)5 DomainSpellList (pcgen.cdom.list.DomainSpellList)5 StringWriter (java.io.StringWriter)4 PCClass (pcgen.core.PCClass)4