Search in sources :

Example 11 with SpellInfo

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

the class SpellSupportFacadeImpl method addSpellToCharacter.

/**
	 * Add a spell to 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 added.
	 * @param bookName The book to add the spell to.
	 * @param metamagicFeats List of the metamagic feats that should be applied to this spell.
	 * @return The new SpellNode, or null if the selection was invalid.
	 */
private SpellNode addSpellToCharacter(SpellNode spell, String bookName, List<Ability> metamagicFeats) {
    if (!(spell.getSpell() instanceof SpellFacadeImplem)) {
        return null;
    }
    if (spell.getSpellcastingClass() == null) {
        return null;
    }
    CharacterSpell charSpell = ((SpellFacadeImplem) spell.getSpell()).getCharSpell();
    if (charSpell == null) {
        return null;
    }
    int level = Integer.parseInt(spell.getSpellLevel());
    for (Ability ability : metamagicFeats) {
        level += ability.getSafe(IntegerKey.ADD_SPELL_LEVEL);
    }
    String errorMsg = pc.addSpell(charSpell, metamagicFeats, spell.getSpellcastingClass().getKeyName(), bookName, level, level);
    if (!StringUtils.isEmpty(errorMsg)) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, errorMsg);
        return null;
    }
    SpellInfo spellInfo = charSpell.getSpellInfoFor(bookName, level, metamagicFeats);
    boolean isKnown = Globals.getDefaultSpellBook().equals(bookName);
    SpellFacadeImplem spellImplem = new SpellFacadeImplem(pc, charSpell.getSpell(), charSpell, spellInfo);
    SpellNodeImpl node = new SpellNodeImpl(spellImplem, spell.getSpellcastingClass(), String.valueOf(spellInfo.getActualLevel()), getRootNode(bookName));
    return node;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 12 with SpellInfo

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

the class Gui2InfoFactory method getHTMLInfo.

@Override
public String getHTMLInfo(SpellFacade spell) {
    if (spell == null || !(spell instanceof SpellFacadeImplem)) {
        return EMPTY_STRING;
    }
    SpellFacadeImplem sfi = (SpellFacadeImplem) spell;
    CharacterSpell cs = sfi.getCharSpell();
    SpellInfo si = sfi.getSpellInfo();
    Spell aSpell = cs.getSpell();
    if (aSpell == null) {
        return EMPTY_STRING;
    }
    final HtmlInfoBuilder b = new HtmlInfoBuilder(OutputNameFormatting.piString(aSpell, false));
    if (si != null) {
        // would add [featList]
        final String addString = si.toString();
        if (!addString.isEmpty()) {
            //$NON-NLS-1$
            b.append(" ").append(addString);
        }
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("InfoSpells.level.title", Integer.toString(si.getOriginalLevel()));
    }
    b.appendLineBreak();
    String classlevels = aSpell.getListAsString(ListKey.SPELL_CLASSLEVEL);
    if (StringUtils.isNotEmpty(classlevels)) {
        b.appendI18nElement("in_clClass", classlevels);
        b.appendLineBreak();
    }
    String domainlevels = aSpell.getListAsString(ListKey.SPELL_DOMAINLEVEL);
    if (StringUtils.isNotEmpty(domainlevels)) {
        b.appendI18nElement("in_domains", domainlevels);
        b.appendLineBreak();
    }
    b.appendI18nElement("in_spellSchool", aSpell.getListAsString(ListKey.SPELL_SCHOOL));
    String subSchool = aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL);
    if (StringUtils.isNotEmpty(subSchool)) {
        b.append(" (").append(subSchool).append(")");
    }
    String spellDescriptor = aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR);
    if (StringUtils.isNotEmpty(spellDescriptor)) {
        b.append(" [").append(spellDescriptor).append("]");
    }
    b.appendLineBreak();
    appendFacts(b, aSpell);
    b.appendLineBreak();
    b.appendI18nElement("in_spellComponents", aSpell.getListAsString(ListKey.COMPONENTS));
    b.appendLineBreak();
    b.appendI18nElement("in_spellCastTime", aSpell.getListAsString(ListKey.CASTTIME));
    b.appendLineBreak();
    b.appendI18nElement("in_spellDuration", pc.parseSpellString(cs, aSpell.getListAsString(ListKey.DURATION)));
    b.appendLineBreak();
    b.appendI18nElement("in_spellRange", pc.getSpellRange(cs, si));
    b.appendSpacer();
    b.appendI18nElement("in_spellTarget", pc.parseSpellString(cs, aSpell.getSafe(StringKey.TARGET_AREA)));
    b.appendLineBreak();
    b.appendI18nElement("in_spellSavingThrow", aSpell.getListAsString(ListKey.SAVE_INFO));
    b.appendSpacer();
    b.appendI18nElement("in_spellSpellResist", aSpell.getListAsString(ListKey.SPELL_RESISTANCE));
    b.appendLineBreak();
    b.appendLineBreak();
    b.appendI18nElement("in_descrip", //$NON-NLS-1$
    pc.parseSpellString(//$NON-NLS-1$
    cs, pc.getDescription(aSpell)));
    final String cString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, aSpell.getPrerequisiteList(), false);
    if (!cString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_requirements", cString);
    }
    b.appendLineBreak();
    String spellSource = SourceFormat.getFormattedString(aSpell, Globals.getSourceDisplay(), true);
    if (!spellSource.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_source", spellSource);
    }
    return b.toString();
}
Also used : CharacterSpell(pcgen.core.character.CharacterSpell) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Aggregations

CharacterSpell (pcgen.core.character.CharacterSpell)12 SpellInfo (pcgen.core.character.SpellInfo)12 ArrayList (java.util.ArrayList)7 PCClass (pcgen.core.PCClass)5 Spell (pcgen.core.spell.Spell)5 CNAbility (pcgen.cdom.content.CNAbility)3 Ability (pcgen.core.Ability)3 PObject (pcgen.core.PObject)3 SpellBook (pcgen.core.character.SpellBook)3 Race (pcgen.core.Race)2 SpecialAbility (pcgen.core.SpecialAbility)2 HtmlInfoBuilder (pcgen.gui2.util.HtmlInfoBuilder)2 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 TreeMap (java.util.TreeMap)1 Formula (pcgen.base.formula.Formula)1 HashMapToList (pcgen.base.util.HashMapToList)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMList (pcgen.cdom.base.CDOMList)1 CDOMObject (pcgen.cdom.base.CDOMObject)1