Search in sources :

Example 1 with BodyStructure

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

the class EquipmentSetFacadeImpl method canEquip.

/**
	 * @see pcgen.core.facade.EquipmentSetFacade#canEquip(pcgen.core.facade.EquipmentSetFacade.EquipNode, pcgen.core.facade.EquipmentFacade)
	 */
@Override
public boolean canEquip(EquipNode node, EquipmentFacade equipment) {
    if (!(equipment instanceof Equipment) || (node == null)) {
        return false;
    }
    Equipment item = (Equipment) equipment;
    // Check for a required location (i.e. you can't carry a natural weapon)
    EquipNode requiredLoc = getNaturalWeaponLoc(equipment);
    if (requiredLoc != null) {
        return validLocationForNaturalWeapon(node, item, requiredLoc);
    }
    // Is this a container? Then check if the object can fit in
    if (node.getNodeType() == NodeType.EQUIPMENT) {
        EquipmentFacade parent = node.getEquipment();
        if ((parent instanceof Equipment) && ((Equipment) parent).isContainer()) {
            // Check if it fits
            if (((Equipment) parent).canContain(theCharacter, item) == 1) {
                return true;
            }
        }
    }
    if (node.getNodeType() == NodeType.PHANTOM_SLOT) {
        // Check first for an already full or taken slot
        if (!getNodes().containsElement(node)) {
            return false;
        }
        EquipSlot slot = ((EquipNodeImpl) node).getSlot();
        if (slot.canContainType(item.getType())) {
            if (item.isWeapon()) {
                final String slotName = slot.getSlotName();
                if (item.isUnarmed() && slotName.equals(Constants.EQUIP_LOCATION_UNARMED)) {
                    return true;
                }
                if (item.isShield() && slotName.equals(Constants.EQUIP_LOCATION_SHIELD)) {
                    return true;
                }
                // If it is outsized, they can't equip it to a weapon slot
                if (item.isWeaponOutsizedForPC(theCharacter)) {
                    return false;
                }
                if (slotName.startsWith(Constants.EQUIP_LOCATION_BOTH)) {
                    return true;
                }
                if (item.isMelee() && item.isDouble() && slotName.equals(Constants.EQUIP_LOCATION_DOUBLE)) {
                    return true;
                }
                if (item.isWeaponOneHanded(theCharacter)) {
                    if (slotName.equals(Constants.EQUIP_LOCATION_PRIMARY) || slotName.startsWith(Constants.EQUIP_LOCATION_SECONDARY)) {
                        return true;
                    }
                }
            } else {
                return true;
            }
        }
    }
    // Is this a body structure? Then check if the object be placed there
    if (node.getNodeType() == NodeType.BODY_SLOT) {
        BodyStructure root = (BodyStructure) node.getBodyStructure();
        if (root.isHoldsAnyType()) {
            return !root.isForbidden(item.getTrueTypeList(false));
        }
    }
    // This item can't be equipped in this location
    return false;
}
Also used : EquipmentFacade(pcgen.facade.core.EquipmentFacade) EquipSlot(pcgen.core.character.EquipSlot) Equipment(pcgen.core.Equipment) BodyStructure(pcgen.core.BodyStructure)

Example 2 with BodyStructure

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

the class EquipmentSetFacadeImplTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    dataset = new MockDataSetFacade(SettingsHandler.getGame());
    dataset.addEquipmentLocation(new BodyStructure(Constants.EQUIP_LOCATION_EQUIPPED, true));
    dataset.addEquipmentLocation(new BodyStructure(LOC_HANDS, false));
    dataset.addEquipmentLocation(new BodyStructure(LOC_BODY, false));
    if (SystemCollections.getUnmodifiableEquipSlotList().isEmpty()) {
        EquipSlot equipSlot = new EquipSlot();
        equipSlot.setSlotName(SLOT_WEAPON);
        equipSlot.addContainedType("Weapon");
        equipSlot.setContainNum(1);
        equipSlot.setSlotNumType("HANDS");
        SystemCollections.addToEquipSlotsList(equipSlot, SettingsHandler.getGame().getName());
        Globals.setEquipSlotTypeCount("HANDS", "2");
        equipSlot = new EquipSlot();
        equipSlot.setSlotName(SLOT_RING);
        equipSlot.addContainedType("Ring");
        equipSlot.setContainNum(2);
        equipSlot.setSlotNumType("BODY");
        SystemCollections.addToEquipSlotsList(equipSlot, SettingsHandler.getGame().getName());
        Globals.setEquipSlotTypeCount("BODY", "1");
    }
    uiDelegate = new MockUIDelegate();
    todoManager = new TodoManager();
    equipmentList = new EquipmentListFacadeImpl();
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) BodyStructure(pcgen.core.BodyStructure)

Example 3 with BodyStructure

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

the class EquipmentSetFacadeImpl method moveEquipment.

@Override
public boolean moveEquipment(EquipNode node, int numRowsToMove) {
    // Confirm our assumptions
    if (!(node instanceof EquipNodeImpl) || !(node.getBodyStructure() instanceof BodyStructure) || (node.getNodeType() != NodeType.EQUIPMENT) || (node.getParent() == null)) {
        return false;
    }
    if (numRowsToMove == 0) {
        return true;
    }
    BodyStructure bodyStruct = (BodyStructure) node.getBodyStructure();
    if (!bodyStruct.isHoldsAnyType()) {
        return false;
    }
    EquipNodeImpl equipNode = (EquipNodeImpl) node;
    List<EquipNode> orderedEquipNodes = new ArrayList<>(nodeList.getContents());
    Collections.sort(orderedEquipNodes);
    // Get current location
    int currLoc = orderedEquipNodes.indexOf(node);
    if (currLoc < 0) {
        return false;
    }
    // Calculate new location
    EquipNodeImpl beforeNode;
    boolean addAsLastChildOfParent = false;
    if (numRowsToMove < 0) {
        beforeNode = scanBackForNewLoc(equipNode, orderedEquipNodes, numRowsToMove * -1, currLoc);
    } else {
        beforeNode = scanForwardForNewLoc(equipNode, orderedEquipNodes, numRowsToMove, currLoc);
        addAsLastChildOfParent = beforeNode == null;
    }
    // Move the equipment item
    Map<String, EquipNodeImpl> origPathToNode = buildPathNodeMap();
    Map<String, EquipSet> origPathToEquipSet = buildPathEquipSetMap();
    nodeList.removeElement(equipNode);
    String origIdPath = equipNode.getIdPath();
    EquipSet parentEs = charDisplay.getEquipSetByIdPath(EquipSet.getParentPath(origIdPath));
    EquipSet nodeEs = charDisplay.getEquipSetByIdPath(origIdPath);
    String newIdPath;
    if (addAsLastChildOfParent) {
        newIdPath = EquipmentSetFacadeImpl.getNewIdPath(charDisplay, parentEs);
    } else {
        newIdPath = shiftEquipSetsDown(parentEs, beforeNode, origPathToNode, origPathToEquipSet);
    }
    nodeEs.setIdPath(newIdPath);
    equipNode.setIdPath(newIdPath);
    nodeList.addElement(equipNode);
    // Update children of the item
    updateContainerPath(origIdPath, newIdPath, origPathToNode, origPathToEquipSet);
    return true;
}
Also used : EquipSet(pcgen.core.character.EquipSet) BodyStructure(pcgen.core.BodyStructure) ArrayList(java.util.ArrayList)

Example 4 with BodyStructure

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

the class EquipmentSetFacadeImpl method sortEquipment.

@Override
public boolean sortEquipment(EquipNode parentNode) {
    // Confirm our assumptions
    if (!(parentNode instanceof EquipNodeImpl) || !(parentNode.getBodyStructure() instanceof BodyStructure) || ((parentNode.getNodeType() != NodeType.EQUIPMENT) && (parentNode.getNodeType() != NodeType.BODY_SLOT))) {
        return false;
    }
    BodyStructure bodyStruct = (BodyStructure) parentNode.getBodyStructure();
    if (!bodyStruct.isHoldsAnyType()) {
        return false;
    }
    String pid = ((EquipNodeImpl) parentNode).idPath;
    boolean isBodyStructure = parentNode.getBodyStructure() instanceof BodyStructure;
    List<EquipNodeImpl> childList = new ArrayList<>();
    Map<String, EquipNodeImpl> origPathToNode = buildPathNodeMap();
    Map<String, EquipSet> origPathToEquipSet = buildPathEquipSetMap();
    for (Map.Entry<String, EquipNodeImpl> entry : origPathToNode.entrySet()) {
        final String origPath = entry.getKey();
        final EquipNodeImpl node = entry.getValue();
        EquipSet es = origPathToEquipSet.get(origPath);
        if (node.parent == parentNode) {
            childList.add(node);
            if (pid == null) {
                pid = es.getParentIdPath();
            }
        }
    }
    // Sort child list
    childList.sort(new EquipNameComparator());
    // Renumber paths
    // need to start from a unique id if only sorting some nodes at a level
    int id = isBodyStructure ? theCharacter.getNewChildId(pid) : 1;
    NumberFormat format = new DecimalFormat("00");
    for (EquipNodeImpl childNode : childList) {
        String origPath = childNode.idPath;
        String newPath = pid + '.' + format.format(id);
        nodeList.removeElement(childNode);
        EquipSet es = origPathToEquipSet.get(origPath);
        es.setIdPath(newPath);
        updateContainerPath(origPath, newPath, origPathToNode, origPathToEquipSet);
        childNode.setIdPath(newPath);
        nodeList.addElement(childNode);
        id++;
    }
    return true;
}
Also used : EquipSet(pcgen.core.character.EquipSet) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) BodyStructure(pcgen.core.BodyStructure) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NumberFormat(java.text.NumberFormat)

Aggregations

BodyStructure (pcgen.core.BodyStructure)4 ArrayList (java.util.ArrayList)2 EquipSet (pcgen.core.character.EquipSet)2 EquipSlot (pcgen.core.character.EquipSlot)2 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Equipment (pcgen.core.Equipment)1 EquipmentFacade (pcgen.facade.core.EquipmentFacade)1