use of pcgen.cdom.inst.EquipmentHead 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.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class Equipment method getSlots.
/**
* The number of "Slots" that this item requires The slot type is derived
* from system/special/equipmentslot.lst
*
* @param aPC the PC with the Equipment
* @return slots
*/
public int getSlots(final PlayerCharacter aPC) {
int iSlots = getSafe(IntegerKey.SLOTS);
EquipmentHead head = getEquipmentHeadReference(1);
if (head != null) {
for (EquipmentModifier eqMod : head.getSafeListFor(ListKey.EQMOD)) {
iSlots += (int) eqMod.bonusTo(aPC, "EQM", "HANDS", this);
iSlots += (int) eqMod.bonusTo(aPC, "EQM", "SLOTS", this);
}
}
if (iSlots < 0) {
iSlots = 0;
}
return iSlots;
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class Equipment method getEquipmentHead.
public EquipmentHead getEquipmentHead(int index) {
if (index <= 0) {
throw new IndexOutOfBoundsException(Integer.toString(index));
}
int headsIndex = index - 1;
int currentSize = heads.size();
EquipmentHead head;
if (headsIndex >= currentSize) {
for (int i = 0; i < headsIndex - currentSize; i++) {
heads.add(null);
}
head = new EquipmentHead(this, index);
heads.add(head);
} else {
head = heads.get(headsIndex);
if (head == null) {
head = new EquipmentHead(this, index);
heads.set(headsIndex, head);
}
}
return head;
}
use of pcgen.cdom.inst.EquipmentHead 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.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class ModifierFacet method dataRemoved.
/**
* Triggered when one of the Facets to which ModifierFacet listens fires a
* DataFacetChangeEvent to indicate a CDOMObject was removed from a Player
* Character.
*
* Long term this method needs to be symmetric with dataAdded.
*
* @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 dataRemoved(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CharID id = dfce.getCharID();
CDOMObject obj = dfce.getCDOMObject();
List<VarModifier<?>> modifiers = obj.getListFor(ListKey.MODIFY);
if (modifiers != null) {
ScopeInstance inst = scopeFacet.get(id, obj);
for (VarModifier<?> vm : modifiers) {
processRemoval(id, obj, vm, inst);
}
}
if (obj instanceof Equipment) {
Equipment equip = (Equipment) obj;
for (EquipmentHead head : equip.getEquipmentHeads()) {
ScopeInstance inst = scopeFacet.get(id, head);
modifiers = head.getListFor(ListKey.MODIFY);
if (modifiers != null) {
for (VarModifier<?> vm : modifiers) {
processRemoval(id, equip, vm, inst);
}
}
}
}
}
Aggregations