Search in sources :

Example 11 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class ProficiencyToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail("Equipment Token PROFICIENCY syntax " + "without a Subtoken is invalid: PROFICIENCY:" + value, context);
    }
    if (pipeLoc != value.lastIndexOf(Constants.PIPE)) {
        return new ParseResult.Fail(getTokenName() + " expecting only one '|', " + "format is: SubToken|ProfName value was: " + value, context);
    }
    String subtoken = value.substring(0, pipeLoc);
    String prof = value.substring(pipeLoc + 1);
    if (prof == null || prof.isEmpty()) {
        return new ParseResult.Fail("PROFICIENCY cannot have " + "empty second argument: " + value, context);
    }
    if (subtoken.equals("WEAPON")) {
        // This can be reactivated if .CLEAR is implemented, to allow .MOD to override the proficiency			
        //			if (context.getObjectContext().getObject(eq, ObjectKey.WEAPON_PROF) != null)
        //			{
        //				return new ParseResult.Fail(
        //					"Only one PROFICIENCY:WEAPON is allowed per item. Token was PROFICIENCY:"
        //						+ value, context);
        //			}
        CDOMSingleRef<WeaponProf> wp = context.getReferenceContext().getCDOMReference(WeaponProf.class, prof);
        context.getObjectContext().put(eq, ObjectKey.WEAPON_PROF, wp);
    } else if (subtoken.equals("ARMOR")) {
        //			if (context.getObjectContext().getObject(eq, ObjectKey.ARMOR_PROF) != null)
        //			{
        //				return new ParseResult.Fail(
        //					"Only one PROFICIENCY:ARMOR is allowed per item. Token was PROFICIENCY:"
        //						+ value, context);
        //			}
        CDOMSingleRef<ArmorProf> wp = context.getReferenceContext().getCDOMReference(ArmorProf.class, prof);
        context.getObjectContext().put(eq, ObjectKey.ARMOR_PROF, wp);
    } else if (subtoken.equals("SHIELD")) {
        //			if (context.getObjectContext().getObject(eq, ObjectKey.SHIELD_PROF) != null)
        //			{
        //				return new ParseResult.Fail(
        //					"Only one PROFICIENCY:SHIELD is allowed per item. Token was PROFICIENCY:"
        //						+ value, context);
        //			}
        CDOMSingleRef<ShieldProf> wp = context.getReferenceContext().getCDOMReference(ShieldProf.class, prof);
        context.getObjectContext().put(eq, ObjectKey.SHIELD_PROF, wp);
    } else {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Unknown Subtoken for PROFICIENCY: " + subtoken);
        cpr.addErrorMessage("  Subtoken must be " + "WEAPON, ARMOR or SHIELD");
        return cpr;
    }
    return ParseResult.SUCCESS;
}
Also used : ShieldProf(pcgen.core.ShieldProf) WeaponProf(pcgen.core.WeaponProf) ArmorProf(pcgen.core.ArmorProf) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Example 12 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class RaceToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, KitRace kitRace, String value) {
    if (Constants.NONESELECTED.equals(value)) {
        ComplexParseResult pr = new ComplexParseResult();
        pr.addWarningMessage("NONESELECTED is not necessary in KIT RACE: " + "Token is not processed");
        return pr;
    }
    CDOMSingleRef<Race> ref = context.getReferenceContext().getCDOMReference(RACE_CLASS, value);
    kitRace.setRace(ref);
    return ParseResult.SUCCESS;
}
Also used : KitRace(pcgen.core.kit.KitRace) Race(pcgen.core.Race) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult)

Example 13 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class HitdieLst method parseToken.

@Override
public ParseResult parseToken(LoadContext context, PCClassLevel level, String value) {
    try {
        String lock = value;
        int pipeLoc = lock.indexOf(Constants.PIPE);
        if (pipeLoc != -1) {
            return new ParseResult.Fail(getTokenName() + " is invalid has a pipe: " + value, context);
        }
        Processor<HitDie> hdm;
        if (lock.startsWith("%/")) {
            // HITDIE:%/num --- divides the classes hit die by num.
            int denom = Integer.parseInt(lock.substring(2));
            if (denom <= 0) {
                return new ParseResult.Fail(getTokenName() + " was expecting a Positive Integer " + "for dividing Lock, was : " + lock.substring(2), context);
            }
            hdm = new HitDieFormula(new DividingFormula(denom));
        } else if (lock.startsWith("%*")) {
            // HITDIE:%*num --- multiplies the classes hit die by num.
            int mult = Integer.parseInt(lock.substring(2));
            if (mult <= 0) {
                return new ParseResult.Fail(getTokenName() + " was expecting a Positive " + "Integer for multiplying Lock, was : " + lock.substring(2), context);
            }
            hdm = new HitDieFormula(new MultiplyingFormula(mult));
        } else if (lock.startsWith("%+")) {
            // possibly redundant with BONUS:HD MAX|num
            // HITDIE:%+num --- adds num to the classes hit die.
            int add = Integer.parseInt(lock.substring(2));
            if (add <= 0) {
                return new ParseResult.Fail(getTokenName() + " was expecting a Positive " + "Integer for adding Lock, was : " + lock.substring(2), context);
            }
            hdm = new HitDieFormula(new AddingFormula(add));
        } else if (lock.startsWith("%-")) {
            // HITDIE:%-num --- subtracts num from the classes hit die.
            // possibly redundant with BONUS:HD MAX|num if that will
            // take negative numbers.
            int sub = Integer.parseInt(lock.substring(2));
            if (sub <= 0) {
                return new ParseResult.Fail(getTokenName() + " was expecting a Positive " + "Integer for subtracting Lock, was : " + lock.substring(2), context);
            }
            hdm = new HitDieFormula(new SubtractingFormula(sub));
        } else if (lock.startsWith("%up")) {
            // HITDIE:%upnum --- moves the hit die num steps up the die size
            // list d4,d6,d8,d10,d12. Stops at d12.
            int steps = Integer.parseInt(lock.substring(3));
            if (steps <= 0) {
                return new ParseResult.Fail("Invalid Step Count: " + steps + " in " + getTokenName() + " up (must be positive)", context);
            }
            if (steps >= 5) {
                return new ParseResult.Fail("Invalid Step Count: " + steps + " in " + getTokenName() + " up (too large)", context);
            }
            hdm = new HitDieStep(steps, new HitDie(12));
        } else if (lock.startsWith("%Hup")) {
            // HITDIE:%upnum --- moves the hit die num steps up the die size
            // list d4,d6,d8,d10,d12. Stops at d12.
            int steps = Integer.parseInt(lock.substring(4));
            if (steps <= 0) {
                return new ParseResult.Fail("Invalid Step Count: " + steps + " in " + getTokenName(), context);
            }
            hdm = new HitDieStep(steps, null);
        } else if (lock.startsWith("%down")) {
            // HITDIE:%downnum --- moves the hit die num steps down the die
            // size
            // list d4,d6,d8,d10,d12. Stops at d4.
            int steps = Integer.parseInt(lock.substring(5));
            if (steps <= 0) {
                return new ParseResult.Fail("Invalid Step Count: " + steps + " in " + getTokenName() + " down (must be positive)", context);
            }
            if (steps >= 5) {
                return new ParseResult.Fail("Invalid Step Count: " + steps + " in " + getTokenName() + " down (too large)", context);
            }
            hdm = new HitDieStep(-steps, new HitDie(4));
        } else if (lock.startsWith("%Hdown")) {
            // HITDIE:%downnum --- moves the hit die num steps down the die
            // size
            // list. No limit.
            int steps = Integer.parseInt(lock.substring(6));
            if (steps <= 0) {
                return new ParseResult.Fail("Invalid Step Count: " + steps + " in " + getTokenName(), context);
            }
            hdm = new HitDieStep(-steps, null);
        } else {
            int i = Integer.parseInt(lock);
            if (i <= 0) {
                return new ParseResult.Fail("Invalid HitDie: " + i + " in " + getTokenName(), context);
            }
            // HITDIE:num --- sets the hit die to num regardless of class.
            hdm = new HitDieLock(new HitDie(i));
        }
        context.getObjectContext().put(level, ObjectKey.HITDIE, hdm);
        return ParseResult.SUCCESS;
    } catch (NumberFormatException nfe) {
        ComplexParseResult pr = new ComplexParseResult();
        pr.addErrorMessage("Invalid Number in " + getTokenName() + ": " + nfe.getLocalizedMessage());
        pr.addErrorMessage("  Must be an Integer");
        return pr;
    }
}
Also used : HitDieFormula(pcgen.cdom.processor.HitDieFormula) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) MultiplyingFormula(pcgen.base.formula.MultiplyingFormula) HitDieLock(pcgen.cdom.processor.HitDieLock) AddingFormula(pcgen.base.formula.AddingFormula) HitDieStep(pcgen.cdom.processor.HitDieStep) HitDie(pcgen.cdom.content.HitDie) DividingFormula(pcgen.base.formula.DividingFormula) SubtractingFormula(pcgen.base.formula.SubtractingFormula)

Example 14 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class AddLst method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(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);
    }
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        if (Constants.LST_DOT_CLEAR.equals(value)) {
            if (obj instanceof PCClassLevel) {
                ComplexParseResult cpr = new ComplexParseResult();
                cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
                cpr.addErrorMessage("  A non-level limited .CLEAR was " + "used in a Class Level line in " + obj.getKeyName());
                return cpr;
            }
        } else if (value.startsWith(".CLEAR.LEVEL")) {
            if (!(obj instanceof PCClassLevel)) {
                ComplexParseResult cpr = new ComplexParseResult();
                cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
                cpr.addErrorMessage("  A level limited .CLEAR ( " + value + " ) was not used in a Class Level line in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName());
                return cpr;
            }
            String levelString = value.substring(12);
            try {
                int level = Integer.parseInt(levelString);
                if (level != obj.get(IntegerKey.LEVEL)) {
                    ComplexParseResult cpr = new ComplexParseResult();
                    cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
                    cpr.addErrorMessage("  A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
                    cpr.addErrorMessage("  But was asked to clear a " + "different Class Level ( " + level + " ) than the Class Level Line it appeared on: " + obj.getKeyName());
                    return cpr;
                }
            } catch (NumberFormatException e) {
                ComplexParseResult cpr = new ComplexParseResult();
                cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
                cpr.addErrorMessage("  A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
                cpr.addErrorMessage("  But the level ( " + levelString + " ) was not an integer in: " + obj.getKeyName());
                return cpr;
            }
        } else {
            return new ParseResult.Fail(getTokenName() + " requires a SubToken and argument, found: " + value, context);
        }
        context.getObjectContext().removeList(obj, ListKey.ADD);
        return ParseResult.SUCCESS;
    }
    return context.processSubToken(obj, getTokenName(), value.substring(0, pipeLoc), value.substring(pipeLoc + 1));
}
Also used : ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) NonInteractive(pcgen.cdom.base.NonInteractive) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) Ungranted(pcgen.cdom.base.Ungranted) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 15 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class ChangeprofLst 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);
    }
    // value should be of the format:
    // Name1,TYPE.type1,Name3=Prof1|Name4,Name5=Prof2
    //
    // e.g.: TYPE.Hammer,Hand Axe=Simple|Urgosh,Waraxe=Martial
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    List<ChangeProf> list = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        int equalLoc = tokText.indexOf('=');
        if (equalLoc < 0) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": No = found. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        } else if (equalLoc != tokText.lastIndexOf('=')) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": Two = found.  " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        }
        String newType = tokText.substring(equalLoc + 1);
        if (newType.isEmpty()) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": Empty Result Type.  " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        }
        if (newType.indexOf(Constants.DOT) != -1) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": Invalid (Compound) Result Type: cannot contain a period (.)  " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        }
        String[] val = { newType };
        CDOMGroupRef<WeaponProf> newTypeProf = context.getReferenceContext().getCDOMTypeReference(WEAPONPROF_CLASS, val);
        String profs = tokText.substring(0, equalLoc);
        if (profs.isEmpty()) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": Empty Source Prof.  " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        }
        StringTokenizer pTok = new StringTokenizer(profs, Constants.COMMA);
        while (pTok.hasMoreTokens()) {
            CDOMReference<WeaponProf> wp = TokenUtilities.getTypeOrPrimitive(context, WEAPONPROF_CLASS, pTok.nextToken());
            list.add(new ChangeProf(wp, newTypeProf));
        }
    }
    for (ChangeProf cp : list) {
        context.getObjectContext().addToList(obj, ListKey.CHANGEPROF, cp);
    }
    return ParseResult.SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) WeaponProf(pcgen.core.WeaponProf) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) Ungranted(pcgen.cdom.base.Ungranted) StringTokenizer(java.util.StringTokenizer) ChangeProf(pcgen.cdom.content.ChangeProf)

Aggregations

ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)25 ParseResult (pcgen.rules.persistence.token.ParseResult)12 StringTokenizer (java.util.StringTokenizer)11 Ungranted (pcgen.cdom.base.Ungranted)6 PCClass (pcgen.core.PCClass)5 ArrayList (java.util.ArrayList)4 Ability (pcgen.core.Ability)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 AddingFormula (pcgen.base.formula.AddingFormula)2 DividingFormula (pcgen.base.formula.DividingFormula)2 Formula (pcgen.base.formula.Formula)2 MultiplyingFormula (pcgen.base.formula.MultiplyingFormula)2 SubtractingFormula (pcgen.base.formula.SubtractingFormula)2 CDOMReference (pcgen.cdom.base.CDOMReference)2 CategorizedChooseInformation (pcgen.cdom.base.CategorizedChooseInformation)2 CollectionToChoiceSet (pcgen.cdom.choiceset.CollectionToChoiceSet)2 HitDie (pcgen.cdom.content.HitDie)2 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)2 PCClassLevel (pcgen.cdom.inst.PCClassLevel)2 HitDieFormula (pcgen.cdom.processor.HitDieFormula)2