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;
}
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);
}
}
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();
}
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);
}
}
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);
}
}
}
}
}
Aggregations