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;
}
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;
}
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;
}
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;
}
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));
}
Aggregations