Search in sources :

Example 36 with Equipment

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();
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) List(java.util.List) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder)

Example 37 with Equipment

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();
}
Also used : Equipment(pcgen.core.Equipment) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder)

Example 38 with Equipment

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;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet)

Example 39 with Equipment

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);
    }
}
Also used : Equipment(pcgen.core.Equipment) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) LoadValidator(pcgen.rules.context.LoadValidator)

Example 40 with Equipment

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();
}
Also used : StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment)

Aggregations

Equipment (pcgen.core.Equipment)166 PlayerCharacter (pcgen.core.PlayerCharacter)41 ArrayList (java.util.ArrayList)28 StringTokenizer (java.util.StringTokenizer)25 EquipSet (pcgen.core.character.EquipSet)22 CDOMObject (pcgen.cdom.base.CDOMObject)20 LoadContext (pcgen.rules.context.LoadContext)15 SizeAdjustment (pcgen.core.SizeAdjustment)11 EquipmentHead (pcgen.cdom.inst.EquipmentHead)10 WeaponProf (pcgen.core.WeaponProf)10 CharID (pcgen.cdom.enumeration.CharID)9 WieldCategory (pcgen.core.character.WieldCategory)9 CDOMReference (pcgen.cdom.base.CDOMReference)8 ArmorProf (pcgen.core.ArmorProf)8 EquipmentModifier (pcgen.core.EquipmentModifier)8 Race (pcgen.core.Race)8 ShieldProf (pcgen.core.ShieldProf)8 BonusObj (pcgen.core.bonus.BonusObj)8 Test (org.junit.Test)7 ScopeInstance (pcgen.base.formula.base.ScopeInstance)7