use of pcgen.cdom.base.ConcretePersistentTransitionChoice in project pcgen by PCGen.
the class ClassSkillsTokenTest method testUnparseSingleRanked.
@Test
public void testUnparseSingleRanked() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
addSingleRef(refs, "TestWP1");
ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
primaryProf.addToListFor(ListKey.ADD, tc);
tc.setChoiceActor(new ClassSkillChoiceActor(fighter, 3));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "TestWP1,AUTORANK=3");
}
use of pcgen.cdom.base.ConcretePersistentTransitionChoice in project pcgen by PCGen.
the class AbilityTokenTest method testUnparseComplex.
@Test
public void testUnparseComplex() throws PersistenceLayerException {
List<CDOMReference<Ability>> refs = createSingle("TestWP1");
AbilityRefChoiceSet rcs = new AbilityRefChoiceSet(CDOMDirectSingleRef.getRef(AbilityCategory.FEAT), refs, Nature.VIRTUAL);
assert (rcs.getGroupingState().isValid());
AbilityChoiceSet cs = new AbilityChoiceSet(getSubToken().getTokenName(), rcs);
cs.setTitle("Virtual Feat Selection");
PersistentTransitionChoice<CNAbilitySelection> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.getFormulaFor(3));
tc.allowStack(true);
tc.setStackLimit(2);
tc.setChoiceActor(subtoken);
primaryProf.addToListFor(ListKey.ADD, tc);
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "3|FEAT|VIRTUAL|STACKS=2,TestWP1");
}
use of pcgen.cdom.base.ConcretePersistentTransitionChoice in project pcgen by PCGen.
the class RemoveFeatToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
AbilityCategory category = AbilityCategory.FEAT;
Nature nature = Nature.NORMAL;
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String activeValue = sep.next();
Formula count;
if (!sep.hasNext()) {
count = FormulaFactory.ONE;
} else {
count = FormulaFactory.getFormulaFor(activeValue);
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
return new ParseResult.Fail("Count in " + getFullName() + " must be > 0", context);
}
activeValue = sep.next();
}
if (sep.hasNext()) {
return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value, context);
}
if (isEmpty(activeValue) || hasIllegalSeparator(',', activeValue)) {
return ParseResult.INTERNAL_ERROR;
}
List<CDOMReference<Ability>> refs = new ArrayList<>();
List<PrimitiveChoiceSet<CNAbilitySelection>> pcs = new ArrayList<>();
ParsingSeparator tok = new ParsingSeparator(activeValue, ',');
tok.addGroupingPair('[', ']');
tok.addGroupingPair('(', ')');
boolean foundAny = false;
boolean foundOther = false;
ReferenceManufacturer<Ability> rm = context.getReferenceContext().getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT);
while (tok.hasNext()) {
CDOMReference<Ability> ab = null;
String token = tok.next();
if ("CHOICE".equals(token) || Constants.LST_ANY.equals(token)) {
foundAny = true;
ab = rm.getAllReference();
} else if (token.startsWith(Constants.LST_CLASS_DOT) || token.startsWith(Constants.LST_CLASS_EQUAL)) {
String className = token.substring(6);
if (className.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " must have Class name after " + token, context);
}
CDOMSingleRef<PCClass> pcc = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, className);
AbilityFromClassChoiceSet acs = new AbilityFromClassChoiceSet(pcc);
pcs.add(acs);
} else {
foundOther = true;
ab = TokenUtilities.getTypeOrPrimitive(rm, token);
if (ab == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid reference: " + token, context);
}
}
if (ab != null) {
refs.add(ab);
}
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
}
if (!refs.isEmpty()) {
AbilityRefChoiceSet rcs = new AbilityRefChoiceSet(CDOMDirectSingleRef.getRef(category), refs, nature);
pcs.add(rcs);
}
if (pcs.isEmpty()) {
return new ParseResult.Fail("Internal Error: " + getFullName() + " did not have any references: " + value, context);
}
PrimitiveChoiceSet<CNAbilitySelection> ascs;
if (pcs.size() == 1) {
ascs = pcs.get(0);
} else {
ascs = new CompoundOrChoiceSet<>(pcs, Constants.COMMA);
}
ChoiceSet<CNAbilitySelection> cs = new ChoiceSet<>(getTokenName(), ascs, true);
cs.setTitle("Select for removal");
PersistentTransitionChoice<CNAbilitySelection> tc = new ConcretePersistentTransitionChoice<>(cs, count);
context.getObjectContext().addToList(obj, ListKey.REMOVE, tc);
tc.allowStack(true);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.ConcretePersistentTransitionChoice in project pcgen by PCGen.
the class TemplateFeatToken method process.
@Override
public boolean process(LoadContext context, PCTemplate pct) {
List<CDOMReference<Ability>> list = pct.getListFor(ListKey.FEAT_TOKEN_LIST);
if (list != null && !list.isEmpty()) {
AbilityRefChoiceSet rcs = new AbilityRefChoiceSet(CDOMDirectSingleRef.getRef(AbilityCategory.FEAT), list, Nature.NORMAL);
ChoiceSet<CNAbilitySelection> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Feat Choice");
PersistentTransitionChoice<CNAbilitySelection> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
context.getObjectContext().put(pct, ObjectKey.TEMPLATE_FEAT, tc);
tc.setChoiceActor(this);
}
return true;
}
Aggregations