Search in sources :

Example 31 with EquipmentHead

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

the class EqModAttachment method finishEquipment.

public static void finishEquipment(Equipment eq) {
    for (int i = 1; i <= 2; i++) {
        EquipmentHead head = eq.getEquipmentHeadReference(i);
        if (head == null) {
            continue;
        }
        List<EqModRef> modInfoList = head.getListFor(ListKey.EQMOD_INFO);
        if (modInfoList == null) {
            continue;
        }
        for (EqModRef modRef : modInfoList) {
            List<EquipmentModifier> modlist = head.getListFor(ListKey.EQMOD);
            EquipmentModifier eqMod = modRef.getRef().get();
            String eqModKey = eqMod.getKeyName();
            EquipmentModifier curMod = null;
            if (modlist != null) {
                for (EquipmentModifier mod : modlist) {
                    if (mod.getKeyName().equals(eqModKey)) {
                        curMod = mod;
                        break;
                    }
                }
            }
            // If not already attached, then add a new one
            if (curMod == null) {
                // add qualifiers to modifier
                if (!eqMod.getSafe(StringKey.CHOICE_STRING).isEmpty()) {
                    eqMod = eqMod.clone();
                }
                eq.addToEqModifierList(eqMod, i == 1);
            } else {
                eqMod = curMod;
            }
            // Add the associated choices
            if (!eqMod.getSafe(StringKey.CHOICE_STRING).isEmpty()) {
                List<String> choices = modRef.getChoices();
                for (String x : choices) {
                    Integer min = eqMod.get(IntegerKey.MIN_CHARGES);
                    if (min != null && min > 0 || (eqMod.getSafe(StringKey.CHOICE_STRING).startsWith("EQBUILDER"))) {
                        // We clear the associated info to avoid a
                        // buildup of info
                        // like number of charges.
                        eq.removeAllAssociations(eqMod);
                    }
                    eq.addAssociation(eqMod, x);
                }
            }
        }
    }
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) EquipmentModifier(pcgen.core.EquipmentModifier) EqModRef(pcgen.cdom.helper.EqModRef)

Example 32 with EquipmentHead

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

the class PCGVer2Parser method parseEquipmentLine.

private void parseEquipmentLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal Equipment line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    String itemKey;
    Equipment aEquip;
    PCGElement element;
    // the first element defines the item key name
    element = tokens.getElements().get(0);
    itemKey = EntityEncoder.decode(element.getText());
    // Check for an equipment key that has been updated.
    itemKey = EquipmentMigration.getNewEquipmentKey(itemKey, pcgenVersion, SettingsHandler.getGame().getName());
    // might be dynamically created container
    aEquip = thePC.getEquipmentNamed(itemKey);
    if (aEquip == null) {
        // Must load custom equipment from the .pcg file
        // before we check the Global list (which may get
        // loaded from customeEquipment.lst) as equipment
        // in the PC's .pcg may contain additional info
        // such as Charges on a wand, etc
        //
        // Make sure that we are not picking up custom items!
        aEquip = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, itemKey);
        if (aEquip != null) {
            if (aEquip.isType(Constants.TYPE_CUSTOM)) {
                aEquip = null;
            } else {
                // standard item
                aEquip = aEquip.clone();
            }
        }
        if (line.indexOf(IOConstants.TAG_CUSTOMIZATION) >= 0) {
            // might be customized item
            for (Iterator<PCGElement> it = tokens.getElements().iterator(); it.hasNext(); ) {
                element = it.next();
                if (IOConstants.TAG_CUSTOMIZATION.equals(element.getName())) {
                    String baseItemKey = Constants.EMPTY_STRING;
                    String customProperties = Constants.EMPTY_STRING;
                    for (PCGElement child : element.getChildren()) {
                        final String childTag = child.getName();
                        if (IOConstants.TAG_BASEITEM.equals(childTag)) {
                            baseItemKey = EntityEncoder.decode(child.getText());
                            // Check for an equipment key that has been updated.
                            baseItemKey = EquipmentMigration.getNewEquipmentKey(baseItemKey, pcgenVersion, SettingsHandler.getGame().getName());
                        } else if (IOConstants.TAG_DATA.equals(childTag)) {
                            customProperties = EntityEncoder.decode(child.getText());
                        }
                    }
                    if (aEquip != null && baseItemKey.equals(aEquip.getBaseItemName())) {
                        // We clear out any eqmods that the base item has as the
                        // EQMODs on the saved item override them.
                        EquipmentHead head = aEquip.getEquipmentHeadReference(1);
                        if (head != null) {
                            head.removeListFor(ListKey.EQMOD);
                            head.removeListFor(ListKey.EQMOD_INFO);
                        }
                        aEquip.setBase();
                        //$NON-NLS-1$ //$NON-NLS-2$
                        aEquip.load(customProperties, "$", "=", thePC);
                        aEquip.setToCustomSize(thePC);
                    } else {
                        // Make sure that we are not picking up custom items!
                        Equipment aEquip2 = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, baseItemKey);
                        if (aEquip2 != null) {
                            // Make sure we are not getting a custom item
                            if (aEquip2.isType(Constants.TYPE_CUSTOM)) {
                                aEquip2 = null;
                            } else {
                                // standard item
                                aEquip = aEquip2.clone();
                                // We clear out any eqmods that the base item has as the
                                // EQMODs on the saved item override them.
                                EquipmentHead head = aEquip.getEquipmentHeadReference(1);
                                if (head != null) {
                                    head.removeListFor(ListKey.EQMOD);
                                    head.removeListFor(ListKey.EQMOD_INFO);
                                }
                                aEquip.setBase();
                                aEquip.load(customProperties, "$", "=", //$NON-NLS-1$//$NON-NLS-2$
                                thePC);
                                aEquip.setToCustomSize(thePC);
                                aEquip.remove(StringKey.OUTPUT_NAME);
                                if (!aEquip.isType(Constants.TYPE_CUSTOM)) {
                                    aEquip.addType(Type.CUSTOM);
                                }
                                Globals.getContext().getReferenceContext().importObject(aEquip.clone());
                            }
                        }
                    }
                    break;
                }
            }
        }
        if (aEquip == null) {
            final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
            "Warnings.PCGenParser.EquipmentNotFound", itemKey);
            warnings.add(msg);
            return;
        }
        thePC.addEquipment(aEquip);
    }
    for (final Iterator<PCGElement> it = tokens.getElements().iterator(); it.hasNext(); ) {
        element = it.next();
        String tag = element.getName();
        if (IOConstants.TAG_QUANTITY.equals(tag)) {
            float oldQty = aEquip.getQty();
            aEquip.setQty(element.getText());
            thePC.updateEquipmentQty(aEquip, oldQty, aEquip.getQty());
        } else if (IOConstants.TAG_OUTPUTORDER.equals(tag)) {
            int index = 0;
            try {
                index = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
            // nothing we can or have to do about this
            }
            aEquip.setOutputIndex(index);
            if (aEquip.isAutomatic()) {
                thePC.cacheOutputIndex(aEquip);
            }
        } else if (IOConstants.TAG_COST.equals(tag)) {
        // TODO This else if switch currently does nothing?
        } else if (IOConstants.TAG_WT.equals(tag)) {
        // TODO This else if switch currently does nothing?
        } else if (IOConstants.TAG_NOTE.equals(tag)) {
            aEquip.setNote(element.getText());
        }
    }
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment)

Example 33 with EquipmentHead

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

the class NaturalattacksLst method createNaturalWeapon.

/**
	 * Create the Natural weapon equipment item aTok = primary weapon
	 * name,weapon type,num attacks,damage for Example:
	 * Tentacle,Weapon.Natural.Melee.Slashing,*4,1d6
	 *
	 * @param aTok
	 * @param size
	 * @return natural weapon
	 */
private Equipment createNaturalWeapon(LoadContext context, CDOMObject obj, String wpn) {
    StringTokenizer commaTok = new StringTokenizer(wpn, Constants.COMMA);
    int numTokens = commaTok.countTokens();
    if (numTokens < 4) {
        Logging.errorPrint("Invalid Build of " + "Natural Weapon in " + getTokenName() + ": " + wpn);
        return null;
    }
    String attackName = commaTok.nextToken();
    if (attackName.equalsIgnoreCase(Constants.LST_NONE)) {
        Logging.errorPrint("Attempt to Build 'None' as a " + "Natural Weapon in " + getTokenName() + ": " + wpn);
        return null;
    }
    attackName = attackName.intern();
    Equipment anEquip = new Equipment();
    anEquip.setName(attackName);
    anEquip.put(ObjectKey.PARENT, obj);
    /*
		 * This really can't be raw equipment... It really never needs to be
		 * referred to, but this means that duplicates are never being detected
		 * and resolved... this needs to have a KEY defined, to keep it
		 * unique... hopefully this is good enough :)
		 *
		 * CONSIDER This really isn't that great, because it's String dependent,
		 * and may not remove identical items... it certainly works, but is ugly
		 */
    // anEquip.setKeyName(obj.getClass().getSimpleName() + ","
    // + obj.getKeyName() + "," + wpn);
    /*
		 * Perhaps the construction above should be through context just to
		 * guarantee uniqueness of the key?? - that's too paranoid
		 */
    EquipmentHead equipHead = anEquip.getEquipmentHead(1);
    String profType = commaTok.nextToken();
    if (hasIllegalSeparator('.', profType)) {
        return null;
    }
    StringTokenizer dotTok = new StringTokenizer(profType, Constants.DOT);
    while (dotTok.hasMoreTokens()) {
        Type type = Type.getConstant(dotTok.nextToken());
        anEquip.addToListFor(ListKey.TYPE, type);
    }
    String numAttacks = commaTok.nextToken();
    boolean attacksFixed = !numAttacks.isEmpty() && numAttacks.charAt(0) == '*';
    if (attacksFixed) {
        numAttacks = numAttacks.substring(1);
    }
    anEquip.put(ObjectKey.ATTACKS_PROGRESS, !attacksFixed);
    try {
        int bonusAttacks = Integer.parseInt(numAttacks) - 1;
        final BonusObj aBonus = Bonus.newBonus(context, "WEAPON|ATTACKS|" + bonusAttacks);
        if (aBonus == null) {
            Logging.errorPrint(getTokenName() + " was given invalid number of attacks: " + bonusAttacks);
            return null;
        }
        anEquip.addToListFor(ListKey.BONUS, aBonus);
    } catch (NumberFormatException exc) {
        Logging.errorPrint("Non-numeric value for number of attacks in " + getTokenName() + ": '" + numAttacks + '\'');
        return null;
    }
    equipHead.put(StringKey.DAMAGE, commaTok.nextToken());
    // sage_sam 02 Dec 2002 for Bug #586332
    // allow hands to be required to equip natural weapons
    int handsrequired = 0;
    while (commaTok.hasMoreTokens()) {
        final String hString = commaTok.nextToken();
        if (hString.startsWith("SPROP=")) {
            anEquip.addToListFor(ListKey.SPECIAL_PROPERTIES, SpecialProperty.createFromLst(hString.substring(6)));
        } else {
            try {
                handsrequired = Integer.parseInt(hString);
            } catch (NumberFormatException exc) {
                Logging.errorPrint("Non-numeric value for hands required: '" + hString + '\'');
                return null;
            }
        }
    }
    anEquip.put(IntegerKey.SLOTS, handsrequired);
    anEquip.put(ObjectKey.WEIGHT, BigDecimal.ZERO);
    WeaponProf cwp = context.getReferenceContext().silentlyGetConstructedCDOMObject(WEAPONPROF_CLASS, attackName);
    if (cwp == null) {
        cwp = context.getReferenceContext().constructNowIfNecessary(WEAPONPROF_CLASS, attackName);
        cwp.addToListFor(ListKey.TYPE, Type.NATURAL);
    }
    CDOMSingleRef<WeaponProf> wp = context.getReferenceContext().getCDOMReference(WEAPONPROF_CLASS, attackName);
    anEquip.put(ObjectKey.WEAPON_PROF, wp);
    anEquip.addToListFor(ListKey.IMPLIED_WEAPONPROF, wp);
    if (!ControlUtilities.hasControlToken(context, CControl.CRITRANGE)) {
        equipHead.put(IntegerKey.CRIT_RANGE, 1);
    }
    if (!ControlUtilities.hasControlToken(context, CControl.CRITMULT)) {
        equipHead.put(IntegerKey.CRIT_MULT, 2);
    }
    return anEquip;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) StringTokenizer(java.util.StringTokenizer) Type(pcgen.cdom.enumeration.Type) Equipment(pcgen.core.Equipment) BonusObj(pcgen.core.bonus.BonusObj) WeaponProf(pcgen.core.WeaponProf)

Example 34 with EquipmentHead

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

the class ModifierFacet method dataAdded.

/**
	 * Triggered when one of the Facets to which ModifierFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was added to 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, 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) {
            processAddition(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) {
                    processAddition(id, head, vm, inst);
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) VarModifier(pcgen.cdom.content.VarModifier) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Example 35 with EquipmentHead

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

the class DamageToken method unparse.

@Override
public String[] unparse(LoadContext context, Equipment eq) {
    EquipmentHead head = eq.getEquipmentHeadReference(1);
    if (head == null) {
        return null;
    }
    String damage = context.getObjectContext().getString(head, StringKey.DAMAGE);
    if (damage == null) {
        return null;
    }
    return new String[] { damage };
}
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