Search in sources :

Example 16 with ReferenceChoiceSet

use of pcgen.cdom.choiceset.ReferenceChoiceSet in project pcgen by PCGen.

the class ClassSkillsTokenTest 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");
}
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 17 with ReferenceChoiceSet

use of pcgen.cdom.choiceset.ReferenceChoiceSet in project pcgen by PCGen.

the class ClassSkillsTokenTest 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");
}
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 18 with ReferenceChoiceSet

use of pcgen.cdom.choiceset.ReferenceChoiceSet 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");
}
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 19 with ReferenceChoiceSet

use of pcgen.cdom.choiceset.ReferenceChoiceSet in project pcgen by PCGen.

the class LanguageToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject 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<Language>> refs = new ArrayList<>();
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        CDOMReference<Language> lang = TokenUtilities.getReference(context, LANGUAGE_CLASS, tokText);
        if (lang == null) {
            return new ParseResult.Fail("  Error was encountered while parsing " + getFullName() + ": " + value + " had an invalid reference: " + tokText, context);
        }
        refs.add(lang);
    }
    ReferenceChoiceSet<Language> rcs = new ReferenceChoiceSet<>(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    ChoiceSet<Language> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Language Choice");
    PersistentTransitionChoice<Language> tc = new ConcretePersistentTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) ParsingSeparator(pcgen.base.text.ParsingSeparator) Language(pcgen.core.Language) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 20 with ReferenceChoiceSet

use of pcgen.cdom.choiceset.ReferenceChoiceSet in project pcgen by PCGen.

the class SkillToken method parseToken.

@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
    if (isEmpty(value)) {
        return new ParseResult.Fail("Value in " + getFullName() + " may not be empty", context);
    }
    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;
    }
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<Skill> ref;
        if (Constants.LST_ANY.equalsIgnoreCase(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
        } else {
            ref = TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, token);
            if (ref == null) {
                return new ParseResult.Fail("  Error was encountered while parsing " + getFullName() + ": " + token + " is not a valid reference: " + value, context);
            }
        }
        refs.add(ref);
    }
    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<>("SKILL", rcs, true);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    tc.setChoiceActor(this);
    tc.allowStack(true);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) ParsingSeparator(pcgen.base.text.ParsingSeparator) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Aggregations

ChoiceSet (pcgen.cdom.base.ChoiceSet)21 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)21 ArrayList (java.util.ArrayList)19 CDOMReference (pcgen.cdom.base.CDOMReference)19 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)18 Skill (pcgen.core.Skill)13 Test (org.junit.Test)12 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)12 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)10 StringTokenizer (java.util.StringTokenizer)9 Formula (pcgen.base.formula.Formula)8 ParsingSeparator (pcgen.base.text.ParsingSeparator)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)3 ClassSkillList (pcgen.cdom.list.ClassSkillList)2 CDOMListObject (pcgen.cdom.base.CDOMListObject)1 NonInteractive (pcgen.cdom.base.NonInteractive)1 Ungranted (pcgen.cdom.base.Ungranted)1 ModifyChoiceDecorator (pcgen.cdom.choiceset.ModifyChoiceDecorator)1 CNAbility (pcgen.cdom.content.CNAbility)1