Search in sources :

Example 1 with AssociatedPrereqObject

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

the class ConsolidatedListCommitStrategy method getChangesInMasterList.

@Override
public <T extends CDOMObject> AssociatedChanges<T> getChangesInMasterList(String tokenName, CDOMObject owner, CDOMReference<? extends CDOMList<T>> swl) {
    Set<CDOMObject> added = masterList.getSecondaryKeySet(swl);
    MapToList<T, AssociatedPrereqObject> owned = new TreeMapToList<>(CDOMObjectUtilities.CDOM_SORTER);
    for (CDOMObject lw : added) {
        List<AssociatedPrereqObject> list = masterList.getListFor(swl, lw);
        for (AssociatedPrereqObject assoc : list) {
            if (owner.equals(assoc.getAssociation(AssociationKey.OWNER))) {
                owned.addToListFor((T) lw, assoc);
                break;
            }
        }
    }
    return new AssociatedCollectionChanges<>(owned, null, false);
}
Also used : TreeMapToList(pcgen.base.util.TreeMapToList) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 2 with AssociatedPrereqObject

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

the class ListChanges method getAdded.

@Override
public Collection<CDOMReference<T>> getAdded() {
    TreeSet<CDOMReference<T>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
    Collection<CDOMReference<T>> listMods = positive.getListMods(list);
    if (listMods != null) {
        for (CDOMReference<T> ref : listMods) {
            for (AssociatedPrereqObject assoc : positive.getListAssociations(list, ref)) {
                if (tokenName.equals(assoc.getAssociation(AssociationKey.TOKEN))) {
                    set.add(ref);
                }
            }
        }
    }
    return set;
}
Also used : TreeSet(java.util.TreeSet) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 3 with AssociatedPrereqObject

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

the class ListChanges method getRemoved.

@Override
public Collection<CDOMReference<T>> getRemoved() {
    TreeSet<CDOMReference<T>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
    if (negative == null) {
        return set;
    }
    Collection<CDOMReference<T>> listMods = negative.getListMods(list);
    if (listMods != null) {
        for (CDOMReference<T> ref : listMods) {
            for (AssociatedPrereqObject assoc : negative.getListAssociations(list, ref)) {
                if (tokenName.equals(assoc.getAssociation(AssociationKey.TOKEN))) {
                    set.add(ref);
                }
            }
        }
    }
    return set;
}
Also used : TreeSet(java.util.TreeSet) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 4 with AssociatedPrereqObject

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

the class AbstractListContext method remove.

private <BT extends CDOMObject, L extends CDOMList<BT>> void remove(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.removeFromList(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 5 with AssociatedPrereqObject

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

the class SpellsFacet method dataAdded.

/**
	 * Adds a SpellLikeAbility to this facet if the CDOMObject added to a Player
	 * Character contains a SPELLS entry.
	 * 
	 * Triggered when one of the Facets to which SpellsFacet 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) {
    CharID id = dfce.getCharID();
    CDOMObject cdo = dfce.getCDOMObject();
    Collection<CDOMReference<Spell>> mods = cdo.getListMods(Spell.SPELLS);
    if (mods == null) {
        return;
    }
    for (CDOMReference<Spell> ref : mods) {
        Collection<AssociatedPrereqObject> assocs = cdo.getListAssociations(Spell.SPELLS, ref);
        Collection<Spell> spells = ref.getContainedObjects();
        for (AssociatedPrereqObject apo : assocs) {
            Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
            String timeunit = apo.getAssociation(AssociationKey.TIME_UNIT);
            // The timeunit needs to default to day as per the docs
            if (timeunit == null) {
                timeunit = "Day";
            }
            String casterlevel = apo.getAssociation(AssociationKey.CASTER_LEVEL);
            String dcformula = apo.getAssociation(AssociationKey.DC_FORMULA);
            String book = apo.getAssociation(AssociationKey.SPELLBOOK);
            String ident = cdo.getQualifiedKey();
            for (Spell sp : spells) {
                SpellLikeAbility sla = new SpellLikeAbility(sp, times, timeunit, book, casterlevel, dcformula, ident);
                sla.addAllPrerequisites(apo.getPrerequisiteList());
                add(id, sla, cdo);
            }
        }
    }
}
Also used : Formula(pcgen.base.formula.Formula) CDOMObject(pcgen.cdom.base.CDOMObject) SpellLikeAbility(pcgen.cdom.content.SpellLikeAbility) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference) Spell(pcgen.core.spell.Spell) 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