Search in sources :

Example 21 with Equipment

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

the class CharacterFacadeImpl method removePurchasedEquipment.

/**
	 * @see pcgen.core.facade.CharacterFacade#removePurchasedEquipment(pcgen.core.facade.EquipmentFacade, int)
	 */
@Override
public void removePurchasedEquipment(EquipmentFacade equipment, int quantity, boolean free) {
    if (equipment == null || quantity <= 0) {
        return;
    }
    Equipment equipItemToAdjust = (Equipment) equipment;
    Equipment updatedItem = theCharacter.getEquipmentNamed(equipItemToAdjust.getName());
    double numRemoved = 0;
    // see if item is already in inventory; update it
    if (updatedItem != null) {
        final double prevQty = (updatedItem.qty() < 0) ? 0 : updatedItem.qty();
        numRemoved = Math.min(quantity, prevQty);
        final double newQty = Math.max(prevQty - numRemoved, 0);
        if (newQty <= 0) {
            // completely remove item
            updatedItem.setNumberCarried(new Float(0));
            updatedItem.setLocation(EquipmentLocation.NOT_CARRIED);
            final Equipment eqParent = updatedItem.getParent();
            if (eqParent != null) {
                eqParent.removeChild(theCharacter, updatedItem);
            }
            theCharacter.removeEquipment(updatedItem);
            purchasedEquip.removeElement(updatedItem);
        } else {
            // update item count
            theCharacter.updateEquipmentQty(updatedItem, prevQty, newQty);
            Float qty = new Float(newQty);
            updatedItem.setQty(qty);
            updatedItem.setNumberCarried(qty);
            purchasedEquip.setQuantity(equipment, qty.intValue());
        }
        theCharacter.updateEquipmentQty(updatedItem, prevQty, newQty);
        Float qty = new Float(newQty);
        updatedItem.setQty(qty);
        updatedItem.setNumberCarried(qty);
    }
    // Update the PC and equipment
    if (!free) {
        double itemCost = calcItemCost(updatedItem, numRemoved * -1, (GearBuySellScheme) gearBuySellSchemeRef.get());
        theCharacter.adjustGold(itemCost * -1);
    }
    theCharacter.setCalcEquipmentList();
    theCharacter.setDirty(true);
    updateWealthFields();
}
Also used : Equipment(pcgen.core.Equipment)

Example 22 with Equipment

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

the class CharacterFacadeImpl method isQualifiedFor.

/**
	 * @see pcgen.core.facade.CharacterFacade#isQualifiedFor(pcgen.core.facade.EquipmentFacade)
	 */
@Override
public boolean isQualifiedFor(EquipmentFacade equipment) {
    final Equipment equip = (Equipment) equipment;
    final boolean accept = PrereqHandler.passesAll(equip.getPrerequisiteList(), theCharacter, equip);
    if (accept && (equip.isShield() || equip.isWeapon() || equip.isArmor())) {
        return theCharacter.isProficientWith(equip);
    }
    return accept;
}
Also used : Equipment(pcgen.core.Equipment)

Example 23 with Equipment

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

the class CharacterFacadeImpl method openCustomizer.

private Equipment openCustomizer(Equipment aEq) {
    if (aEq == null) {
        return null;
    }
    Equipment newEquip = aEq.clone();
    if (!newEquip.containsKey(ObjectKey.BASE_ITEM)) {
        newEquip.put(ObjectKey.BASE_ITEM, CDOMDirectSingleRef.getRef(aEq));
    }
    List<VarModifier<?>> modifiers = newEquip.getListFor(ListKey.MODIFY);
    if (modifiers != null) {
        for (VarModifier<?> vm : modifiers) {
            theCharacter.addModifier(vm, newEquip, newEquip);
        }
    }
    for (EquipmentHead head : newEquip.getEquipmentHeads()) {
        modifiers = head.getListFor(ListKey.MODIFY);
        if (modifiers != null) {
            for (VarModifier<?> vm : modifiers) {
                theCharacter.addModifier(vm, head, head);
            }
        }
    }
    EquipmentBuilderFacadeImpl builder = new EquipmentBuilderFacadeImpl(newEquip, theCharacter, delegate);
    CustomEquipResult result = delegate.showCustomEquipDialog(this, builder);
    if (newEquip != null && result != CustomEquipResult.CANCELLED) {
        dataSet.addEquipment(newEquip);
    }
    //TODO if this is returning null, then the SolverManager needs to destroy the unused channels :/
    return result == CustomEquipResult.PURCHASE ? newEquip : null;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) VarModifier(pcgen.cdom.content.VarModifier) CustomEquipResult(pcgen.facade.core.UIDelegate.CustomEquipResult)

Example 24 with Equipment

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

the class CharacterFacadeImpl method addNote.

@Override
public void addNote(List<EquipmentFacade> targets) {
    List<Equipment> notedEquip = new ArrayList<>();
    for (EquipmentFacade equipmentFacade : targets) {
        if (equipmentFacade instanceof Equipment) {
            notedEquip.add((Equipment) equipmentFacade);
        }
    }
    if (notedEquip.isEmpty()) {
        return;
    }
    for (Equipment equip : notedEquip) {
        String note = getNote(equip);
        if (note == null) {
            return;
        }
        equip.setNote(note);
        purchasedEquip.modifyElement(equip);
    }
}
Also used : EquipmentFacade(pcgen.facade.core.EquipmentFacade) Equipment(pcgen.core.Equipment) ArrayList(java.util.ArrayList)

Example 25 with Equipment

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

the class CharacterFacadeImpl method removeTempBonus.

@Override
public void removeTempBonus(TempBonusFacade bonusFacade) {
    if (bonusFacade == null || !(bonusFacade instanceof TempBonusFacadeImpl)) {
        return;
    }
    TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) bonusFacade;
    Equipment aEq = null;
    if (tempBonus.getTarget() instanceof Equipment) {
        aEq = (Equipment) tempBonus.getTarget();
    }
    CDOMObject originObj = tempBonus.getOriginObj();
    TempBonusHelper.removeBonusFromCharacter(theCharacter, aEq, originObj);
    appliedTempBonuses.removeElement(tempBonus);
    refreshStatScores();
    postLevellingUpdates();
}
Also used : Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject)

Aggregations

Equipment (pcgen.core.Equipment)166 PlayerCharacter (pcgen.core.PlayerCharacter)41 ArrayList (java.util.ArrayList)28 StringTokenizer (java.util.StringTokenizer)25 EquipSet (pcgen.core.character.EquipSet)22 CDOMObject (pcgen.cdom.base.CDOMObject)20 LoadContext (pcgen.rules.context.LoadContext)15 SizeAdjustment (pcgen.core.SizeAdjustment)11 EquipmentHead (pcgen.cdom.inst.EquipmentHead)10 WeaponProf (pcgen.core.WeaponProf)10 CharID (pcgen.cdom.enumeration.CharID)9 WieldCategory (pcgen.core.character.WieldCategory)9 CDOMReference (pcgen.cdom.base.CDOMReference)8 ArmorProf (pcgen.core.ArmorProf)8 EquipmentModifier (pcgen.core.EquipmentModifier)8 Race (pcgen.core.Race)8 ShieldProf (pcgen.core.ShieldProf)8 BonusObj (pcgen.core.bonus.BonusObj)8 Test (org.junit.Test)7 ScopeInstance (pcgen.base.formula.base.ScopeInstance)7