Search in sources :

Example 46 with PrerequisiteOperator

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

the class PreSpellWriter 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 47 with PrerequisiteOperator

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

the class PreVariableWriter method specialCase.

@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    if (prereq.getKind() != null) {
        return false;
    }
    String handled = kindHandled();
    String count = prereq.getOperand();
    try {
        int i = Integer.parseInt(count);
        if (prereq.getPrerequisiteCount() != i) {
            return false;
        }
    } catch (NumberFormatException e) {
        return false;
    }
    PrerequisiteOperator oper = null;
    for (Prerequisite p : prereq.getPrerequisites()) {
        //
        if (!handled.equalsIgnoreCase(p.getKind())) {
            return false;
        }
        //
        if (oper == null) {
            oper = p.getOperator();
        } else {
            if (!oper.equals(p.getOperator())) {
                return false;
            }
        }
    }
    writer.write("PREVAR");
    if (prereq.getOperator() == PrerequisiteOperator.LT) {
        writer.write(oper.invert().toString().toUpperCase());
    } else {
        writer.write(oper.toString().toUpperCase());
    }
    writer.write(':' + (prereq.isOverrideQualify() ? "Q:" : ""));
    boolean first = true;
    for (Prerequisite p : prereq.getPrerequisites()) {
        if (!first) {
            writer.write(',');
        }
        writer.write(p.getKey());
        writer.write(',');
        writer.write(p.getOperand());
        first = false;
    }
    return true;
}
Also used : PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 48 with PrerequisiteOperator

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

the class PreStatWriter 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('!');
    }
    PrerequisiteOperator operator = prereq.getOperator();
    writer.write("PRESTAT");
    if (!operator.equals(PrerequisiteOperator.GTEQ) && !operator.equals(PrerequisiteOperator.LT)) {
        writer.write(operator.toString().toUpperCase());
    }
    writer.write(':');
    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 49 with PrerequisiteOperator

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

the class PreStatWriter 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 {
        PrerequisiteOperator operator = prereq.getOperator();
        if (operator.equals(PrerequisiteOperator.LT)) {
            writer.write("!");
        }
        writer.write("PRESTAT");
        if (!operator.equals(PrerequisiteOperator.GTEQ) && !operator.equals(PrerequisiteOperator.LT)) {
            writer.write(operator.toString().toUpperCase());
        }
        writer.write(":1," + prereq.getKey() + '=' + prereq.getOperand());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator) IOException(java.io.IOException)

Example 50 with PrerequisiteOperator

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

the class PreAbilityWriter method specialCase.

@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false);
    if (po == null) {
        return false;
    }
    if (hasSubordinateCheckMult(prereq)) {
        return false;
    }
    String cat = null;
    boolean foundCat = false;
    for (Prerequisite p : prereq.getPrerequisites()) {
        if (foundCat) {
            String thiscat = p.getCategoryName();
            if (thiscat == null) {
                if (cat != null) {
                    return false;
                }
            } else {
                if (!thiscat.equals(cat)) {
                    return false;
                }
            }
        } else {
            cat = p.getCategoryName();
            foundCat = true;
        }
    }
    if (!po.equals(prereq.getOperator())) {
        writer.write('!');
    }
    writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : ""));
    writer.write(po.equals(PrerequisiteOperator.GTEQ) ? prereq.getOperand() : "1");
    if (prereq.isOriginalCheckMult()) {
        writer.write(",CHECKMULT");
    }
    if (cat == null) {
        writer.write(",CATEGORY=ANY");
    } else {
        writer.write(",CATEGORY=" + cat);
    }
    for (Prerequisite p : prereq.getPrerequisites()) {
        writer.write(',');
        writer.write(p.getKey());
        if (p.getSubKey() != null) {
            writer.write(" (");
            writer.write(p.getSubKey());
            writer.write(")");
        }
    }
    return true;
}
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