use of pcgen.cdom.content.AbilitySelection in project pcgen by PCGen.
the class CollectionToAbilitySelection method addMultiplySelectableAbility.
private Collection<AbilitySelection> addMultiplySelectableAbility(final PlayerCharacter aPC, Ability ability, String subName) {
boolean isPattern = false;
String nameRoot = null;
if (subName != null) {
final int percIdx = subName.indexOf('%');
if (percIdx > -1) {
isPattern = true;
nameRoot = subName.substring(0, percIdx);
} else if (!subName.isEmpty()) {
nameRoot = subName;
}
}
ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
final List<String> availableList = getAvailableList(aPC, chooseInfo);
if (nameRoot != null && !nameRoot.isEmpty()) {
for (int n = availableList.size() - 1; n >= 0; --n) {
final String aString = availableList.get(n);
if (!aString.startsWith(nameRoot)) {
availableList.remove(n);
}
}
if (isPattern && !availableList.isEmpty()) {
availableList.add(nameRoot);
}
}
List<AbilitySelection> returnList = new ArrayList<>(availableList.size());
for (String s : availableList) {
returnList.add(new AbilitySelection(ability, s));
}
return returnList;
}
use of pcgen.cdom.content.AbilitySelection in project pcgen by PCGen.
the class ChooseFeatSelectionToken method decodeChoice.
@Override
public AbilitySelection decodeChoice(LoadContext context, String s) {
Ability ability = context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, s);
if (ability == null) {
List<String> choices = new ArrayList<>();
String baseKey = AbilityUtilities.getUndecoratedName(s, choices);
ability = context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, baseKey);
if (ability == null) {
throw new IllegalArgumentException("String in decodeChoice " + "must be a Feat Key " + "(or Feat Key with Selection if appropriate), was: " + s);
}
return new AbilitySelection(ability, choices.get(0));
} else if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
/*
* MULT:YES, CHOOSE:NOCHOICE can land here
*
* TODO There needs to be better validation at some point that this
* is proper (meaning it is actually CHOOSE:NOCHOICE!)
*/
return new AbilitySelection(ability, "");
} else {
return new AbilitySelection(ability, null);
}
}
use of pcgen.cdom.content.AbilitySelection in project pcgen by PCGen.
the class AbilitySelectionTokenTest method testDecodeChoice.
@Test
public void testDecodeChoice() {
try {
pca.decodeChoice(context, "Category=Special Ability|ItemName");
fail();
} catch (IllegalArgumentException e) {
// OK
}
Ability item = construct("ItemName");
AbilitySelection as = new AbilitySelection(item, null);
assertEquals(as, pca.decodeChoice(context, "CATEGORY=FEAT|ItemName"));
Ability paren = construct("ParenName (test)");
as = new AbilitySelection(paren, null);
assertEquals(as, pca.decodeChoice(context, "CATEGORY=Feat|ParenName (test)"));
Ability sel = construct("ChooseName");
sel.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
StringToken st = new plugin.lsttokens.choose.StringToken();
ParseResult pr = st.parseToken(Globals.getContext(), sel, "selection|Acrobatics");
assertTrue(pr.passed());
Globals.getContext().commit();
as = new AbilitySelection(sel, "selection");
assertEquals(as, pca.decodeChoice(context, "CATEGORY=Feat|ChooseName|selection"));
}
use of pcgen.cdom.content.AbilitySelection in project pcgen by PCGen.
the class AbilitySelectionTokenTest method testEncodeChoice.
@Test
public void testEncodeChoice() {
Ability item = construct("ItemName");
AbilitySelection as = new AbilitySelection(item, null);
assertEquals("CATEGORY=FEAT|ItemName", pca.encodeChoice(as));
Ability paren = construct("ParenName (test)");
as = new AbilitySelection(paren, null);
assertEquals("CATEGORY=FEAT|ParenName (test)", pca.encodeChoice(as));
Ability sel = construct("ChooseName");
sel.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
StringToken st = new plugin.lsttokens.choose.StringToken();
ParseResult pr = st.parseToken(Globals.getContext(), sel, "selection|Acrobatics");
assertTrue(pr.passed());
Globals.getContext().commit();
as = new AbilitySelection(sel, "selection");
assertEquals("CATEGORY=FEAT|ChooseName|selection", pca.encodeChoice(as));
}
use of pcgen.cdom.content.AbilitySelection in project pcgen by PCGen.
the class CollectionToAbilitySelection method processAbility.
private void processAbility(PlayerCharacter character, Set<AbilitySelection> returnSet, AbilityWithChoice awc) {
Ability a = awc.getAbility();
if (infiniteLoopDetectionStack.contains(a)) {
Stack<Ability> current = new Stack<>();
current.addAll(infiniteLoopDetectionStack);
Logging.errorPrint("Error: Circular Expansion Found: " + reportCircularExpansion(current));
return;
}
try {
infiniteLoopDetectionStack.push(a);
if (a.getSafe(ObjectKey.MULTIPLE_ALLOWED).booleanValue()) {
returnSet.addAll(addMultiplySelectableAbility(character, a, awc.getChoice()));
} else {
returnSet.add(new AbilitySelection(a, null));
}
} finally {
infiniteLoopDetectionStack.pop();
}
}
Aggregations