use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class Gui2InfoFactory method getCostValue.
/**
* @param equipMod
* @return Object
*/
protected String getCostValue(EquipmentModifier equipMod) {
int iPlus = equipMod.getSafe(IntegerKey.PLUS);
StringBuilder eCost = new StringBuilder(20);
if (iPlus != 0) {
eCost.append("Plus:").append(iPlus);
}
Formula baseCost = equipMod.getSafe(FormulaKey.BASECOST);
if (!"0".equals(baseCost.toString())) {
if (eCost.length() != 0) {
eCost.append(", ");
}
eCost.append("Precost:").append(baseCost);
}
Formula cost = equipMod.getSafe(FormulaKey.BASECOST);
if (!"0".equals(cost.toString())) {
if (eCost.length() != 0) {
eCost.append(", ");
}
eCost.append("Cost:").append(cost);
}
String sRet = eCost.toString();
return sRet;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class VisionFacet method getActiveVision.
/**
* Returns a non-null copy of the Collection of Vision objects which are
* active on the Player Character identified by the given CharID.
*
* This method is value-semantic in that ownership of the returned
* Collection is transferred to the class calling this method. Modification
* of the returned Collection will not modify this VisionFacet and
* modification of this VisionFacet will not modify the returned Collection.
* Modifications to the returned Collection will also not modify any future
* or previous objects returned by this (or other) methods on VisionFacet.
* If you wish to modify the information stored in this VisionFacet, you
* must use the add*() and remove*() methods of VisionFacet.
*
* @param id
* The CharID identifying the Player Character for which the
* active Vision objects is to be returned
* @return a non-null copy of the Collection of Vision objects which are
* active on the Player Character identified by the given CharID
*/
public Collection<Vision> getActiveVision(CharID id) {
Map<QualifiedObject<Vision>, Set<Object>> componentMap = getCachedMap(id);
if (componentMap == null) {
return Collections.emptyList();
}
Map<VisionType, Integer> map = new HashMap<>();
for (Map.Entry<QualifiedObject<Vision>, Set<Object>> me : componentMap.entrySet()) {
QualifiedObject<Vision> qo = me.getKey();
for (Object source : me.getValue()) {
if (prerequisiteFacet.qualifies(id, qo, source)) {
String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
Vision v = qo.getRawObject();
Formula distance = v.getDistance();
int a = formulaResolvingFacet.resolve(id, distance, sourceString).intValue();
VisionType visType = v.getType();
Integer current = map.get(visType);
if (current == null || current < a) {
map.put(visType, 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
*/
for (VisionType vType : VisionType.getAllVisionTypes()) {
int aVal = (int) bonusCheckingFacet.getBonus(id, "VISION", vType.toString());
if (aVal > 0) {
Integer current = map.get(vType);
map.put(vType, aVal + (current == null ? 0 : current));
}
}
TreeSet<Vision> returnSet = new TreeSet<>();
for (Map.Entry<VisionType, Integer> me : map.entrySet()) {
returnSet.add(new Vision(me.getKey(), FormulaFactory.getFormulaFor(me.getValue())));
}
return returnSet;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class CountToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, KitSpells kitSpells, String value) {
Formula formula = FormulaFactory.getFormulaFor(value);
if (!formula.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
}
kitSpells.setCount(formula);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class EquipBuyToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String activeValue = sep.next();
if (looksLikeAPrerequisite(activeValue)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
}
Formula f = FormulaFactory.getFormulaFor(activeValue);
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
List<Prerequisite> prereqs = new ArrayList<>();
while (sep.hasNext()) {
activeValue = sep.next();
Prerequisite prereq = getPrerequisite(activeValue);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
prereqs.add(prereq);
}
kit.put(ObjectKey.EQUIP_BUY, new QualifiedObject<>(f, prereqs));
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class TotalCostToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String activeValue = sep.next();
if (looksLikeAPrerequisite(activeValue)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
}
Formula f = FormulaFactory.getFormulaFor(activeValue);
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
List<Prerequisite> prereqs = new ArrayList<>();
while (sep.hasNext()) {
activeValue = sep.next();
Prerequisite prereq = getPrerequisite(activeValue);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put total costs after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
prereqs.add(prereq);
}
kit.put(ObjectKey.KIT_TOTAL_COST, new QualifiedObject<>(f, prereqs));
return ParseResult.SUCCESS;
}
Aggregations