Search in sources :

Example 41 with EquipmentHead

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

the class AlteqmodToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Equipment eq, String value) {
    StringTokenizer dotTok = new StringTokenizer(value, Constants.DOT);
    EquipmentHead head = eq.getEquipmentHead(2);
    while (dotTok.hasMoreTokens()) {
        String modInfo = dotTok.nextToken();
        if (modInfo.equalsIgnoreCase(Constants.NONE)) {
            Logging.deprecationPrint("'NONE' EqMod in " + getTokenName() + " will be ignored", context);
            continue;
        }
        ParseResult pr = checkForIllegalSeparator('|', modInfo);
        if (!pr.passed()) {
            return pr;
        }
        StringTokenizer aTok = new StringTokenizer(modInfo, Constants.PIPE);
        // The type of EqMod, eg: ABILITYPLUS
        String eqModKey = aTok.nextToken();
        if (eqModKey.equals(EQMOD_WEIGHT)) {
            if (aTok.hasMoreTokens()) {
                context.getObjectContext().put(eq, ObjectKey.WEIGHT_MOD, new BigDecimal(aTok.nextToken().replace(',', '.')));
            }
            continue;
        }
        if (eqModKey.equals(EQMOD_DAMAGE)) {
            if (aTok.hasMoreTokens()) {
                context.getObjectContext().put(eq, StringKey.DAMAGE_OVERRIDE, aTok.nextToken());
            }
            continue;
        }
        CDOMSingleRef<EquipmentModifier> ref = context.getReferenceContext().getCDOMReference(EQMOD_CLASS, eqModKey);
        EqModRef modref = new EqModRef(ref);
        while (aTok.hasMoreTokens()) {
            modref.addChoice(aTok.nextToken().replace('=', '|'));
        }
        context.getObjectContext().addToList(head, ListKey.EQMOD_INFO, modref);
    }
    return ParseResult.SUCCESS;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) StringTokenizer(java.util.StringTokenizer) EquipmentModifier(pcgen.core.EquipmentModifier) ParseResult(pcgen.rules.persistence.token.ParseResult) EqModRef(pcgen.cdom.helper.EqModRef) BigDecimal(java.math.BigDecimal)

Example 42 with EquipmentHead

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

the class CritmultToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
    if (ControlUtilities.hasControlToken(context, CControl.CRITMULT)) {
        return new ParseResult.Fail(getTokenName() + " is disabled when CRITMULT control is used: " + value, context);
    }
    Integer cm = null;
    if ((!value.isEmpty()) && (value.charAt(0) == 'x')) {
        try {
            cm = Integer.valueOf(value.substring(1));
            if (cm.intValue() <= 0) {
                return new ParseResult.Fail(getTokenName() + " cannot be <= 0", context);
            }
        } catch (NumberFormatException nfe) {
            return new ParseResult.Fail(getTokenName() + " was expecting an Integer: " + value, context);
        }
    } else if ("-".equals(value)) {
        cm = -1;
    }
    if (cm == null) {
        return new ParseResult.Fail(getTokenName() + " was expecting x followed by an integer " + "or the special value '-' (representing no value)", context);
    }
    EquipmentHead primHead = eq.getEquipmentHead(1);
    context.getObjectContext().put(primHead, IntegerKey.CRIT_MULT, cm);
    return ParseResult.SUCCESS;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 43 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)

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