Search in sources :

Example 31 with CharacterSpell

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();
}
Also used : PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 32 with CharacterSpell

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();
}
Also used : StringTokenizer(java.util.StringTokenizer) CDOMObject(pcgen.cdom.base.CDOMObject) CharacterSpell(pcgen.core.character.CharacterSpell) PCClass(pcgen.core.PCClass) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell)

Example 33 with CharacterSpell

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>&nbsp;");
                b.append(String.valueOf(i));
                //$NON-NLS-1$
                b.append("&nbsp;</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();
}
Also used : ArrayList(java.util.ArrayList) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder) CharacterSpell(pcgen.core.character.CharacterSpell) PCClass(pcgen.core.PCClass) TreeMap(java.util.TreeMap) SpellInfo(pcgen.core.character.SpellInfo)

Example 34 with CharacterSpell

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;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 35 with CharacterSpell

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