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