Search in sources :

Example 1 with SpellLikeAbility

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);
            }
        }
    }
}
Also used : Formula(pcgen.base.formula.Formula) CDOMObject(pcgen.cdom.base.CDOMObject) SpellLikeAbility(pcgen.cdom.content.SpellLikeAbility) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference) Spell(pcgen.core.spell.Spell) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 2 with SpellLikeAbility

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);
    }
}
Also used : Formula(pcgen.base.formula.Formula) PlayerCharacter(pcgen.core.PlayerCharacter) SpellBook(pcgen.core.character.SpellBook) Race(pcgen.core.Race) SpellLikeAbility(pcgen.cdom.content.SpellLikeAbility) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Aggregations

Formula (pcgen.base.formula.Formula)2 SpellLikeAbility (pcgen.cdom.content.SpellLikeAbility)2 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 CharID (pcgen.cdom.enumeration.CharID)1 PlayerCharacter (pcgen.core.PlayerCharacter)1 Race (pcgen.core.Race)1 CharacterSpell (pcgen.core.character.CharacterSpell)1 SpellBook (pcgen.core.character.SpellBook)1 SpellInfo (pcgen.core.character.SpellInfo)1 Spell (pcgen.core.spell.Spell)1