Search in sources :

Example 6 with EqModRef

use of pcgen.cdom.helper.EqModRef in project pcgen by PCGen.

the class EqmodToken method unparse.

@Override
public String[] unparse(LoadContext context, Equipment eq) {
    AbstractObjectContext obj = context.getObjectContext();
    String damage = obj.getString(eq, StringKey.DAMAGE_OVERRIDE);
    Set<String> set = new TreeSet<>();
    if (damage != null) {
        set.add(EQMOD_DAMAGE + Constants.PIPE + damage);
    }
    BigDecimal weight = obj.getObject(eq, ObjectKey.WEIGHT_MOD);
    if (weight != null) {
        set.add(EQMOD_WEIGHT + Constants.PIPE + weight.toString().replace('.', ','));
    }
    EquipmentHead head = eq.getEquipmentHeadReference(1);
    if (head != null) {
        Changes<EqModRef> changes = obj.getListChanges(head, ListKey.EQMOD_INFO);
        Collection<EqModRef> added = changes.getAdded();
        if (added != null) {
            for (EqModRef modRef : added) {
                String key = modRef.getRef().getLSTformat(false);
                StringBuilder sb = new StringBuilder();
                sb.append(key);
                for (String s : modRef.getChoices()) {
                    sb.append(Constants.PIPE);
                    sb.append(s.replace('|', '='));
                }
                set.add(sb.toString());
            }
        }
    }
    if (set.isEmpty()) {
        return null;
    }
    return new String[] { StringUtil.join(set, Constants.DOT) };
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) AbstractObjectContext(pcgen.rules.context.AbstractObjectContext) TreeSet(java.util.TreeSet) EqModRef(pcgen.cdom.helper.EqModRef) BigDecimal(java.math.BigDecimal)

Example 7 with EqModRef

use of pcgen.cdom.helper.EqModRef 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 8 with EqModRef

use of pcgen.cdom.helper.EqModRef in project pcgen by PCGen.

the class AlteqmodToken method unparse.

@Override
public String[] unparse(LoadContext context, Equipment eq) {
    AbstractObjectContext obj = context.getObjectContext();
    String damage = obj.getString(eq, StringKey.DAMAGE_OVERRIDE);
    Set<String> set = new TreeSet<>();
    if (damage != null) {
        set.add(EQMOD_DAMAGE + Constants.PIPE + damage);
    }
    BigDecimal weight = obj.getObject(eq, ObjectKey.WEIGHT_MOD);
    if (weight != null) {
        set.add(EQMOD_WEIGHT + Constants.PIPE + weight.toString().replace('.', ','));
    }
    EquipmentHead head = eq.getEquipmentHeadReference(2);
    if (head != null) {
        Changes<EqModRef> changes = obj.getListChanges(head, ListKey.EQMOD_INFO);
        Collection<EqModRef> added = changes.getAdded();
        if (added != null) {
            for (EqModRef modRef : added) {
                String key = modRef.getRef().getLSTformat(false);
                StringBuilder sb = new StringBuilder();
                sb.append(key);
                for (String s : modRef.getChoices()) {
                    sb.append(Constants.PIPE);
                    sb.append(s.replace('|', '='));
                }
                set.add(sb.toString());
            }
        }
    }
    if (set.isEmpty()) {
        return null;
    }
    return new String[] { StringUtil.join(set, Constants.DOT) };
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) AbstractObjectContext(pcgen.rules.context.AbstractObjectContext) TreeSet(java.util.TreeSet) EqModRef(pcgen.cdom.helper.EqModRef) BigDecimal(java.math.BigDecimal)

Example 9 with EqModRef

use of pcgen.cdom.helper.EqModRef 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

EqModRef (pcgen.cdom.helper.EqModRef)9 BigDecimal (java.math.BigDecimal)5 EquipmentHead (pcgen.cdom.inst.EquipmentHead)5 EquipmentModifier (pcgen.core.EquipmentModifier)5 StringTokenizer (java.util.StringTokenizer)3 TreeSet (java.util.TreeSet)3 ParseResult (pcgen.rules.persistence.token.ParseResult)3 AbstractObjectContext (pcgen.rules.context.AbstractObjectContext)2 ArrayList (java.util.ArrayList)1 Equipment (pcgen.core.Equipment)1 SizeAdjustment (pcgen.core.SizeAdjustment)1 EquipSet (pcgen.core.character.EquipSet)1