@param acs is the CharacterSpell object containing the spell which is to be modified @param aFeatList is the list of feats to be added to the SpellInfo object @param classKey is the name of the class whose list of character spells will be
(CharacterSpell acs, final List<Ability> aFeatList, final String classKey, final String bookName, final int adjSpellLevel, final int spellLevel)
| 4061 | * value indicates the reason the add function failed. |
| 4062 | */ |
| 4063 | public String addSpell(CharacterSpell acs, final List<Ability> aFeatList, final String classKey, |
| 4064 | final String bookName, final int adjSpellLevel, final int spellLevel) |
| 4065 | { |
| 4066 | if (acs == null) |
| 4067 | { |
| 4068 | return "Invalid parameter to add spell"; |
| 4069 | } |
| 4070 | |
| 4071 | PCClass aClass = null; |
| 4072 | final Spell aSpell = acs.getSpell(); |
| 4073 | |
| 4074 | if ((bookName == null) || (bookName.isEmpty())) |
| 4075 | { |
| 4076 | return "Invalid spell list/book name."; |
| 4077 | } |
| 4078 | |
| 4079 | if (!hasSpellBook(bookName)) |
| 4080 | { |
| 4081 | return "Could not find spell list/book " + bookName; |
| 4082 | } |
| 4083 | |
| 4084 | if (classKey != null) |
| 4085 | { |
| 4086 | aClass = getClassKeyed(classKey); |
| 4087 | |
| 4088 | if ((aClass == null) && (classKey.lastIndexOf('(') >= 0)) |
| 4089 | { |
| 4090 | aClass = getClassKeyed(classKey.substring(0, classKey.lastIndexOf('(')).trim()); |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | // If this is a spellbook, the class doesn't have to be one the PC has |
| 4095 | // already. |
| 4096 | SpellBook spellBook = getSpellBookByName(bookName); |
| 4097 | if (aClass == null && spellBook.getType() == SpellBook.TYPE_SPELL_BOOK) |
| 4098 | { |
| 4099 | aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, |
| 4100 | classKey); |
| 4101 | if ((aClass == null) && (classKey.lastIndexOf('(') >= 0)) |
| 4102 | { |
| 4103 | aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, |
| 4104 | classKey.substring(0, classKey.lastIndexOf('(')).trim()); |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | if (aClass == null) |
| 4109 | { |
| 4110 | return "No class keyed " + classKey; |
| 4111 | } |
| 4112 | |
| 4113 | if (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS) && !bookName.equals(Globals.getDefaultSpellBook())) |
| 4114 | { |
| 4115 | return aClass.getDisplayName() + " can only add to " + Globals.getDefaultSpellBook(); |
| 4116 | } |
| 4117 | |
| 4118 | // Divine spellcasters get no bonus spells at level 0 |
| 4119 | // TODO: allow classes to define how many bonus spells they get each |
| 4120 | // level! |