Search in sources :

Example 1 with ConditionalSelectionActor

use of pcgen.cdom.content.ConditionalSelectionActor in project pcgen by PCGen.

the class ArmorProfToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String armorProf;
    // Do not initialize, null is significant!
    Prerequisite prereq = null;
    boolean isPre = false;
    if (value.indexOf("[") == -1) {
        // Supported version of PRExxx using |.  Needs to be at the front of the
        // Parsing code because many objects expect the pre to have been determined
        // Ahead of time.  Until deprecated code is removed, it will have to stay
        // like this.
        armorProf = value;
        StringTokenizer tok = new StringTokenizer(armorProf, Constants.PIPE);
        while (tok.hasMoreTokens()) {
            String token = tok.nextToken();
            if (PreParserFactory.isPreReqString(token)) {
                if (isPre) {
                    String errorText = "Invalid " + getTokenName() + ": " + value + "  PRExxx must be at the END of the Token";
                    Logging.errorPrint(errorText);
                    return new ParseResult.Fail(errorText, context);
                }
                prereq = getPrerequisite(token);
                if (prereq == null) {
                    return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
                }
                int preStart = value.indexOf(token) - 1;
                armorProf = value.substring(0, preStart);
                isPre = true;
            }
        }
    } else {
        return new ParseResult.Fail("Use of [] for Prerequisites has been removed. " + "Please use | based standard", context);
    }
    ParseResult pr = checkSeparatorsAndNonEmpty('|', armorProf);
    if (!pr.passed()) {
        return pr;
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(armorProf, Constants.PIPE);
    List<CDOMReference<ArmorProf>> armorProfs = new ArrayList<>();
    List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String aProf = tok.nextToken();
        if (Constants.LST_PERCENT_LIST.equals(aProf)) {
            foundOther = true;
            ChooseSelectionActor<ArmorProf> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<ArmorProf> cca = new ConditionalSelectionActor<>(this);
                cca.addPrerequisite(prereq);
                cra = cca;
            }
            context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
        } else if (Constants.LST_ALL.equalsIgnoreCase(aProf)) {
            foundAny = true;
            armorProfs.add(context.getReferenceContext().getCDOMAllReference(ARMORPROF_CLASS));
        } else if (aProf.startsWith("ARMORTYPE.") || aProf.startsWith("ARMORTYPE=")) {
            foundOther = true;
            CDOMReference<Equipment> ref = TokenUtilities.getTypeReference(context, EQUIPMENT_CLASS, "ARMOR." + aProf.substring(10));
            if (ref == null) {
                return ParseResult.INTERNAL_ERROR;
            }
            equipTypes.add(ref);
        } else {
            foundOther = true;
            armorProfs.add(context.getReferenceContext().getCDOMReference(ARMORPROF_CLASS, aProf));
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    if (!armorProfs.isEmpty() || !equipTypes.isEmpty()) {
        ArmorProfProvider pp = new ArmorProfProvider(armorProfs, equipTypes);
        if (prereq != null) {
            pp.addPrerequisite(prereq);
        }
        context.getObjectContext().addToList(obj, ListKey.AUTO_ARMORPROF, pp);
    }
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ArrayList(java.util.ArrayList) StringTokenizer(java.util.StringTokenizer) ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) Equipment(pcgen.core.Equipment) ArmorProf(pcgen.core.ArmorProf) CDOMReference(pcgen.cdom.base.CDOMReference) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 2 with ConditionalSelectionActor

use of pcgen.cdom.content.ConditionalSelectionActor in project pcgen by PCGen.

the class ShieldProfToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String shieldProf;
    // Do not initialize, null is significant!
    Prerequisite prereq = null;
    boolean isPre = false;
    if (value.indexOf("[") == -1) {
        // Supported version of PRExxx using |.  Needs to be at the front of the
        // Parsing code because many objects expect the pre to have been determined
        // Ahead of time.  Until deprecated code is removed, it will have to stay
        // like this.
        shieldProf = value;
        StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE);
        while (tok.hasMoreTokens()) {
            String token = tok.nextToken();
            if (PreParserFactory.isPreReqString(token)) {
                if (isPre) {
                    String errorText = "Invalid " + getTokenName() + ": " + value + "  PRExxx must be at the END of the Token";
                    Logging.errorPrint(errorText);
                    return new ParseResult.Fail(errorText, context);
                }
                prereq = getPrerequisite(token);
                if (prereq == null) {
                    return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
                }
                int preStart = value.indexOf(token) - 1;
                shieldProf = value.substring(0, preStart);
                isPre = true;
            }
        }
    } else {
        return new ParseResult.Fail("Use of [] for Prerequisites has been removed. " + "Please use | based standard", context);
    }
    ParseResult pr = checkForIllegalSeparator('|', shieldProf);
    if (!pr.passed()) {
        return pr;
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE);
    List<CDOMReference<ShieldProf>> shieldProfs = new ArrayList<>();
    List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String aProf = tok.nextToken();
        if (Constants.LST_PERCENT_LIST.equals(aProf)) {
            foundOther = true;
            ChooseSelectionActor<ShieldProf> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<ShieldProf> cca = new ConditionalSelectionActor<>(this);
                cca.addPrerequisite(prereq);
                cra = cca;
            }
            context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
        } else if (Constants.LST_ALL.equalsIgnoreCase(aProf)) {
            foundAny = true;
            shieldProfs.add(context.getReferenceContext().getCDOMAllReference(SHIELDPROF_CLASS));
        } else if (aProf.startsWith("SHIELDTYPE.") || aProf.startsWith("SHIELDTYPE=")) {
            foundOther = true;
            CDOMReference<Equipment> ref = TokenUtilities.getTypeReference(context, EQUIPMENT_CLASS, "SHIELD." + aProf.substring(11));
            if (ref == null) {
                return ParseResult.INTERNAL_ERROR;
            }
            equipTypes.add(ref);
        } else {
            foundOther = true;
            shieldProfs.add(context.getReferenceContext().getCDOMReference(SHIELDPROF_CLASS, aProf));
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    if (!shieldProfs.isEmpty() || !equipTypes.isEmpty()) {
        ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
        if (prereq != null) {
            pp.addPrerequisite(prereq);
        }
        context.getObjectContext().addToList(obj, ListKey.AUTO_SHIELDPROF, pp);
    }
    return ParseResult.SUCCESS;
}
Also used : ShieldProf(pcgen.core.ShieldProf) ParseResult(pcgen.rules.persistence.token.ParseResult) ArrayList(java.util.ArrayList) StringTokenizer(java.util.StringTokenizer) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) Equipment(pcgen.core.Equipment) ShieldProfProvider(pcgen.cdom.helper.ShieldProfProvider) CDOMReference(pcgen.cdom.base.CDOMReference) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 3 with ConditionalSelectionActor

use of pcgen.cdom.content.ConditionalSelectionActor in project pcgen by PCGen.

the class EquipToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String equipItems;
    // Do not initialize, null is significant!
    Prerequisite prereq = null;
    /*
		 * CONSIDER There is the ability to consolidate this PREREQ processing
		 * into AutoLst.java (since it's the same across AUTO SubTokens)
		 */
    boolean isPre = false;
    if (value.indexOf("[") == -1) {
        // Supported version of PRExxx using |.  Needs to be at the front of the
        // Parsing code because many objects expect the pre to have been determined
        // Ahead of time.  Until deprecated code is removed, it will have to stay
        // like this.
        equipItems = value;
        StringTokenizer tok = new StringTokenizer(equipItems, Constants.PIPE);
        while (tok.hasMoreTokens()) {
            String token = tok.nextToken();
            if (PreParserFactory.isPreReqString(token)) {
                if (isPre) {
                    String errorText = "Invalid " + getTokenName() + ": " + value + "  PRExxx must be at the END of the Token";
                    Logging.errorPrint(errorText);
                    return new ParseResult.Fail(errorText, context);
                }
                prereq = getPrerequisite(token);
                if (prereq == null) {
                    return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
                }
                int preStart = value.indexOf(token) - 1;
                equipItems = value.substring(0, preStart);
                isPre = true;
            }
        }
    } else {
        return new ParseResult.Fail("Use of [] for Prerequisites is no longer supported, " + "please use | based standard", context);
    }
    ParseResult pr = checkForIllegalSeparator('|', equipItems);
    if (!pr.passed()) {
        return pr;
    }
    StringTokenizer tok = new StringTokenizer(equipItems, Constants.PIPE);
    while (tok.hasMoreTokens()) {
        String aProf = tok.nextToken();
        if (Constants.LST_PERCENT_LIST.equals(aProf)) {
            ChooseSelectionActor<Equipment> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<Equipment> cca = new ConditionalSelectionActor<>(this);
                cca.addPrerequisite(prereq);
                cra = cca;
            }
            context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
        } else {
            CDOMReference<Equipment> ref = TokenUtilities.getTypeOrPrimitive(context, EQUIPMENT_CLASS, aProf);
            if (ref == null) {
                return ParseResult.INTERNAL_ERROR;
            }
            context.getObjectContext().addToList(obj, ListKey.EQUIPMENT, new QualifiedObject<>(ref, prereq));
        }
    }
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) StringTokenizer(java.util.StringTokenizer) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) Equipment(pcgen.core.Equipment) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 4 with ConditionalSelectionActor

use of pcgen.cdom.content.ConditionalSelectionActor in project pcgen by PCGen.

the class LangToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String lang = value;
    ParseResult pr = checkSeparatorsAndNonEmpty('|', lang);
    if (!pr.passed()) {
        return pr;
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(lang, Constants.PIPE);
    boolean isPre = false;
    // Do not initialize, null is significant!
    Prerequisite prereq = null;
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (PreParserFactory.isPreReqString(token)) {
            if (isPre) {
                String errorText = "Invalid " + getTokenName() + ": " + value + "  PRExxx must be at the END of the Token";
                Logging.errorPrint(errorText);
                return new ParseResult.Fail(errorText, context);
            }
            prereq = getPrerequisite(token);
            if (prereq == null) {
                return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
            }
            int preStart = value.indexOf(token) - 1;
            lang = value.substring(0, preStart);
            isPre = true;
        }
    }
    boolean firstToken = true;
    tok = new StringTokenizer(lang, Constants.PIPE);
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (Constants.LST_DOT_CLEAR.equals(token)) {
            if (!firstToken) {
                return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
            }
            context.getObjectContext().removeList(obj, ListKey.AUTO_LANGUAGE);
        } else if (Constants.LST_PERCENT_LIST.equals(token)) {
            ChooseSelectionActor<Language> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<Language> cca = new ConditionalSelectionActor<>(this);
                cca.addPrerequisite(prereq);
                cra = cca;
            }
            foundOther = true;
            context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
        } else if (Constants.LST_ALL.equals(token)) {
            foundAny = true;
            context.getObjectContext().addToList(obj, ListKey.AUTO_LANGUAGE, new QualifiedObject<>(context.getReferenceContext().getCDOMAllReference(LANGUAGE_CLASS), prereq));
        } else {
            foundOther = true;
            CDOMReference<Language> ref = TokenUtilities.getTypeOrPrimitive(context, LANGUAGE_CLASS, token);
            if (ref == null) {
                return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName(), context);
            }
            context.getObjectContext().addToList(obj, ListKey.AUTO_LANGUAGE, new QualifiedObject<>(ref, prereq));
        }
        firstToken = false;
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) StringTokenizer(java.util.StringTokenizer) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) Language(pcgen.core.Language) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 5 with ConditionalSelectionActor

use of pcgen.cdom.content.ConditionalSelectionActor in project pcgen by PCGen.

the class WeaponProfToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String weaponProfs;
    // Do not initialize, null is significant!
    Prerequisite prereq = null;
    boolean isPre = false;
    if (value.indexOf("[") == -1) {
        // Supported version of PRExxx using |.  Needs to be at the front of the
        // Parsing code because many objects expect the pre to have been determined
        // Ahead of time.  Until deprecated code is removed, it will have to stay
        // like this.
        weaponProfs = value;
        StringTokenizer tok = new StringTokenizer(weaponProfs, Constants.PIPE);
        while (tok.hasMoreTokens()) {
            String token = tok.nextToken();
            if (PreParserFactory.isPreReqString(token)) {
                if (isPre) {
                    String errorText = "Invalid " + getTokenName() + ": " + value + "  PRExxx must be at the END of the Token";
                    Logging.errorPrint(errorText);
                    return new ParseResult.Fail(errorText, context);
                }
                prereq = getPrerequisite(token);
                if (prereq == null) {
                    return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
                }
                int preStart = value.indexOf(token) - 1;
                weaponProfs = value.substring(0, preStart);
                isPre = true;
                ParseResult fail = checkForLoopPrereqs(prereq, context);
                if (fail != null) {
                    return fail;
                }
            }
        }
    } else {
        return new ParseResult.Fail("Use of [] for Prerequisites has been removed. " + "Please use | based standard", context);
    }
    ParseResult pr = checkForIllegalSeparator('|', weaponProfs);
    if (!pr.passed()) {
        return pr;
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(weaponProfs, Constants.PIPE);
    WeaponProfProvider wpp = new WeaponProfProvider();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (Constants.LST_PERCENT_LIST.equals(token)) {
            foundOther = true;
            ChooseSelectionActor<WeaponProf> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<WeaponProf> cca = new ConditionalSelectionActor<>(this);
                cca.addPrerequisite(prereq);
                cra = cca;
            }
            context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
        } else if ("DEITYWEAPONS".equals(token)) {
            foundOther = true;
            context.getObjectContext().put(obj, ObjectKey.HAS_DEITY_WEAPONPROF, new QualifiedObject<>(Boolean.TRUE, prereq));
        } else {
            if (Constants.LST_ALL.equalsIgnoreCase(token)) {
                foundAny = true;
                CDOMGroupRef<WeaponProf> allRef = context.getReferenceContext().getCDOMAllReference(WEAPONPROF_CLASS);
                wpp.addWeaponProfAll(allRef);
            } else {
                foundOther = true;
                if (token.startsWith(Constants.LST_TYPE_DOT) || token.startsWith(Constants.LST_TYPE_EQUAL)) {
                    CDOMGroupRef<WeaponProf> rr = TokenUtilities.getTypeReference(context, WEAPONPROF_CLASS, token.substring(5));
                    if (rr == null) {
                        return ParseResult.INTERNAL_ERROR;
                    }
                    wpp.addWeaponProfType(rr);
                } else {
                    CDOMSingleRef<WeaponProf> ref = context.getReferenceContext().getCDOMReference(WEAPONPROF_CLASS, token);
                    wpp.addWeaponProf(ref);
                }
            }
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    if (!wpp.isEmpty()) {
        if (prereq != null) {
            wpp.addPrerequisite(prereq);
        }
        context.getObjectContext().addToList(obj, ListKey.WEAPONPROF, wpp);
    }
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) WeaponProf(pcgen.core.WeaponProf) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) StringTokenizer(java.util.StringTokenizer) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) QualifiedObject(pcgen.core.QualifiedObject) CDOMGroupRef(pcgen.cdom.reference.CDOMGroupRef) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

StringTokenizer (java.util.StringTokenizer)5 ConditionalSelectionActor (pcgen.cdom.content.ConditionalSelectionActor)5 Prerequisite (pcgen.core.prereq.Prerequisite)5 ParseResult (pcgen.rules.persistence.token.ParseResult)5 Equipment (pcgen.core.Equipment)3 ArrayList (java.util.ArrayList)2 CDOMReference (pcgen.cdom.base.CDOMReference)2 ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)1 ArmorProfProvider (pcgen.cdom.helper.ArmorProfProvider)1 ShieldProfProvider (pcgen.cdom.helper.ShieldProfProvider)1 WeaponProfProvider (pcgen.cdom.helper.WeaponProfProvider)1 CDOMGroupRef (pcgen.cdom.reference.CDOMGroupRef)1 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)1 ArmorProf (pcgen.core.ArmorProf)1 Language (pcgen.core.Language)1 QualifiedObject (pcgen.core.QualifiedObject)1 ShieldProf (pcgen.core.ShieldProf)1 WeaponProf (pcgen.core.WeaponProf)1