Search in sources :

Example 16 with CDOMObject

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

the class AbstractListContext method commit.

void commit() {
    ListCommitStrategy commit = getCommitStrategy();
    for (CDOMReference<? extends CDOMList<?>> list : edits.positiveMasterMap.getKeySet()) {
        //Note: Intentional Generics Violation due to Sun Compiler
        commitDirect((CDOMReference) list);
    }
    for (CDOMReference<? extends CDOMList<?>> list : edits.negativeMasterMap.getKeySet()) {
        //Note: Intentional Generics Violation due to Sun Compiler
        removeDirect((CDOMReference) list);
    }
    for (URI uri : edits.globalClearSet.getKeySet()) {
        for (CDOMObject owner : edits.globalClearSet.getSecondaryKeySet(uri)) {
            for (String tokenName : edits.globalClearSet.getTertiaryKeySet(uri, owner)) {
                for (CDOMReference<? extends CDOMList<?>> list : edits.globalClearSet.getListFor(uri, owner, tokenName)) {
                    commit.removeAllFromList(tokenName, owner, list);
                }
            }
        }
    }
    for (URI uri : edits.negativeMap.getKeySet()) {
        for (CDOMObject owner : edits.negativeMap.getSecondaryKeySet(uri)) {
            CDOMObject neg = edits.negativeMap.get(uri, owner);
            Collection<CDOMReference<? extends CDOMList<?>>> modifiedLists = neg.getModifiedLists();
            for (CDOMReference<? extends CDOMList<?>> list : modifiedLists) {
                //Note: Intentional Generics Violation due to Sun Compiler
                remove(owner, neg, (CDOMReference) list);
            }
        }
    }
    for (URI uri : edits.positiveMap.getKeySet()) {
        for (CDOMObject owner : edits.positiveMap.getSecondaryKeySet(uri)) {
            CDOMObject neg = edits.positiveMap.get(uri, owner);
            Collection<CDOMReference<? extends CDOMList<?>>> modifiedLists = neg.getModifiedLists();
            for (CDOMReference<? extends CDOMList<?>> list : modifiedLists) {
                //Note: Intentional Generics Violation due to Sun Compiler
                add(owner, neg, (CDOMReference) list);
            }
        }
    }
    for (String token : edits.masterAllClear.getKeySet()) {
        for (OwnerURI ou : edits.masterAllClear.getListFor(token)) {
            commit.clearAllMasterLists(token, ou.owner);
        }
    }
    rollback();
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) CDOMList(pcgen.cdom.base.CDOMList) URI(java.net.URI) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 17 with CDOMObject

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

Example 18 with CDOMObject

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

the class StartingLanguageFacet method dataAdded.

/**
	 * Adds available Languages to this facet when a CDOMObject added to a
	 * Player Character makes Languages available to the Player Character.
	 * 
	 * Triggered when one of the Facets to which StartingLanguageFacet 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<Language>> list = cdo.getListMods(Language.STARTING_LIST);
    if (list != null) {
        CharID id = dfce.getCharID();
        for (CDOMReference<Language> ref : list) {
            addAll(id, ref.getContainedObjects(), cdo);
        }
    }
}
Also used : Language(pcgen.core.Language) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 19 with CDOMObject

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

the class KnownSpellInputFacet method dataAdded.

/**
	 * Triggered when one of the Facets to which ConditionallyKnownSpellFacet
	 * 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<? extends CDOMList<?>>> listrefs = cdo.getModifiedLists();
    CharID id = dfce.getCharID();
    for (CDOMReference<? extends CDOMList<?>> ref : listrefs) {
        processListRef(id, cdo, ref);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) CDOMList(pcgen.cdom.base.CDOMList) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 20 with CDOMObject

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

the class ModifierFacet method dataRemoved.

/**
	 * Triggered when one of the Facets to which ModifierFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was removed from a Player
	 * Character.
	 * 
	 * Long term this method needs to be symmetric with dataAdded.
	 * 
	 * @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 dataRemoved(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CharID id = dfce.getCharID();
    CDOMObject obj = dfce.getCDOMObject();
    List<VarModifier<?>> modifiers = obj.getListFor(ListKey.MODIFY);
    if (modifiers != null) {
        ScopeInstance inst = scopeFacet.get(id, obj);
        for (VarModifier<?> vm : modifiers) {
            processRemoval(id, obj, vm, inst);
        }
    }
    if (obj instanceof Equipment) {
        Equipment equip = (Equipment) obj;
        for (EquipmentHead head : equip.getEquipmentHeads()) {
            ScopeInstance inst = scopeFacet.get(id, head);
            modifiers = head.getListFor(ListKey.MODIFY);
            if (modifiers != null) {
                for (VarModifier<?> vm : modifiers) {
                    processRemoval(id, equip, vm, inst);
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) VarModifier(pcgen.cdom.content.VarModifier) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Aggregations

CDOMObject (pcgen.cdom.base.CDOMObject)235 Test (org.junit.Test)68 CharID (pcgen.cdom.enumeration.CharID)53 PCTemplate (pcgen.core.PCTemplate)30 ArrayList (java.util.ArrayList)22 PCClass (pcgen.core.PCClass)18 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)17 Race (pcgen.core.Race)17 Equipment (pcgen.core.Equipment)15 PlayerCharacter (pcgen.core.PlayerCharacter)15 Map (java.util.Map)14 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)14 CDOMReference (pcgen.cdom.base.CDOMReference)14 BonusObj (pcgen.core.bonus.BonusObj)14 IdentityHashMap (java.util.IdentityHashMap)12 Set (java.util.Set)12 VariableKey (pcgen.cdom.enumeration.VariableKey)11 HashMap (java.util.HashMap)10 CNAbility (pcgen.cdom.content.CNAbility)10 Spell (pcgen.core.spell.Spell)9