@Override public void grantAbilities(MOB mob, boolean isBorrowedClass) { super.grantAbilities(mob, isBorrowedClass); // if he already has one, don't give another! if (mob.playerStats() != null) { final int classLevel = mob.baseCharStats().getClassLevel(this); if (classLevel < 2) return; if ((classLevel % 2) != 0) return; int maxSkills = classLevel / 2; // now only give one, for current level, respecting alignment! // first, get a list of all skills you don't qualify for that you MIGHT have gained or will // gain final List<Ability> choices = new Vector<Ability>(); for (final Enumeration<Ability> a = CMClass.abilities(); a.hasMoreElements(); ) { final Ability A = a.nextElement(); final int lql = CMLib.ableMapper().lowestQualifyingLevel(A.ID()); if ((CMLib.ableMapper().qualifyingLevel(mob, A) <= 0) && (lql < 25) && (lql > 0) && (!CMLib.ableMapper().getSecretSkill(A.ID())) && (CMLib.ableMapper().qualifiesByAnyCharClass(A.ID())) && (CMLib.ableMapper().availableToTheme(A.ID(), Area.THEME_FANTASY, true)) && (!CMLib.ableMapper().qualifiesOnlyByClan(mob, A)) && (!CMLib.ableMapper().qualifiesOnlyByRace(mob, A)) && (A.isAutoInvoked() || ((A.triggerStrings() != null) && (A.triggerStrings().length > 0)))) choices.add(A); } // now count those you already have for (int a = choices.size() - 1; a >= 0; a--) { final Ability A = choices.get(a); if (mob.fetchAbility(A.ID()) != null) maxSkills--; } if (maxSkills < 1) // if that reduced you to 0, you are done. return; // now eliminate those you already have, and those that are // above your level, if you are <25 for (int a = choices.size() - 1; a >= 0; a--) { final Ability A = choices.get(a); final int lql = CMLib.ableMapper().lowestQualifyingLevel(A.ID()); if ((mob.fetchAbility(ID()) != null) || ((lql != classLevel) && (lql != classLevel - 1) && (classLevel < 25))) choices.remove(a); } if (choices.size() == 0) return; final Ability A = choices.get(CMLib.dice().roll(1, choices.size(), -1)); if (A != null) giveMobAbility(mob, A, 0, "", isBorrowedClass); } else { final List<AbilityMapper.AbilityMapping> V = CMLib.ableMapper() .getUpToLevelListings(ID(), mob.charStats().getClassLevel(ID()), false, false); for (final AbilityMapper.AbilityMapping able : V) { final Ability A = CMClass.getAbility(able.abilityID); if ((A != null) && (!CMLib.ableMapper().getAllQualified(ID(), true, A.ID())) && (!CMLib.ableMapper().getDefaultGain(ID(), true, A.ID()))) giveMobAbility( mob, A, CMLib.ableMapper().getDefaultProficiency(ID(), true, A.ID()), CMLib.ableMapper().getDefaultParm(ID(), true, A.ID()), isBorrowedClass); } } }