Search in sources :

Example 96 with Equipment

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

the class ActiveEqModFacet method dataRemoved.

/**
	 * Removes the EqMods associated with a piece of Equipment which is
	 * unequipped by a Player Character.
	 * 
	 * Triggered when one of the Facets to which ActiveEqModFacet listens fires
	 * a DataFacetChangeEvent to indicate a piece of Equipment was unequipped by
	 * a Player Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, Equipment> dfce) {
    CharID id = dfce.getCharID();
    Equipment eq = dfce.getCDOMObject();
    for (EquipmentModifier eqMod : eq.getEqModifierList(true)) {
        remove(id, eqMod, eq);
    }
    for (EquipmentModifier eqMod : eq.getEqModifierList(false)) {
        remove(id, eqMod, eq);
    }
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) Equipment(pcgen.core.Equipment) CharID(pcgen.cdom.enumeration.CharID)

Example 97 with Equipment

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

the class TotalWeightFacet method getTotalWeight.

/**
	 * Returns the total Equipment weight for the Player Character identified by
	 * the given CharID.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            total Equipment weight is to be returned
	 * @return The total Equipment weight for the Player Character identified by
	 *         the given CharID
	 */
public Float getTotalWeight(CharID id) {
    float totalWeight = 0;
    final Float floatZero = 0.0f;
    boolean firstClothing = !Globals.checkRule(RuleConstants.CLOTHINGENCUMBRANCE);
    PlayerCharacter pc = trackingFacet.getPC(id);
    for (Equipment eq : equipmentFacet.getSet(id)) {
        // Loop through the list of top
        if ((eq.getCarried().compareTo(floatZero) > 0) && (eq.getParent() == null)) {
            if (eq.getChildCount() > 0) {
                totalWeight += (eq.getWeightAsDouble(pc) + eq.getContainedWeight(pc));
            } else {
                if (firstClothing && eq.isEquipped() && eq.isType("CLOTHING")) {
                    // The first equipped set of clothing should have a
                    // weight of 0. Feature #437410
                    firstClothing = false;
                    totalWeight += (eq.getWeightAsDouble(pc) * Math.max(eq.getCarried() - 1, 0));
                } else {
                    totalWeight += (eq.getWeightAsDouble(pc) * eq.getCarried());
                }
            }
        }
    }
    return totalWeight;
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment)

Example 98 with Equipment

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

the class CharacterFacadeImpl method isQualifiedFor.

@Override
public boolean isQualifiedFor(EquipmentFacade equipFacade, EquipModFacade eqModFacade) {
    if (!(equipFacade instanceof Equipment) || !(eqModFacade instanceof EquipmentModifier)) {
        return false;
    }
    Equipment equip = (Equipment) equipFacade;
    EquipmentModifier eqMod = (EquipmentModifier) eqModFacade;
    //TODO: Handle second head
    return equip.canAddModifier(theCharacter, eqMod, true);
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) Equipment(pcgen.core.Equipment)

Example 99 with Equipment

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

the class CharacterFacadeImpl method deleteCustomEquipment.

@Override
public void deleteCustomEquipment(EquipmentFacade eqFacade) {
    if (eqFacade == null || !(eqFacade instanceof Equipment)) {
        return;
    }
    Equipment itemToBeDeleted = (Equipment) eqFacade;
    if (!itemToBeDeleted.isType(Constants.TYPE_CUSTOM)) {
        return;
    }
    if (!delegate.showWarningConfirm(LanguageBundle.getString(//$NON-NLS-1$
    "in_igDeleteCustomWarnTitle"), //$NON-NLS-1$
    LanguageBundle.getFormattedString(//$NON-NLS-1$
    "in_igDeleteCustomWarning", itemToBeDeleted))) {
        return;
    }
    removePurchasedEquipment(itemToBeDeleted, Integer.MAX_VALUE, false);
    Globals.getContext().getReferenceContext().forget(itemToBeDeleted);
    if (dataSet.getEquipment() instanceof DefaultListFacade<?>) {
        ((DefaultListFacade<EquipmentFacade>) dataSet.getEquipment()).removeElement(itemToBeDeleted);
    }
}
Also used : Equipment(pcgen.core.Equipment) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 100 with Equipment

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

the class GetVarCommand method run.

/**
	 * Runs getvar on the inStack. The parameter is popped
	 * off the {@code inStack}, and the variable's value is
	 * pushed back to the top of {@code inStack}.
	 * @param inStack the jep stack
	 * @throws ParseException
	 */
//Uses JEP, which doesn't use generics
@SuppressWarnings("unchecked")
@Override
public void run(final Stack inStack) throws ParseException {
    // check the stack
    checkStack(inStack);
    // get the parameter from the stack
    final Object param1;
    Object param2 = null;
    //
    if (curNumberOfParameters == 1) {
        param1 = inStack.pop();
    } else if (curNumberOfParameters == 2) {
        param2 = inStack.pop();
        param1 = inStack.pop();
        if (!(param2 instanceof Double)) {
            throw new ParseException("Invalid parameter type");
        }
    } else {
        throw new ParseException("Invalid parameter count");
    }
    if (param1 instanceof String) {
        Float result = null;
        if (parent instanceof PlayerCharacter) {
            final PlayerCharacter character = (PlayerCharacter) parent;
            result = getVariableForCharacter(character, param1);
        } else if (parent instanceof Equipment) {
            boolean bPrimary = true;
            if (param2 != null) {
                bPrimary = (((Double) param2).intValue() != 0);
            }
            result = ((Equipment) parent).getVariableValue((String) param1, "", bPrimary, null);
        } else if (parent instanceof VariableProcessorPC) {
            final VariableProcessorPC vpc = (VariableProcessorPC) parent;
            // check to see if this is just a variable
            result = vpc.lookupVariable((String) param1, variableSource, null);
            if (result == null) {
                result = vpc.getVariableValue(null, (String) param1, variableSource, 0);
            }
        } else if (parent instanceof VariableProcessorEq) {
            VariableProcessorEq veq = (VariableProcessorEq) parent;
            result = veq.getVariableValue(null, (String) param1, variableSource, 0);
        } else if (parent == null) {
            Logging.errorPrint("Ignored request for var " + String.valueOf(param1) + " with no parent.");
        }
        if (result == null) {
            throw new ParseException("Error retreiving variable:" + param1);
        }
        inStack.push(result.doubleValue());
    } else {
        throw new ParseException("Invalid parameter type");
    }
}
Also used : VariableProcessorPC(pcgen.core.VariableProcessorPC) PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) VariableProcessorEq(pcgen.core.VariableProcessorEq) ParseException(org.nfunk.jep.ParseException)

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