Search in sources :

Example 11 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class SpellSupportFacadeImpl method removeSpellFromCharacter.

/**
	 * Remove a spell from the named book for the character. The request will be 
	 * validated and any errors shown to the user by the UIDelegate.
	 * 
	 * @param spell The spell to be removed.
	 * @param bookName The book to remove the spell from.
	 * @return True if the removal worked, false if the selection was invalid.
	 */
private boolean removeSpellFromCharacter(SpellNode spell, String bookName) {
    if (!(spell.getSpell() instanceof SpellFacadeImplem)) {
        return false;
    }
    SpellFacadeImplem sfi = (SpellFacadeImplem) spell.getSpell();
    CharacterSpell charSpell = sfi.getCharSpell();
    SpellInfo spellInfo = sfi.getSpellInfo();
    if (charSpell == null || spellInfo == null) {
        return false;
    }
    final String errorMsg = pc.delSpell(spellInfo, (PCClass) spell.getSpellcastingClass(), bookName);
    if (errorMsg.length() > 0) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, errorMsg);
        ShowMessageDelegate.showMessageDialog(errorMsg, Constants.APPLICATION_NAME, MessageType.ERROR);
        return false;
    }
    return true;
}
Also used : CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 12 with CharacterSpell

use of pcgen.core.character.CharacterSpell 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)

Example 13 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class KitSpells method updatePCSpells.

/**
	 * Add spells from this Kit to the PC
	 *
	 * @param  pc       The PC to add the spells to
	 * @param  aSpell   A Spell to add to the PC
	 * @param  pcClass  The class instance the spells are to be added to.
	 */
private void updatePCSpells(final PlayerCharacter pc, final KitSpellBookEntry aSpell, final PCClass pcClass) {
    Spell spell = aSpell.getSpell();
    int spLevel = 99;
    // Check to see if we have any domains that have this spell.
    PObject owner = null;
    if (pc.hasDomains()) {
        for (Domain domain : pc.getDomainSet()) {
            List<? extends CDOMList<Spell>> lists = pc.getSpellLists(domain);
            int newLevel = SpellLevel.getFirstLevelForKey(spell, lists, pc);
            if (newLevel > 0 && newLevel < spLevel) {
                spLevel = newLevel;
                owner = domain;
            }
        }
    }
    if (spLevel == 99) {
        spLevel = SpellLevel.getFirstLevelForKey(spell, pc.getSpellLists(pcClass), pc);
        owner = pcClass;
    }
    if (spLevel < 0) {
        Logging.errorPrint("SPELLS: " + pcClass.getDisplayName() + " cannot cast spell \"" + spell.getKeyName() + "\"");
        return;
    }
    final CharacterSpell cs = new CharacterSpell(owner, spell);
    final List<CDOMSingleRef<Ability>> modifierList = aSpell.getModifiers();
    int adjustedLevel = spLevel;
    List<Ability> metamagicFeatList = new ArrayList<>();
    for (CDOMSingleRef<Ability> feat : modifierList) {
        Ability anAbility = feat.get();
        adjustedLevel += anAbility.getSafe(IntegerKey.ADD_SPELL_LEVEL);
        metamagicFeatList.add(anAbility);
    }
    if (metamagicFeatList.size() <= 0) {
        metamagicFeatList = null;
    }
    if (!pc.hasSpellBook(aSpell.getBookName())) {
        pc.addSpellBook(aSpell.getBookName());
    }
    for (int numTimes = 0; numTimes < aSpell.getCopies(); numTimes++) {
        final String aString = pc.addSpell(cs, metamagicFeatList, pcClass.getKeyName(), aSpell.getBookName(), adjustedLevel, spLevel);
        if (!aString.isEmpty()) {
            Logging.errorPrint("Add spell failed:" + aString);
            return;
        }
    }
}
Also used : Ability(pcgen.core.Ability) ArrayList(java.util.ArrayList) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell) Domain(pcgen.core.Domain)

Example 14 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class NPCGenerator method selectSpell.

private void selectSpell(final PlayerCharacter aPC, final PCClass aClass, final Domain aDomain, final String aBookName, final WeightedCollection<Spell> aSpellList, final int aLevel) {
    boolean added = false;
    while (!added) {
        final Spell spell = aSpellList.getRandomValue();
        // TODO - How do I check if this spell is prohibiited?
        final CharacterSpell cs;
        if (aDomain != null) {
            cs = new CharacterSpell(aDomain, spell);
        } else {
            cs = new CharacterSpell(aClass, spell);
        }
        final String aString = aPC.addSpell(cs, new ArrayList<>(), aClass.getKeyName(), aBookName, aLevel, aLevel);
        if (!aString.isEmpty()) {
            //$NON-NLS-1$
            Logging.debugPrint("Add spell failed: " + aString);
        } else {
            added = true;
        }
    }
}
Also used : CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 15 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class SpellMemTokenTest method testSpontaneousCasterKnown.

/**
	 * Test the SPELLMEM tag for a spontaneous caster. Checks that the
	 * list of known spells is auto populated and that the spell can be
	 * retrieved correctly.
	 */
public void testSpontaneousCasterKnown() {
    PlayerCharacter character = getCharacter();
    String spellBook = "Travel";
    character.setRace(human);
    character.incrementClassLevel(1, arcaneClass, true);
    PCClass ac = character.getClassKeyed(arcaneClass.getKeyName());
    CharacterSpell aCharacterSpell = new CharacterSpell(ac, testSpell);
    aCharacterSpell.addInfo(1, 1, null);
    character.addCharacterSpell(ac, aCharacterSpell);
    character.addSpellBook(spellBook);
    List<CharacterSpell> spellList = character.getCharacterSpells(ac, testSpell, "", 1);
    CharacterSpell charSpell = spellList.get(0);
    String result = character.addSpell(charSpell, null, arcaneClass.getKeyName(), Globals.getDefaultSpellBook(), 1, 1);
    assertEquals("No CHA, so should reject attempt to add spell", "You can only learn 0 spells for level 1 " + "\nand there are no higher-level slots available.", result);
    SpellMemToken token = new SpellMemToken();
    assertEquals("Retrieve spell from known list of arcane caster.", "Test Spell", token.getToken("SPELLMEM.0.0.1.0.NAME", character, null));
}
Also used : SpellMemToken(plugin.exporttokens.SpellMemToken) PlayerCharacter(pcgen.core.PlayerCharacter) CharacterSpell(pcgen.core.character.CharacterSpell) PCClass(pcgen.core.PCClass)

Aggregations

CharacterSpell (pcgen.core.character.CharacterSpell)41 Spell (pcgen.core.spell.Spell)22 ArrayList (java.util.ArrayList)16 PCClass (pcgen.core.PCClass)12 SpellInfo (pcgen.core.character.SpellInfo)12 PObject (pcgen.core.PObject)7 SpellBook (pcgen.core.character.SpellBook)6 Ability (pcgen.core.Ability)5 StringTokenizer (java.util.StringTokenizer)4 CNAbility (pcgen.cdom.content.CNAbility)4 Formula (pcgen.base.formula.Formula)3 CDOMList (pcgen.cdom.base.CDOMList)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 PlayerCharacter (pcgen.core.PlayerCharacter)3 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)2 CDOMReference (pcgen.cdom.base.CDOMReference)2 ClassSource (pcgen.cdom.helper.ClassSource)2 SpellSchool (pcgen.cdom.identifier.SpellSchool)2 ClassSpellList (pcgen.cdom.list.ClassSpellList)2 DomainSpellList (pcgen.cdom.list.DomainSpellList)2