MCPcopy Create free account
hub / github.com/PCGen/pcgen / delSpell

Method delSpell

code/src/java/pcgen/core/PlayerCharacter.java:4703–4754  ·  view source on GitHub ↗

Return value indicates whether or not a spell was deleted. @param si @param aClass @param bookName @return String

(SpellInfo si, final PCClass aClass, final String bookName)

Source from the content-addressed store, hash-verified

4701 * @return String
4702 */
4703 public String delSpell(SpellInfo si, final PCClass aClass, final String bookName)
4704 {
4705 if ((bookName == null) || (bookName.isEmpty()))
4706 {
4707 return "Invalid spell book name.";
4708 }
4709
4710 if (aClass == null)
4711 {
4712 return "Error: Class is null";
4713 }
4714
4715 final CharacterSpell acs = si.getOwner();
4716
4717 final boolean isDefault = bookName.equals(Globals.getDefaultSpellBook());
4718
4719 // yes, you can remove spells from the default spellbook,
4720 // but they will just get added back in when the character
4721 // is re-loaded. But, allow them to do it anyway, just in case
4722 // there is some weird spell that keeps getting loaded by
4723 // accident (or is saved in the .pcg file)
4724 if (isDefault
4725 && this.getSpellSupport(aClass).isAutoKnownSpell(acs.getSpell(), si.getActualLevel(), false, this))
4726 {
4727 Logging.errorPrint(
4728 "Notice: removing " + acs.getSpell().getDisplayName() + " even though it is an auto known spell");
4729 }
4730
4731 SpellBook spellBook = getSpellBookByName(bookName);
4732 if (spellBook.getType() == SpellBook.TYPE_SPELL_BOOK)
4733 {
4734 int pagesPerSpell = si.getNumPages() / si.getTimes();
4735 spellBook.setNumPagesUsed(spellBook.getNumPagesUsed() - pagesPerSpell);
4736 spellBook.setNumSpells(spellBook.getNumSpells() - 1);
4737 si.setNumPages(si.getNumPages() - pagesPerSpell);
4738 }
4739 si.setTimes(si.getTimes() - 1);
4740
4741 if (si.getTimes() <= 0)
4742 {
4743 acs.removeSpellInfo(si);
4744 }
4745
4746 // Remove the spell form the character's class instance if it
4747 // is no longer present in any book
4748 if (acs.getInfoList().isEmpty())
4749 {
4750 removeCharacterSpell(aClass, acs);
4751 }
4752
4753 return "";
4754 }
4755
4756 /**
4757 * Calculate different kinds of bonuses to saves. possible tokens are

Callers 2

testAddSpellsMethod · 0.95

Calls 15

getDefaultSpellBookMethod · 0.95
getSpellSupportMethod · 0.95
getSpellMethod · 0.95
errorPrintMethod · 0.95
getSpellBookByNameMethod · 0.95
getTypeMethod · 0.95
setNumPagesUsedMethod · 0.95
getNumPagesUsedMethod · 0.95
setNumSpellsMethod · 0.95
getNumSpellsMethod · 0.95
removeSpellInfoMethod · 0.95
getInfoListMethod · 0.95

Tested by 1

testAddSpellsMethod · 0.76