Search in sources :

Example 6 with EquipSlot

use of pcgen.core.character.EquipSlot in project pcgen by PCGen.

the class EquipmentSetFacadeImpl method createWeaponEquipSlot.

private EquipSlot createWeaponEquipSlot(EquipSlot slot, String slotName) {
    EquipSlot wpnSlot = slot.clone();
    wpnSlot.setSlotName(slotName);
    return wpnSlot;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot)

Example 7 with EquipSlot

use of pcgen.core.character.EquipSlot in project pcgen by PCGen.

the class EquipmentSetFacadeImpl method addCompatWeaponSlots.

/**
	 * Add back to the list any weapon slots that are now valid again. Called
	 * after a weapon is removed from a character and the weapon;s node has
	 * been added back to the node list.
	 *
	 * @param restoredNode The weapon equip node being restored.
	 */
private void addCompatWeaponSlots(final EquipNodeImpl restoredNode) {
    List<EquipNode> weaponSlots = getIncompatibleWeaponSlots(restoredNode);
    Set<EquipNode> incompatNodes = new HashSet<>();
    for (EquipNode equipNode : nodeList) {
        if ((equipNode.getNodeType() == NodeType.EQUIPMENT) && affectsWeaponSlots(equipNode)) {
            EquipSlot slot = ((EquipNodeImpl) equipNode).getSlot();
            if ((slot != null) && (equipSlotNodeMap.get(slot) != null)) {
                incompatNodes.addAll(getIncompatibleWeaponSlots((EquipNodeImpl) equipSlotNodeMap.get(slot)));
            }
        }
    }
    weaponSlots.removeAll(incompatNodes);
    for (EquipNode node : weaponSlots) {
        nodeList.addElement(0, node);
    }
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) HashSet(java.util.HashSet)

Example 8 with EquipSlot

use of pcgen.core.character.EquipSlot in project pcgen by PCGen.

the class EquipmentSetFacadeImpl method createNaturalWeaponSlots.

private void createNaturalWeaponSlots() {
    for (EquipSlot slot : SystemCollections.getUnmodifiableEquipSlotList()) {
        if (//$NON-NLS-1$
        slot.canContainType("WEAPON")) {
            for (EquipNode node : nodeList) {
                if ((node.getNodeType() == NodeType.BODY_SLOT) && slot.getBodyStructureName().equalsIgnoreCase(node.getBodyStructure().toString())) {
                    createNaturalWeaponSlot(slot, node, Constants.EQUIP_LOCATION_NATURAL_PRIMARY);
                    createNaturalWeaponSlot(slot, node, Constants.EQUIP_LOCATION_NATURAL_SECONDARY);
                    return;
                }
            }
        }
    }
}
Also used : EquipSlot(pcgen.core.character.EquipSlot)

Example 9 with EquipSlot

use of pcgen.core.character.EquipSlot 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 10 with EquipSlot

use of pcgen.core.character.EquipSlot in project pcgen by PCGen.

the class PlayerCharacter method getSingleLocation.

/**
	 * If an item can only go in one location, return the name of that location
	 * to add to an EquipSet
	 *
	 * @param eqI
	 * @return single location
	 */
private String getSingleLocation(Equipment eqI) {
    // Handle natural weapons
    String loc = getNaturalWeaponLocation(eqI);
    if (loc != null) {
        return loc;
    }
    // unless they are also armor (ie: with Armor Spikes)
    if ((eqI.isWeapon()) && !(eqI.isArmor())) {
        return Constants.EMPTY_STRING;
    }
    List<EquipSlot> eqSlotList = SystemCollections.getUnmodifiableEquipSlotList();
    if ((eqSlotList == null) || eqSlotList.isEmpty()) {
        return Constants.EMPTY_STRING;
    }
    for (EquipSlot es : eqSlotList) {
        // see if this EquipSlot can contain this item TYPE
        if (es.canContainType(eqI.getType())) {
            return es.getSlotName();
        }
    }
    return Constants.EMPTY_STRING;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot)

Aggregations

EquipSlot (pcgen.core.character.EquipSlot)15 EquipSet (pcgen.core.character.EquipSet)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Equipment (pcgen.core.Equipment)3 BodyStructure (pcgen.core.BodyStructure)2 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 Type (pcgen.cdom.enumeration.Type)1 AbilityFacade (pcgen.facade.core.AbilityFacade)1 BodyStructureFacade (pcgen.facade.core.BodyStructureFacade)1 EquipmentFacade (pcgen.facade.core.EquipmentFacade)1 DefaultListFacade (pcgen.facade.util.DefaultListFacade)1