Search in sources :

Example 56 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class AddFeatToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String addType = sep.next();
    if (!"FEAT".equals(addType)) {
        return new ParseResult.Fail("Incompatible with ADD:FEAT:" + value);
    }
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
        count = FormulaFactory.ONE;
    } else {
        count = FormulaFactory.getFormulaFor(activeValue);
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
            return new ParseResult.Fail("Count in ADD:FEAT must be > 0", context);
        }
        activeValue = sep.next();
    }
    if (sep.hasNext()) {
        return new ParseResult.Fail("ADD:FEAT had too many pipe separated items: " + value, context);
    }
    try {
        if (!context.processToken(obj, "ADD", "ABILITY|" + count.toString() + "|FEAT|NORMAL|" + activeValue)) {
            Logging.replayParsedMessages();
            return new ParseResult.Fail("Delegation Error from ADD:FEAT");
        }
    } catch (PersistenceLayerException e) {
        return new ParseResult.Fail("Delegation Error from ADD:FEAT: " + e.getLocalizedMessage());
    }
    return ParseResult.SUCCESS;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 57 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class AddVFeatToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String addType = sep.next();
    if (!"VFEAT".equals(addType)) {
        return new ParseResult.Fail("Incompatible with ADD:VFEAT: " + value);
    }
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
        count = FormulaFactory.ONE;
    } else {
        count = FormulaFactory.getFormulaFor(activeValue);
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
            return new ParseResult.Fail("Count in ADD:VFEAT must be > 0", context);
        }
        activeValue = sep.next();
    }
    if (sep.hasNext()) {
        return new ParseResult.Fail("ADD:VFEAT had too many pipe separated items: " + value, context);
    }
    try {
        if (!context.processToken(obj, "ADD", "ABILITY|" + count.toString() + "|FEAT|VIRTUAL|" + activeValue)) {
            Logging.replayParsedMessages();
            return new ParseResult.Fail("Delegation Error from ADD:VFEAT");
        }
    } catch (PersistenceLayerException e) {
        return new ParseResult.Fail("Delegation Error from ADD:VFEAT: " + e.getLocalizedMessage());
    }
    return ParseResult.SUCCESS;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 58 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreEquipSecondaryWriter method write.

/**
	 * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
	 */
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
    checkValidOperator(prereq, operatorsHandled());
    try {
        if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
            writer.write('!');
        }
        writer.write("PREEQUIPSECONDARY:" + (prereq.isOverrideQualify() ? "Q:" : ""));
        writer.write(prereq.getOperand());
        writer.write(',');
        writer.write(prereq.getKey());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) IOException(java.io.IOException)

Example 59 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreCityWriter method write.

/**
	 * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
	 */
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
    checkValidOperator(prereq, operatorsHandled());
    try {
        if (prereq.getOperator().equals(PrerequisiteOperator.NEQ)) {
            writer.write('!');
        }
        writer.write("PRECITY:" + (prereq.isOverrideQualify() ? "Q:" : ""));
        writer.write(prereq.getKey());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) IOException(java.io.IOException)

Example 60 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreClassWriter method write.

/**
	 * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
	 */
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
    checkValidOperator(prereq, operatorsHandled());
    try {
        if (prereq.getOperator() == PrerequisiteOperator.LT) {
            writer.write('!');
        }
        writer.write("PRECLASS:" + (prereq.isOverrideQualify() ? "Q:" : "") + "1,");
        writer.write(prereq.getKey());
        writer.write('=');
        writer.write(prereq.getOperand());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) IOException(java.io.IOException)

Aggregations

PersistenceLayerException (pcgen.persistence.PersistenceLayerException)180 IOException (java.io.IOException)74 Prerequisite (pcgen.core.prereq.Prerequisite)62 StringWriter (java.io.StringWriter)17 StringTokenizer (java.util.StringTokenizer)17 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)15 LoadContext (pcgen.rules.context.LoadContext)14 URI (java.net.URI)12 Campaign (pcgen.core.Campaign)11 ParseResult (pcgen.rules.persistence.token.ParseResult)11 PCClass (pcgen.core.PCClass)10 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 URISyntaxException (java.net.URISyntaxException)8 TreeSet (java.util.TreeSet)8 CDOMReference (pcgen.cdom.base.CDOMReference)8 PlayerCharacter (pcgen.core.PlayerCharacter)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8 PCClassLoader (pcgen.persistence.lst.PCClassLoader)8