Search in sources :

Example 66 with Ability

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

the class Gui2InfoFactory method getChoices.

@Override
public String getChoices(AbilityFacade abilityFacade) {
    if (abilityFacade == null || !(abilityFacade instanceof Ability)) {
        return EMPTY_STRING;
    }
    final Ability ability = (Ability) abilityFacade;
    final StringBuilder result = new StringBuilder(100);
    Collection<CNAbility> targetAbilities = pc.getMatchingCNAbilities(ability);
    if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
        processAbilities(result, targetAbilities, chooseInfo);
    }
    return result.toString();
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 67 with Ability

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

the class SourceFileLoader method createLangBonusObject.

public static void createLangBonusObject(LoadContext context) {
    Ability a = context.getReferenceContext().constructCDOMObject(Ability.class, "*LANGBONUS");
    context.getReferenceContext().reassociateCategory(AbilityCategory.LANGBONUS, a);
    a.put(ObjectKey.INTERNAL, true);
    context.unconditionallyProcess(a, "CHOOSE", "LANG|!PC,LANGBONUS");
    context.unconditionallyProcess(a, "VISIBLE", "NO");
    context.unconditionallyProcess(a, "AUTO", "LANG|%LIST");
    context.unconditionallyProcess(a, "MULT", "YES");
}
Also used : Ability(pcgen.core.Ability)

Example 68 with Ability

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

the class FeatLoader method loadDefaultFeats.

/**
	 * This method loads the default feats with the first feat source.
	 * @param context
	 * @param firstSource CampaignSourceEntry first loaded by this loader
	 */
private void loadDefaultFeats(LoadContext context, CampaignSourceEntry firstSource) {
    Ability wpFeat = context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, Constants.INTERNAL_WEAPON_PROF);
    if (wpFeat == null) {
        /* Add catch-all feat for weapon proficiencies that cannot be granted as part
			 * of a Feat eg. Simple weapons should normally be applied to the Simple
			 * Weapon Proficiency feat, but it does not allow multiples (either all or
			 * nothing).  So monk class weapons will get dumped into this bucket.  */
        String aLine = Constants.INTERNAL_WEAPON_PROF + "\tOUTPUTNAME:Weapon Proficiency\tTYPE:General" + "\tVISIBLE:NO\tMULT:YES\tSTACK:YES\tCHOOSE:NOCHOICE" + "\tDESC:You attack with this specific weapon normally," + " non-proficiency incurs a -4 to hit penalty." + "\tSOURCELONG:PCGen Internal";
        try {
            parseLine(context, null, aLine, firstSource);
        } catch (PersistenceLayerException ple) {
            Logging.errorPrint("Unable to parse the internal default feats '" + aLine + "': " + ple.getMessage());
        }
        defaultFeatsLoaded = true;
    }
}
Also used : Ability(pcgen.core.Ability) PersistenceLayerException(pcgen.persistence.PersistenceLayerException)

Example 69 with Ability

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

the class AbilityLoader method includeObject.

/**
	 * This method should be called by finishObject implementations in
	 * order to check if the parsed object is affected by an INCLUDE or
	 * EXCLUDE request.
	 *
	 * @param cdo PObject to determine whether to include in
	 *         Globals etc.
	 * @return boolean true if the object should be included, else false
	 *         to exclude it
	 */
@Override
protected final boolean includeObject(SourceEntry source, CDOMObject cdo) {
    // Null check; never add nulls or objects without a name/key name
    if ((cdo == null) || (cdo.getDisplayName() == null) || (cdo.getDisplayName().trim().isEmpty()) || (cdo.getKeyName() == null) || (cdo.getKeyName().trim().isEmpty())) {
        return false;
    }
    Ability ability = (Ability) cdo;
    // If includes were present, check includes for given object
    List<String> includeItems = source.getIncludeItems();
    if (!includeItems.isEmpty()) {
        if (includeItems.contains(ability.getCategory() + "," + ability.getKeyName())) {
            return true;
        }
        if (includeItems.contains(ability.getKeyName())) {
            Logging.deprecationPrint("Deprecated INCLUDE value when loading " + source.getURI() + " . Abilities (including feats) must always have " + "categories (e.g. " + "INCLUDE:CATEGORY=cat1,key1,key2|CATEGORY=cat2,key3 ).");
            return true;
        }
        return false;
    }
    // If excludes were present, check excludes for given object
    List<String> excludeItems = source.getExcludeItems();
    if (!excludeItems.isEmpty()) {
        if (excludeItems.contains(ability.getCategory() + "," + ability.getKeyName())) {
            return false;
        }
        if (excludeItems.contains(ability.getKeyName())) {
            Logging.deprecationPrint("Deprecated EXCLUDE value when loading " + source.getURI() + " . Abilities (including feats) must always have " + "categories (e.g. " + "EXCLUDE:CATEGORY=cat1,key1,key2|CATEGORY=cat2,key3 ).");
            return false;
        }
        return true;
    }
    return true;
}
Also used : Ability(pcgen.core.Ability)

Example 70 with Ability

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

the class Aspect method getAspectText.

/**
	 * Gets the name string after having substituting all variables.
	 * 
	 * @param aPC The PlayerCharacter used to evaluate formulas.
	 * @param abilities the abilities for which the Aspect text should be compiled
	 * 
	 * @return The fully substituted description string.
	 */
public String getAspectText(final PlayerCharacter aPC, List<CNAbility> abilities) {
    final StringBuilder buf = new StringBuilder(50);
    if ((abilities == null) || (abilities.isEmpty())) {
        return "";
    }
    Ability sampleAbilityObject = abilities.get(0).getAbility();
    if (!qualifies(aPC, sampleAbilityObject)) {
        return "";
    }
    for (final String comp : theComponents) {
        if (comp.startsWith(VAR_MARKER)) {
            final int ind = Integer.parseInt(comp.substring(VAR_MARKER.length()));
            if (theVariables == null || ind > theVariables.size()) {
                buf.append(Constants.EMPTY_STRING);
                continue;
            }
            final String var = theVariables.get(ind - 1);
            if (var.equals(VAR_NAME)) {
                buf.append(sampleAbilityObject.getOutputName());
            } else if (var.equals(VAR_LIST)) {
                List<String> assocList = new ArrayList<>();
                for (CNAbility cna : abilities) {
                    assocList.addAll(aPC.getAssociationList(cna));
                }
                String joinString;
                if (assocList.size() == 2) {
                    joinString = " and ";
                } else {
                    joinString = ", ";
                }
                Collections.sort(assocList);
                buf.append(StringUtil.joinToStringBuilder(assocList, joinString));
            } else if (//$NON-NLS-1$
            var.startsWith("\"")) {
                buf.append(var.substring(1, var.length() - 1));
            } else {
                //$NON-NLS-1$
                buf.append(aPC.getVariableValue(var, "Aspect").intValue());
            }
        } else {
            buf.append(comp);
        }
    }
    return buf.toString();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) ArrayList(java.util.ArrayList) List(java.util.List)

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