Search in sources :

Example 11 with Formula

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;
}
Also used : Formula(pcgen.base.formula.Formula)

Example 12 with Formula

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;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) VisionType(pcgen.util.enumeration.VisionType) Formula(pcgen.base.formula.Formula) QualifiedObject(pcgen.core.QualifiedObject) Vision(pcgen.core.Vision) CDOMObject(pcgen.cdom.base.CDOMObject) TreeSet(java.util.TreeSet) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with Formula

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;
}
Also used : Formula(pcgen.base.formula.Formula)

Example 14 with Formula

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;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 15 with Formula

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;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

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