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;
}
}
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());
}
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());
}
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);
}
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);
}
}
}
Aggregations