Search in sources :

Example 21 with ChoiceSet

use of pcgen.cdom.base.ChoiceSet 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 22 with ChoiceSet

use of pcgen.cdom.base.ChoiceSet 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 23 with ChoiceSet

use of pcgen.cdom.base.ChoiceSet in project pcgen by PCGen.

the class KitLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (obj instanceof NonInteractive) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
    }
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
    if (!count.isValid()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
    }
    if (!count.isStatic()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " must be a number", context);
    }
    if (count.resolveStatic().intValue() <= 0) {
        return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
    }
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
    }
    List<CDOMReference<Kit>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<Kit> ref;
        if (Constants.LST_ALL.equals(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(KIT_CLASS);
        } else {
            ref = context.getReferenceContext().getCDOMReference(KIT_CLASS, token);
        }
        refs.add(ref);
    }
    ReferenceChoiceSet<Kit> rcs = new ReferenceChoiceSet<>(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    ChoiceSet<Kit> cs = new ChoiceSet<>(getTokenName(), new QualifiedDecorator<>(rcs));
    cs.setTitle("Kit Selection");
    TransitionChoice<Kit> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.KIT_CHOICE, tc);
    tc.setRequired(false);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) Ungranted(pcgen.cdom.base.Ungranted) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) Kit(pcgen.core.Kit) NonInteractive(pcgen.cdom.base.NonInteractive) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 24 with ChoiceSet

use of pcgen.cdom.base.ChoiceSet 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;
}
Also used : ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) AbilityFromClassChoiceSet(pcgen.cdom.choiceset.AbilityFromClassChoiceSet) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Nature(pcgen.cdom.enumeration.Nature) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PrimitiveChoiceSet(pcgen.cdom.base.PrimitiveChoiceSet) ParseResult(pcgen.rules.persistence.token.ParseResult) AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet) AbilityFromClassChoiceSet(pcgen.cdom.choiceset.AbilityFromClassChoiceSet) CompoundOrChoiceSet(pcgen.cdom.choiceset.CompoundOrChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) PrimitiveChoiceSet(pcgen.cdom.base.PrimitiveChoiceSet) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) ParsingSeparator(pcgen.base.text.ParsingSeparator) AbilityCategory(pcgen.core.AbilityCategory) CDOMReference(pcgen.cdom.base.CDOMReference) AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet)

Example 25 with ChoiceSet

use of pcgen.cdom.base.ChoiceSet 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;
}
Also used : AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) CDOMReference(pcgen.cdom.base.CDOMReference) AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice)

Aggregations

ChoiceSet (pcgen.cdom.base.ChoiceSet)25 ArrayList (java.util.ArrayList)22 CDOMReference (pcgen.cdom.base.CDOMReference)22 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)21 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)20 Skill (pcgen.core.Skill)13 Test (org.junit.Test)12 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)12 StringTokenizer (java.util.StringTokenizer)11 Formula (pcgen.base.formula.Formula)11 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)10 ParsingSeparator (pcgen.base.text.ParsingSeparator)7 ParseResult (pcgen.rules.persistence.token.ParseResult)7 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)5 CDOMListObject (pcgen.cdom.base.CDOMListObject)2 NonInteractive (pcgen.cdom.base.NonInteractive)2 PrimitiveChoiceSet (pcgen.cdom.base.PrimitiveChoiceSet)2 Ungranted (pcgen.cdom.base.Ungranted)2 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)2 CNAbility (pcgen.cdom.content.CNAbility)2