availableSpells sk4p 13 Dec 2002 For learning or preparing a spell: Are there slots available at this level or higher Fixes BUG [569517] @param level the level being checked for availability @param aClass the class under consideration @param bookName the name of the
(final int level, final PCClass aClass, final String bookName, final boolean knownLearned, final boolean isSpecialtySpell)
| 5990 | * @return true or false, a new spell can be added |
| 5991 | */ |
| 5992 | public boolean availableSpells(final int level, final PCClass aClass, final String bookName, |
| 5993 | final boolean knownLearned, final boolean isSpecialtySpell) |
| 5994 | { |
| 5995 | boolean available = false; |
| 5996 | FactKey<String> fk = FactKey.valueOf("SpellType"); |
| 5997 | String spelltype = aClass.getResolved(fk); |
| 5998 | final boolean isDivine = ("Divine".equalsIgnoreCase(spelltype)); |
| 5999 | final boolean canUseHigher = knownLearned ? useHigherKnownSlots : useHigherPreppedSlots; |
| 6000 | int knownTot; |
| 6001 | int knownNon; |
| 6002 | int knownSpec; |
| 6003 | int memTot; |
| 6004 | int memNon; |
| 6005 | int memSpec; |
| 6006 | |
| 6007 | // int excTot |
| 6008 | int excNon; |
| 6009 | |
| 6010 | // int excTot |
| 6011 | int excSpec; |
| 6012 | int lowExcSpec = 0; |
| 6013 | int lowExcNon = 0; |
| 6014 | int goodExcSpec = 0; |
| 6015 | int goodExcNon = 0; |
| 6016 | |
| 6017 | for (int i = 0; i < level; ++i) |
| 6018 | { |
| 6019 | // Get the number of castable slots |
| 6020 | if (knownLearned) |
| 6021 | { |
| 6022 | knownNon = this.getSpellSupport(aClass).getKnownForLevel(i, this); |
| 6023 | knownSpec = this.getSpellSupport(aClass).getSpecialtyKnownForLevel(i, this); |
| 6024 | } else |
| 6025 | { |
| 6026 | // Get the number of castable slots |
| 6027 | knownTot = this.getSpellSupport(aClass).getCastForLevel(i, bookName, true, true, this); |
| 6028 | knownNon = this.getSpellSupport(aClass).getCastForLevel(i, bookName, false, true, this); |
| 6029 | knownSpec = knownTot - knownNon; |
| 6030 | } |
| 6031 | |
| 6032 | // Now get the number of spells memorised, total and specialities |
| 6033 | memTot = SpellCountCalc.memorizedSpellForLevelBook(this, aClass, i, bookName); |
| 6034 | memSpec = SpellCountCalc.memorizedSpecialtiesForLevelBook(i, bookName, this, aClass); |
| 6035 | memNon = memTot - memSpec; |
| 6036 | |
| 6037 | // Excess castings |
| 6038 | excSpec = knownSpec - memSpec; |
| 6039 | excNon = knownNon - memNon; |
| 6040 | |
| 6041 | // Now we spend these slots making up any deficits in lower levels |
| 6042 | // |
| 6043 | while ((excNon > 0) && (lowExcNon < 0)) |
| 6044 | { |
| 6045 | --excNon; |
| 6046 | ++lowExcNon; |
| 6047 | } |
| 6048 | |
| 6049 | while ((excSpec > 0) && (lowExcSpec < 0)) |