use of pcgen.core.Equipment in project pcgen by PCGen.
the class Gui2InfoFactory method getHTMLInfo.
@Override
public String getHTMLInfo(TempBonusFacade tempBonusFacade) {
if (tempBonusFacade == null) {
return EMPTY_STRING;
}
if (!(tempBonusFacade instanceof TempBonusFacadeImpl)) {
final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
infoText.appendTitleElement(tempBonusFacade.toString());
return infoText.toString();
}
TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) tempBonusFacade;
CDOMObject originObj = tempBonus.getOriginObj();
final HtmlInfoBuilder infoText;
if (originObj instanceof Equipment) {
infoText = getEquipmentHtmlInfo((Equipment) originObj);
} else {
infoText = new HtmlInfoBuilder();
infoText.appendTitleElement(OutputNameFormatting.piString(originObj, false));
//$NON-NLS-1$ //$NON-NLS-2$
infoText.append(" (").append(tempBonus.getOriginType()).append(")");
}
if (tempBonus.getTarget() != null) {
String targetName = charDisplay.getName();
if (tempBonus.getTarget() instanceof CDOMObject) {
targetName = ((CDOMObject) tempBonus.getTarget()).getKeyName();
}
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_itmInfoLabelTextTarget", targetName);
StringBuilder bonusValues = new StringBuilder(100);
Map<BonusObj, TempBonusInfo> bonusMap = pc.getTempBonusMap(originObj.getKeyName(), targetName);
boolean first = true;
List<BonusObj> bonusList = new ArrayList<>(bonusMap.keySet());
bonusList.sort(new BonusComparator());
for (BonusObj bonusObj : bonusList) {
if (!first) {
//$NON-NLS-1$
bonusValues.append(", ");
}
first = false;
//$NON-NLS-1$
String adj = ADJ_FMT.format(bonusObj.resolve(pc, ""));
//$NON-NLS-1$
bonusValues.append(adj + " " + bonusObj.getDescription());
}
if (bonusValues.length() > 0) {
infoText.appendLineBreak();
infoText.appendI18nElement(//$NON-NLS-1$
"in_itmInfoLabelTextEffect", bonusValues.toString());
}
}
if (originObj instanceof Spell) {
Spell aSpell = (Spell) originObj;
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement(//$NON-NLS-1$
"in_spellDuration", aSpell.getListAsString(ListKey.DURATION));
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement(//$NON-NLS-1$
"in_spellRange", aSpell.getListAsString(ListKey.RANGE));
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement(//$NON-NLS-1$
"in_spellTarget", aSpell.getSafe(StringKey.TARGET_AREA));
}
String aString = originObj.getSafe(StringKey.TEMP_DESCRIPTION);
if (StringUtils.isEmpty(aString) && originObj instanceof Spell) {
Spell sp = (Spell) originObj;
aString = DescriptionFormatting.piWrapDesc(sp, pc.getDescription(sp), false);
} else if (StringUtils.isEmpty(aString) && originObj instanceof Ability) {
Ability ab = (Ability) originObj;
List<CNAbility> wrappedAbility = Collections.singletonList(CNAbilityFactory.getCNAbility(ab.getCDOMCategory(), Nature.NORMAL, ab));
aString = DescriptionFormatting.piWrapDesc(ab, pc.getDescription(wrappedAbility), false);
}
if (!aString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_itmInfoLabelTextDesc", aString);
}
aString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, originObj.getPrerequisiteList(), false);
if (!aString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_requirements", aString);
}
infoText.appendLineBreak();
infoText.appendI18nElement(//$NON-NLS-1$
"in_itmInfoLabelTextSource", SourceFormat.getFormattedString(originObj, Globals.getSourceDisplay(), true));
return infoText.toString();
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class Gui2InfoFactory method getHTMLInfo.
/**
* @see pcgen.core.facade.InfoFactory#getHTMLInfo(pcgen.core.facade.EquipmentFacade)
*/
@Override
public String getHTMLInfo(EquipmentFacade equipFacade) {
if (equipFacade == null || !(equipFacade instanceof Equipment)) {
return EMPTY_STRING;
}
Equipment equip = (Equipment) equipFacade;
final HtmlInfoBuilder b = getEquipmentHtmlInfo(equip);
String bString = equip.getSource();
if (!bString.isEmpty()) {
b.appendLineBreak();
//$NON-NLS-1$
b.appendI18nElement("in_igInfoLabelTextSource", bString);
}
b.appendLineBreak();
return b.toString();
}
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();
}
Aggregations