Search in sources :

Example 6 with SpellInfo

use of pcgen.core.character.SpellInfo 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 7 with SpellInfo

use of pcgen.core.character.SpellInfo 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 8 with SpellInfo

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

the class SpellMemToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter aPC, ExportHandler eh) {
    StringBuilder retValue = new StringBuilder();
    // New Token syntax - SPELLMEM.x instead of SPELLMEMx
    final StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    aTok.nextToken();
    final int classNum;
    classNum = Integer.parseInt(aTok.nextToken());
    final int bookNum = Integer.parseInt(aTok.nextToken());
    final int spellLevel = Integer.parseInt(aTok.nextToken());
    final int spellNumber = Integer.parseInt(aTok.nextToken());
    boolean found = false;
    String aLabel = "NAME";
    if (aTok.hasMoreTokens()) {
        aLabel = aTok.nextToken();
    }
    String altLabel = "";
    if (aTok.hasMoreTokens()) {
        altLabel = aTok.nextToken();
    }
    final PObject aObject = aPC.getSpellClassAtIndex(classNum);
    if ((aObject == null) && eh != null && eh.getExistsOnly() && (classNum != -1)) {
        eh.setNoMoreItems(true);
    }
    String bookName = Globals.getDefaultSpellBook();
    if (bookNum > 0) {
        bookName = aPC.getDisplay().getSpellBookNames().get(bookNum);
    }
    if ((aObject != null) || (classNum == -1)) {
        if (classNum == -1) {
            bookName = Globals.getDefaultSpellBook();
        }
        CharacterSpell selectedCSpell = null;
        if (!"".equals(bookName)) {
            Spell aSpell = null;
            if (classNum == -1) {
                // List of all the character's spells (including SLAs)
                final List<CharacterSpell> charSpellList = new ArrayList<>();
                // For each class
                for (PCClass pcClass : aPC.getDisplay().getClassSet()) {
                    // Get the spells provided by the class
                    List<CharacterSpell> aList = aPC.getCharacterSpells(pcClass, null, bookName, spellLevel);
                    for (CharacterSpell cs : aList) {
                        // Add to the list if they are not there already
                        if (!charSpellList.contains(cs)) {
                            charSpellList.add(cs);
                        }
                    }
                }
                // Sort the list
                Collections.sort(charSpellList);
                // Set cs to the spell asked for
                if (spellNumber < charSpellList.size()) {
                    selectedCSpell = charSpellList.get(spellNumber);
                    aSpell = selectedCSpell.getSpell();
                    found = true;
                }
            } else if (aObject != null) {
                // List of spells provided by this PObject
                final List<CharacterSpell> charSpells = aPC.getCharacterSpells(aObject, null, bookName, spellLevel);
                if (spellNumber < charSpells.size()) {
                    selectedCSpell = charSpells.get(spellNumber);
                    aSpell = selectedCSpell.getSpell();
                    found = true;
                }
            } else if (eh != null && eh.getInLabel() && eh.getCheckBefore()) {
                eh.setCanWrite(false);
            }
            // We never found the requested spell
            if (selectedCSpell == null) {
                if (eh != null && eh.getExistsOnly()) {
                    eh.setNoMoreItems(true);
                }
                return retValue.toString();
            }
            // Get the SpellInfo for the selected spell
            final SpellInfo si = selectedCSpell.getSpellInfoFor(bookName, spellLevel);
            if (found && (aSpell != null) && (si != null)) {
                if ("NAME".equals(aLabel) || "OUTPUTNAME".equals(aLabel)) {
                    retValue.append(OutputNameFormatting.getOutputName(aSpell) + si.toString());
                } else if ("BASENAME".equals(aLabel)) {
                    retValue.append(OutputNameFormatting.getOutputName(aSpell));
                } else if ("APPLIEDNAME".equals(aLabel)) {
                    retValue.append(getAppliedName(si));
                } else if ("PPCOST".equals(aLabel)) {
                    if (si.getActualPPCost() != -1) {
                        retValue.append(si.getActualPPCost());
                    }
                } else if ("TIMES".equals(aLabel)) {
                    if (si.getTimes() == SpellInfo.TIMES_AT_WILL) {
                        retValue.append("At Will");
                    } else {
                        retValue.append(String.valueOf(si.getTimes()));
                    }
                } else if ("TIMEUNIT".equals(aLabel)) {
                    retValue.append(String.valueOf(si.getTimeUnit()));
                } else // if (aSpell != null) can't be null
                {
                    if ("RANGE".equals(aLabel)) {
                        retValue.append(aPC.getSpellRange(selectedCSpell, si));
                    } else if ("CASTERLEVEL".equals(aLabel)) {
                        retValue.append(aPC.getCasterLevelForSpell(selectedCSpell));
                    } else if ("CASTINGTIME".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.CASTTIME));
                    } else if ("COMPONENTS".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.COMPONENTS));
                    } else if ("CONCENTRATION".equals(aLabel)) {
                        if (SettingsHandler.getGame().getSpellBaseConcentration() != "") {
                            int concentration = aPC.getConcentration(aSpell, selectedCSpell, si);
                            retValue.append(Delta.toString(concentration));
                        }
                    } else if ("COST".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(ObjectKey.COST).toString());
                    } else if ("DC".equals(aLabel)) {
                        String SaveInfo = aSpell.getListAsString(ListKey.SAVE_INFO);
                        if (!"".equals(SaveInfo) && !"None".equals(SaveInfo) && !"No".equals(SaveInfo)) {
                            int dc = aPC.getDC(aSpell, selectedCSpell, si);
                            retValue.append(String.valueOf(dc));
                        }
                    } else if ("DURATION".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aSpell.getListAsString(ListKey.DURATION));
                        retValue.append(mString);
                    } else if ("DESC".equals(aLabel) || "EFFECT".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aPC.getDescription(aSpell));
                        retValue.append(mString);
                    } else if ("TARGET".equals(aLabel) || "EFFECTYPE".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aSpell.getSafe(StringKey.TARGET_AREA));
                        retValue.append(mString);
                    } else if ("SAVEINFO".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SAVE_INFO));
                    } else if ("SCHOOL".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_SCHOOL));
                    } else if ("SOURCELEVEL".equals(aLabel)) {
                        retValue.append(replaceTokenSpellMemSourceLevel(aSpell, aPC));
                    } else if ("SOURCE".equals(aLabel)) {
                        retValue.append(SourceFormat.getFormattedString(aSpell, Globals.getSourceDisplay(), true));
                    } else if ("SOURCESHORT".equals(aLabel)) {
                        retValue.append(SourceFormat.formatShort(aSpell, 8));
                    } else if ("SOURCEPAGE".equals(aLabel)) {
                        retValue.append(aSpell.get(StringKey.SOURCE_PAGE));
                    } else if ("SOURCEWEB".equals(aLabel)) {
                        String aTemp = aSpell.get(StringKey.SOURCE_WEB);
                        if (aTemp != null && !aTemp.isEmpty()) {
                            retValue.append(aTemp);
                        }
                    } else if ("SOURCELINK".equals(aLabel)) {
                        String aTemp = aSpell.get(StringKey.SOURCE_LINK);
                        if (aTemp != null && !aTemp.isEmpty()) {
                            retValue.append(aTemp);
                        }
                    } else if ("SUBSCHOOL".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL));
                    } else if ("DESCRIPTOR".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR));
                    } else if ("FULLSCHOOL".equals(aLabel)) {
                        String aTemp = aSpell.getListAsString(ListKey.SPELL_SCHOOL);
                        if ((!aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL).isEmpty()) && (!"NONE".equalsIgnoreCase(aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL).trim()))) {
                            aTemp += (" (" + aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL) + ')');
                        }
                        if (!aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR).isEmpty()) {
                            aTemp += (" [" + aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR) + ']');
                        }
                        retValue.append(aTemp);
                    } else if ("SR".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_RESISTANCE));
                    } else if ("SRSHORT".equals(aLabel)) {
                        if ("No".equals(aSpell.getListAsString(ListKey.SPELL_RESISTANCE))) {
                            retValue.append('N');
                        } else {
                            retValue.append('Y');
                        }
                    } else if ("CLASS".equals(aLabel)) {
                        retValue.append(OutputNameFormatting.getOutputName(aObject));
                    } else if ("DCSTAT".equals(aLabel)) {
                        if (aObject instanceof PCClass) {
                            PCClass aClass = (PCClass) aObject;
                            retValue.append(aClass.getSpellBaseStat());
                        }
                    } else if ("TYPE".equals(aLabel)) {
                        PCClass aClass = null;
                        if (aObject instanceof PCClass) {
                            aClass = (PCClass) aObject;
                        }
                        if (aClass != null) {
                            retValue.append(aClass.getSpellType());
                        }
                    } else if (aLabel.startsWith("DESCRIPTION")) {
                        final String sString = getItemDescription("SPELL", aSpell.getKeyName(), aPC.getDescription(aSpell), aPC);
                        if (!altLabel.isEmpty()) {
                            retValue.append(sString.replaceAll("\r?\n", altLabel));
                        } else {
                            retValue.append(sString);
                        }
                    } else if (aLabel.startsWith("BONUSSPELL")) {
                        String sString = "*";
                        if (aLabel.length() > 10) {
                            sString = aLabel.substring(10);
                        }
                        retValue.append(getBonusSpellValue(aPC, spellLevel, sString, altLabel, aObject, bookName, selectedCSpell, aSpell));
                    } else if ("XPCOST".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(IntegerKey.XP_COST));
                    } else if ("CT".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(IntegerKey.CASTING_THRESHOLD));
                    }
                }
            } else if (eh != null && eh.getExistsOnly()) {
                eh.setNoMoreItems(true);
            }
        } else if (eh != null && eh.getExistsOnly()) {
            eh.setNoMoreItems(true);
        }
    }
    return retValue.toString();
}
Also used : ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) StringTokenizer(java.util.StringTokenizer) PObject(pcgen.core.PObject) ArrayList(java.util.ArrayList) HashMapToList(pcgen.base.util.HashMapToList) CDOMList(pcgen.cdom.base.CDOMList) List(java.util.List) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 9 with SpellInfo

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

the class PCCountSpellTimesTermEvaluator method resolve.

@Override
public Float resolve(PlayerCharacter pc) {
    String bookName = (classNum == -1) ? Globals.getDefaultSpellBook() : (bookNum > 0) ? pc.getDisplay().getSpellBookNames().get(bookNum) : Globals.getDefaultSpellBook();
    if (!"".equals(bookName)) {
        List<CharacterSpell> csList = new ArrayList<>();
        if (classNum == -1) {
            csList = new ArrayList<>();
            for (PObject cl : pc.getDisplay().getClassSet()) {
                for (CharacterSpell cs : pc.getCharacterSpells(cl, bookName)) {
                    if (!csList.contains(cs)) {
                        csList.add(cs);
                    }
                }
            }
            Collections.sort(csList);
        } else {
            final PObject pcClass = pc.getSpellClassAtIndex(classNum);
            if (pcClass != null) {
                csList = pc.getCharacterSpells(pcClass, null, bookName, spellLevel);
            }
        }
        boolean found = false;
        SpellInfo si = null;
        if (spellNumber < csList.size()) {
            final CharacterSpell cs = csList.get(spellNumber);
            si = cs.getSpellInfoFor(bookName, spellLevel);
            found = true;
        }
        if (found && (si != null)) {
            return (float) si.getTimes();
        }
    }
    return 0.0f;
}
Also used : PObject(pcgen.core.PObject) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 10 with SpellInfo

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

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