use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class Equipment method getPostSizingCostForHead.
/**
* Calculate the parts of the cost for the equipment's head that are not
* affected by size.
*
* @param aPC The character who owns the equipment.
* @param modifierCosts The array of costs to be doubled if the location demands it
* @param primaryHead Are we calculating for the primary or alternate head.
* @return The cost, non doubling cost and total plus of the head
*/
private EquipmentHeadCostSummary getPostSizingCostForHead(final PlayerCharacter aPC, final List<BigDecimal> modifierCosts, boolean primaryHead) {
EquipmentHeadCostSummary costSum = new EquipmentHeadCostSummary();
EquipmentHead head = getEquipmentHeadReference(primaryHead ? 1 : 2);
if (head != null) {
for (EquipmentModifier eqMod : head.getSafeListFor(ListKey.EQMOD)) {
int iCount = getSelectCorrectedAssociationCount(eqMod);
if (iCount < 1) {
iCount = 1;
}
BigDecimal eqModCost;
Formula cost = eqMod.getSafe(FormulaKey.COST);
String costFormula = cost.toString();
if (hasAssociations(eqMod) && !costFormula.equals(EqModCost.getCost(eqMod, getFirstAssociation(eqMod)))) {
eqModCost = BigDecimal.ZERO;
for (String assoc : getAssociationList(eqMod)) {
String v = calcEqModCost(aPC, EqModCost.getCost(eqMod, assoc), primaryHead);
final BigDecimal thisModCost = new BigDecimal(v);
eqModCost = eqModCost.add(thisModCost);
if (!EqModCost.getCostDouble(eqMod)) {
costSum.nonDoubleCost = costSum.nonDoubleCost.add(thisModCost);
} else {
modifierCosts.add(thisModCost);
}
}
iCount = 1;
} else {
String v = calcEqModCost(aPC, cost.toString(), primaryHead);
eqModCost = new BigDecimal(v);
if (!EqModCost.getCostDouble(eqMod)) {
costSum.nonDoubleCost = costSum.nonDoubleCost.add(eqModCost);
} else {
modifierCosts.add(eqModCost);
}
}
// Per D20 FAQ adjustments for special materials are per piece;
if (eqMod.isType("BaseMaterial")) {
eqModCost = eqModCost.multiply(new BigDecimal(getSafe(IntegerKey.BASE_QUANTITY)));
}
costSum.postSizeCost = costSum.postSizeCost.add(eqModCost);
costSum.headPlus += (eqMod.getSafe(IntegerKey.PLUS) * iCount);
}
}
return costSum;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class Equipment method getPreSizingCostForHead.
/**
* Calculate the parts of the cost for the equipment's head that are
* affected by size.
*
* @param aPC The character who owns the equipment.
* @param primaryHead Are we calculating for the primary or alternate head.
* @return The cost of the head
*/
private BigDecimal getPreSizingCostForHead(final PlayerCharacter aPC, boolean primaryHead) {
BigDecimal c = BigDecimal.ZERO;
EquipmentHead head = getEquipmentHeadReference(primaryHead ? 1 : 2);
if (head != null) {
bonusPrimary = primaryHead;
for (EquipmentModifier eqMod : head.getSafeListFor(ListKey.EQMOD)) {
int iCount = getSelectCorrectedAssociationCount(eqMod);
if (iCount < 1) {
iCount = 1;
}
Formula baseCost = eqMod.getSafe(FormulaKey.BASECOST);
Number bc = baseCost.resolve(this, primaryHead, aPC, "");
final BigDecimal eqModCost = new BigDecimal(bc.toString());
c = c.add(eqModCost.multiply(new BigDecimal(Integer.toString(getSafe(IntegerKey.BASE_QUANTITY) * iCount))));
c = c.add(EqModCost.addItemCosts(eqMod, aPC, "ITEMCOST", getSafe(IntegerKey.BASE_QUANTITY) * iCount, this));
}
}
return c;
}
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 SpellsFacet method dataAdded.
/**
* Adds a SpellLikeAbility to this facet if the CDOMObject added to a Player
* Character contains a SPELLS entry.
*
* Triggered when one of the Facets to which SpellsFacet listens fires a
* DataFacetChangeEvent to indicate a CDOMObject was added to a Player
* Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CharID id = dfce.getCharID();
CDOMObject cdo = dfce.getCDOMObject();
Collection<CDOMReference<Spell>> mods = cdo.getListMods(Spell.SPELLS);
if (mods == null) {
return;
}
for (CDOMReference<Spell> ref : mods) {
Collection<AssociatedPrereqObject> assocs = cdo.getListAssociations(Spell.SPELLS, ref);
Collection<Spell> spells = ref.getContainedObjects();
for (AssociatedPrereqObject apo : assocs) {
Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
String timeunit = apo.getAssociation(AssociationKey.TIME_UNIT);
// The timeunit needs to default to day as per the docs
if (timeunit == null) {
timeunit = "Day";
}
String casterlevel = apo.getAssociation(AssociationKey.CASTER_LEVEL);
String dcformula = apo.getAssociation(AssociationKey.DC_FORMULA);
String book = apo.getAssociation(AssociationKey.SPELLBOOK);
String ident = cdo.getQualifiedKey();
for (Spell sp : spells) {
SpellLikeAbility sla = new SpellLikeAbility(sp, times, timeunit, book, casterlevel, dcformula, ident);
sla.addAllPrerequisites(apo.getPrerequisiteList());
add(id, sla, cdo);
}
}
}
}
Aggregations