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