Search in sources :

Example 6 with Equipment

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

the class EquipmentSetFacadeImpl method addEquipment.

@Override
public EquipmentFacade addEquipment(EquipNode node, EquipmentFacade equipment, int quantity, EquipNode beforeNode) {
    if (!(node instanceof EquipNodeImpl)) {
        return null;
    }
    if (!(equipment instanceof Equipment)) {
        return null;
    }
    Equipment item = (Equipment) equipment;
    EquipNodeImpl targetNode = (EquipNodeImpl) node;
    // Validate the item can go into the location.
    if (!canEquip(targetNode, equipment)) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_equipCannotEquipToLocation", item.toString(), targetNode.toString()));
        return null;
    }
    EquipNodeImpl parent;
    EquipSet parentEs;
    EquipSlot equipSlot;
    String locName;
    switch(targetNode.getNodeType()) {
        case BODY_SLOT:
            parent = targetNode;
            parentEs = eqSet;
            equipSlot = null;
            locName = parent.toString();
            break;
        case PHANTOM_SLOT:
            parent = (EquipNodeImpl) targetNode.getParent();
            parentEs = eqSet;
            equipSlot = targetNode.getSlot();
            locName = equipSlot.toString();
            break;
        case EQUIPMENT:
            parent = targetNode;
            parentEs = charDisplay.getEquipSetByIdPath(parent.getIdPath());
            equipSlot = targetNode.getSlot();
            locName = parent.toString();
            break;
        default:
            // Should never occur
            return null;
    }
    // Check for adding more instances to an existing item, but don't merge containers
    if (!item.isContainer()) {
        for (EquipNode existing : nodeList) {
            if (parent.equals(existing.getParent()) && (existing.getNodeType() == NodeType.EQUIPMENT)) {
                EquipNodeImpl existingImpl = (EquipNodeImpl) existing;
                if ((equipSlot != null) && !equipSlot.equals(existingImpl.getSlot())) {
                    continue;
                }
                Equipment existingItem = (Equipment) existing.getEquipment();
                if (existingItem.equals(item)) {
                    int totalQuantity = (int) (existingItem.getQty() + quantity);
                    existingItem.setQty(totalQuantity);
                    EquipSet es = charDisplay.getEquipSetByIdPath(((EquipNodeImpl) existing).getIdPath());
                    es.setQty(es.getQty() + quantity);
                    updateTotalWeight(existingItem, quantity, parent.getBodyStructure());
                    fireQuantityChanged(existing);
                    updateTotalQuantity(existingItem, quantity);
                    updateNaturalWeaponSlots();
                    updatePhantomSlots();
                    return existingItem;
                }
            }
        }
    }
    // Create equip set for the item
    String id;
    if ((beforeNode != null) && (beforeNode instanceof EquipNodeImpl)) {
        id = shiftEquipSetsDown(parentEs, (EquipNodeImpl) beforeNode, buildPathNodeMap(), buildPathEquipSetMap());
    } else {
        id = EquipmentSetFacadeImpl.getNewIdPath(charDisplay, parentEs);
    }
    Equipment newItem = item.clone();
    EquipSet newSet = new EquipSet(id, locName, newItem.getName(), newItem);
    newItem.setQty(quantity);
    newSet.setQty((float) quantity);
    theCharacter.addEquipSet(newSet);
    Equipment eqTarget = parentEs.getItem();
    if ((eqTarget != null) && eqTarget.isContainer()) {
        eqTarget.insertChild(theCharacter, newItem);
        newItem.setParent(eqTarget);
    }
    // Create EquipNode for the item
    EquipNodeImpl itemNode = new EquipNodeImpl(parent, equipSlot, newItem, id);
    nodeList.addElement(itemNode);
    if ((targetNode.getNodeType() == NodeType.PHANTOM_SLOT) && (getNumFreeSlots(targetNode) <= 0)) {
        nodeList.removeElement(targetNode);
        for (EquipNode inompatNode : getIncompatibleWeaponSlots(targetNode)) {
            nodeList.removeElement(inompatNode);
        }
    }
    updateTotalWeight(newItem, quantity, parent.getBodyStructure());
    updateTotalQuantity(newItem, quantity);
    updateNaturalWeaponSlots();
    updateOutputOrder();
    theCharacter.calcActiveBonuses();
    updatePhantomSlots();
    characterFacadeImpl.postEquippingUpdates();
    return newItem;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet)

Example 7 with Equipment

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

the class SourceFileLoader method finishLoad.

private void finishLoad(final List<Campaign> aSelectedCampaignsList, LoadContext context) {
    createLangBonusObject(context);
    AbstractReferenceContext refContext = context.getReferenceContext();
    refContext.buildDeferredObjects();
    refContext.buildDerivedObjects();
    referenceAllCategories(context);
    context.resolveDeferredTokens();
    LoadValidator validator = new LoadValidator(aSelectedCampaignsList);
    refContext.validate(validator);
    refContext.resolveReferences(validator);
    context.resolvePostValidationTokens();
    context.resolvePostDeferredTokens();
    ReferenceContextUtilities.validateAssociations(refContext, validator);
    for (Equipment eq : refContext.getConstructedCDOMObjects(Equipment.class)) {
        eq.setToCustomSize(null);
        EqModAttachment.finishEquipment(eq);
    }
}
Also used : Equipment(pcgen.core.Equipment) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) LoadValidator(pcgen.rules.context.LoadValidator)

Example 8 with Equipment

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

the class AbstractProfProvider method getLstFormat.

/**
	 * Returns the LST format for this AbstractProfProvider. Provided primarily
	 * to allow the Token/Loader system to properly unparse the
	 * AbstractProfProvider.
	 * 
	 * @return The LST format of this AbstractProfProvider
	 */
@Override
public String getLstFormat() {
    StringBuilder sb = new StringBuilder();
    boolean typeEmpty = byEquipType.isEmpty();
    if (!direct.isEmpty()) {
        sb.append(ReferenceUtilities.joinLstFormat(direct, Constants.PIPE));
        if (!typeEmpty) {
            sb.append(Constants.PIPE);
        }
    }
    if (!typeEmpty) {
        boolean needPipe = false;
        String subType = getSubType();
        String dot = Constants.DOT;
        for (CDOMReference<Equipment> ref : byEquipType) {
            if (needPipe) {
                sb.append(Constants.PIPE);
            }
            needPipe = true;
            String lstFormat = ref.getLSTformat(false);
            if (lstFormat.startsWith("TYPE=")) {
                sb.append(subType).append("TYPE=");
                StringTokenizer st = new StringTokenizer(lstFormat.substring(5), dot);
                boolean needDot = false;
                while (st.hasMoreTokens()) {
                    String tok = st.nextToken();
                    if (!tok.equals(subType)) {
                        if (needDot) {
                            sb.append(dot);
                        }
                        needDot = true;
                        sb.append(tok);
                    }
                }
            }
        }
    }
    return sb.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment)

Example 9 with Equipment

use of pcgen.core.Equipment 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)

Example 10 with Equipment

use of pcgen.core.Equipment 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

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