Search in sources :

Example 1 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class ChooserUtilities method getConfiguredController.

public static <T> ChoiceManagerList<T> getConfiguredController(final ChooseDriver aPObject, final PlayerCharacter aPC, final AbilityCategory category, List<String> reservedList) {
    ChoiceManagerList aMan = getChoiceManager(aPObject, aPC);
    if (aMan == null) {
        return null;
    }
    if (aPObject instanceof CNAbility) {
        CNAbility driver = (CNAbility) aPObject;
        Ability a = driver.getAbility();
        AbilityCategory cat;
        if (category == null) {
            cat = SettingsHandler.getGame().getAbilityCategory(a.getCategory());
        } else {
            cat = category;
        }
        aMan.setController(new AbilityChooseController(a, cat, aPC, aMan));
        List<CNAbility> abilities = aPC.getMatchingCNAbilities(a);
        for (CNAbility cna : abilities) {
            reservedList.addAll(aPC.getAssociationList(cna));
        }
    } else if (aPObject instanceof Skill) {
        Skill s = (Skill) aPObject;
        aMan.setController(new SkillChooseController(s, aPC));
    }
    return aMan;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) Skill(pcgen.core.Skill) AbilityCategory(pcgen.core.AbilityCategory)

Example 2 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class BonusCalc method bonusTo.

public static double bonusTo(PObject po, String aType, String aName, final Object obj, final Collection<BonusObj> aBonusList, final PlayerCharacter aPC) {
    if ((aBonusList == null) || (aBonusList.isEmpty())) {
        return 0;
    }
    double retVal = 0;
    aType = aType.toUpperCase();
    aName = aName.toUpperCase();
    final String aTypePlusName = new StringBuilder(aType).append('.').append(aName).append('.').toString();
    if (!BonusCalc.dontRecurse && (po instanceof Ability) && (AbilityUtilities.isFeat(obj)) && !Globals.checkRule(RuleConstants.FEATPRE)) {
        // SUCK!  This is horrid, but bonusTo is actually recursive with respect to
        // passesPreReqToGain and there is no other way to do this without decomposing the
        // dependencies.  I am loathe to break working code.
        // This addresses bug #709677 -- Feats give bonuses even if you no longer qualify
        BonusCalc.dontRecurse = true;
        boolean returnZero = false;
        if (!po.qualifies(aPC, po)) {
            returnZero = true;
        }
        BonusCalc.dontRecurse = false;
        if (returnZero) {
            return 0;
        }
    }
    int iTimes = 1;
    if (aPC != null && "VAR".equals(aType)) {
        iTimes = Math.max(1, aPC.getConsolidatedAssociationList(po).size());
    }
    for (BonusObj bonus : aBonusList) {
        String bString = bonus.toString().toUpperCase();
        if (aPC != null && !aPC.getConsolidatedAssociationList(po).isEmpty()) {
            int span = 4;
            int idx = bString.indexOf("%VAR");
            if (idx == -1) {
                idx = bString.indexOf("%LIST|");
                span = 5;
            }
            if (idx >= 0) {
                final String firstPart = bString.substring(0, idx);
                final String secondPart = bString.substring(idx + span);
                for (String assoc : aPC.getConsolidatedAssociationList(po)) {
                    final String xString = new StringBuilder(50).append(firstPart).append(assoc).append(secondPart).toString().toUpperCase();
                    retVal += BonusCalc.calcBonus(po, xString, aType, aName, aTypePlusName, obj, iTimes, bonus, aPC);
                }
            }
        } else {
            retVal += BonusCalc.calcBonus(po, bString, aType, aName, aTypePlusName, obj, iTimes, bonus, aPC);
        }
    }
    return retVal;
}
Also used : Ability(pcgen.core.Ability) BonusObj(pcgen.core.bonus.BonusObj)

Example 3 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class EqModSpellInfo method setSpellInfo.

/**
	 * Here be dragons
	 * 
	 * Builds up a big mad string representing the spell info and then stores it
	 * in the first entry of associated.
	 * 
	 * TODO store this a separate fields or as a spell object or some other way
	 * that doesn't involve turning this into a string and then parsing the
	 * string when we want to do something with the info.
	 * 
	 * @param parent
	 *            TODO
	 * @param spellCastingClass
	 *            a PCClass Object, the class that this spell will be cast as
	 * @param theSpell
	 *            a Spell Object
	 * @param spellVariant
	 *            a string
	 * @param spellType
	 *            arcane, divine, etc.
	 * @param spellLevel
	 *            an int the level of the spell
	 * @param spellCasterLevel
	 *            Caster level the spell is cast at
	 * @param spellMetamagicFeats
	 *            Any metamagic feats applied
	 * @param charges
	 *            how many times can it be cast
	 */
public static void setSpellInfo(Equipment parent, EquipmentModifier eqMod, final CDOMObject spellCastingClass, final Spell theSpell, final String spellVariant, final String spellType, final int spellLevel, final int spellCasterLevel, final Object[] spellMetamagicFeats, final int charges) {
    final StringBuilder spellInfo = new StringBuilder(100);
    spellInfo.append("SPELLNAME[").append(theSpell.getKeyName()).append("] ");
    spellInfo.append("CASTER[").append(spellCastingClass.getKeyName()).append("] ");
    if (!spellVariant.isEmpty()) {
        spellInfo.append("VARIANT[").append(spellVariant).append("] ");
    }
    spellInfo.append("SPELLTYPE[").append(spellType).append("] ");
    spellInfo.append("SPELLLEVEL[").append(spellLevel).append("] ");
    spellInfo.append("CASTERLEVEL[").append(spellCasterLevel).append("] ");
    if (charges > 0) {
        spellInfo.append(s_CHARGES).append('[').append(charges).append("] ");
    }
    if ((spellMetamagicFeats != null) && (spellMetamagicFeats.length > 0)) {
        /*
			 * Have considered whether this needs to be expanded to include
			 * Category. These are actually Feats and the information is only
			 * used by toString()
			 */
        spellInfo.append("METAFEATS[");
        for (int i = 0; i < spellMetamagicFeats.length; i++) {
            final Ability aFeat = (Ability) spellMetamagicFeats[i];
            if (i != 0) {
                spellInfo.append(", ");
            }
            spellInfo.append(aFeat.getKeyName());
        }
        spellInfo.append("] ");
    }
    parent.addAssociation(eqMod, spellInfo.toString());
}
Also used : Ability(pcgen.core.Ability)

Example 4 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class GrantedAbilityFacet method getCNAbilities.

public Collection<CNAbility> getCNAbilities(CharID id, Ability ability) {
    Set<CNAbility> returnList = new HashSet<>();
    List<List<SourcedCNAS>> list = getList(id);
    if (list != null) {
        Category<Ability> cat = ability.getCDOMCategory();
        for (List<SourcedCNAS> array : list) {
            CNAbility cna = array.get(0).cnas.getCNAbility();
            if (cna.getAbilityCategory().getParentCategory().equals(cat) && cna.getAbilityKey().equals(ability.getKeyName())) {
                returnList.add(cna);
            }
        }
    }
    return returnList;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 5 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class NPCGenerator method getFeatWeights.

private WeightedCollection<Ability> getFeatWeights(final PCClass aClass) {
    WeightedCollection<Ability> weightedCollection = theConfiguration.getAbilityWeights(aClass.getKeyName(), AbilityCategory.FEAT);
    if (weightedCollection == null) {
        weightedCollection = new WeightedCollection<>();
        // any other type
        for (Ability ability : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, AbilityCategory.FEAT).getAllObjects()) {
            int weight = 1;
            if (ability.getSafe(ObjectKey.VISIBILITY) != Visibility.DEFAULT) {
                continue;
            }
            if (//$NON-NLS-1$
            ability.isType("GENERAL")) {
                weight = 5;
            }
            weightedCollection.add(ability, weight);
        }
    }
    return weightedCollection;
}
Also used : Ability(pcgen.core.Ability)

Aggregations

Ability (pcgen.core.Ability)279 CNAbility (pcgen.cdom.content.CNAbility)128 AbilityCategory (pcgen.core.AbilityCategory)60 PlayerCharacter (pcgen.core.PlayerCharacter)54 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)43 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)25 ParseResult (pcgen.rules.persistence.token.ParseResult)21 HashMapToList (pcgen.base.util.HashMapToList)15 PCClass (pcgen.core.PCClass)15 Spell (pcgen.core.spell.Spell)15 StringTokenizer (java.util.StringTokenizer)14 TestContext (plugin.lsttokens.editcontext.testsupport.TestContext)13 LoadContext (pcgen.rules.context.LoadContext)12 SpecialAbility (pcgen.core.SpecialAbility)11 CharacterSpell (pcgen.core.character.CharacterSpell)11 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)11 List (java.util.List)10 CDOMObject (pcgen.cdom.base.CDOMObject)10 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10