use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.
the class SpellListBookToken method getToken.
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
StringBuilder retValue = new StringBuilder();
SpellListTokenParams params = new SpellListTokenParams(tokenSource, SpellListToken.SPELLTAG_BOOK);
final PObject aObject = pc.getSpellClassAtIndex(params.getClassNum());
if (aObject != null) {
String bookName = Globals.getDefaultSpellBook();
if (params.getBookNum() > 0) {
bookName = pc.getDisplay().getSpellBookNames().get(params.getBookNum());
}
final List<CharacterSpell> spells = pc.getCharacterSpells(aObject, null, bookName, params.getLevel());
boolean needcomma = false;
for (CharacterSpell cs : spells) {
if (needcomma) {
retValue.append(", ");
}
needcomma = true;
retValue.append(OutputNameFormatting.getOutputName(cs.getSpell()));
}
if (!needcomma && eh != null && eh.getExistsOnly()) {
eh.setNoMoreItems(true);
}
}
return retValue.toString();
}
use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.
the class SpellListClassToken method getToken.
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
int i;
StringBuilder retValue = new StringBuilder();
// Determine the tag type
final StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
aTok.nextToken();
i = Integer.parseInt(aTok.nextToken());
//
final CDOMObject aObject = pc.getSpellClassAtIndex(i);
if (aObject != null) {
PCClass aClass = null;
if (aObject instanceof PCClass) {
aClass = (PCClass) aObject;
}
if ((aClass != null)) {
if (tokenSource.endsWith(".CASTERLEVEL")) {
retValue.append(pc.getCasterLevelForClass(aClass));
} else if (tokenSource.endsWith(".CONCENTRATION")) {
if (SettingsHandler.getGame().getSpellBaseConcentration() != "") {
Spell sp = new Spell();
CharacterSpell cs = new CharacterSpell(aClass, sp);
int concentration = pc.getConcentration(sp, cs, aClass, 0, 0, aClass);
retValue.append(Delta.toString(concentration));
}
} else if (tokenSource.endsWith(".LEVEL")) {
retValue.append(String.valueOf(pc.getDisplay().getLevel(aClass) + (int) pc.getTotalBonusTo("PCLEVEL", aClass.getKeyName())));
} else {
retValue.append(OutputNameFormatting.getOutputName(aObject));
}
}
}
return retValue.toString();
}
use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.
the class Gui2InfoFactory method produceSpellListInfo.
/**
* Produce the HTML info label for a prepared spell list.
* @param book The spell list being output.
* @return The HTML info for the list.
*/
private String produceSpellListInfo(SpellBook spelllist) {
final HtmlInfoBuilder b = new HtmlInfoBuilder(spelllist.getName());
//$NON-NLS-1$
b.append(" (");
b.append(spelllist.getTypeName());
//$NON-NLS-1$
b.append(")");
b.appendLineBreak();
if (spelllist.getDescription() != null) {
//$NON-NLS-1$
b.appendI18nElement("in_descrip", spelllist.getDescription());
b.appendLineBreak();
}
// Look at each spell on each spellcasting class
for (PCClass pcClass : charDisplay.getClassSet()) {
Map<Integer, Integer> spellCountMap = new TreeMap<>();
int highestSpellLevel = -1;
Collection<? extends CharacterSpell> sp = charDisplay.getCharacterSpells(pcClass);
List<CharacterSpell> classSpells = new ArrayList<>(sp);
// Add in the spells granted by objects
pc.addBonusKnownSpellsToList(pcClass, classSpells);
for (CharacterSpell charSpell : classSpells) {
for (SpellInfo spellInfo : charSpell.getInfoList()) {
if (!spelllist.getName().equals(spellInfo.getBook())) {
continue;
}
int level = spellInfo.getActualLevel();
int count = spellCountMap.containsKey(level) ? spellCountMap.get(level) : 0;
count += spellInfo.getTimes();
spellCountMap.put(level, count);
if (level > highestSpellLevel) {
highestSpellLevel = level;
}
}
}
if (!spellCountMap.isEmpty()) {
//$NON-NLS-1$
b.append("<table border=1><tr><td><font size=-1><b>");
b.append(OutputNameFormatting.piString(pcClass, false));
//$NON-NLS-1$
b.append("</b></font></td>");
for (int i = 0; i <= highestSpellLevel; ++i) {
//$NON-NLS-1$
b.append("<td><font size=-2><b><center> ");
b.append(String.valueOf(i));
//$NON-NLS-1$
b.append(" </b></center></font></td>");
}
//$NON-NLS-1$
b.append("</tr>");
//$NON-NLS-1$
b.append("<tr><td><font size=-1><b>Prepared</b></font></td>");
for (int i = 0; i <= highestSpellLevel; ++i) {
//$NON-NLS-1$
b.append("<td><font size=-1><center>");
b.append(String.valueOf(spellCountMap.get(i) == null ? 0 : spellCountMap.get(i)));
//$NON-NLS-1$
b.append("</center></font></td>");
}
//$NON-NLS-1$
b.append("</tr></table>");
b.appendLineBreak();
}
}
return b.toString();
}
use of pcgen.core.character.CharacterSpell 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.CharacterSpell 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