Search in sources :

Example 46 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbilityToken method allow.

@Override
public boolean allow(CNAbilitySelection choice, PlayerCharacter pc, boolean allowStack) {
    CNAbility cna = choice.getCNAbility();
    Ability ability = cna.getAbility();
    if (!ability.getSafe(ObjectKey.VISIBILITY).equals(Visibility.DEFAULT)) {
        return false;
    }
    boolean isVirtual = Nature.VIRTUAL.equals(cna.getNature());
    if (!isVirtual && !ability.qualifies(pc, ability)) {
        return false;
    }
    String selection = choice.getSelection();
    // Avoid any already selected
    return !AbilityUtilities.alreadySelected(pc, ability, selection, allowStack);
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 47 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbstractCharacterTestCase method applyAbility.

public static CNAbility applyAbility(PlayerCharacter character, AbilityCategory cat, Ability a, String assoc) {
    if (a.getCDOMCategory() == null) {
        fail("Attempt to apply an Ability " + a.getKeyName() + " that never received a Category");
    }
    CNAbility cna = CNAbilityFactory.getCNAbility(cat, Nature.NORMAL, a);
    CNAbilitySelection cnas = new CNAbilitySelection(cna, assoc);
    character.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
    return cna;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 48 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbilityToken method getList.

private <R> List<R> getList(PlayerCharacter pc, Ability a) {
    // workaround for cloning issue
    List<R> availableList = new ArrayList<>();
    List<CNAbility> theFeats = pc.getMatchingCNAbilities(a);
    for (CNAbility ability : theFeats) {
        @SuppressWarnings("unchecked") List<? extends R> list = (List<? extends R>) pc.getDetailedAssociations(ability);
        if (list != null) {
            availableList.addAll(list);
        }
    }
    return availableList;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 49 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class DescriptionTest method testComplexVariableReplacement.

/**
	 * Test complex replacements.
	 */
public void testComplexVariableReplacement() {
    final Ability dummy = new Ability();
    dummy.setKeyName("Dummy");
    Globals.getContext().unconditionallyProcess(dummy, "CATEGORY", "FEAT");
    Globals.getContext().unconditionallyProcess(dummy, "CHOOSE", "LANG|ALL");
    Globals.getContext().unconditionallyProcess(dummy, "MULT", "YES");
    Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Associated 1");
    Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Associated 2");
    dummy.put(VariableKey.getConstant("TestVar"), FormulaFactory.getFormulaFor(2));
    Globals.getContext().getReferenceContext().resolveReferences(null);
    PlayerCharacter pc = getCharacter();
    final Description desc = new Description("%1 test %3 %2");
    desc.addVariable("TestVar");
    dummy.addToListFor(ListKey.DESCRIPTION, desc);
    List<CNAbility> wrappedDummy = Collections.singletonList(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, dummy));
    assertEquals("0 test  ", desc.getDescription(pc, wrappedDummy));
    AbilityCategory category = AbilityCategory.FEAT;
    CNAbility cna = pcgenFinalize(dummy, "Associated 1", pc, category);
    pcgenFinalize(dummy, "Associated 2", pc, category);
    assertEquals("2 test  ", desc.getDescription(pc, wrappedDummy));
    desc.addVariable("%CHOICE");
    dummy.addToListFor(ListKey.DESCRIPTION, desc);
    List<CNAbility> wrappedPCA = Collections.singletonList(cna);
    assertEquals("2 test  Associated 1", desc.getDescription(pc, wrappedPCA));
    desc.addVariable("%LIST");
    assertEquals("Replacement of %LIST failed", "2 test Associated 1 and Associated 2 Associated 1", desc.getDescription(pc, wrappedPCA));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility)

Example 50 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class ModifyfeatchoiceToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Ability ability, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    List<CDOMReference<Ability>> refs = new ArrayList<>();
    ReferenceManufacturer<Ability> rm = context.getReferenceContext().getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT);
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<Ability> ref = TokenUtilities.getTypeOrPrimitive(rm, token);
        if (ref == null) {
            return ParseResult.INTERNAL_ERROR;
        }
        refs.add(ref);
    }
    ReferenceChoiceSet<Ability> rcs = new ReferenceChoiceSet<>(refs);
    ModifyChoiceDecorator gfd = new ModifyChoiceDecorator(rcs);
    ChoiceSet<CNAbility> cs = new ChoiceSet<>(getTokenName(), gfd);
    TabInfo ti = context.getReferenceContext().silentlyGetConstructedCDOMObject(TabInfo.class, Tab.ABILITIES.toString());
    String singularName = ti.getResolvedName();
    if (singularName.endsWith("s")) {
        singularName = singularName.substring(0, singularName.length() - 1);
    }
    cs.setTitle("Select a " + singularName + " to modify");
    TransitionChoice<CNAbility> tc = new ConcreteTransitionChoice<>(cs, FormulaFactory.ONE);
    tc.setRequired(false);
    context.getObjectContext().put(ability, ObjectKey.MODIFY_CHOICE, tc);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) CNAbility(pcgen.cdom.content.CNAbility) StringTokenizer(java.util.StringTokenizer) TabInfo(pcgen.cdom.content.TabInfo) ModifyChoiceDecorator(pcgen.cdom.choiceset.ModifyChoiceDecorator) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Aggregations

CNAbility (pcgen.cdom.content.CNAbility)131 Ability (pcgen.core.Ability)77 ArrayList (java.util.ArrayList)37 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)28 AbilityCategory (pcgen.core.AbilityCategory)26 Test (org.junit.Test)21 HashMapToList (pcgen.base.util.HashMapToList)16 List (java.util.List)15 PlayerCharacter (pcgen.core.PlayerCharacter)9 Language (pcgen.core.Language)7 HashSet (java.util.HashSet)5 Nature (pcgen.cdom.enumeration.Nature)5 SpecialAbility (pcgen.core.SpecialAbility)5 BonusObj (pcgen.core.bonus.BonusObj)5 BigDecimal (java.math.BigDecimal)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 LoadContext (pcgen.rules.context.LoadContext)4 StringTokenizer (java.util.StringTokenizer)3 GenericMapToList (pcgen.base.util.GenericMapToList)3 PCClass (pcgen.core.PCClass)3