use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCClass obj, String value) {
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.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);
}
ParseResult pr = checkSeparatorsAndNonEmpty(',', activeValue);
if (!pr.passed()) {
return pr;
}
List<CDOMReference<Skill>> refs = new ArrayList<>();
StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
CDOMGroupRef<Skill> allRef = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
Integer autoRank = null;
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
if (Constants.LST_ALL.equals(tokText) || Constants.LST_ANY.equals(tokText)) {
refs.add(allRef);
} else {
if (Constants.LST_UNTRAINED.equals(tokText)) {
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>(tokText, SKILL_CLASS, allRef, ObjectKey.USE_UNTRAINED, Boolean.TRUE);
omr.returnIncludesNulls(true);
refs.add(omr);
} else if (Constants.LST_TRAINED.equals(tokText)) {
refs.add(new ObjectMatchingReference<>(tokText, SKILL_CLASS, allRef, ObjectKey.USE_UNTRAINED, Boolean.FALSE));
} else if (Constants.LST_EXCLUSIVE.equals(tokText)) {
refs.add(new ObjectMatchingReference<>(tokText, SKILL_CLASS, allRef, ObjectKey.EXCLUSIVE, Boolean.TRUE));
} else if (Constants.LST_NONEXCLUSIVE.equals(tokText) || Constants.LST_CROSS_CLASS.equals(tokText)) {
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>(tokText, SKILL_CLASS, allRef, ObjectKey.EXCLUSIVE, Boolean.FALSE);
omr.returnIncludesNulls(true);
refs.add(omr);
} else if (tokText.startsWith("AUTORANK=")) {
if (autoRank != null) {
return new ParseResult.Fail("Cannot have two " + "AUTORANK= items in " + getFullName() + ": " + value, context);
}
String rankString = tokText.substring(9);
try {
autoRank = Integer.decode(rankString);
if (autoRank <= 0) {
return new ParseResult.Fail("Expected AUTORANK= to be" + " greater than zero, found: " + autoRank, context);
}
} catch (NumberFormatException e) {
return new ParseResult.Fail("Expected AUTORANK= to have" + " an integer value, found: " + rankString, context);
}
} else {
CDOMReference<Skill> skref = TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, tokText);
if (skref == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getFullName() + ": " + value + " had an invalid reference: " + tokText, context);
}
refs.add(skref);
}
}
}
if (refs.isEmpty()) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains no skill reference: " + value, context);
}
ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
}
ChoiceSet<Skill> cs = new ChoiceSet<>(getTokenName(), rcs, true);
PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, count);
ClassSkillChoiceActor actor = new ClassSkillChoiceActor(obj, autoRank);
tc.setChoiceActor(actor);
context.getObjectContext().addToList(obj, ListKey.ADD, tc);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class AddClassSkillsTest method testGetChoicesListWithClassSkill.
/**
* Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
*/
@Test
public void testGetChoicesListWithClassSkill() {
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
String classPCCText = "CLASS:Cleric HD:8 TYPE:Base.PC ABB:Clr\n" + "CLASS:Cleric STARTSKILLPTS:2 CSKILL:KEY_Knowledge (Dungeoneering)";
PCClass po;
try {
po = parsePCClassText(classPCCText, source);
} catch (PersistenceLayerException e) {
throw new UnreachableError(e);
}
getCharacter().incrementClassLevel(1, po, false);
PCTemplate pct = new PCTemplate();
Skill bluff = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, "KEY_Bluff");
pct.addToListFor(ListKey.CSKILL, CDOMDirectSingleRef.getRef(bluff));
getCharacter().addTemplate(pct);
Globals.getContext().unconditionallyProcess(po, "ADD", "CLASSSKILLS|2|KEY_Bluff,KEY_Listen,KEY_Knowledge (Arcana)");
assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
List<PersistentTransitionChoice<?>> choiceList = po.getListFor(ListKey.ADD);
assertEquals(1, choiceList.size());
TransitionChoice<?> choice = choiceList.get(0);
Collection<?> choiceSet = choice.getChoices().getSet(getCharacter());
assertEquals(3, choiceSet.size());
Set<Object> limitedSet = new HashSet<>();
ClassSkillChoiceActor csca = new ClassSkillChoiceActor(po, 0);
for (Object sc : choiceSet) {
if (csca.allow((Skill) sc, getCharacter(), true)) {
limitedSet.add(sc);
}
}
assertEquals(2, limitedSet.size());
assertEquals(2, choice.getCount().resolve(getCharacter(), ""));
List<String> choiceStrings = new ArrayList<>();
for (Object o : limitedSet) {
choiceStrings.add(o.toString());
}
assertTrue(choiceStrings.contains("Listen"));
assertTrue(choiceStrings.contains("Knowledge (Arcana)"));
}
use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsLevelTokenTest method testUnparseTrained.
@Test
public void testUnparseTrained() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("TRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, Boolean.FALSE);
omr.returnIncludesNulls(true);
refs.add(omr);
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, null));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "TRAINED");
}
use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsLevelTokenTest method testUnparseNonExclusive.
@Test
public void testUnparseNonExclusive() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("NONEXCLUSIVE", Skill.class, getAllRef(), ObjectKey.EXCLUSIVE, Boolean.FALSE);
omr.returnIncludesNulls(true);
refs.add(omr);
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, null));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "NONEXCLUSIVE");
}
use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsTokenTest method testUnparseExclusive.
@Test
public void testUnparseExclusive() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("EXCLUSIVE", Skill.class, getAllRef(), ObjectKey.EXCLUSIVE, Boolean.TRUE);
omr.returnIncludesNulls(true);
refs.add(omr);
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, null));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "EXCLUSIVE");
}
Aggregations