Search in sources :

Example 56 with Formula

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

the class SizeToken method parseNonEmptyToken.

@Override
public ParseResult parseNonEmptyToken(LoadContext context, Race race, String value) {
    CDOMSingleRef<SizeAdjustment> size = context.getReferenceContext().getCDOMReference(SizeAdjustment.class, value);
    Formula sizeFormula = new FixedSizeFormula(size);
    context.getObjectContext().put(race, FormulaKey.SIZE, sizeFormula);
    return ParseResult.SUCCESS;
}
Also used : FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula) Formula(pcgen.base.formula.Formula) SizeAdjustment(pcgen.core.SizeAdjustment) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula)

Example 57 with Formula

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

the class XtraskillptsperlvlToken method parseNonEmptyToken.

@Override
public ParseResult parseNonEmptyToken(LoadContext context, Race race, 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(race, FormulaKey.SKILL_POINTS_PER_LEVEL, formula);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula)

Example 58 with Formula

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

the class KnownToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel level, String value) {
    context.getObjectContext().removeList(level, ListKey.KNOWN);
    ParsingSeparator sep = new ParsingSeparator(value, ',');
    sep.addGroupingPair('(', ')');
    while (sep.hasNext()) {
        String tok = sep.next();
        try {
            if (Integer.parseInt(tok) < 0) {
                return new ParseResult.Fail("Invalid Spell Count: " + tok + " is less than zero", context);
            }
        } catch (NumberFormatException e) {
        // OK, it must be a formula...
        }
        Formula formula = FormulaFactory.getFormulaFor(tok);
        if (!formula.isValid()) {
            return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
        }
        context.getObjectContext().addToList(level, ListKey.KNOWN, formula);
    }
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator)

Example 59 with Formula

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

the class SizeFacet method calcRacialSizeInt.

private int calcRacialSizeInt(CharID id) {
    SizeFacetInfo info = getConstructingInfo(id);
    int iSize = SizeUtilities.getDefaultSizeAdjustment().get(IntegerKey.SIZEORDER);
    Race race = raceFacet.get(id);
    if (race != null) {
        // get the base size for the race
        Formula size = race.getSafe(FormulaKey.SIZE);
        iSize = formulaResolvingFacet.resolve(id, size, "").intValue();
        // with something like SIZE:L
        for (PCTemplate template : templateFacet.getSet(id)) {
            Formula sizeFormula = template.get(FormulaKey.SIZE);
            if (sizeFormula != null) {
                iSize = formulaResolvingFacet.resolve(id, sizeFormula, template.getKeyName()).intValue();
            }
        }
    }
    info.racialSizeInt = iSize;
    return iSize;
}
Also used : Formula(pcgen.base.formula.Formula) Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate)

Example 60 with Formula

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

the class VisionFacet method getActiveVision.

/**
	 * Returns a Vision object for the given VisionType for the Player Character
	 * identified by the given CharID.
	 * 
	 * For a Player Character that is not changed between calls to this method,
	 * this method does not guarantee returning a Vision object of the same
	 * identity for the same given VisionType. While the two Vision objects will
	 * pass object equality (.equals()), they are not guaranteed to pass (or
	 * guaranteed to fail) instance identity (a == b). This allows VisionFacet
	 * to reserve the right to cache results, but does not require it.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            Vision of the given VisionType is to be returned
	 * @param type
	 *            The VisionType for which the Vision is to be returned
	 * @return A Vision object for the given VisionType for the Player Character
	 *         identified by the given CharID.
	 */
public Vision getActiveVision(CharID id, VisionType type) {
    Map<QualifiedObject<Vision>, Set<Object>> componentMap = getCachedMap(id);
    if (componentMap == null) {
        return null;
    }
    Integer i = null;
    for (Map.Entry<QualifiedObject<Vision>, Set<Object>> me : componentMap.entrySet()) {
        QualifiedObject<Vision> qo = me.getKey();
        Vision v = qo.getRawObject();
        VisionType visType = v.getType();
        if (type.equals(visType)) {
            for (Object source : me.getValue()) {
                if (prerequisiteFacet.qualifies(id, qo, source)) {
                    String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
                    Formula distance = v.getDistance();
                    int a = formulaResolvingFacet.resolve(id, distance, sourceString).intValue();
                    if (i == null || i < a) {
                        i = a;
                    }
                }
            }
        }
    }
    /*
		 * parse through the global list of vision tags and see if this PC has
		 * any BONUS:VISION tags which will create a new visionMap entry, and
		 * add any BONUS to existing entries in the map
		 */
    int a = (int) bonusCheckingFacet.getBonus(id, "VISION", type.toString());
    if (a > 0) {
        if (i == null || i < a) {
            i = a;
        }
    }
    if (i == null) {
        return null;
    }
    return new Vision(type, FormulaFactory.getFormulaFor(i));
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) VisionType(pcgen.util.enumeration.VisionType) Formula(pcgen.base.formula.Formula) QualifiedObject(pcgen.core.QualifiedObject) Vision(pcgen.core.Vision) CDOMObject(pcgen.cdom.base.CDOMObject) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) HashMap(java.util.HashMap) Map(java.util.Map)

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