use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class KitGear method apply.
@Override
public void apply(PlayerCharacter aPC) {
final Equipment existing = aPC.getEquipmentNamed(theEquipment.getName());
if (existing == null) {
theEquipment.setQty(new Float(theQty));
aPC.addEquipment(theEquipment);
Globals.getContext().getReferenceContext().importObject(theEquipment);
} else {
existing.setQty(existing.qty() + theQty);
}
// If the target is null, try and grab it incase it is there now
Equipment theTarget = null;
EquipSet eSet;
if (!theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_CARRIED) && !theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_NOTCARRIED) && !theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_EQUIPPED)) {
theTarget = EquipmentUtilities.findEquipmentByBaseKey(aPC.getEquipmentMasterList(), theLocation);
if (theTarget == null) {
theLocation = Constants.EQUIP_LOCATION_CARRIED;
}
}
if (theTarget == null) {
eSet = aPC.getEquipSetByIdPath(EquipSet.DEFAULT_SET_PATH);
} else {
eSet = aPC.getEquipSetForItem(aPC.getEquipSetByIdPath(EquipSet.DEFAULT_SET_PATH), theTarget);
}
//
// Equip the item to the default EquipSet.
//
aPC.addEquipToTarget(eSet, theTarget, theLocation, theEquipment, new Float(theQty));
aPC.setGold(aPC.getGold().subtract(theCost));
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class EquipmentSetFacadeImpl method quantityChanged.
@Override
public void quantityChanged(EquipmentListEvent e) {
EquipmentFacade equipmentFacade = e.getEquipment();
if (equippedItemsList.containsElement(equipmentFacade)) {
int quantity = purchasedList.getQuantity(equipmentFacade) - equippedItemsList.getQuantity(equipmentFacade);
if (quantity < 0) {
if (Logging.isDebugMode()) {
Logging.debugPrint("Currently equipped item " + equipmentFacade + " is being partially removed " + quantity + " from " + equippedItemsList.getQuantity(equipmentFacade));
}
int numStillToRemove = -1 * quantity;
List<EquipNodeImpl> affectedList = findEquipmentNodes(equipmentFacade);
// TODO: Custom sort order
affectedList.sort(new EquipLocImportantComparator());
for (EquipNodeImpl equipNode : affectedList) {
EquipSet eSet = charDisplay.getEquipSetByIdPath(equipNode.getIdPath());
if (eSet != null) {
int numToRemove = Math.min(eSet.getQty().intValue(), numStillToRemove);
removeEquipment(equipNode, numToRemove);
numStillToRemove -= numToRemove;
}
if (numStillToRemove <= 0) {
return;
}
}
}
}
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class EquipmentSetFacadeImpl method addChildrenToPath.
/**
* Recursive method to build up a tree of EquipNodes. It finds from the
* equipment list those children of the item specified by the idPath and
* adds them to the paths list. It will then do the same for each child
* that was found. If the parent is null then all direct children will be
* attached to the relevant body structure nodes.
*
* @param idPath The equipset id of the parent record.
* @param equipList The list of equipsets to be added.
* @param parent The parent node
*/
private void addChildrenToPath(String idPath, List<EquipSet> equipList, EquipNodeImpl parent) {
List<EquipNodeImpl> children = new ArrayList<>();
// process all EquipNodeImpl Items
for (int iSet = 0; iSet < equipList.size(); ++iSet) {
EquipSet es = equipList.get(iSet);
if (es.getParentIdPath().equals(idPath)) {
EquipSlot slot = Globals.getEquipSlotByName(es.getName());
EquipNodeImpl slotNode = (EquipNodeImpl) equipSlotNodeMap.get(slot);
EquipNodeImpl parentNode = parent;
if (parentNode == null) {
if (slotNode != null) {
parentNode = (EquipNodeImpl) slotNode.getParent();
} else {
for (EquipNode scanNode : nodeList) {
if ((scanNode.getNodeType() == NodeType.BODY_SLOT) && scanNode.toString().equals(es.getName())) {
parentNode = (EquipNodeImpl) scanNode;
break;
}
if ((scanNode.getNodeType() == NodeType.PHANTOM_SLOT) && scanNode.toString().equals(es.getName())) {
parentNode = (EquipNodeImpl) scanNode.getParent();
slotNode = (EquipNodeImpl) scanNode;
slot = ((EquipNodeImpl) scanNode).getSlot();
break;
}
}
}
}
if (parentNode != null) {
EquipNodeImpl node = new EquipNodeImpl(parentNode, slot, es.getItem(), es.getIdPath());
nodeList.addElement(node);
if ((slotNode != null) && (slotNode.getNodeType() == NodeType.PHANTOM_SLOT) && (getNumFreeSlots(slotNode) <= 0)) {
nodeList.removeElement(slotNode);
for (EquipNode inompatNode : getIncompatibleWeaponSlots(slotNode)) {
nodeList.removeElement(inompatNode);
}
}
updateTotalQuantity(es.getItem(), es.getItem().getQty().intValue());
// updateTotalWeight(es.getItem(), es.getItem().getQty(),
// parentNode.getBodyStructure());
// add to list for recursive calls
children.add(node);
} else {
Logging.errorPrint("Could not find parent for " + es.getName() + " for item " + es.getItem() + " at path " + es.getIdPath());
}
// and remove from tempSetList so
// it won't get processed again
equipList.remove(es);
--iSet;
}
}
// Now process the children
for (final EquipNodeImpl equipNodeImpl : children) {
addChildrenToPath(equipNodeImpl.getIdPath(), equipList, equipNodeImpl);
}
}
use of pcgen.core.character.EquipSet 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;
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class EquipmentSetFacadeImpl method updateContainerPath.
/**
* Update the path of any items contained within an equipment item being moved.
*
* @param parentOrigPath The original path of the container.
* @param parentNewPath The new path of the container.
* @param origPathToNode The map of the equipment nodes by path.
* @param origPathToEquipSet The map of the equipment sets by path.
*/
private void updateContainerPath(String parentOrigPath, String parentNewPath, Map<String, EquipNodeImpl> origPathToNode, Map<String, EquipSet> origPathToEquipSet) {
for (final Map.Entry<String, EquipSet> entry : origPathToEquipSet.entrySet()) {
String origItemPath = entry.getKey();
EquipSet itemEs = entry.getValue();
if (origItemPath.startsWith(parentOrigPath) && !origItemPath.equals(parentOrigPath)) {
String newItemPath = origItemPath.replace(parentOrigPath, parentNewPath);
itemEs.setIdPath(newItemPath);
EquipNodeImpl node = origPathToNode.get(origItemPath);
if (node != null) {
node.setIdPath(newItemPath);
nodeList.modifyElement(node);
}
}
}
}
Aggregations