Search in sources :

Example 11 with SpellBook

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

the class PCGVer2Creator method appendSpellBookLines.

/*
	 * ###############################################################
	 * Spell List Information methods
	 * ###############################################################
	 */
/*
	 * #Spell List Information
	 * SPELLLIST:sourceclassname|spelllistentry|spelllistentry
	 */
private void appendSpellBookLines(StringBuilder buffer) {
    for (SpellBook book : charDisplay.getSpellBooks()) {
        String bookName = book.getName();
        if (!bookName.equals(Globals.getDefaultSpellBook()) && !bookName.equals(Constants.INNATE_SPELL_BOOK_NAME)) {
            buffer.append(IOConstants.TAG_SPELLBOOK).append(':');
            buffer.append(book.getName());
            buffer.append('|');
            buffer.append(IOConstants.TAG_TYPE).append(':');
            buffer.append(book.getType());
            if (book.getName().equals(thePC.getSpellBookNameToAutoAddKnown())) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_AUTOADDKNOWN).append(':');
                buffer.append('Y');
            }
            buffer.append(IOConstants.LINE_SEP);
        }
    }
}
Also used : SpellBook(pcgen.core.character.SpellBook)

Example 12 with SpellBook

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

the class PCGVer2Parser method parseSpellBookLines.

/*
	 * ###############################################################
	 * Spell Book Information methods
	 * ###############################################################
	 */
/*
	 * #Spell Book Information
	 * SPELLBOOK:bookname|TYPE:spellbooktype
	 */
private void parseSpellBookLines(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal Spell book ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    SpellBook aSpellBook = null;
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        if (IOConstants.TAG_SPELLBOOK.equals(tag)) {
            final String bookName = EntityEncoder.decode(element.getText());
            aSpellBook = new SpellBook(bookName, SpellBook.TYPE_PREPARED_LIST);
        } else if (IOConstants.TAG_TYPE.equals(tag)) {
            try {
                aSpellBook.setType(Integer.parseInt(element.getText()));
            } catch (NumberFormatException nfe) {
                // nothing we can do about it
                final String message = "Spell book " + aSpellBook.getName() + " had an illegal type: " + element.getText() + " in line " + line;
                warnings.add(message);
            }
        } else if (IOConstants.TAG_AUTOADDKNOWN.equals(tag)) {
            if (IOConstants.VALUE_Y.equals(element.getText())) {
                thePC.setSpellBookNameToAutoAddKnown(aSpellBook.getName());
            }
        }
    }
    if (aSpellBook == null) {
        warnings.add("Internal Error: Did not build Spell Book from SPELLBOOK line");
    } else {
        thePC.addSpellBook(aSpellBook);
    }
}
Also used : SpellBook(pcgen.core.character.SpellBook)

Example 13 with SpellBook

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

the class SpellBookFacet method dataAdded.

/**
	 * Adds a SpellBook to this facet if the Equipment added to a Player
	 * Character was a SpellBook.
	 * 
	 * Triggered when one of the Facets to which SpellBookFacet listens fires a
	 * DataFacetChangeEvent to indicate a piece of Equipment was added to a
	 * Player Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, Equipment> dfce) {
    Equipment eq = dfce.getCDOMObject();
    if (eq.isType(Constants.TYPE_SPELLBOOK)) {
        CharID id = dfce.getCharID();
        String baseBookname = eq.getName();
        String bookName = eq.getName();
        int qty = (int) eq.qty();
        for (int i = 0; i < qty; i++) {
            if (i > 0) {
                bookName = baseBookname + " #" + (i + 1);
            }
            SpellBook book = getBookNamed(id, bookName);
            if (book == null) {
                book = new SpellBook(bookName, SpellBook.TYPE_SPELL_BOOK);
            }
            book.setEquip(eq);
            if (!containsBookNamed(id, book.getName())) {
                add(id, book);
            }
        }
    }
}
Also used : Equipment(pcgen.core.Equipment) SpellBook(pcgen.core.character.SpellBook) CharID(pcgen.cdom.enumeration.CharID)

Example 14 with SpellBook

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

the class SpellSupportFacadeImpl method getRootNode.

private RootNodeImpl getRootNode(String bookName) {
    if (Globals.getDefaultSpellBook().equals(bookName)) {
        return null;
    }
    RootNodeImpl rootNode = rootNodeMap.get(bookName);
    if (rootNode == null) {
        SpellBook book = charDisplay.getSpellBookByName(bookName);
        if (book == null) {
            return null;
        }
        rootNode = new RootNodeImpl(book);
        rootNodeMap.put(bookName, rootNode);
    }
    return rootNode;
}
Also used : SpellBook(pcgen.core.character.SpellBook)

Aggregations

SpellBook (pcgen.core.character.SpellBook)14 CharacterSpell (pcgen.core.character.CharacterSpell)6 Spell (pcgen.core.spell.Spell)4 SpellInfo (pcgen.core.character.SpellInfo)3 ArrayList (java.util.ArrayList)2 PCClass (pcgen.core.PCClass)2 PObject (pcgen.core.PObject)2 StringTokenizer (java.util.StringTokenizer)1 Formula (pcgen.base.formula.Formula)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 CNAbility (pcgen.cdom.content.CNAbility)1 SpellLikeAbility (pcgen.cdom.content.SpellLikeAbility)1 CharID (pcgen.cdom.enumeration.CharID)1 ClassSource (pcgen.cdom.helper.ClassSource)1 ClassSpellList (pcgen.cdom.list.ClassSpellList)1 Ability (pcgen.core.Ability)1 Domain (pcgen.core.Domain)1 Equipment (pcgen.core.Equipment)1 PlayerCharacter (pcgen.core.PlayerCharacter)1