Search in sources :

Example 6 with Formula

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

the class ChallengeRatingFacet method getClassCRMod.

private int getClassCRMod(CharID id, PCClass cl) {
    int crMod = 0;
    ClassType aClassType = SettingsHandler.getGame().getClassTypeByName(cl.getClassType());
    if (aClassType != null) {
        String crmf = aClassType.getCRMod();
        Formula crm = FormulaFactory.getFormulaFor(crmf);
        crMod = Math.min(crMod, formulaResolvingFacet.resolve(id, crm, cl.getQualifiedKey()).intValue());
    } else {
        // use old method to determine the class type from TYPE. 
        for (Type type : cl.getTrueTypeList(false)) {
            aClassType = SettingsHandler.getGame().getClassTypeByName(type.toString());
            if (aClassType != null) {
                String crmf = aClassType.getCRMod();
                Formula crm = FormulaFactory.getFormulaFor(crmf);
                crMod = Math.min(crMod, formulaResolvingFacet.resolve(id, crm, cl.getQualifiedKey()).intValue());
            }
        }
    }
    return crMod;
}
Also used : Formula(pcgen.base.formula.Formula) Type(pcgen.cdom.enumeration.Type) ClassType(pcgen.core.ClassType) ClassType(pcgen.core.ClassType)

Example 7 with Formula

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

the class LevelFacet method getLevelAdjustment.

/**
	 * Returns the level adjustment for the Player Character identified by the
	 * given CharID.
	 * 
	 * @param id
	 *            The CharID of the Player Character for which the level
	 *            adjustment will be returned
	 * @return The level adjustment for the Player Character identified by the
	 *         given CharID
	 */
public int getLevelAdjustment(CharID id) {
    Race race = raceFacet.get(id);
    int levelAdj = 0;
    if (race != null) {
        Formula raceLA = race.getSafe(FormulaKey.LEVEL_ADJUSTMENT);
        levelAdj += formulaResolvingFacet.resolve(id, raceLA, "").intValue();
    }
    for (PCTemplate template : templateFacet.getSet(id)) {
        Formula templateLA = template.getSafe(FormulaKey.LEVEL_ADJUSTMENT);
        levelAdj += formulaResolvingFacet.resolve(id, templateLA, "").intValue();
    }
    return levelAdj;
}
Also used : Formula(pcgen.base.formula.Formula) Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate)

Example 8 with Formula

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

the class VariableFacet method getVariableValue.

/**
	 * Returns the numeric variable value for the given VariableKey on the
	 * Player Character identified by the given CharID. If a variable has more
	 * than one value, the given isMax argument is used to determine if this
	 * method returns the maximum (true) or minimum (false) of the calculated
	 * values.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            numeric variable value is to be returned
	 * @param key
	 *            The VariableKey identifying the variable which the value
	 *            is to be returned
	 * @param isMax
	 *            Used to determine if this method returns the maximum (true) or
	 *            minimum (false) of the calculated values when the Player
	 *            Character contains more than one value for the given
	 *            VariableKey
	 * @return The numeric variable value for the given VariableKey on the
	 *         Player Character identified by the given CharID
	 */
public Double getVariableValue(CharID id, VariableKey key, boolean isMax) {
    Map<VariableKey, Map<Formula, Set<CDOMObject>>> vkMap = getCachedMap(id);
    if (vkMap == null) {
        return null;
    }
    Map<Formula, Set<CDOMObject>> fMap = vkMap.get(key);
    if (fMap == null) {
        return null;
    }
    Double returnValue = null;
    for (Map.Entry<Formula, Set<CDOMObject>> me : fMap.entrySet()) {
        Formula f = me.getKey();
        Set<CDOMObject> sources = me.getValue();
        for (CDOMObject source : sources) {
            double newVal = formulaResolvingFacet.resolve(id, f, source.getQualifiedKey()).doubleValue();
            if (returnValue == null) {
                returnValue = newVal;
            } else if ((returnValue > newVal) ^ isMax) {
                returnValue = newVal;
            }
        }
    }
    return returnValue;
}
Also used : Formula(pcgen.base.formula.Formula) Set(java.util.Set) WrappedMapSet(pcgen.base.util.WrappedMapSet) VariableKey(pcgen.cdom.enumeration.VariableKey) CDOMObject(pcgen.cdom.base.CDOMObject) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with Formula

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

the class ChooserUtilities method getChoiceManager.

/**
	 * Make a ChoiceManager Object for the chooser appropriate for
	 * aPObject.getChoiceString();
	 * 
	 * @param aPObject
	 * @param aPC
	 * 
	 * @return an initialized ChoiceManager
	 */
public static ChoiceManagerList getChoiceManager(ChooseDriver aPObject, PlayerCharacter aPC) {
    ChooseInformation<?> chooseInfo = aPObject.getChooseInfo();
    if (chooseInfo != null) {
        Formula selectionsPerUnitCost = aPObject.getSelectFormula();
        int cost = selectionsPerUnitCost.resolve(aPC, "").intValue();
        return chooseInfo.getChoiceManager(aPObject, cost);
    }
    return null;
}
Also used : Formula(pcgen.base.formula.Formula)

Example 10 with Formula

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

the class ActiveSpellsFacet method process.

/**
	 * Currently used as a global reset for the spell list, since
	 * ActiveSpellsFacet does not currently listen to all scenarios which can
	 * alter Spells granted to a Player Character.
	 * 
	 * Use of this method outside this facet is discouraged, as the long term
	 * goal is to get all of the processing for Spells into this Facet.
	 * Therefore, use of this global reset indicates incomplete implementation
	 * of Spells processing in this facet, and should be an indication that
	 * additional work is required in order to enhance the capability of this
	 * facet to appropriately update the Spells for a Player Character.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character that requires a
	 *            reset on the list of spells granted to the Player Character.
	 */
public void process(CharID id) {
    Race race = raceFacet.get(id);
    removeAll(id, race);
    PlayerCharacter pc = trackingFacet.getPC(id);
    for (SpellLikeAbility sla : spellsFacet.getQualifiedSet(id)) {
        Formula times = sla.getCastTimes();
        int resolvedTimes = formulaResolvingFacet.resolve(id, times, sla.getQualifiedKey()).intValue();
        String book = sla.getSpellBook();
        final CharacterSpell cs = new CharacterSpell(race, sla.getSpell());
        cs.setFixedCasterLevel(sla.getFixedCasterLevel());
        SpellInfo si = cs.addInfo(0, resolvedTimes, book);
        si.setTimeUnit(sla.getCastTimeUnit());
        si.setFixedDC(sla.getDC());
        pc.addSpellBook(new SpellBook(book, SpellBook.TYPE_INNATE_SPELLS));
        add(id, cs, race);
    }
}
Also used : Formula(pcgen.base.formula.Formula) PlayerCharacter(pcgen.core.PlayerCharacter) SpellBook(pcgen.core.character.SpellBook) Race(pcgen.core.Race) SpellLikeAbility(pcgen.cdom.content.SpellLikeAbility) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

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