Search in sources :

Example 1 with SpellReferenceChoiceSet

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

the class SpelllistToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    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() || 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<? extends CDOMListObject<Spell>>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<? extends CDOMListObject<Spell>> ref;
        if (Constants.LST_ALL.equals(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(SPELLLIST_CLASS);
        } else if (token.startsWith("DOMAIN.")) {
            ref = context.getReferenceContext().getCDOMReference(DOMAINSPELLLIST_CLASS, token.substring(7));
        } else {
            ref = context.getReferenceContext().getCDOMReference(SPELLLIST_CLASS, token);
        }
        refs.add(ref);
    }
    PrimitiveChoiceSet<CDOMListObject<Spell>> rcs = new SpellReferenceChoiceSet(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    ChoiceSet<? extends CDOMListObject<Spell>> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Select class whose list of spells this class will use");
    TransitionChoice<CDOMListObject<Spell>> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(pcc, ObjectKey.SPELLLIST_CHOICE, tc);
    tc.setRequired(false);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) SpellReferenceChoiceSet(pcgen.cdom.choiceset.SpellReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) PrimitiveChoiceSet(pcgen.cdom.base.PrimitiveChoiceSet) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CDOMListObject(pcgen.cdom.base.CDOMListObject) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) CDOMReference(pcgen.cdom.base.CDOMReference) SpellReferenceChoiceSet(pcgen.cdom.choiceset.SpellReferenceChoiceSet)

Aggregations

ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Formula (pcgen.base.formula.Formula)1 CDOMListObject (pcgen.cdom.base.CDOMListObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 ChoiceSet (pcgen.cdom.base.ChoiceSet)1 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)1 PrimitiveChoiceSet (pcgen.cdom.base.PrimitiveChoiceSet)1 SpellReferenceChoiceSet (pcgen.cdom.choiceset.SpellReferenceChoiceSet)1 Spell (pcgen.core.spell.Spell)1