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