Search in sources :

Example 66 with CDOMReference

use of pcgen.cdom.base.CDOMReference 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 67 with CDOMReference

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

the class AbstractProfProvider method providesEquipmentType.

/**
	 * Returns true if this AbstractProfProvider provides proficiency with the
	 * given Equipment TYPE. This only tests against the Equipment TYPE
	 * reference list provided during construction of the AbstractProfProvider.
	 * 
	 * @param typeString
	 *            The TYPE of Equipment to be tested to see if this
	 *            AbstractProfProvider provides proficiency with the given
	 *            Equipment TYPE
	 * @return true if this AbstractProfProvider provides proficiency with the
	 *         given Equipment TYPE.
	 */
@Override
@SuppressWarnings("PMD.AvoidBranchingStatementAsLastInLoop")
public boolean providesEquipmentType(String typeString) {
    if (typeString == null || typeString.isEmpty()) {
        return false;
    }
    Set<String> types = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    Collections.addAll(types, typeString.split("\\."));
    REF: for (CDOMReference<Equipment> ref : byEquipType) {
        StringTokenizer tok = new StringTokenizer(ref.getLSTformat(false).substring(5), ".");
        while (tok.hasMoreTokens()) {
            if (!types.contains(tok.nextToken())) {
                continue REF;
            }
        }
        return true;
    }
    return false;
}
Also used : StringTokenizer(java.util.StringTokenizer) TreeSet(java.util.TreeSet) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 68 with CDOMReference

use of pcgen.cdom.base.CDOMReference 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 69 with CDOMReference

use of pcgen.cdom.base.CDOMReference 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 70 with CDOMReference

use of pcgen.cdom.base.CDOMReference 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

CDOMReference (pcgen.cdom.base.CDOMReference)125 ArrayList (java.util.ArrayList)57 StringTokenizer (java.util.StringTokenizer)40 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)35 ParseResult (pcgen.rules.persistence.token.ParseResult)30 Skill (pcgen.core.Skill)24 ChoiceSet (pcgen.cdom.base.ChoiceSet)22 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)21 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)19 Prerequisite (pcgen.core.prereq.Prerequisite)18 Formula (pcgen.base.formula.Formula)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 Spell (pcgen.core.spell.Spell)15 TreeSet (java.util.TreeSet)14 Test (org.junit.Test)14 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)12 CharID (pcgen.cdom.enumeration.CharID)11 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)11 ParsingSeparator (pcgen.base.text.ParsingSeparator)10 CDOMList (pcgen.cdom.base.CDOMList)10