Search in sources :

Example 26 with PrerequisiteOperator

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

the class PreDamageReductionWriter 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 27 with PrerequisiteOperator

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

the class PreDeityAlignWriter method specialCase.

@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    //
    if (prereq.getKind() == null) {
        PrerequisiteOperator oper = null;
        for (Prerequisite p : prereq.getPrerequisites()) {
            //
            if (!kindHandled().equalsIgnoreCase(p.getKind())) {
                return false;
            }
            //
            if (oper == null) {
                oper = p.getOperator();
            } else {
                if (!oper.equals(p.getOperator())) {
                    return false;
                }
            }
        }
        if (oper.equals(PrerequisiteOperator.EQ) && !"1".equals(prereq.getOperand())) {
            return false;
        }
        if (PrerequisiteOperator.LT.equals(prereq.getOperator())) {
            writer.write('!');
        }
        writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : ""));
        boolean first = true;
        for (Prerequisite p : prereq.getPrerequisites()) {
            if (!first) {
                writer.write(',');
            }
            writer.write(p.getOperand());
            first = false;
        }
        return true;
    }
    return false;
}
Also used : PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 28 with PrerequisiteOperator

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

the class PreDeityDomainWriter method specialCase.

@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false);
    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());
    }
    return true;
}
Also used : PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 29 with PrerequisiteOperator

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

the class PreWieldWriter method specialCase.

@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false);
    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());
    }
    return true;
}
Also used : PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 30 with PrerequisiteOperator

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

the class AbstractPrerequisiteWriter method getConsolidateMethod.

protected PrerequisiteOperator getConsolidateMethod(String handled, Prerequisite prereq, boolean ranked) {
    // If this is NOT a PREMULT... fail
    if (prereq.getKind() != null) {
        return null;
    }
    PrerequisiteOperator oper = null;
    for (Prerequisite p : prereq.getPrerequisites()) {
        //
        if (!ranked && !"1".equals(p.getOperand())) {
            return null;
        }
        //
        if (!handled.equalsIgnoreCase(p.getKind())) {
            return null;
        }
        //
        if (oper == null) {
            oper = p.getOperator();
        } else {
            if (!oper.equals(p.getOperator())) {
                return null;
            }
        }
    }
    String count = prereq.getOperand();
    if (PrerequisiteOperator.LT.equals(oper)) {
        try {
            int i = Integer.parseInt(count);
            if (prereq.getPrerequisiteCount() != i) {
                return null;
            }
        } catch (NumberFormatException e) {
            return null;
        }
    } else if (!PrerequisiteOperator.GTEQ.equals(oper)) {
        // TODO Not sure whether these can be consolidated...
        return null;
    }
    return oper;
}
Also used : PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

PrerequisiteOperator (pcgen.core.prereq.PrerequisiteOperator)52 Prerequisite (pcgen.core.prereq.Prerequisite)50 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)2 IOException (java.io.IOException)1