Search in sources :

Example 36 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead 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 37 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead 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 38 with EquipmentHead

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

the class AltcritmultToken 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 altHead = eq.getEquipmentHead(2);
    context.getObjectContext().put(altHead, IntegerKey.CRIT_MULT, cm);
    return ParseResult.SUCCESS;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 39 with EquipmentHead

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

the class AltcritrangeToken method unparse.

@Override
public String[] unparse(LoadContext context, Equipment eq) {
    EquipmentHead head = eq.getEquipmentHeadReference(2);
    if (head == null) {
        return null;
    }
    Integer mult = context.getObjectContext().getInteger(head, IntegerKey.CRIT_RANGE);
    if (mult == null) {
        return null;
    }
    if (mult < 0) {
        context.addWriteMessage(getTokenName() + " cannot be negative: " + mult);
        return null;
    }
    return new String[] { mult.toString() };
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead)

Example 40 with EquipmentHead

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

the class PartToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
    int pipeLoc = value.indexOf('|');
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " requires <integer>|<token>");
    }
    String partNumString = value.substring(0, pipeLoc);
    int partNumber;
    try {
        partNumber = Integer.parseInt(partNumString);
    } catch (NumberFormatException e) {
        return new ParseResult.Fail(getTokenName() + " requires <integer>|<token> ... " + partNumString + " was not an integer");
    }
    if (partNumber <= 0) {
        return new ParseResult.Fail(getTokenName() + " requires a positive integer. " + partNumber + " was not positive");
    }
    EquipmentHead part = eq.getEquipmentHead(partNumber);
    String partToken = value.substring(pipeLoc + 1);
    int colonLoc = partToken.indexOf(':');
    if (colonLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " requires <integer>|<token>:<token content>, but no colon was found in: " + value);
    }
    String tokenName = partToken.substring(0, colonLoc);
    String tokenValue = partToken.substring(colonLoc + 1);
    LoadContext subContext = context.dropIntoContext("EQUIPMENT.PART");
    boolean processToken;
    try {
        processToken = subContext.processToken(part, tokenName, tokenValue);
    } catch (PersistenceLayerException e) {
        return new ParseResult.Fail(getTokenName() + " encountered an error (" + e.getMessage() + ") in the token content of: " + value);
    }
    if (processToken) {
        return ParseResult.SUCCESS;
    }
    return new ParseResult.Fail(getTokenName() + " encountered an error in the token content of: " + value);
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) EquipmentHead(pcgen.cdom.inst.EquipmentHead) ParseResult(pcgen.rules.persistence.token.ParseResult) LoadContext(pcgen.rules.context.LoadContext)

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