Search in sources :

Example 51 with EquipSet

use of pcgen.core.character.EquipSet 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 52 with EquipSet

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

the class EquipmentSetFacadeImpl method shiftEquipSetsDown.

/**
	 * Shift the equipment sets down to make room for an item to be inserted.
	 * @param parentSet The equipment set the item is being inserted into.
	 * @param startingNode The first equipment node to be moved down.
	 * @param origPathToNode A map of the equipment nodes to their original paths.
	 * @param origPathToEquipSet A map of the equipment sets to their original paths.
	 * @return The path which has been available.
	 */
private String shiftEquipSetsDown(EquipSet parentSet, EquipNodeImpl startingNode, Map<String, EquipNodeImpl> origPathToNode, Map<String, EquipSet> origPathToEquipSet) {
    String pid = "0";
    NumberFormat format = (parentSet != null) ? new DecimalFormat("00") : new DecimalFormat("0");
    if (parentSet != null) {
        pid = parentSet.getIdPath();
    }
    //Logging.errorPrint("Moving children of " + parentSet + " down, starting with " + startingNode + " .");
    String startingPath = startingNode.idPath;
    int startingId = EquipSet.getIdFromPath(startingPath);
    for (Map.Entry<String, EquipNodeImpl> entry : origPathToNode.entrySet()) {
        String origPath = entry.getKey();
        EquipNodeImpl node = entry.getValue();
        EquipSet es = origPathToEquipSet.get(origPath);
        int esId = es.getId();
        if (es.getParentIdPath().equals(pid)) {
            if (esId >= startingId) {
                esId++;
            }
            String newPath = pid + '.' + format.format(esId);
            es.setIdPath(newPath);
            updateContainerPath(origPath, newPath, origPathToNode, origPathToEquipSet);
            node.setIdPath(newPath);
            nodeList.modifyElement(node);
        }
    }
    String newPath = pid + '.' + format.format(startingId);
    return newPath;
}
Also used : EquipSet(pcgen.core.character.EquipSet) DecimalFormat(java.text.DecimalFormat) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NumberFormat(java.text.NumberFormat)

Example 53 with EquipSet

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

the class EquipmentSetFacadeImpl method elementRemoved.

@Override
public void elementRemoved(ListEvent<EquipmentFacade> e) {
    EquipmentFacade equipmentFacade = e.getElement();
    if (equippedItemsList.containsElement(equipmentFacade)) {
        if (Logging.isDebugMode()) {
            Logging.debugPrint("Currently equipped item " + equipmentFacade + " is being removed.");
        }
    }
    List<EquipNodeImpl> affectedList = findEquipmentNodes(equipmentFacade);
    for (EquipNodeImpl equipNode : affectedList) {
        EquipSet eSet = charDisplay.getEquipSetByIdPath(equipNode.getIdPath());
        if (eSet != null) {
            removeEquipment(equipNode, eSet.getQty().intValue());
        }
    }
}
Also used : EquipmentFacade(pcgen.facade.core.EquipmentFacade) EquipSet(pcgen.core.character.EquipSet)

Example 54 with EquipSet

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

the class EquipmentSetFacadeImpl method removeEquipment.

/**
	 * @see pcgen.core.facade.EquipmentSetFacade#removeEquipment(pcgen.core.facade.EquipmentSetFacade.EquipNode, int)
	 */
@Override
public EquipmentFacade removeEquipment(EquipNode node, int quantity) {
    if (!(node instanceof EquipNodeImpl) || (node.getNodeType() != NodeType.EQUIPMENT)) {
        return null;
    }
    EquipNodeImpl targetNode = (EquipNodeImpl) node;
    EquipNodeImpl parentNode = (EquipNodeImpl) node.getParent();
    EquipSet eSet = charDisplay.getEquipSetByIdPath(targetNode.getIdPath());
    if (eSet == null) {
        Logging.errorPrint("No equipset found for node " + targetNode + " path " + targetNode.getIdPath());
        return null;
    }
    int newQty = (int) (eSet.getQty() - quantity);
    Equipment eqI = eSet.getItem();
    if (newQty <= 0) {
        // If it was a container, remove all children
        removeChildren(node);
        // remove Equipment (via EquipSet) from the PC
        theCharacter.delEquipSet(eSet);
        nodeList.removeElement(targetNode);
        // the container Equipment Object
        if (parentNode.getNodeType() == NodeType.EQUIPMENT) {
            Equipment eqP = eqI.getParent();
            if (eqP != null) {
                eqP.removeChild(theCharacter, eqI);
            }
        } else if (targetNode.getSlot() != null) {
            final EquipNodeImpl restoredNode = (EquipNodeImpl) equipSlotNodeMap.get(targetNode.getSlot());
            if ((restoredNode != null) && !nodeList.containsElement(restoredNode)) {
                nodeList.addElement(0, restoredNode);
                addCompatWeaponSlots(restoredNode);
            }
        }
    } else {
        eSet.setQty((float) newQty);
        fireQuantityChanged(targetNode);
    }
    updateTotalWeight(eqI, quantity * -1, targetNode.getBodyStructure());
    updateTotalQuantity(eqI, quantity * -1);
    updateNaturalWeaponSlots();
    theCharacter.calcActiveBonuses();
    updatePhantomSlots();
    return eqI;
}
Also used : Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet)

Example 55 with EquipSet

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

the class EquipmentSetFacadeImpl method getNewIdPath.

/**
	 * returns new id_Path with the last id one higher than the current
	 * highest id for EquipSets with the same ParentIdPath.
	 * TODO: This needs to be moved to the core.
	 * @param display The display interface for the character owning the equipset.
	 * @param parentSet The parent of the equipset that is being created, null if it a root set.
	 * @return new id path
	 **/
static String getNewIdPath(CharacterDisplay display, EquipSet parentSet) {
    String pid = "0";
    int newID = 0;
    if (parentSet != null) {
        pid = parentSet.getIdPath();
    }
    for (EquipSet es : display.getEquipSet()) {
        if (es.getParentIdPath().equals(pid) && (es.getId() > newID)) {
            newID = es.getId();
        }
    }
    ++newID;
    NumberFormat format = (parentSet != null) ? new DecimalFormat("00") : new DecimalFormat("0");
    return pid + '.' + format.format(newID);
}
Also used : EquipSet(pcgen.core.character.EquipSet) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Aggregations

EquipSet (pcgen.core.character.EquipSet)79 PlayerCharacter (pcgen.core.PlayerCharacter)32 Equipment (pcgen.core.Equipment)22 ArrayList (java.util.ArrayList)12 BonusObj (pcgen.core.bonus.BonusObj)11 HashMap (java.util.HashMap)9 LoadContext (pcgen.rules.context.LoadContext)8 EquipNode (pcgen.facade.core.EquipmentSetFacade.EquipNode)7 DecimalFormat (java.text.DecimalFormat)4 NumberFormat (java.text.NumberFormat)4 List (java.util.List)4 Map (java.util.Map)4 EquipmentList (pcgen.core.EquipmentList)4 PCTemplate (pcgen.core.PCTemplate)4 EquipSlot (pcgen.core.character.EquipSlot)4 LinkedHashMap (java.util.LinkedHashMap)3 Ability (pcgen.core.Ability)3 EquipmentModifier (pcgen.core.EquipmentModifier)3 StringTokenizer (java.util.StringTokenizer)2 CNAbility (pcgen.cdom.content.CNAbility)2