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