Search in sources :

Example 31 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class PreAbilityRoundRobin method testCombineSubNegative.

@Override
public void testCombineSubNegative() {
    String original = "!PREMULT:2,[!PRE" + getBaseString() + ":1," + getPrefix() + "Foo],[!PRE" + getBaseString() + ":1," + getPrefix() + "Spot]";
    String consolidatedPre = "PRE" + getBaseString() + ":1," + getPrefix() + "Foo,Spot";
    try {
        Prerequisite p = PreParserFactory.getInstance().parse(original);
        PrerequisiteWriterInterface writer = PrerequisiteWriterFactory.getInstance().getWriter(p.getKind());
        if (writer == null) {
            fail("Could not find Writer for: " + p.getKind());
        }
        StringWriter w = new StringWriter();
        writer.write(w, p);
        boolean consolidated = w.toString().equals(consolidatedPre);
        boolean separate = w.toString().equals(original);
        assertTrue(consolidated || separate);
    } catch (PersistenceLayerException e) {
        fail(e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringWriter(java.io.StringWriter) PrerequisiteWriterInterface(pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 32 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class PreAbilityRoundRobin method testCombineSubCheckMult.

public void testCombineSubCheckMult() {
    // runSimpleRoundRobin("PREMULT:2,[!PRE" + getBaseString() + ":1,"
    // + "CHECKMULT," + getPrefix() + "Foo],[!PRE" + getBaseString()
    // + ":1," + "CHECKMULT," + getPrefix() + "Spot]", "!PRE"
    // + getBaseString() + ":1," + "CHECKMULT," + getPrefix()
    // + "Foo,Spot");
    String original = "PREMULT:2,[!PRE" + getBaseString() + ":1," + "CHECKMULT," + getPrefix() + "Foo],[!PRE" + getBaseString() + ":1," + "CHECKMULT," + getPrefix() + "Spot]";
    String consolidatedPre = "!PRE" + getBaseString() + ":1," + "CHECKMULT," + getPrefix() + "Foo,Spot";
    try {
        Prerequisite p = PreParserFactory.getInstance().parse(original);
        PrerequisiteWriterInterface writer = PrerequisiteWriterFactory.getInstance().getWriter(p.getKind());
        if (writer == null) {
            fail("Could not find Writer for: " + p.getKind());
        }
        StringWriter w = new StringWriter();
        writer.write(w, p);
        boolean consolidated = w.toString().equals(consolidatedPre);
        boolean separate = w.toString().equals(original);
        assertTrue(consolidated || separate);
    } catch (PersistenceLayerException e) {
        fail(e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringWriter(java.io.StringWriter) PrerequisiteWriterInterface(pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 33 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class PreSpellSchoolSubWriter method specialCase.

@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, true);
    if (po == null) {
        return false;
    }
    if (!po.equals(prereq.getOperator())) {
        writer.write('!');
    }
    writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : ""));
    writer.write(po.equals(PrerequisiteOperator.GTEQ) ? prereq.getOperand() : "1");
    for (Prerequisite p : prereq.getPrerequisites()) {
        writer.write(',');
        writer.write(p.getKey());
        writer.write('=');
        writer.write(p.getOperand());
    }
    return true;
}
Also used : PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 34 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class PreSpellTypeWriter method specialCase.

/**
	 * @see pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter#specialCase(java.io.Writer writer, pcgen.core.prereq.Prerequisite prereq)
	 */
@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, true);
    if (po == null) {
        return false;
    }
    if (!po.equals(prereq.getOperator())) {
        writer.write('!');
    }
    writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : ""));
    writer.write(po.equals(PrerequisiteOperator.GTEQ) ? prereq.getOperand() : "1");
    for (Prerequisite p : prereq.getPrerequisites()) {
        writer.write(',');
        writer.write(p.getKey());
        writer.write('=');
        writer.write(p.getOperand());
    }
    return true;
}
Also used : PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 35 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class PreSpellSchoolWriter method specialCase.

@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, true);
    if (po == null) {
        return false;
    }
    if (po != prereq.getOperator()) {
        writer.write('!');
    }
    writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : ""));
    writer.write(po == PrerequisiteOperator.GTEQ ? prereq.getOperand() : "1");
    for (Prerequisite p : prereq.getPrerequisites()) {
        writer.write(',');
        writer.write(p.getKey());
        writer.write('=');
        writer.write(p.getOperand());
    }
    return true;
}
Also used : PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

Prerequisite (pcgen.core.prereq.Prerequisite)267 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)62 Test (org.junit.Test)61 PrerequisiteOperator (pcgen.core.prereq.PrerequisiteOperator)50 StringTokenizer (java.util.StringTokenizer)36 ArrayList (java.util.ArrayList)35 StringWriter (java.io.StringWriter)19 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)19 CDOMReference (pcgen.cdom.base.CDOMReference)18 ParseResult (pcgen.rules.persistence.token.ParseResult)18 BonusObj (pcgen.core.bonus.BonusObj)13 TreeSet (java.util.TreeSet)12 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)12 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10 Domain (pcgen.core.Domain)10 QualifiedObject (pcgen.core.QualifiedObject)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 PrerequisiteWriter (pcgen.persistence.lst.output.prereq.PrerequisiteWriter)9 Ungranted (pcgen.cdom.base.Ungranted)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8