Search in sources :

Example 1 with ConcreteTransitionChoice

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

the class RegionLst 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);
    String item = tok.nextToken();
    Formula count = FormulaFactory.getFormulaFor(item);
    if (!count.isValid()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
    }
    if (count.isStatic()) {
        if (!tok.hasMoreTokens()) {
            return new ParseResult.Fail(getTokenName() + " cannot have only a count: " + value, context);
        }
        item = tok.nextToken();
        if (count.resolveStatic().intValue() <= 0) {
            return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0: " + value, context);
        }
    } else {
        count = FormulaFactory.ONE;
    }
    List<Region> regions = new ArrayList<>();
    while (true) {
        regions.add(Region.getConstant(item));
        if (!tok.hasMoreTokens()) {
            break;
        }
        item = tok.nextToken();
    }
    SimpleChoiceSet<Region> rcs = new SimpleChoiceSet<>(regions);
    ChoiceSet<Region> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Region Selection");
    TransitionChoice<Region> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(obj, ObjectKey.REGION_CHOICE, tc);
    tc.setRequired(false);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) SimpleChoiceSet(pcgen.cdom.choiceset.SimpleChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) Ungranted(pcgen.cdom.base.Ungranted) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) SimpleChoiceSet(pcgen.cdom.choiceset.SimpleChoiceSet) NonInteractive(pcgen.cdom.base.NonInteractive) Region(pcgen.cdom.enumeration.Region)

Example 2 with ConcreteTransitionChoice

use of pcgen.cdom.base.ConcreteTransitionChoice 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 3 with ConcreteTransitionChoice

use of pcgen.cdom.base.ConcreteTransitionChoice 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)

Example 4 with ConcreteTransitionChoice

use of pcgen.cdom.base.ConcreteTransitionChoice 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)

Example 5 with ConcreteTransitionChoice

use of pcgen.cdom.base.ConcreteTransitionChoice 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)

Aggregations

ArrayList (java.util.ArrayList)5 StringTokenizer (java.util.StringTokenizer)5 ChoiceSet (pcgen.cdom.base.ChoiceSet)5 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)5 Formula (pcgen.base.formula.Formula)4 CDOMReference (pcgen.cdom.base.CDOMReference)4 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)3 NonInteractive (pcgen.cdom.base.NonInteractive)2 Ungranted (pcgen.cdom.base.Ungranted)2 CDOMListObject (pcgen.cdom.base.CDOMListObject)1 PrimitiveChoiceSet (pcgen.cdom.base.PrimitiveChoiceSet)1 ModifyChoiceDecorator (pcgen.cdom.choiceset.ModifyChoiceDecorator)1 SimpleChoiceSet (pcgen.cdom.choiceset.SimpleChoiceSet)1 SpellReferenceChoiceSet (pcgen.cdom.choiceset.SpellReferenceChoiceSet)1 CNAbility (pcgen.cdom.content.CNAbility)1 TabInfo (pcgen.cdom.content.TabInfo)1 Region (pcgen.cdom.enumeration.Region)1 ClassSkillList (pcgen.cdom.list.ClassSkillList)1 Ability (pcgen.core.Ability)1 Kit (pcgen.core.Kit)1