Search in sources :

Example 16 with Equipment

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

the class AbstractGlobalTargetedSaveRestoreTest method testAutoArmorProf.

@Test
public void testAutoArmorProf() {
    T target = create(getObjectClass(), "Target");
    ArmorProf granted = create(ArmorProf.class, "Granted");
    create(ArmorProf.class, "Ignored");
    new plugin.lsttokens.auto.ArmorProfToken().parseToken(context, target, "Granted");
    Object o = prepare(target);
    finishLoad();
    Equipment e = new Equipment();
    e.addToListFor(ListKey.TYPE, Type.ARMOR);
    e.put(ObjectKey.ARMOR_PROF, CDOMDirectSingleRef.getRef(granted));
    assertFalse(pc.isProficientWith(e));
    applyObject(target);
    assertTrue(pc.isProficientWith(e));
    runRoundRobin(getPreEqualityCleanup());
    assertTrue(pc.isProficientWith(e));
    assertTrue(reloadedPC.isProficientWith(e));
    remove(o);
    reloadedPC.setDirty(true);
    assertFalse(reloadedPC.isProficientWith(e));
}
Also used : Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) ArmorProf(pcgen.core.ArmorProf) Test(org.junit.Test)

Example 17 with Equipment

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

the class AbstractGlobalTargetedSaveRestoreTest method testAutoShieldProfList.

@Test
public void testAutoShieldProfList() {
    ShieldProf granted = create(ShieldProf.class, "Granted");
    create(ShieldProf.class, "Ignored");
    T target = create(getObjectClass(), "Target");
    new plugin.lsttokens.auto.ShieldProfToken().parseToken(context, target, "%LIST");
    new plugin.lsttokens.choose.ShieldProficiencyToken().parseToken(context, target, "Granted|Ignored");
    additionalChooseSet(target);
    Object o = prepare(target);
    finishLoad();
    Equipment e = new Equipment();
    e.addToListFor(ListKey.TYPE, Type.SHIELD);
    e.put(ObjectKey.SHIELD_PROF, CDOMDirectSingleRef.getRef(granted));
    assertFalse(pc.isProficientWith(e));
    applyObject(target);
    assertTrue(pc.isProficientWith(e));
    runRoundRobin(getPreEqualityCleanup());
    assertTrue(pc.isProficientWith(e));
    assertTrue(reloadedPC.isProficientWith(e));
    remove(o);
    reloadedPC.setDirty(true);
    if (isSymmetric()) {
        assertFalse(reloadedPC.isProficientWith(e));
    }
}
Also used : ShieldProf(pcgen.core.ShieldProf) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) Test(org.junit.Test)

Example 18 with Equipment

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

the class AbstractGlobalTargetedSaveRestoreTest method testAutoShieldProf.

@Test
public void testAutoShieldProf() {
    ShieldProf granted = create(ShieldProf.class, "Granted");
    create(ShieldProf.class, "Ignored");
    T target = create(getObjectClass(), "Target");
    new plugin.lsttokens.auto.ShieldProfToken().parseToken(context, target, "Granted");
    Object o = prepare(target);
    finishLoad();
    Equipment e = new Equipment();
    e.addToListFor(ListKey.TYPE, Type.SHIELD);
    e.put(ObjectKey.SHIELD_PROF, CDOMDirectSingleRef.getRef(granted));
    assertFalse(pc.isProficientWith(e));
    applyObject(target);
    assertTrue(pc.isProficientWith(e));
    runRoundRobin(getPreEqualityCleanup());
    assertTrue(pc.isProficientWith(e));
    assertTrue(reloadedPC.isProficientWith(e));
    remove(o);
    reloadedPC.setDirty(true);
    assertFalse(reloadedPC.isProficientWith(e));
}
Also used : ShieldProf(pcgen.core.ShieldProf) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) Test(org.junit.Test)

Example 19 with Equipment

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

the class AbstractGlobalTargetedSaveRestoreTest method testAutoArmorProfList.

@Test
public void testAutoArmorProfList() {
    T target = create(getObjectClass(), "Target");
    ArmorProf granted = create(ArmorProf.class, "Granted");
    create(ArmorProf.class, "Ignored");
    new plugin.lsttokens.auto.ArmorProfToken().parseToken(context, target, "%LIST");
    new plugin.lsttokens.choose.ArmorProficiencyToken().parseToken(context, target, "Granted|Ignored");
    additionalChooseSet(target);
    Object o = prepare(target);
    finishLoad();
    Equipment e = new Equipment();
    e.addToListFor(ListKey.TYPE, Type.ARMOR);
    e.put(ObjectKey.ARMOR_PROF, CDOMDirectSingleRef.getRef(granted));
    assertFalse(pc.isProficientWith(e));
    applyObject(target);
    assertTrue(pc.isProficientWith(e));
    runRoundRobin(getPreEqualityCleanup());
    assertTrue(pc.isProficientWith(e));
    assertTrue(reloadedPC.isProficientWith(e));
    remove(o);
    reloadedPC.setDirty(true);
    if (isSymmetric()) {
        assertFalse(reloadedPC.isProficientWith(e));
    }
}
Also used : Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) ArmorProf(pcgen.core.ArmorProf) Test(org.junit.Test)

Example 20 with Equipment

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

the class CharacterFacadeImpl method addPurchasedEquipment.

/**
	 * @see pcgen.core.facade.CharacterFacade#addPurchasedEquipment(pcgen.core.facade.EquipmentFacade, int)
	 */
@Override
public void addPurchasedEquipment(EquipmentFacade equipment, int quantity, boolean customize, boolean free) {
    if (equipment == null || quantity <= 0) {
        return;
    }
    //		int nextOutputIndex = 1;
    Equipment equipItemToAdjust = (Equipment) equipment;
    if (customize) {
        equipItemToAdjust = openCustomizer(equipItemToAdjust);
        if (equipItemToAdjust == null) {
            return;
        }
    } else {
        if (equipItemToAdjust.getSafe(ObjectKey.MOD_CONTROL).getModifiersRequired()) {
            if (!hasBeenAdjusted(equipItemToAdjust)) {
                delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString(//$NON-NLS-1$
                "in_igBuyMustCustomizeItemFirst"));
                return;
            }
        }
    }
    Equipment updatedItem = theCharacter.getEquipmentNamed(equipItemToAdjust.getName());
    if (!free && !canAfford(equipItemToAdjust, quantity, (GearBuySellScheme) gearBuySellSchemeRef.get())) {
        delegate.showInfoMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
        LanguageBundle.getFormattedString(//$NON-NLS-1$
        "in_igBuyInsufficientFunds", //$NON-NLS-1$
        quantity, equipItemToAdjust.getName()));
        return;
    }
    if (updatedItem != null) {
        // item is already in inventory; update it
        final double prevQty = (updatedItem.qty() < 0) ? 0 : updatedItem.qty();
        final double newQty = prevQty + quantity;
        theCharacter.updateEquipmentQty(updatedItem, prevQty, newQty);
        Float qty = new Float(newQty);
        updatedItem.setQty(qty);
        purchasedEquip.setQuantity(equipment, qty.intValue());
    } else {
        // item is not in inventory; add it
        updatedItem = equipItemToAdjust.clone();
        if (updatedItem != null) {
            // Set the number carried and add it to the character
            Float qty = new Float(quantity);
            updatedItem.setQty(qty);
            theCharacter.addEquipment(updatedItem);
        }
        purchasedEquip.addElement(updatedItem, quantity);
    }
    // Update the PC and equipment
    if (!free) {
        double itemCost = calcItemCost(updatedItem, quantity, (GearBuySellScheme) gearBuySellSchemeRef.get());
        theCharacter.adjustGold(itemCost * -1);
    }
    theCharacter.setCalcEquipmentList();
    theCharacter.setDirty(true);
    updateWealthFields();
}
Also used : Equipment(pcgen.core.Equipment)

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