use of pcgen.core.Equipment in project pcgen by PCGen.
the class EquipmentListFacadeImpl method refresh.
/**
* Refresh the equipment list facade with the supplied data.
* @param list The new list of equipment.
*/
public void refresh(List<Equipment> list) {
equipmentList = new ArrayList<>(list);
quantityMap = new HashMap<>();
for (Equipment equipment : list) {
quantityMap.put(equipment, equipment.getQty().intValue());
}
fireElementsChanged(this);
}
use of pcgen.core.Equipment 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;
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class EquipmentSetFacadeImpl method updateOutputOrder.
/**
* Reorder the equipment for output to cater for any changes in the
* equipment list. Note this assumes this equipment set is the active one
* as it updates the character's master equipment list.
*/
private void updateOutputOrder() {
List<EquipNode> orderedEquipNodes = new ArrayList<>(nodeList.getContents());
Collections.sort(orderedEquipNodes);
List<Equipment> processed = new ArrayList<>(orderedEquipNodes.size());
int outputIndex = 1;
for (EquipNode equipNode : orderedEquipNodes) {
if (equipNode.getEquipment() != null) {
Equipment equip = theCharacter.getEquipmentNamed(equipNode.getEquipment().toString());
// If an item is split in multiple places, don't overwrite its order
if ((equip != null) && !processed.contains(equip)) {
equip.setOutputIndex(outputIndex++);
processed.add(equip);
}
}
}
}
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();
}
Aggregations