Search in sources :

Example 11 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class PCGVer2Parser method parseFeatLine.

/*
	 * ###############################################################
	 * Character Feats methods
	 * ###############################################################
	 */
private void parseFeatLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalFeat", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the Ability key name
    if (it.hasNext()) {
        final PCGElement element = it.next();
        final String abilityKey = EntityEncoder.decode(element.getText());
        /* First, check to see if the PC already has this ability. If so,
			 * then we just need to mod it. Otherwise we need to create a new
			 * one and add it using non-aggregate (when using aggregate, we
			 * get clones of the PCs actual feats, which don't get saved or
			 * preserved) */
        Ability anAbility = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, abilityKey);
        if (anAbility == null) {
            final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
            "Warnings.PCGenParser.CouldntAddAbility", abilityKey);
            warnings.add(msg);
            return;
        }
        CNAbility pcAbility = CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, anAbility);
        if (!anAbility.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
            thePC.addAbility(new CNAbilitySelection(pcAbility), UserSelection.getInstance(), UserSelection.getInstance());
        }
        parseFeatsHandleAppliedToAndSaveTags(it, pcAbility);
        featsPresent = true;
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 12 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class GlobalSpellKnownTest method testConditional.

public void testConditional() {
    Ability source = create(Ability.class, "Source");
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, source);
    ParseResult result = token.parseToken(context, source, "CLASS|Wizard=2|Fireball|PREVARLTEQ:3,MyCasterLevel");
    if (result != ParseResult.SUCCESS) {
        result.printMessages();
        fail("Test Setup Failed");
    }
    finishLoad();
    assertEquals(baseCount(), targetFacetCount());
    CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.AUTOMATIC, source));
    directAbilityFacet.add(id, cas, UserSelection.getInstance());
    assertFalse(containsExpected());
    PCTemplate varsource = create(PCTemplate.class, "VarSource");
    varsource.put(VariableKey.getConstant("MyCasterLevel"), FormulaFactory.getFormulaFor(4.0));
    templateInputFacet.directAdd(id, varsource, null);
    pc.calcActiveBonuses();
    assertTrue(containsExpected());
    assertEquals(baseCount() + 1, targetFacetCount());
    directAbilityFacet.remove(id, cas, UserSelection.getInstance());
    pc.calcActiveBonuses();
    assertEquals(baseCount(), targetFacetCount());
}
Also used : Ability(pcgen.core.Ability) ParseResult(pcgen.rules.persistence.token.ParseResult) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) PCTemplate(pcgen.core.PCTemplate)

Example 13 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractContentTokenTest method testFromAbility.

@Test
public void testFromAbility() throws PersistenceLayerException {
    Ability source = create(Ability.class, "Source");
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, source);
    processToken(source);
    assertEquals(baseCount(), targetFacetCount());
    CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.AUTOMATIC, source));
    directAbilityFacet.add(id, cas, UserSelection.getInstance());
    assertTrue(containsExpected());
    assertEquals(baseCount() + 1, targetFacetCount());
    directAbilityFacet.remove(id, cas, UserSelection.getInstance());
    assertEquals(baseCount(), targetFacetCount());
}
Also used : Ability(pcgen.core.Ability) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Test(org.junit.Test) AbstractTokenModelTest(tokenmodel.testsupport.AbstractTokenModelTest)

Example 14 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class CharacterAbilities method removeCategorisedAbility.

private void removeCategorisedAbility(AbilityCategory cat, Ability ability, Nature nature) {
    CNAbilitySelection cas;
    if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ability), "");
    } else {
        cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ability));
    }
    removeElement(cas);
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 15 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbilitySelectionApplication method dataAdded.

@Override
public void dataAdded(DataFacetChangeEvent<CharID, CNAbilitySelection> dfce) {
    CharID id = dfce.getCharID();
    PlayerCharacter pc = pcFacet.getPC(id);
    CNAbilitySelection cnas = dfce.getCDOMObject();
    CNAbility cna = cnas.getCNAbility();
    Ability ability = cna.getAbility();
    String selection = cnas.getSelection();
    if (selection != null) {
        ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
        if (chooseInfo != null) {
            applySelection(pc, chooseInfo, cna, selection);
        }
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) CharID(pcgen.cdom.enumeration.CharID)

Aggregations

CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)70 CNAbility (pcgen.cdom.content.CNAbility)35 Test (org.junit.Test)28 Ability (pcgen.core.Ability)26 ArrayList (java.util.ArrayList)17 AbilityCategory (pcgen.core.AbilityCategory)7 CDOMReference (pcgen.cdom.base.CDOMReference)6 PlayerCharacter (pcgen.core.PlayerCharacter)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)5 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)5 Nature (pcgen.cdom.enumeration.Nature)5 PCTemplate (pcgen.core.PCTemplate)5 CharID (pcgen.cdom.enumeration.CharID)4 List (java.util.List)3 AbilityChoiceSet (pcgen.cdom.base.ChoiceSet.AbilityChoiceSet)3 SpecialAbility (pcgen.core.SpecialAbility)3 BonusObj (pcgen.core.bonus.BonusObj)3 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)3 HashSet (java.util.HashSet)2