Search in sources :

Example 21 with CDOMObject

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

the class MonsterClassFacet method dataRemoved.

/**
	 * Removes monster classes from the Player Character when the CDOMObject
	 * which granted the monster classes is removed from the Player Character.
	 * 
	 * Triggered when one of the Facets to which MonsterClassFacet listens fires
	 * a DataFacetChangeEvent to indicate a CDOMObject was removed from a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    LevelCommandFactory lcf = cdo.get(ObjectKey.MONSTER_CLASS);
    if (lcf != null) {
        CharID id = dfce.getCharID();
        int levelCount = formulaResolvingFacet.resolve(id, lcf.getLevelCount(), "").intValue();
        PlayerCharacter pc = trackingFacet.getPC(id);
        pc.incrementClassLevel(-levelCount, lcf.getPCClass(), true);
    }
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) PlayerCharacter(pcgen.core.PlayerCharacter) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Example 22 with CDOMObject

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

the class MonsterClassFacet method dataAdded.

/**
	 * Adds monster classes to the Player Character when a CDOMObject which
	 * grants monster classes is added to the Player Character.
	 * 
	 * Triggered when one of the Facets to which MonsterClassFacet 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();
    // Get existing classes
    ClassInfo ci = classFacet.removeAllClasses(id);
    //
    for (int i = levelInfoFacet.getCount(id) - 1; i >= 0; --i) {
        PCLevelInfo pli = levelInfoFacet.get(id, i);
        final String classKeyName = pli.getClassKeyName();
        final PCClass aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKeyName);
        if (aClass.isMonster()) {
            levelInfoFacet.remove(id, pli);
        }
    }
    PlayerCharacter pc = trackingFacet.getPC(id);
    final List<PCLevelInfo> existingLevelInfo = new ArrayList<>(levelInfoFacet.getSet(id));
    levelInfoFacet.removeAll(id);
    // Make sure monster classes are added first
    if (!pc.isImporting()) {
        LevelCommandFactory lcf = cdo.get(ObjectKey.MONSTER_CLASS);
        if (lcf != null) {
            int levelCount = formulaResolvingFacet.resolve(id, lcf.getLevelCount(), "").intValue();
            pc.incrementClassLevel(levelCount, lcf.getPCClass(), true);
        }
    }
    levelInfoFacet.addAll(id, existingLevelInfo);
    //
    if (!pc.isImporting() && ci != null && !ci.isEmpty()) {
        int totalLevels = levelFacet.getTotalLevels(id);
        for (PCClass pcClass : ci.getClassSet()) {
            //
            if (!pcClass.isMonster()) {
                classFacet.addClass(id, pcClass);
                int cLevels = ci.getLevel(pcClass);
                classFacet.setLevel(id, pcClass, cLevels);
                pc.setSkillPool(pcClass, 0);
                int cMod = 0;
                for (int j = 0; j < cLevels; ++j) {
                    cMod += pc.recalcSkillPointMod(pcClass, ++totalLevels);
                }
                pc.setSkillPool(pcClass, cMod);
            }
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) ClassInfo(pcgen.cdom.facet.model.ClassFacet.ClassInfo)

Example 23 with CDOMObject

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

the class RemoteModifierFacet method dataAdded.

@Override
public void dataAdded(DataFacetChangeEvent<CharID, VarScoped> dfce) {
    CharID id = dfce.getCharID();
    VarScoped vs = dfce.getCDOMObject();
    /*
		 * If this can have local variables, find what may have been modified by
		 * previous objects
		 */
    for (RemoteModifier<?> rm : getSet(id)) {
        VarScoped src = get(id, rm);
        ScopeInstance inst = scopeFacet.get(id, src);
        processAdd(id, rm, vs, inst);
        if (vs instanceof Equipment) {
            Equipment e = (Equipment) vs;
            for (EquipmentHead head : e.getEquipmentHeads()) {
                processAdd(id, rm, head, inst);
            }
        }
    }
    /*
		 * Look at what newly added object can modify on others
		 */
    if (vs instanceof CDOMObject) {
        ScopeInstance inst = scopeFacet.get(id, vs);
        List<RemoteModifier<?>> list = ((CDOMObject) vs).getListFor(ListKey.REMOTE_MODIFIER);
        if (list != null) {
            Set<? extends VarScoped> targets = varScopedFacet.getSet(id);
            for (RemoteModifier<?> rm : list) {
                set(id, rm, vs);
                //Apply to existing as necessary
                for (VarScoped obj : targets) {
                    processAdd(id, rm, obj, inst);
                    if (obj instanceof Equipment) {
                        Equipment e = (Equipment) obj;
                        for (EquipmentHead head : e.getEquipmentHeads()) {
                            processAdd(id, rm, head, inst);
                        }
                    }
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) RemoteModifier(pcgen.cdom.content.RemoteModifier) VarScoped(pcgen.base.formula.base.VarScoped) CharID(pcgen.cdom.enumeration.CharID)

Example 24 with CDOMObject

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

the class ShieldProfFacet method dataAdded.

/**
	 * Processes added CDOMObjects to determine whether they contained an
	 * AUTO:SHIELDPROF, and if so, processes the contents of that token to add
	 * the appropriate ShieldProfProviders to the Player Character.
	 * 
	 * Triggered when one of the Facets to which ShieldProfFacet 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<ShieldProfProvider> shieldProfs = cdo.getListFor(ListKey.AUTO_SHIELDPROF);
    if (shieldProfs != null) {
        shieldProfProviderFacet.addAll(dfce.getCharID(), shieldProfs, cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) ShieldProfProvider(pcgen.cdom.helper.ShieldProfProvider)

Example 25 with CDOMObject

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

the class PrerequisiteFacet method qualifies.

/**
	 * Returns true if the Player Character identified by the given CharID
	 * qualifies for the given QualifyingObject when the QualifyingObject is
	 * from the given source.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character on which the
	 *            prerequisite test will be performed
	 * @param obj
	 *            The QualifyingObject which contains the prerequisite(s) to be
	 *            tested
	 * @param source
	 *            The source of the QualifyingObject, which is used to given
	 *            context to the prerequisites being tested
	 * @return true if the Player Character identified by the given CharID
	 *         qualifies for the given QualifyingObject when the
	 *         QualifyingObject is from the given source; false otherwise
	 */
public boolean qualifies(CharID id, QualifyingObject obj, Object source) {
    PlayerCharacter pc = trackingFacet.getPC(id);
    CDOMObject cdo = null;
    if (source instanceof CDOMObject) {
        cdo = (CDOMObject) source;
    }
    return obj.qualifies(pc, cdo);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CDOMObject(pcgen.cdom.base.CDOMObject)

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