Search in sources :

Example 71 with Formula

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

the class OptionToken method unparse.

@Override
public String[] unparse(LoadContext context, BaseKit kit) {
    Collection<OptionBound> bounds = kit.getBounds();
    if (bounds == null) {
        return null;
    }
    List<String> list = new ArrayList<>();
    for (OptionBound bound : bounds) {
        Formula min = bound.getOptionMin();
        Formula max = bound.getOptionMax();
        if (min == null || max == null) {
            // Error if only one is null
            return null;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(min);
        if (!min.equals(max)) {
            sb.append(',').append(max);
        }
        list.add(sb.toString());
    }
    return new String[] { StringUtil.join(list, Constants.PIPE) };
}
Also used : Formula(pcgen.base.formula.Formula) OptionBound(pcgen.cdom.helper.OptionBound) ArrayList(java.util.ArrayList)

Example 72 with Formula

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

the class CountToken method parseNonEmptyToken.

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

Example 73 with Formula

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

the class EquipBuyToken method unparse.

@Override
public String[] unparse(LoadContext context, Kit kit) {
    QualifiedObject<Formula> qo = kit.get(ObjectKey.EQUIP_BUY);
    if (qo == null) {
        return null;
    }
    Formula f = qo.getRawObject();
    List<Prerequisite> prereqs = qo.getPrerequisiteList();
    String ab = f.toString();
    if (prereqs != null && !prereqs.isEmpty()) {
        ab = ab + Constants.PIPE + getPrerequisiteString(context, prereqs);
    }
    return new String[] { ab };
}
Also used : Formula(pcgen.base.formula.Formula) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 74 with Formula

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

the class QtyToken method parseNonEmptyToken.

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

Example 75 with Formula

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

the class ValuesToken method processRange.

private boolean processRange(KitTable kitTable, KitGear optionInfo, String range) {
    if (isEmpty(range) || hasIllegalSeparator(',', range)) {
        return false;
    }
    ParsingSeparator sep = new ParsingSeparator(range, ',');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String minString = sep.next();
    String maxString;
    if (sep.hasNext()) {
        maxString = sep.next();
    } else {
        maxString = range;
    }
    if (sep.hasNext()) {
        return false;
    }
    Formula min = FormulaFactory.getFormulaFor(minString);
    if (!min.isValid()) {
        Logging.errorPrint("Min Formula in " + getTokenName() + " was not valid: " + min.toString());
        return false;
    }
    Formula max = FormulaFactory.getFormulaFor(maxString);
    if (!max.isValid()) {
        Logging.errorPrint("Max Formula in " + getTokenName() + " was not valid: " + max.toString());
        return false;
    }
    kitTable.addGear(optionInfo, min, max);
    return true;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator)

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