Add spells from this Kit to the PC @param pc The PC to add the spells to @param aSpell A Spell to add to the PC @param pcClass The class instance the spells are to be added to.
(final PlayerCharacter pc, final KitSpellBookEntry aSpell, final PCClass pcClass)
| 250 | * @param pcClass The class instance the spells are to be added to. |
| 251 | */ |
| 252 | private void updatePCSpells(final PlayerCharacter pc, final KitSpellBookEntry aSpell, final PCClass pcClass) |
| 253 | { |
| 254 | Spell spell = aSpell.getSpell(); |
| 255 | |
| 256 | int spLevel = 99; |
| 257 | |
| 258 | // Check to see if we have any domains that have this spell. |
| 259 | |
| 260 | PObject owner = null; |
| 261 | if (pc.hasDomains()) |
| 262 | { |
| 263 | for (Domain domain : pc.getDomainSet()) |
| 264 | { |
| 265 | List<? extends CDOMList<Spell>> lists = pc.getSpellLists(domain); |
| 266 | int newLevel = SpellLevel.getFirstLevelForKey(spell, lists, pc); |
| 267 | if (newLevel > 0 && newLevel < spLevel) |
| 268 | { |
| 269 | spLevel = newLevel; |
| 270 | owner = domain; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if (spLevel == 99) |
| 276 | { |
| 277 | spLevel = SpellLevel.getFirstLevelForKey(spell, pc.getSpellLists(pcClass), pc); |
| 278 | owner = pcClass; |
| 279 | } |
| 280 | |
| 281 | if (spLevel < 0) |
| 282 | { |
| 283 | Logging.errorPrint( |
| 284 | "SPELLS: " + pcClass.getDisplayName() + " cannot cast spell \"" + spell.getKeyName() + "\""); |
| 285 | |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | final CharacterSpell cs = new CharacterSpell(owner, spell); |
| 290 | final List<CDOMSingleRef<Ability>> modifierList = aSpell.getModifiers(); |
| 291 | int adjustedLevel = spLevel; |
| 292 | List<Ability> metamagicFeatList = new ArrayList<>(); |
| 293 | for (CDOMSingleRef<Ability> feat : modifierList) |
| 294 | { |
| 295 | Ability anAbility = feat.get(); |
| 296 | adjustedLevel += anAbility.getSafe(IntegerKey.ADD_SPELL_LEVEL); |
| 297 | metamagicFeatList.add(anAbility); |
| 298 | } |
| 299 | if (metamagicFeatList.isEmpty()) |
| 300 | { |
| 301 | metamagicFeatList = null; |
| 302 | } |
| 303 | if (!pc.hasSpellBook(aSpell.getBookName())) |
| 304 | { |
| 305 | pc.addSpellBook(aSpell.getBookName()); |
| 306 | } |
| 307 | |
| 308 | for (int numTimes = 0; numTimes < aSpell.getCopies(); numTimes++) |
| 309 | { |
no test coverage detected