Search in sources :

Example 6 with ReferenceChoiceSet

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

Example 7 with ReferenceChoiceSet

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

the class EquipToken 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<Equipment>> refs = new ArrayList<>();
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        CDOMReference<Equipment> lang = TokenUtilities.getTypeOrPrimitive(context, EQUIPMENT_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<Equipment> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Equipment> cs = new ChoiceSet<>(getTokenName(), new QualifiedDecorator<>(rcs));
    cs.setTitle("Equipment Choice");
    PersistentTransitionChoice<Equipment> 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) Equipment(pcgen.core.Equipment) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 8 with ReferenceChoiceSet

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

the class TemplateToken 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<PCTemplate>> refs = new ArrayList<>();
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    while (tok.hasMoreTokens()) {
        refs.add(context.getReferenceContext().getCDOMReference(PCTEMPLATE_CLASS, tok.nextToken()));
    }
    ReferenceChoiceSet<PCTemplate> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<PCTemplate> cs = new ChoiceSet<>("TEMPLATE", rcs);
    PersistentTransitionChoice<PCTemplate> 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) PCTemplate(pcgen.core.PCTemplate) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 9 with ReferenceChoiceSet

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

the class ModifyfeatchoiceToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Ability ability, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    List<CDOMReference<Ability>> refs = new ArrayList<>();
    ReferenceManufacturer<Ability> rm = context.getReferenceContext().getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT);
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<Ability> ref = TokenUtilities.getTypeOrPrimitive(rm, token);
        if (ref == null) {
            return ParseResult.INTERNAL_ERROR;
        }
        refs.add(ref);
    }
    ReferenceChoiceSet<Ability> rcs = new ReferenceChoiceSet<>(refs);
    ModifyChoiceDecorator gfd = new ModifyChoiceDecorator(rcs);
    ChoiceSet<CNAbility> cs = new ChoiceSet<>(getTokenName(), gfd);
    TabInfo ti = context.getReferenceContext().silentlyGetConstructedCDOMObject(TabInfo.class, Tab.ABILITIES.toString());
    String singularName = ti.getResolvedName();
    if (singularName.endsWith("s")) {
        singularName = singularName.substring(0, singularName.length() - 1);
    }
    cs.setTitle("Select a " + singularName + " to modify");
    TransitionChoice<CNAbility> tc = new ConcreteTransitionChoice<>(cs, FormulaFactory.ONE);
    tc.setRequired(false);
    context.getObjectContext().put(ability, ObjectKey.MODIFY_CHOICE, tc);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) CNAbility(pcgen.cdom.content.CNAbility) StringTokenizer(java.util.StringTokenizer) TabInfo(pcgen.cdom.content.TabInfo) ModifyChoiceDecorator(pcgen.cdom.choiceset.ModifyChoiceDecorator) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 10 with ReferenceChoiceSet

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

the class SkilllistToken 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<ClassSkillList>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<ClassSkillList> ref;
        if (Constants.LST_ALL.equals(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS);
        } else {
            ref = context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, token);
        }
        refs.add(ref);
    }
    ReferenceChoiceSet<ClassSkillList> rcs = new ReferenceChoiceSet<>(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value);
    }
    ChoiceSet<ClassSkillList> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Select class whose class-skills this class will inherit");
    TransitionChoice<ClassSkillList> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(pcc, ObjectKey.SKILLLIST_CHOICE, tc);
    tc.setRequired(false);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ClassSkillList(pcgen.cdom.list.ClassSkillList) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) 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