Search in sources :

Example 6 with EquipmentHead

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;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Formula(pcgen.base.formula.Formula) BigDecimal(java.math.BigDecimal)

Example 7 with EquipmentHead

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;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead)

Example 8 with EquipmentHead

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;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead)

Example 9 with EquipmentHead

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;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Formula(pcgen.base.formula.Formula) BigDecimal(java.math.BigDecimal)

Example 10 with EquipmentHead

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);
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) VarModifier(pcgen.cdom.content.VarModifier) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Aggregations

EquipmentHead (pcgen.cdom.inst.EquipmentHead)43 Equipment (pcgen.core.Equipment)10 BigDecimal (java.math.BigDecimal)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 CDOMObject (pcgen.cdom.base.CDOMObject)5 EqModRef (pcgen.cdom.helper.EqModRef)5 StringTokenizer (java.util.StringTokenizer)4 ScopeInstance (pcgen.base.formula.base.ScopeInstance)4 CharID (pcgen.cdom.enumeration.CharID)4 Type (pcgen.cdom.enumeration.Type)4 ArrayList (java.util.ArrayList)3 VarScoped (pcgen.base.formula.base.VarScoped)3 VarModifier (pcgen.cdom.content.VarModifier)3 EquipmentModifier (pcgen.core.EquipmentModifier)3 TreeSet (java.util.TreeSet)2 Formula (pcgen.base.formula.Formula)2 RemoteModifier (pcgen.cdom.content.RemoteModifier)2 WeaponProf (pcgen.core.WeaponProf)2 BonusObj (pcgen.core.bonus.BonusObj)2 AbstractObjectContext (pcgen.rules.context.AbstractObjectContext)2