Search in sources :

Example 1 with ClassSkillChoiceActor

use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.

the class ClassSkillsLevelTokenTest 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");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 2 with ClassSkillChoiceActor

use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.

the class ClassSkillsLevelTokenTest 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");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 3 with ClassSkillChoiceActor

use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.

the class ClassSkillsLevelTokenTest method testUnparseUntrained.

@Test
public void testUnparseUntrained() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("UNTRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, 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() + '|' + "UNTRAINED");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 4 with ClassSkillChoiceActor

use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.

the class ClassSkillsTokenTest method testUnparseUntrained.

@Test
public void testUnparseUntrained() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("UNTRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, 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() + '|' + "UNTRAINED");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 5 with ClassSkillChoiceActor

use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.

the class ClassSkillsLevelToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCClassLevel 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);
    // TODO This is a hack, to get this to work pre-CDOM
    PCClass parent = (PCClass) obj.get(ObjectKey.TOKEN_PARENT);
    ClassSkillChoiceActor actor = new ClassSkillChoiceActor(parent, autoRank);
    tc.setChoiceActor(actor);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    return ParseResult.SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ParseResult(pcgen.rules.persistence.token.ParseResult) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) PCClass(pcgen.core.PCClass) StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) ParsingSeparator(pcgen.base.text.ParsingSeparator) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Aggregations

ArrayList (java.util.ArrayList)15 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)15 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)14 Skill (pcgen.core.Skill)13 CDOMReference (pcgen.cdom.base.CDOMReference)12 ChoiceSet (pcgen.cdom.base.ChoiceSet)12 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)12 Test (org.junit.Test)11 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)10 Formula (pcgen.base.formula.Formula)4 PersistentTransitionChoice (pcgen.cdom.base.PersistentTransitionChoice)3 StringTokenizer (java.util.StringTokenizer)2 ParsingSeparator (pcgen.base.text.ParsingSeparator)2 PCClass (pcgen.core.PCClass)2 ParseResult (pcgen.rules.persistence.token.ParseResult)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 UnreachableError (pcgen.base.lang.UnreachableError)1 Campaign (pcgen.core.Campaign)1