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