Search in sources :

Example 21 with EquipmentModifier

use of pcgen.core.EquipmentModifier 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 22 with EquipmentModifier

use of pcgen.core.EquipmentModifier in project pcgen by PCGen.

the class ReplacesToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, EquipmentModifier mod, String value) {
    context.getObjectContext().removeList(mod, ListKey.REPLACED_KEYS);
    StringTokenizer tok = new StringTokenizer(value, Constants.COMMA);
    while (tok.hasMoreTokens()) {
        CDOMSingleRef<EquipmentModifier> ref = context.getReferenceContext().getCDOMReference(EquipmentModifier.class, tok.nextToken());
        context.getObjectContext().addToList(mod, ListKey.REPLACED_KEYS, ref);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) EquipmentModifier(pcgen.core.EquipmentModifier)

Example 23 with EquipmentModifier

use of pcgen.core.EquipmentModifier in project pcgen by PCGen.

the class Gui2InfoFactory method getHTMLInfo.

@Override
public String getHTMLInfo(EquipModFacade equipModFacade, EquipmentFacade equipFacade) {
    if (equipModFacade == null || !(equipModFacade instanceof EquipmentModifier) || equipFacade == null || !(equipFacade instanceof Equipment)) {
        return EMPTY_STRING;
    }
    EquipmentModifier equipMod = (EquipmentModifier) equipModFacade;
    Equipment equip = (Equipment) equipFacade;
    final StringBuilder title = new StringBuilder(50);
    title.append(OutputNameFormatting.piString(equipMod, false));
    final HtmlInfoBuilder b = new HtmlInfoBuilder(null, false);
    b.appendTitleElement(title.toString());
    b.appendLineBreak();
    //$NON-NLS-1$
    b.appendI18nElement(//$NON-NLS-1$
    "in_igInfoLabelTextType", StringUtil.join(equipMod.getTrueTypeList(true), ". "));
    // Various cost types
    int iPlus = equipMod.getSafe(IntegerKey.PLUS);
    if (iPlus != 0) {
        b.appendLineBreak();
        b.appendI18nElement("in_igInfoLabelTextPlus", String.valueOf(iPlus));
    }
    Formula baseCost = equipMod.getSafe(FormulaKey.BASECOST);
    if (!"0".equals(baseCost.toString())) {
        b.appendLineBreak();
        b.appendI18nElement("in_igInfoLabelTextPrecost", String.valueOf(baseCost));
    }
    Formula cost = equipMod.getSafe(FormulaKey.COST);
    if (!"0".equals(cost.toString())) {
        b.appendLineBreak();
        b.appendI18nElement("in_igEqModelColCost", String.valueOf(cost));
    }
    //Description
    String desc = pc.getDescription(equipMod);
    if (!desc.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nFormattedElement(//$NON-NLS-1$
        "in_InfoDescription", DescriptionFormatting.piWrapDesc(equipMod, desc, false));
    }
    // Special properties
    StringBuilder sb = new StringBuilder(100);
    boolean first = true;
    for (SpecialProperty sp : equipMod.getSafeListFor(ListKey.SPECIAL_PROPERTIES)) {
        if (!first) {
            sb.append(", ");
        }
        first = false;
        sb.append(sp.getDisplayName());
    }
    if (sb.length() > 0) {
        b.appendLineBreak();
        b.appendI18nElement("in_igInfoLabelTextSprop", sb.toString());
    }
    final String cString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, equip, equipMod.getPrerequisiteList(), false);
    if (!cString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextReq", cString);
    }
    String bString = equipMod.getSource();
    if (!bString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextSource", bString);
    }
    b.appendLineBreak();
    return b.toString();
}
Also used : Formula(pcgen.base.formula.Formula) EquipmentModifier(pcgen.core.EquipmentModifier) Equipment(pcgen.core.Equipment) SpecialProperty(pcgen.core.SpecialProperty) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder)

Example 24 with EquipmentModifier

use of pcgen.core.EquipmentModifier in project pcgen by PCGen.

the class EqmodToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Equipment eq, String value) {
    StringTokenizer dotTok = new StringTokenizer(value, Constants.DOT);
    EquipmentHead head = eq.getEquipmentHead(1);
    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 25 with EquipmentModifier

use of pcgen.core.EquipmentModifier 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)

Aggregations

EquipmentModifier (pcgen.core.EquipmentModifier)25 Equipment (pcgen.core.Equipment)8 EqModRef (pcgen.cdom.helper.EqModRef)5 StringTokenizer (java.util.StringTokenizer)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 BigDecimal (java.math.BigDecimal)3 Test (org.junit.Test)3 EquipmentHead (pcgen.cdom.inst.EquipmentHead)3 BonusObj (pcgen.core.bonus.BonusObj)3 EquipSet (pcgen.core.character.EquipSet)3 ArrayList (java.util.ArrayList)2 Formula (pcgen.base.formula.Formula)2 CharID (pcgen.cdom.enumeration.CharID)2 GameMode (pcgen.core.GameMode)2 PCTemplate (pcgen.core.PCTemplate)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 Race (pcgen.core.Race)2 SizeAdjustment (pcgen.core.SizeAdjustment)2 LoadContext (pcgen.rules.context.LoadContext)2 HashSet (java.util.HashSet)1