use of pcgen.cdom.content.SpellLikeAbility 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);
}
}
}
}
use of pcgen.cdom.content.SpellLikeAbility in project pcgen by PCGen.
the class ActiveSpellsFacet method process.
/**
* Currently used as a global reset for the spell list, since
* ActiveSpellsFacet does not currently listen to all scenarios which can
* alter Spells granted to a Player Character.
*
* Use of this method outside this facet is discouraged, as the long term
* goal is to get all of the processing for Spells into this Facet.
* Therefore, use of this global reset indicates incomplete implementation
* of Spells processing in this facet, and should be an indication that
* additional work is required in order to enhance the capability of this
* facet to appropriately update the Spells for a Player Character.
*
* @param id
* The CharID identifying the Player Character that requires a
* reset on the list of spells granted to the Player Character.
*/
public void process(CharID id) {
Race race = raceFacet.get(id);
removeAll(id, race);
PlayerCharacter pc = trackingFacet.getPC(id);
for (SpellLikeAbility sla : spellsFacet.getQualifiedSet(id)) {
Formula times = sla.getCastTimes();
int resolvedTimes = formulaResolvingFacet.resolve(id, times, sla.getQualifiedKey()).intValue();
String book = sla.getSpellBook();
final CharacterSpell cs = new CharacterSpell(race, sla.getSpell());
cs.setFixedCasterLevel(sla.getFixedCasterLevel());
SpellInfo si = cs.addInfo(0, resolvedTimes, book);
si.setTimeUnit(sla.getCastTimeUnit());
si.setFixedDC(sla.getDC());
pc.addSpellBook(new SpellBook(book, SpellBook.TYPE_INNATE_SPELLS));
add(id, cs, race);
}
}
Aggregations