Search in sources :

Example 21 with Ungranted

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

the class TemplateLst method parseToken.

@Override
public ParseResult parseToken(LoadContext context, CDOMObject cdo, String value) {
    if (cdo instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + cdo.getClass().getSimpleName(), context);
    }
    ListKey<CDOMReference<PCTemplate>> lk;
    String remaining;
    boolean consolidate = false;
    boolean specialLegal = false;
    if (value.startsWith(Constants.LST_CHOOSE_COLON)) {
        lk = ListKey.TEMPLATE_CHOOSE;
        remaining = value.substring(Constants.LST_CHOOSE_COLON.length());
        consolidate = true;
    } else if (value.startsWith(ADDCHOICE_COLON)) {
        lk = ListKey.TEMPLATE_ADDCHOICE;
        remaining = value.substring(ADDCHOICE_COLON.length());
    } else {
        lk = ListKey.TEMPLATE;
        remaining = value;
        specialLegal = true;
    }
    if (isEmpty(remaining) || hasIllegalSeparator('|', remaining)) {
        return ParseResult.INTERNAL_ERROR;
    }
    StringTokenizer tok = new StringTokenizer(remaining, Constants.PIPE);
    List<CDOMReference<PCTemplate>> list = new ArrayList<>();
    List<CDOMReference<PCTemplate>> removelist = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String templKey = tok.nextToken();
        if (specialLegal && templKey.endsWith(".REMOVE")) {
            removelist.add(context.getReferenceContext().getCDOMReference(PCTEMPLATE_CLASS, templKey.substring(0, templKey.length() - 7)));
        } else if (specialLegal && templKey.equals(Constants.LST_PERCENT_LIST)) {
            context.getObjectContext().addToList(cdo, ListKey.NEW_CHOOSE_ACTOR, this);
        } else {
            ReferenceManufacturer<PCTemplate> rm = context.getReferenceContext().getManufacturer(PCTEMPLATE_CLASS);
            CDOMReference<PCTemplate> ref = TokenUtilities.getTypeOrPrimitive(rm, templKey);
            if (ref == null) {
                return ParseResult.INTERNAL_ERROR;
            }
            list.add(ref);
        }
    }
    if (consolidate) {
        CDOMCompoundOrReference<PCTemplate> ref = new CDOMCompoundOrReference<>(PCTEMPLATE_CLASS, Constants.LST_CHOOSE_COLON);
        for (CDOMReference<PCTemplate> r : list) {
            ref.addReference(r);
        }
        ref.trimToSize();
        list.clear();
        list.add(ref);
    }
    for (CDOMReference<PCTemplate> ref : list) {
        context.getObjectContext().addToList(cdo, lk, ref);
    }
    if (!removelist.isEmpty()) {
        for (CDOMReference<PCTemplate> ref : removelist) {
            context.getObjectContext().addToList(cdo, ListKey.REMOVE_TEMPLATES, ref);
        }
    }
    return ParseResult.SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) Ungranted(pcgen.cdom.base.Ungranted) StringTokenizer(java.util.StringTokenizer) CDOMCompoundOrReference(pcgen.cdom.reference.CDOMCompoundOrReference) PCTemplate(pcgen.core.PCTemplate) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceManufacturer(pcgen.cdom.reference.ReferenceManufacturer)

Example 22 with Ungranted

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

the class UdamLst method parseToken.

@Override
public ParseResult parseToken(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);
    }
    ParseResult pr = ParseResult.SUCCESS;
    if (Constants.LST_DOT_CLEAR.equals(value)) {
        /*
			 * TODO This cross-polluting and certainly not "editor friendly",
			 * thus will need to be changed after 5.16
			 */
        if (obj instanceof PCClassLevel || obj instanceof PCClass) {
            PCClass pcc;
            if (obj instanceof PCClassLevel) {
                pcc = (PCClass) obj.get(ObjectKey.TOKEN_PARENT);
            } else {
                pcc = (PCClass) obj;
            }
            context.getObjectContext().removeList(pcc, ListKey.UNARMED_DAMAGE);
            for (PCClassLevel level : pcc.getOriginalClassLevelCollection()) {
                context.getObjectContext().removeList(level, ListKey.UNARMED_DAMAGE);
            }
        } else {
            context.getObjectContext().removeList(obj, ListKey.UNARMED_DAMAGE);
        }
    } else {
        pr = checkForIllegalSeparator(',', value);
        if (!pr.passed()) {
            return pr;
        }
        final StringTokenizer tok = new StringTokenizer(value, Constants.COMMA);
        if (context.getObjectContext().containsListFor(obj, ListKey.UNARMED_DAMAGE)) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addWarningMessage(obj.getDisplayName() + " already has " + getTokenName() + " set.");
            cpr.addWarningMessage(" It will be redefined, " + "but you should be using " + getTokenName() + ":.CLEAR");
            pr = cpr;
            context.getObjectContext().removeList(obj, ListKey.UNARMED_DAMAGE);
        }
        while (tok.hasMoreTokens()) {
            context.getObjectContext().addToList(obj, ListKey.UNARMED_DAMAGE, tok.nextToken());
        }
    }
    return pr;
}
Also used : StringTokenizer(java.util.StringTokenizer) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) PCClass(pcgen.core.PCClass) Ungranted(pcgen.cdom.base.Ungranted) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 23 with Ungranted

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

the class UnencumberedmoveLst 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);
    }
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    boolean hasArmor = false;
    boolean hasMove = false;
    Load loadMove = null;
    Load loadArmor = null;
    while (tok.hasMoreTokens()) {
        String loadString = tok.nextToken();
        if (loadString.equalsIgnoreCase("MediumLoad")) {
            ParseResult pr = validateOnlyMove(hasMove);
            if (!pr.passed()) {
                return pr;
            }
            loadMove = Load.MEDIUM;
            hasMove = true;
        } else if (loadString.equalsIgnoreCase("HeavyLoad")) {
            ParseResult pr = validateOnlyMove(hasMove);
            if (!pr.passed()) {
                return pr;
            }
            loadMove = Load.HEAVY;
            hasMove = true;
        } else if (loadString.equalsIgnoreCase("Overload")) {
            ParseResult pr = validateOnlyMove(hasMove);
            if (!pr.passed()) {
                return pr;
            }
            loadMove = Load.OVERLOAD;
            hasMove = true;
        } else if (loadString.equalsIgnoreCase("MediumArmor")) {
            ParseResult pr = validateOnlyArmor(hasArmor);
            if (!pr.passed()) {
                return pr;
            }
            loadArmor = Load.MEDIUM;
            hasArmor = true;
        } else if (loadString.equalsIgnoreCase("HeavyArmor")) {
            ParseResult pr = validateOnlyArmor(hasArmor);
            if (!pr.passed()) {
                return pr;
            }
            loadArmor = Load.OVERLOAD;
            hasArmor = true;
        } else if (loadString.equalsIgnoreCase("LightLoad")) {
            ParseResult pr = validateOnlyMove(hasMove);
            if (!pr.passed()) {
                return pr;
            }
            loadMove = Load.LIGHT;
            hasMove = true;
        } else if (loadString.equalsIgnoreCase("LightArmor")) {
            ParseResult pr = validateOnlyMove(hasArmor);
            if (!pr.passed()) {
                return pr;
            }
            loadArmor = Load.LIGHT;
            hasArmor = true;
        } else {
            return new ParseResult.Fail("Invalid value of \"" + loadString + "\" for UNENCUMBEREDMOVE in \"" + obj.getDisplayName() + "\".", context);
        }
    }
    context.getObjectContext().put(obj, ObjectKey.UNENCUMBERED_LOAD, loadMove);
    context.getObjectContext().put(obj, ObjectKey.UNENCUMBERED_ARMOR, loadArmor);
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) Load(pcgen.util.enumeration.Load) ParseResult(pcgen.rules.persistence.token.ParseResult) Ungranted(pcgen.cdom.base.Ungranted)

Example 24 with Ungranted

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

the class SpelllevelLst 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);
    }
    // SPELLLEVEL:CLASS|Name1,Name2=Level1|Spell1,Spell2,Spell3|Name3=Level2|Spell4,Spell5|PRExxx|PRExxx
    String workingValue = value;
    List<Prerequisite> prereqs = new ArrayList<>();
    while (true) {
        int lastPipeLoc = workingValue.lastIndexOf('|');
        if (lastPipeLoc == -1) {
            return new ParseResult.Fail("Invalid " + getTokenName() + " not enough tokens: " + value, context);
        }
        String lastToken = workingValue.substring(lastPipeLoc + 1);
        if (looksLikeAPrerequisite(lastToken)) {
            workingValue = workingValue.substring(0, lastPipeLoc);
            Prerequisite prerequisite = getPrerequisite(lastToken);
            if (prerequisite == null) {
                return new ParseResult.Fail("Invalid prerequisite " + lastToken + " in " + getTokenName() + " tag: " + value, context);
            }
            prereqs.add(prerequisite);
        } else {
            break;
        }
    }
    StringTokenizer tok = new StringTokenizer(workingValue, Constants.PIPE);
    if (tok.countTokens() < 3) {
        return new ParseResult.Fail("Insufficient values in SPELLLEVEL tag: " + value, context);
    }
    // CLASS or DOMAIN
    String tagType = tok.nextToken();
    while (tok.hasMoreTokens()) {
        String tokString = tok.nextToken();
        String spellString = tok.nextToken();
        if (tagType.equalsIgnoreCase("CLASS")) {
            if (!subParse(context, obj, ClassSpellList.class, tokString, spellString, prereqs)) {
                return ParseResult.INTERNAL_ERROR;
            //return new ParseResult.Fail("  " + getTokenName()
            //		+ " error - entire token was " + value, context);
            }
        } else if (tagType.equalsIgnoreCase("DOMAIN")) {
            if (!subParse(context, obj, DomainSpellList.class, tokString, spellString, prereqs)) {
                return new ParseResult.Fail("  " + getTokenName() + " error - entire token was " + value, context);
            }
        } else {
            return new ParseResult.Fail("First token of " + getTokenName() + " must be CLASS or DOMAIN:" + value, context);
        }
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) ArrayList(java.util.ArrayList) ClassSpellList(pcgen.cdom.list.ClassSpellList) Ungranted(pcgen.cdom.base.Ungranted) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 25 with Ungranted

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

the class SrLst method parseToken.

@Override
public ParseResult parseToken(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 (Constants.LST_DOT_CLEAR.equals(value)) {
        context.getObjectContext().remove(obj, ObjectKey.SR);
    } else {
        Formula formula = FormulaFactory.getFormulaFor(value);
        if (!formula.isValid()) {
            return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
        }
        context.getObjectContext().put(obj, ObjectKey.SR, new SpellResistance(formula));
    }
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) SpellResistance(pcgen.cdom.content.SpellResistance) Ungranted(pcgen.cdom.base.Ungranted)

Aggregations

Ungranted (pcgen.cdom.base.Ungranted)28 StringTokenizer (java.util.StringTokenizer)19 ParseResult (pcgen.rules.persistence.token.ParseResult)15 ArrayList (java.util.ArrayList)10 Formula (pcgen.base.formula.Formula)10 Prerequisite (pcgen.core.prereq.Prerequisite)8 CDOMReference (pcgen.cdom.base.CDOMReference)7 ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)6 ParsingSeparator (pcgen.base.text.ParsingSeparator)4 NonInteractive (pcgen.cdom.base.NonInteractive)4 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 Skill (pcgen.core.Skill)3 ChoiceSet (pcgen.cdom.base.ChoiceSet)2 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)2 PCClassLevel (pcgen.cdom.inst.PCClassLevel)2 ClassSpellList (pcgen.cdom.list.ClassSpellList)2 Ability (pcgen.core.Ability)2 Movement (pcgen.core.Movement)2 PCTemplate (pcgen.core.PCTemplate)2 Race (pcgen.core.Race)2