use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class AbstractJunit4CharacterTestCase 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;
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class AspectTest method testSimpleListReplacement.
/**
* Tests simple %LIST replacement.
*/
public void testSimpleListReplacement() {
final Ability pobj = TestHelper.makeAbility("dummy", AbilityCategory.FEAT, "Foo");
Globals.getContext().unconditionallyProcess(pobj, "CHOOSE", "LANG|ALL");
Globals.getContext().unconditionallyProcess(pobj, "MULT", "YES");
Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Foo");
PlayerCharacter pc = getCharacter();
final Aspect aspect = new Aspect(ASPECT_NAME, "%1");
aspect.addVariable("%LIST");
assertEquals("", aspect.getAspectText(pc, buildMap(pobj, AbilityCategory.FEAT, Nature.NORMAL)));
AbilityCategory category = AbilityCategory.FEAT;
CNAbility cna = pcgenFinalize(pobj, "Foo", pc, category);
assertEquals("Foo", aspect.getAspectText(pc, Collections.singletonList(cna)));
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class AspectTest method testComplexVariableReplacement.
/**
* Test complex replacements.
*/
public void testComplexVariableReplacement() {
final Ability dummy = TestHelper.makeAbility("dummy", AbilityCategory.FEAT, "Foo");
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");
Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Associated 3");
dummy.put(VariableKey.getConstant("TestVar"), FormulaFactory.getFormulaFor(2));
PlayerCharacter pc = getCharacter();
final Aspect aspect = new Aspect(ASPECT_NAME, "%1 test %2");
aspect.addVariable("TestVar");
assertEquals("0 test ", aspect.getAspectText(pc, buildMap(dummy, AbilityCategory.FEAT, Nature.NORMAL)));
CNAbility cna = pcgenFinalize(dummy, "Associated 1", pc, AbilityCategory.FEAT);
pcgenFinalize(dummy, "Associated 2", pc, AbilityCategory.FEAT);
assertEquals("2 test ", aspect.getAspectText(pc, Collections.singletonList(cna)));
aspect.addVariable("%LIST");
assertEquals("Replacement of %LIST failed", "2 test Associated 1 and Associated 2", aspect.getAspectText(pc, Collections.singletonList(cna)));
pcgenFinalize(dummy, "Associated 3", pc, AbilityCategory.FEAT);
aspect.addVariable("%LIST");
assertEquals("Replacement of %LIST failed", "2 test Associated 1, Associated 2, Associated 3", aspect.getAspectText(pc, Collections.singletonList(cna)));
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class AbilitySelector method applyChoice.
@Override
public void applyChoice(ChooseDriver obj, AbilitySelection as, PlayerCharacter pc) {
CNAbility cna = CNAbilityFactory.getCNAbility(category.get(), nature, as.getObject());
CNAbilitySelection cnas = new CNAbilitySelection(cna, as.getSelection());
pc.associateSelection(as, cnas);
pc.addAbility(cnas, obj, this);
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class CNAbilitySelection method getAbilitySelectionFromPersistentFormat.
public static CNAbilitySelection getAbilitySelectionFromPersistentFormat(String persistentFormat) {
StringTokenizer st = new StringTokenizer(persistentFormat, Constants.PIPE);
String catString = st.nextToken();
if (!catString.startsWith("CATEGORY=")) {
throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must start with CATEGORY=, found: " + persistentFormat);
}
String cat = catString.substring(9);
AbilityCategory ac = SettingsHandler.getGame().getAbilityCategory(cat);
if (ac == null) {
throw new IllegalArgumentException("Category in getAbilitySelectionFromPersistentFormat " + "must exist found: " + cat);
}
String natureString = st.nextToken();
if (!natureString.startsWith("NATURE=")) {
throw new IllegalArgumentException("Second argument in String in getAbilitySelectionFromPersistentFormat " + "must start with NATURE=, found: " + persistentFormat);
}
String natString = natureString.substring(7);
Nature nat = Nature.valueOf(natString);
String ab = st.nextToken();
Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, ac, ab);
if (a == null) {
throw new IllegalArgumentException("Third argument in String in getAbilitySelectionFromPersistentFormat " + "must be an Ability, but it was not found: " + persistentFormat);
}
String sel = null;
if (st.hasMoreTokens()) {
/*
* No need to check for MULT:YES/NO here, as that is checked
* implicitly in the construction of AbilitySelection below
*/
sel = st.nextToken();
} else if (persistentFormat.endsWith(Constants.PIPE)) {
// Handle the StringTokenizer ignoring blank tokens at the end
sel = "";
}
if (st.hasMoreTokens()) {
throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must have 3 or 4 arguments, but found more: " + persistentFormat);
}
CNAbility cna = CNAbilityFactory.getCNAbility(ac, nat, a);
return new CNAbilitySelection(cna, sel);
}
Aggregations