Search in sources :

Example 1 with CDOMObject

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

the class FollowerOptionFacet method getAvailableFollowers.

/**
	 * Returns a non-null copy of the available FollowerOptions of a given type
	 * for the Player Character represented by the given CharID. This method
	 * returns an empty Map if no objects are in this FollowerOptionFacet for
	 * the Player Character identified by the given CharID.
	 * 
	 * This method is value-semantic in that ownership of the returned Map is
	 * transferred to the class calling this method. Modification of the
	 * returned Map will not modify this FollowerOptionFacet and modification of
	 * this FollowerOptionFacet will not modify the returned Map. Modifications
	 * to the returned Set will also not modify any future or previous objects
	 * returned by this (or other) methods on FollowerOptionFacet. If you wish
	 * to modify the information stored in this FollowerOptionFacet, you must
	 * use the add*() and remove*() methods of FollowerOptionFacet.
	 * 
	 * @param id
	 *            The CharID representing the Player Character for which the
	 *            items in this FollowerOptionFacet should be returned
	 * @param type
	 *            The type of FollowerOption that should be returned
	 * @param comp
	 *            An optional Comparator to be used to sort the FollowerOption
	 *            objects in the returned Map. null is a legal value, and will
	 *            result in the FollowerOptions being sorted by their type
	 * @return A non-null copy of the Map of FollowerOptions in this
	 *         FollowerOptionFacet for the Player Character represented by the
	 *         given CharID
	 */
public Map<FollowerOption, CDOMObject> getAvailableFollowers(CharID id, String type, Comparator<FollowerOption> comp) {
    CaseInsensitiveMap<Map<FollowerOption, Set<CDOMObject>>> componentMap = getCachedMap(id);
    if (componentMap == null) {
        return Collections.emptyMap();
    }
    Map<FollowerOption, Set<CDOMObject>> foMap = componentMap.get(type);
    if (foMap == null) {
        return Collections.emptyMap();
    }
    Map<FollowerOption, CDOMObject> ret = new TreeMap<>(comp);
    for (Map.Entry<FollowerOption, Set<CDOMObject>> me : foMap.entrySet()) {
        FollowerOption fo = me.getKey();
        Set<CDOMObject> target = me.getValue();
        Collection<FollowerOption> expanded = fo.getExpandedOptions();
        for (CDOMObject source : target) {
            for (FollowerOption efo : expanded) {
                /*
					 * TODO This is a bug, and will overwrite the first source
					 * :(
					 */
                ret.put(efo, source);
            }
        }
    }
    return ret;
}
Also used : Set(java.util.Set) WrappedMapSet(pcgen.base.util.WrappedMapSet) FollowerOption(pcgen.core.FollowerOption) CDOMObject(pcgen.cdom.base.CDOMObject) TreeMap(java.util.TreeMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) CaseInsensitiveMap(pcgen.base.util.CaseInsensitiveMap)

Example 2 with CDOMObject

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

the class GlobalSkillCostFacet method dataAdded.

/**
	 * Adds the SkillCost objects granted by CDOMObjects added to the Player
	 * Character to this GlobalSkillCostFacet.
	 * 
	 * Triggered when one of the Facets to which GlobalSkillCostFacet 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();
    CharID id = dfce.getCharID();
    for (CDOMReference<Skill> ref : cdo.getSafeListFor(ListKey.CSKILL)) {
        for (Skill sk : ref.getContainedObjects()) {
            add(id, SkillCost.CLASS, sk, cdo);
        }
    }
    for (CDOMReference<Skill> ref : cdo.getSafeListFor(ListKey.CCSKILL)) {
        for (Skill sk : ref.getContainedObjects()) {
            add(id, SkillCost.CROSS_CLASS, sk, cdo);
        }
    }
}
Also used : Skill(pcgen.core.Skill) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Example 3 with CDOMObject

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

the class HasAnyFavoredClassFacet method dataAdded.

/**
	 * Adds the Any Favored Class capability granted by CDOMObjects added to the
	 * Player Character to this HasAnyFavoredClassFacet.
	 * 
	 * Triggered when one of the Facets to which HasAnyFavoredClassFacet 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();
    Boolean hdw = cdo.get(ObjectKey.ANY_FAVORED_CLASS);
    if (hdw != null) {
        add(dfce.getCharID(), hdw, cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject)

Example 4 with CDOMObject

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

the class SpecialAbilityFacet method dataAdded.

/**
	 * Extracts SpecialAbility objects from CDOMObjects granted to a Player
	 * Character. The SpecialAbility objects are granted to the Player
	 * Character.
	 * 
	 * Triggered when one of the Facets to which SpecialAbilityFacet 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();
    addAll(dfce.getCharID(), cdo.getSafeListFor(ListKey.SAB), cdo);
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject)

Example 5 with CDOMObject

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

the class StatLockFacet method dataAdded.

/**
	 * Adds StatLock objects granted by a CDOMObject which has been added to a
	 * Player Character.
	 * 
	 * Triggered when one of the Facets to which StatLockFacet 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();
    List<StatLock> locks = cdo.getListFor(ListKey.STAT_LOCKS);
    if (locks != null) {
        addAll(dfce.getCharID(), locks, cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) StatLock(pcgen.cdom.helper.StatLock)

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