Search in sources :

Example 1 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.

the class Equipment method addEqModifier.

/**
	 * Adds a feature to the EqModifier attribute of the Equipment object. If a
	 * non-null selectedChoice is supplied, this method will not be interactive,
	 * and will not show a dialog if a choice is required. Instead, the provided
	 * value will be used.
	 * 
	 * @param eqMod
	 *            The feature to be added to the EqModifier attribute
	 * @param bPrimary
	 *            The feature to be added to the EqModifier attribute
	 * @param aPC
	 *            The PC that the modifier is being added for.
	 * @param selectedChoice
	 *            The choice to be used instead of asking the user, should a
	 *            choice be required.
	 * @param equipChoice
	 *            The details of the choice to be made. Used when there are
	 *            secondary options.
	 */
public void addEqModifier(final EquipmentModifier eqMod, final boolean bPrimary, final PlayerCharacter aPC, final String selectedChoice, final EquipmentChoice equipChoice) {
    boolean bImporting = false;
    if ((aPC != null) && aPC.isImporting()) {
        bImporting = true;
    }
    if (!bImporting && !canAddModifier(aPC, eqMod, bPrimary)) {
        return;
    }
    List<CDOMSingleRef<EquipmentModifier>> replaces = eqMod.getListFor(ListKey.REPLACED_KEYS);
    EquipmentHead head = getEquipmentHead(bPrimary ? 1 : 2);
    if (replaces != null) {
        //
        for (CDOMSingleRef<EquipmentModifier> ref : replaces) {
            EquipmentModifier mod = ref.get();
            String key = mod.getKeyName();
            for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
                if (key.equalsIgnoreCase(aMod.getKeyName())) {
                    head.removeFromListFor(ListKey.EQMOD, aMod);
                    head.removeVarModifiers(aPC.getCharID(), aMod);
                    if (bPrimary) {
                        usePrimaryCache = false;
                    } else {
                        useSecondaryCache = false;
                    }
                    setDirty(true);
                }
            }
        }
    }
    if (eqMod.isType("BaseMaterial")) {
        for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
            if (aMod.isType("BaseMaterial")) {
                head.removeFromListFor(ListKey.EQMOD, aMod);
                head.removeVarModifiers(aPC.getCharID(), aMod);
                if (bPrimary) {
                    usePrimaryCache = false;
                } else {
                    useSecondaryCache = false;
                }
                setDirty(true);
            }
        }
    } else if (eqMod.isType("MagicalEnhancement")) {
        for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
            if (aMod.isType("MagicalEnhancement")) {
                head.removeFromListFor(ListKey.EQMOD, aMod);
                head.removeVarModifiers(aPC.getCharID(), aMod);
                if (bPrimary) {
                    usePrimaryCache = false;
                } else {
                    useSecondaryCache = false;
                }
            }
        }
    }
    //
    // Add the modifier if it's not already there
    //
    EquipmentModifier aMod = getEqModifierKeyed(eqMod.getKeyName(), bPrimary);
    if (aMod == null) {
        //
        if (!eqMod.getSafe(StringKey.CHOICE_STRING).isEmpty()) {
            aMod = eqMod.clone();
            if (aMod == null) {
                return;
            }
        } else {
            aMod = eqMod;
        }
        head.addToListFor(ListKey.EQMOD, aMod);
        head.addVarModifiers(aPC.getCharID(), aMod);
        if (bPrimary) {
            usePrimaryCache = false;
        } else {
            useSecondaryCache = false;
        }
    }
    //
    if (!bImporting) {
        boolean allRemoved = false;
        if (selectedChoice != null && !selectedChoice.isEmpty()) {
            if (!eqMod.getSafe(StringKey.CHOICE_STRING).startsWith("EQBUILDER.")) {
                EquipmentChoiceDriver.setChoice(this, aMod, selectedChoice, equipChoice);
                allRemoved = !hasAssociations(aMod);
            }
        } else if (!EquipmentChoiceDriver.getChoice(1, this, aMod, true, aPC)) {
            allRemoved = true;
        }
        if (allRemoved) {
            head.removeFromListFor(ListKey.EQMOD, aMod);
            head.removeVarModifiers(aPC.getCharID(), aMod);
            if (bPrimary) {
                usePrimaryCache = false;
            } else {
                useSecondaryCache = false;
            }
        }
    }
    setBase();
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Example 2 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.

the class Equipment method getDamage.

private String getDamage(PlayerCharacter apc, boolean bPrimary) {
    int headnum = bPrimary ? 1 : 2;
    EquipmentHead head = getEquipmentHeadReference(headnum);
    if (head == null) {
        return "";
    }
    String dam = head.get(StringKey.DAMAGE);
    if (!isWeapon() || (!bPrimary && !isDouble())) {
        return dam == null ? "" : dam;
    }
    if (bPrimary && dam == null) {
        // No need to grab reference, always exists due to if above
        EquipmentHead altHead = getEquipmentHead(2);
        dam = altHead.get(StringKey.DAMAGE);
    }
    String override = get(StringKey.DAMAGE_OVERRIDE);
    if (bPrimary && override != null) {
        // this overides the base damage
        dam = override;
    }
    if (dam == null) {
        dam = getWeaponInfo("DAMAGE", bPrimary);
    }
    final int iSize = sizeInt();
    int iMod = iSize + (int) bonusTo(apc, "EQMWEAPON", "DAMAGESIZE", bPrimary);
    iMod += (int) bonusTo(apc, "WEAPON", "DAMAGESIZE", bPrimary);
    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    if (iMod < 0) {
        iMod = 0;
    } else {
        int maxIndex = ref.getConstructedObjectCount(SizeAdjustment.class) - 1;
        if (iMod > maxIndex) {
            iMod = maxIndex;
        }
    }
    SizeAdjustment sa = ref.getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(iMod);
    return adjustDamage(dam, sa);
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext)

Example 3 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.

the class Equipment method getItemNameFromModifiers.

/**
	 * Get the item name based off the modifiers
	 * 
	 * @param baseName base name of the object, may instead be the base key if generating a key
	 * @return item name based off the modifiers
	 */
public String getItemNameFromModifiers(String baseName) {
    CDOMSingleRef<Equipment> baseItem = get(ObjectKey.BASE_ITEM);
    if (baseItem == null) {
        return getName();
    }
    final List<EquipmentModifier> modList;
    EquipmentHead head = getEquipmentHeadReference(1);
    if (head == null) {
        modList = Collections.emptyList();
    } else {
        modList = head.getSafeListFor(ListKey.EQMOD);
    }
    EquipmentHead althead = getEquipmentHeadReference(2);
    final List<EquipmentModifier> altModList;
    if (althead == null) {
        altModList = Collections.emptyList();
    } else {
        altModList = althead.getSafeListFor(ListKey.EQMOD);
    }
    final List<EquipmentModifier> commonList = new ArrayList<>();
    final List<List<EquipmentModifier>> modListByFC = initSplitModList();
    final List<List<EquipmentModifier>> altModListByFC = initSplitModList();
    final List<List<EquipmentModifier>> commonListByFC = initSplitModList();
    final Equipment baseEquipment = baseItem.get();
    if (baseEquipment != null) {
        modList.removeAll(baseEquipment.getEqModifierList(true));
        altModList.removeAll(baseEquipment.getEqModifierList(false));
    }
    for (Iterator<EquipmentModifier> it = modList.iterator(); it.hasNext(); ) {
        EquipmentModifier eqMod = it.next();
        if (eqMod.getSafe(ObjectKey.VISIBILITY).equals(Visibility.HIDDEN)) {
            it.remove();
        }
    }
    extractListFromCommon(commonList, modList);
    removeCommonFromList(altModList, commonList, "eqMod expected but not found: ");
    // Remove masterwork from the list if magic is present
    suppressMasterwork(commonList);
    // Split the eqmod lists by format category
    splitModListByFormatCat(commonList, commonListByFC);
    splitModListByFormatCat(modList, modListByFC);
    splitModListByFormatCat(altModList, altModListByFC);
    final StringBuilder itemName = new StringBuilder(100);
    // Add in front eq mods
    int fcf = EqModFormatCat.FRONT.ordinal();
    itemName.append(buildEqModDesc(commonListByFC.get(fcf), modListByFC.get(fcf), altModListByFC.get(fcf)));
    if (itemName.length() > 0) {
        itemName.append(' ');
    }
    // Add in the base name, less any modifiers
    baseName = baseName.trim();
    int idx = baseName.indexOf('(');
    if (idx >= 0) {
        itemName.append(baseName.substring(0, idx - 1).trim());
    } else {
        itemName.append(baseName);
    }
    // Add in middle mods
    int fcm = EqModFormatCat.MIDDLE.ordinal();
    String eqmodDesc1 = buildEqModDesc(commonListByFC.get(fcm), modListByFC.get(fcm), altModListByFC.get(fcm));
    if (!eqmodDesc1.isEmpty()) {
        itemName.append(' ').append(eqmodDesc1);
    }
    // Tack on the original modifiers
    if (idx >= 0) {
        itemName.append(' ');
        itemName.append(baseName.substring(idx));
    }
    // Strip off the ending ')' in anticipation of more modifiers
    final int idx1 = itemName.toString().lastIndexOf(')');
    if (idx1 >= 0) {
        itemName.setLength(idx1);
        itemName.append('/');
    } else {
        itemName.append(" (");
    }
    //
    // Put size in name if not the same as the base item
    //
    SizeAdjustment thisSize = getSafe(ObjectKey.SIZE).get();
    if (!getSafe(ObjectKey.BASESIZE).get().equals(thisSize)) {
        itemName.append(thisSize.getDisplayName());
        itemName.append('/');
    }
    // Put in parens mods
    int fcp = EqModFormatCat.PARENS.ordinal();
    itemName.append(buildEqModDesc(commonListByFC.get(fcp), modListByFC.get(fcp), altModListByFC.get(fcp)));
    //
    if (itemName.toString().endsWith("/") || itemName.toString().endsWith(";")) {
        itemName.setLength(itemName.length() - 1);
    }
    itemName.append(')');
    // If there were no modifiers, then strip the empty parenthesis
    final int idx2 = itemName.toString().indexOf(" ()");
    if (idx2 >= 0) {
        itemName.setLength(idx2);
    }
    return itemName.toString();
}
Also used : ArrayList(java.util.ArrayList) EquipmentHead(pcgen.cdom.inst.EquipmentHead) List(java.util.List) ArrayList(java.util.ArrayList) FixedStringList(pcgen.base.util.FixedStringList)

Example 4 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.

the class Equipment method getSpecialProperties.

/**
	 * Returns special properties of an Equipment.
	 * 
	 * @param aPC The PC with the Equipment
	 * @return special properties of an Equipment.
	 */
public String getSpecialProperties(final PlayerCharacter aPC) {
    final List<EquipmentModifier> modList;
    EquipmentHead head = getEquipmentHeadReference(1);
    if (head == null) {
        modList = Collections.emptyList();
    } else {
        modList = head.getSafeListFor(ListKey.EQMOD);
    }
    EquipmentHead althead = getEquipmentHeadReference(2);
    final List<EquipmentModifier> altModList;
    if (althead == null) {
        altModList = Collections.emptyList();
    } else {
        altModList = althead.getSafeListFor(ListKey.EQMOD);
    }
    final List<EquipmentModifier> comn = new ArrayList<>();
    extractListFromCommon(comn, modList);
    removeCommonFromList(altModList, comn, "SPROP: eqMod expected but not found: ");
    final String common = StringUtil.join(getSpecialAbilityTimesList(getSpecialAbilityList(comn, aPC)), ", ");
    final String saList1 = StringUtil.join(getSpecialAbilityTimesList(getSpecialAbilityList(modList, aPC)), ", ");
    final String saList2 = StringUtil.join(getSpecialAbilityTimesList(getSpecialAbilityList(altModList, aPC)), ", ");
    final StringBuilder sp = new StringBuilder(200);
    boolean first = true;
    for (SpecialProperty sprop : getSafeListFor(ListKey.SPECIAL_PROPERTIES)) {
        final String text = sprop.getParsedText(aPC, this, this);
        if (!"".equals(text)) {
            if (!first) {
                sp.append(", ");
            }
            first = false;
            sp.append(text);
        }
    }
    if (!common.isEmpty()) {
        if (!first) {
            sp.append(", ");
        }
        first = false;
        sp.append(common);
    }
    if (!saList1.isEmpty()) {
        if (!first) {
            sp.append(", ");
        }
        first = false;
        if (isDouble()) {
            sp.append("Head1: ");
        }
        sp.append(saList1);
    }
    if (isDouble() && (!saList2.isEmpty())) {
        if (!first) {
            sp.append(", ");
        }
        sp.append("Head2: ").append(saList2);
    }
    return sp.toString();
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) ArrayList(java.util.ArrayList)

Example 5 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.

the class Equipment method getDamageAdjustedForSize.

/**
	 * Gets the damageAdjustedForSize attribute of the Equipment object
	 *
	 * @param aSize
	 *           The size to adjust for
	 * @param bPrimary
	 *           If true get the damage for the primary head, otherwise
	 *           get the damage for the secondary head
	 * @return     The damageAdjustedForSize value
	 */
private String getDamageAdjustedForSize(final SizeAdjustment aSize, final boolean bPrimary) {
    int headnum = bPrimary ? 1 : 2;
    EquipmentHead head = getEquipmentHeadReference(headnum);
    if (head == null) {
        return null;
    }
    String dam = head.get(StringKey.DAMAGE);
    if (!isWeapon() || (!bPrimary && !isDouble())) {
        return dam;
    }
    if (dam == null) {
        dam = getWeaponInfo("DAMAGE", bPrimary);
    }
    return adjustDamage(dam, aSize);
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead)

Aggregations

EquipmentHead (pcgen.cdom.inst.EquipmentHead)43 Equipment (pcgen.core.Equipment)10 BigDecimal (java.math.BigDecimal)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 CDOMObject (pcgen.cdom.base.CDOMObject)5 EqModRef (pcgen.cdom.helper.EqModRef)5 StringTokenizer (java.util.StringTokenizer)4 ScopeInstance (pcgen.base.formula.base.ScopeInstance)4 CharID (pcgen.cdom.enumeration.CharID)4 Type (pcgen.cdom.enumeration.Type)4 ArrayList (java.util.ArrayList)3 VarScoped (pcgen.base.formula.base.VarScoped)3 VarModifier (pcgen.cdom.content.VarModifier)3 EquipmentModifier (pcgen.core.EquipmentModifier)3 TreeSet (java.util.TreeSet)2 Formula (pcgen.base.formula.Formula)2 RemoteModifier (pcgen.cdom.content.RemoteModifier)2 WeaponProf (pcgen.core.WeaponProf)2 BonusObj (pcgen.core.bonus.BonusObj)2 AbstractObjectContext (pcgen.rules.context.AbstractObjectContext)2