Search in sources :

Example 61 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class ChooseLst 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);
    }
    String key;
    String val;
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (value.startsWith("FEAT=")) {
        key = "FEATEQ";
        val = value.substring(5);
    } else if (value.startsWith("LANGAUTO:")) {
        key = "LANGAUTO";
        val = value.substring(9);
    } else if (pipeLoc == -1) {
        key = value;
        val = null;
    } else {
        key = value.substring(0, pipeLoc);
        val = value.substring(pipeLoc + 1);
    }
    if (!((obj instanceof Ability) || (obj instanceof Domain) || (obj instanceof Race) || (obj instanceof PCTemplate) || (obj instanceof Skill) || (obj instanceof EquipmentModifier))) {
        //Allow TEMPBONUS related choose
        if (!"NUMBER".equals(key)) {
            return new ParseResult.Fail(getTokenName() + " is not supported for " + obj.getClass().getSimpleName(), context);
        }
    }
    if (key.startsWith("NUMCHOICES=")) {
        String maxCount = key.substring(11);
        if (maxCount == null || maxCount.isEmpty()) {
            return new ParseResult.Fail("NUMCHOICES in CHOOSE must be a formula: " + value, context);
        }
        Formula f = FormulaFactory.getFormulaFor(maxCount);
        if (!f.isValid()) {
            return new ParseResult.Fail("Number of Choices in " + getTokenName() + " was not valid: " + f.toString(), context);
        }
        context.getObjectContext().put(obj, FormulaKey.NUMCHOICES, f);
        pipeLoc = val.indexOf(Constants.PIPE);
        if (pipeLoc == -1) {
            key = val;
            val = null;
        } else {
            key = val.substring(0, pipeLoc);
            val = val.substring(pipeLoc + 1);
        }
    }
    return context.processSubToken(obj, getTokenName(), key, val);
}
Also used : Ability(pcgen.core.Ability) Formula(pcgen.base.formula.Formula) Skill(pcgen.core.Skill) EquipmentModifier(pcgen.core.EquipmentModifier) Race(pcgen.core.Race) NonInteractive(pcgen.cdom.base.NonInteractive) Domain(pcgen.core.Domain) PCTemplate(pcgen.core.PCTemplate) Ungranted(pcgen.cdom.base.Ungranted)

Example 62 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class DrLst 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 (Constants.LST_DOT_CLEAR.equals(value)) {
        context.getObjectContext().removeList(obj, ListKey.DAMAGE_REDUCTION);
        return ParseResult.SUCCESS;
    }
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    String drString = tok.nextToken();
    ParseResult pr = checkForIllegalSeparator('/', drString);
    if (!pr.passed()) {
        return pr;
    }
    String[] values = drString.split("/");
    if (values.length != 2) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(getTokenName() + " failed to build DamageReduction with value " + value);
        cpr.addErrorMessage("  ...expected a String with one / as a separator");
        return cpr;
    }
    Formula formula = FormulaFactory.getFormulaFor(values[0]);
    if (!formula.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
    }
    DamageReduction dr = new DamageReduction(formula, values[1]);
    if (tok.hasMoreTokens()) {
        String currentToken = tok.nextToken();
        Prerequisite prereq = getPrerequisite(currentToken);
        if (prereq == null) {
            return ParseResult.INTERNAL_ERROR;
        }
        dr.addPrerequisite(prereq);
    }
    context.getObjectContext().addToList(obj, ListKey.DAMAGE_REDUCTION, dr);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) Ungranted(pcgen.cdom.base.Ungranted) DamageReduction(pcgen.cdom.content.DamageReduction) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 63 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class SpellLevelToken method parseTokenWithSeparator.

@Override
public ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    int pipeLoc = value.lastIndexOf('|');
    String activeValue;
    String title;
    if (pipeLoc == -1) {
        activeValue = value;
        title = getDefaultTitle();
    } else {
        String titleString = value.substring(pipeLoc + 1);
        if (titleString.startsWith("TITLE=")) {
            title = titleString.substring(6);
            if (title.startsWith("\"")) {
                title = title.substring(1, title.length() - 1);
            }
            activeValue = value.substring(0, pipeLoc);
        } else {
            activeValue = value;
            title = getDefaultTitle();
        }
    }
    pipeLoc = value.indexOf('|');
    ParsingSeparator sep = new ParsingSeparator(activeValue, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    if (!sep.hasNext()) {
        return new ParseResult.Fail("Found no arguments in " + getFullName() + ": " + value, context);
    }
    List<SpellLevelInfo> sliList = new ArrayList<>();
    while (sep.hasNext()) {
        String token = sep.next();
        PrimitiveCollection<PCClass> pcf = context.getPrimitiveChoiceFilter(context.getReferenceContext().getManufacturer(PCClass.class), token);
        if (!sep.hasNext()) {
            return new ParseResult.Fail("Expected minimum level argument after " + token + " in " + getFullName() + ": " + value, context);
        }
        String minLevelString = sep.next();
        Formula minLevel = FormulaFactory.getFormulaFor(minLevelString);
        if (!sep.hasNext()) {
            return new ParseResult.Fail("Expected maximum level argument after " + minLevelString + " in " + getFullName() + ": " + value, context);
        }
        String maxLevelString = sep.next();
        Formula maxLevel = FormulaFactory.getFormulaFor(maxLevelString);
        if (!maxLevel.isValid()) {
            return new ParseResult.Fail("Max Level Formula in " + getTokenName() + " was not valid: " + maxLevel.toString(), context);
        }
        SpellLevelInfo sli = new SpellLevelInfo(pcf, minLevel, maxLevel);
        sliList.add(sli);
    }
    SpellLevelChooseInformation tc = new SpellLevelChooseInformation(getTokenName(), sliList);
    tc.setTitle(title);
    tc.setChoiceActor(this);
    context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) SpellLevelInfo(pcgen.cdom.helper.SpellLevelInfo) ArrayList(java.util.ArrayList) SpellLevelChooseInformation(pcgen.cdom.base.SpellLevelChooseInformation) PCClass(pcgen.core.PCClass)

Example 64 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class LeveladjustmentToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCTemplate template, String value) {
    Formula formula = FormulaFactory.getFormulaFor(value);
    if (!formula.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
    }
    context.getObjectContext().put(template, FormulaKey.LEVEL_ADJUSTMENT, formula);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula)

Example 65 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class PlayerCharacter method updateBaseSkillMod.

private int updateBaseSkillMod(PCClass pcClass, int spMod) {
    // skill min is 1, unless class gets 0 skillpoints per level (for second
    // apprentice class)
    final int skillMin = (spMod > 0) ? 1 : 0;
    if (pcClass.getSafe(ObjectKey.MOD_TO_SKILLS)) {
        spMod += (int) getStatBonusTo("MODSKILLPOINTS", "NUMBER");
        if (spMod < 1) {
            spMod = 1;
        }
    }
    // Race modifiers apply after Intellegence. BUG 577462
    Formula safe = getRace().getSafe(FormulaKey.SKILL_POINTS_PER_LEVEL);
    spMod += safe.resolve(this, "").intValue();
    // Minimum 1, not sure if bonus
    spMod = Math.max(skillMin, spMod);
    // level can be < 1, better safe than sorry
    for (PCTemplate template : getTemplateSet()) {
        spMod += template.getSafe(IntegerKey.BONUS_CLASS_SKILL_POINTS);
    }
    return spMod;
}
Also used : Formula(pcgen.base.formula.Formula)

Aggregations

Formula (pcgen.base.formula.Formula)106 ArrayList (java.util.ArrayList)30 ParsingSeparator (pcgen.base.text.ParsingSeparator)26 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)18 ParseResult (pcgen.rules.persistence.token.ParseResult)18 CDOMReference (pcgen.cdom.base.CDOMReference)16 StringTokenizer (java.util.StringTokenizer)15 ChoiceSet (pcgen.cdom.base.ChoiceSet)11 Ungranted (pcgen.cdom.base.Ungranted)10 CDOMObject (pcgen.cdom.base.CDOMObject)9 PersistentTransitionChoice (pcgen.cdom.base.PersistentTransitionChoice)9 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)8 PCClass (pcgen.core.PCClass)7 Prerequisite (pcgen.core.prereq.Prerequisite)7 Map (java.util.Map)6 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)6 PCTemplate (pcgen.core.PCTemplate)6 Race (pcgen.core.Race)6 Spell (pcgen.core.spell.Spell)6 HashMap (java.util.HashMap)5