Search in sources :

Example 6 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 7 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)

Example 8 with Ability

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

the class Aspect method printAspect.

public static String printAspect(PlayerCharacter pc, AspectName key, List<CNAbility> abilities, boolean printName) {
    if (abilities.isEmpty()) {
        return "";
    }
    Ability sampleAbilityObject = abilities.get(0).getAbility();
    StringBuilder buff = new StringBuilder(50);
    List<Aspect> aspects = sampleAbilityObject.get(MapKey.ASPECT, key);
    Aspect aspect = lastPassingAspect(aspects, pc, sampleAbilityObject);
    if (aspect != null) {
        if (printName) {
            buff.append(aspect.getName()).append(": ");
        }
        buff.append(aspect.getAspectText(pc, abilities));
    }
    return buff.toString();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 9 with Ability

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

the class CNAbilitySelectionUtilities method canCoExist.

public static boolean canCoExist(CNAbilitySelection cnas1, CNAbilitySelection cnas2) {
    CNAbility cna = cnas1.getCNAbility();
    Ability a = cna.getAbility();
    CNAbility ocna = cnas2.getCNAbility();
    if (!ocna.getAbilityCategory().getParentCategory().equals(cna.getAbilityCategory().getParentCategory())) {
        //This test is only required because Ability only checks key :/
        return true;
    }
    if (!ocna.getAbility().equals(a)) {
        //Different abilities, so doesn't matter...
        return true;
    }
    //Same ability here
    if (!a.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        //If MULT:NO, then can't coexist...
        return false;
    }
    //MULT:YES here
    if (a.getSafe(ObjectKey.STACKS)) {
        //Allows stacking, so always true (give or take NUMCHOICES?)
        return true;
    }
    //STACK:NO here
    if (cnas1.getSelection().equals(cnas2.getSelection())) {
        //enforce STACK:NO
        return false;
    }
    return true;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 10 with Ability

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

the class AbilityTargetSelector method applyChoice.

@Override
public void applyChoice(ChooseDriver obj, T choice, PlayerCharacter pc) {
    Ability ab = ability.get();
    ChooseInformation ci = ab.get(ObjectKey.CHOOSE_INFO);
    detailedApply(obj, ci, choice, pc);
}
Also used : Ability(pcgen.core.Ability) ChooseInformation(pcgen.cdom.base.ChooseInformation)

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