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);
}
}
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);
}
}
}
}
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);
}
}
}
}
}
}
}
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);
}
}
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);
}
Aggregations