Search in sources :

Example 1 with EquipmentModifier

use of pcgen.core.EquipmentModifier in project pcgen by PCGen.

the class KitGear method testApply.

@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
    actingQuantity = quantity;
    actingCost = maxCost;
    actingMods = mods == null ? null : new ArrayList<>(mods);
    actingLocation = theLocationStr;
    if (size != null) {
        actingSize = size.get();
    }
    theEquipment = null;
    theQty = 0;
    theLocation = "";
    theCost = BigDecimal.ZERO;
    processLookups(aKit, aPC);
    int aBuyRate = aKit.getBuyRate(aPC);
    final BigDecimal pcGold = aPC.getGold();
    final BigDecimal fixedTotalCost = aKit.getTotalCost(aPC);
    if (fixedTotalCost != null) {
        // We are going to charge fr the kit once, rather than for every piece of gear
        aBuyRate = 0;
    }
    List<Equipment> eqList = new ArrayList<>(equip.getContainedObjects());
    if (actingCost != null) {
        final BigDecimal bdMaxCost = new BigDecimal(Integer.toString(actingCost));
        for (Iterator<Equipment> i = eqList.iterator(); i.hasNext(); ) {
            if (i.next().getCost(aPC).compareTo(bdMaxCost) > 0) {
                i.remove();
            }
        }
    }
    if (eqList.size() == 1) {
        theEquipment = eqList.get(0);
    } else {
        List<Equipment> selected = new ArrayList<>(1);
        selected = Globals.getChoiceFromList("Choose equipment", eqList, selected, 1, aPC);
        if (selected.size() == 1) {
            theEquipment = selected.get(0);
        }
    }
    //
    // TODO: Check to see if the user has selected an item that
    // requires modification (MOD:R)
    theEquipment = theEquipment.clone();
    //
    // Resize item for character--never resize weapons or ammo, unless it's a
    // natural (weapon)
    boolean tryResize = false;
    SizeAdjustment sizeToSet = aPC.getSizeAdjustment();
    if (actingSize == null) {
        if (theEquipment.isType("Natural") || (sizeToPC != null && sizeToPC) || (!theEquipment.isWeapon() && !theEquipment.isAmmunition())) {
            tryResize = Globals.canResizeHaveEffect(theEquipment, null);
        }
    } else {
        if (sizeToPC != null && sizeToPC) {
            tryResize = Globals.canResizeHaveEffect(theEquipment, null);
        } else {
            sizeToSet = actingSize;
            tryResize = true;
        }
    }
    if (tryResize) {
        theEquipment.resizeItem(aPC, sizeToSet);
    } else {
        // We need setBase() called.  The only way to do that is to resize.
        // We will set the size to itself.
        theEquipment.resizeItem(aPC, theEquipment.getSafe(ObjectKey.SIZE).get());
    }
    //
    if (actingMods != null) {
        for (EqModRef modref : actingMods) {
            /*
				 * Going to do this the long way for now to avoid ugly entanglements
				 */
            StringBuilder sb = new StringBuilder(50);
            EquipmentModifier eqMod = modref.getRef().get();
            sb.append(eqMod.getKeyName());
            for (String assoc : modref.getChoices()) {
                sb.append(Constants.PIPE).append(eval(aPC, assoc));
            }
            theEquipment.addEqModifiers(sb.toString(), true);
        }
    }
    if (tryResize || (actingMods != null)) {
        theEquipment.nameItemFromModifiers(aPC);
    }
    if (actingQuantity == null) {
        theQty = 1;
    } else {
        theQty = actingQuantity.resolve(aPC, "").intValue();
    }
    int origQty = theQty;
    final BigDecimal eqCost = theEquipment.getCost(aPC);
    if (aBuyRate != 0) {
        if (fixedTotalCost == null) {
            final BigDecimal bdBuyRate = new BigDecimal(Integer.toString(aBuyRate)).multiply(new BigDecimal("0.01"));
            // Check to see if the PC can afford to buy this equipment. If
            // not, then decrement the quantity and try again.
            theCost = eqCost.multiply(new BigDecimal(Integer.toString(theQty))).multiply(bdBuyRate);
            while (theQty > 0) {
                if (// PC has enough?
                theCost.compareTo(pcGold) <= 0) {
                    break;
                }
                theCost = eqCost.multiply(new BigDecimal(Integer.toString(--theQty))).multiply(bdBuyRate);
            }
        }
        aPC.setGold(aPC.getGold().subtract(theCost));
    }
    boolean outOfFunds = false;
    if (theQty != origQty) {
        outOfFunds = true;
    }
    if (outOfFunds) {
        warnings.add("GEAR: Could not purchase " + (origQty - theQty) + " " + theEquipment.getName() + ". Not enough funds.");
    }
    //
    if (theQty == 0) {
        return false;
    }
    Equipment testApplyEquipment = theEquipment.clone();
    // Temporarily add the equipment so we can see if we can equip it.
    testApplyEquipment.setQty(new Float(theQty));
    aPC.addEquipment(testApplyEquipment);
    Equipment theTarget = null;
    if (actingLocation != null) {
        theLocation = actingLocation;
        if (!theLocation.equalsIgnoreCase("DEFAULT") && !theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_CARRIED) && !theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_NOTCARRIED) && !theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_EQUIPPED)) {
            theTarget = EquipmentUtilities.findEquipmentByBaseKey(aPC.getEquipmentMasterList(), theLocation);
        } else if (theLocation.equalsIgnoreCase("DEFAULT")) {
            theLocation = "";
        }
        EquipSet eSet = null;
        if (theTarget != null) {
            eSet = aPC.getEquipSetForItem(aPC.getEquipSetByIdPath(EquipSet.DEFAULT_SET_PATH), theTarget);
        }
        if (eSet == null) {
            eSet = aPC.getEquipSetByIdPath(EquipSet.DEFAULT_SET_PATH);
        }
        if (eSet == null) {
            warnings.add("GEAR: Could not find location " + theLocation + " for gear " + testApplyEquipment.getName() + ".");
            return false;
        } else {
            EquipSet eqSet = aPC.addEquipToTarget(eSet, theTarget, theLocation, testApplyEquipment, new Float(-1.0f));
            if (eqSet == null) {
                warnings.add("GEAR: Could not equip " + testApplyEquipment.getName() + " to " + theLocation);
            }
        }
    }
    return true;
}
Also used : EquipSet(pcgen.core.character.EquipSet) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) EquipmentModifier(pcgen.core.EquipmentModifier) Equipment(pcgen.core.Equipment) EqModRef(pcgen.cdom.helper.EqModRef) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 2 with EquipmentModifier

use of pcgen.core.EquipmentModifier in project pcgen by PCGen.

the class GlobalQualifyTest method testFromEqMod.

@Override
@Test
public void testFromEqMod() throws PersistenceLayerException {
    EquipmentModifier source = create(EquipmentModifier.class, "Source");
    ParseResult result = token.parseToken(context, source, "RACE|Dwarf");
    assertFalse(result.passed());
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) ParseResult(pcgen.rules.persistence.token.ParseResult) Test(org.junit.Test) AbstractContentTokenTest(tokencontent.testsupport.AbstractContentTokenTest)

Example 3 with EquipmentModifier

use of pcgen.core.EquipmentModifier in project pcgen by PCGen.

the class EquipmentBuilderFacadeImpl method removeModFromEquipment.

@Override
public boolean removeModFromEquipment(EquipModFacade modifier, EquipmentHead head) {
    if (modifier == null || !(modifier instanceof EquipmentModifier)) {
        return false;
    }
    EquipmentModifier equipMod = (EquipmentModifier) modifier;
    if (baseEquipment.getEqModifierList(true).contains(equipMod)) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_eqCust_RemoveBaseErr", equipMod));
        return false;
    }
    // Trash the cost modifications
    equip.setCostMod("0");
    equip.removeEqModifier(equipMod, head.isPrimary(), character);
    equip.nameItemFromModifiers(character);
    refreshAvailList();
    refreshSelectedList();
    return true;
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier)

Example 4 with EquipmentModifier

use of pcgen.core.EquipmentModifier in project pcgen by PCGen.

the class EquipmentBuilderFacadeImpl method refreshAvailList.

private void refreshAvailList() {
    List<String> aFilter = equip.typeList();
    for (EquipmentHead head : equipHeads) {
        List<EquipModFacade> newEqMods = new ArrayList<>();
        for (EquipmentModifier aEqMod : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(EquipmentModifier.class)) {
            if (equip.isVisible(character, aEqMod, head.isPrimary(), View.VISIBLE_DISPLAY)) {
                if (aEqMod.isType("ALL")) {
                    newEqMods.add(aEqMod);
                } else {
                    for (String aType : aFilter) {
                        if (aEqMod.isType(aType)) {
                            newEqMods.add(aEqMod);
                            break;
                        }
                    }
                }
            }
        }
        availListMap.get(head).updateContents(newEqMods);
    }
}
Also used : EquipModFacade(pcgen.facade.core.EquipModFacade) EquipmentModifier(pcgen.core.EquipmentModifier) ArrayList(java.util.ArrayList)

Example 5 with EquipmentModifier

use of pcgen.core.EquipmentModifier in project pcgen by PCGen.

the class ActiveEqModFacet method dataAdded.

/**
	 * Adds the EqMods associated with a piece of Equipment which is equipped by
	 * a Player Character.
	 * 
	 * Triggered when one of the Facets to which ActiveEqModFacet listens fires
	 * a DataFacetChangeEvent to indicate a piece of Equipment was equipped by 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, Equipment> dfce) {
    /*
		 * In theory, this doesn't need to check for additions/removals from the
		 * EqMod list, because such changes can't happen to equipment that is
		 * currently equipped by the PC (new equipment is a clone, not the
		 * original item)
		 */
    CharID id = dfce.getCharID();
    Equipment eq = dfce.getCDOMObject();
    for (EquipmentModifier eqMod : eq.getEqModifierList(true)) {
        add(id, eqMod, eq);
    }
    for (EquipmentModifier eqMod : eq.getEqModifierList(false)) {
        add(id, eqMod, eq);
    }
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) Equipment(pcgen.core.Equipment) CharID(pcgen.cdom.enumeration.CharID)

Aggregations

EquipmentModifier (pcgen.core.EquipmentModifier)25 Equipment (pcgen.core.Equipment)8 EqModRef (pcgen.cdom.helper.EqModRef)5 StringTokenizer (java.util.StringTokenizer)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 BigDecimal (java.math.BigDecimal)3 Test (org.junit.Test)3 EquipmentHead (pcgen.cdom.inst.EquipmentHead)3 BonusObj (pcgen.core.bonus.BonusObj)3 EquipSet (pcgen.core.character.EquipSet)3 ArrayList (java.util.ArrayList)2 Formula (pcgen.base.formula.Formula)2 CharID (pcgen.cdom.enumeration.CharID)2 GameMode (pcgen.core.GameMode)2 PCTemplate (pcgen.core.PCTemplate)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 Race (pcgen.core.Race)2 SizeAdjustment (pcgen.core.SizeAdjustment)2 LoadContext (pcgen.rules.context.LoadContext)2 HashSet (java.util.HashSet)1