Search in sources :

Example 1 with PrerequisiteTestFactory

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

the class PreRuleTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.Equipment)
	 */
@Override
public int passes(final Prerequisite prereq, final Equipment equipment, PlayerCharacter aPC) throws PrerequisiteException {
    int runningTotal = 0;
    int targetNumber;
    try {
        targetNumber = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException ne) {
        // Not an error, just a string
        targetNumber = 1;
    }
    if (Globals.checkRule(prereq.getKey())) {
        runningTotal = 1;
    }
    for (Prerequisite element : prereq.getPrerequisites()) {
        final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance();
        final PrerequisiteTest test = factory.getTest(element.getKind());
        if (test != null) {
            runningTotal += test.passes(element, equipment, aPC);
        }
    }
    return countedTotal(prereq, prereq.getOperator().compare(runningTotal, targetNumber));
}
Also used : PrerequisiteTestFactory(pcgen.core.prereq.PrerequisiteTestFactory) AbstractPrerequisiteTest(pcgen.core.prereq.AbstractPrerequisiteTest) PrerequisiteTest(pcgen.core.prereq.PrerequisiteTest) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 2 with PrerequisiteTestFactory

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

the class PreVariableTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.Equipment)
	 */
@Override
public int passes(final Prerequisite prereq, final Equipment equipment, PlayerCharacter aPC) throws PrerequisiteException {
    if (aPC == null) {
        return 0;
    }
    //$NON-NLS-1$
    final String eqVar = "EQ:" + equipment.getNonHeadedName();
    final float aVar = //$NON-NLS-1$
    equipment.getVariableValue(prereq.getKey(), eqVar, aPC);
    final float aTarget = //$NON-NLS-1$
    equipment.getVariableValue(prereq.getOperand(), eqVar, aPC);
    float runningTotal = prereq.getOperator().compare(aVar, aTarget);
    if (CoreUtility.doublesEqual(runningTotal, 0.0)) {
        return 0;
    }
    for (Prerequisite element : prereq.getPrerequisites()) {
        final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance();
        final PrerequisiteTest test = factory.getTest(element.getKind());
        if (test != null) {
            // all of the tests must pass, so just
            // assign the value here, don't add
            runningTotal = test.passes(element, equipment, aPC);
            if (CoreUtility.doublesEqual(runningTotal, 0.0)) {
                return 0;
            }
        }
    }
    // as the total could be negative, and isn't running...
    return countedTotal(prereq, 1);
}
Also used : PrerequisiteTestFactory(pcgen.core.prereq.PrerequisiteTestFactory) AbstractPrerequisiteTest(pcgen.core.prereq.AbstractPrerequisiteTest) PrerequisiteTest(pcgen.core.prereq.PrerequisiteTest) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 3 with PrerequisiteTestFactory

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

the class PreRuleTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.PlayerCharacter)
	 */
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) throws PrerequisiteException {
    int runningTotal = 0;
    int targetNumber;
    try {
        targetNumber = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException ne) {
        // Not an error, just a string
        targetNumber = 1;
    }
    if (Globals.checkRule(prereq.getKey())) {
        runningTotal = 1;
    }
    final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance();
    for (Prerequisite element : prereq.getPrerequisites()) {
        final PrerequisiteTest test = factory.getTest(element.getKind());
        if (test != null) {
            runningTotal += test.passes(element, character, source);
        }
    }
    return countedTotal(prereq, prereq.getOperator().compare(runningTotal, targetNumber));
}
Also used : PrerequisiteTestFactory(pcgen.core.prereq.PrerequisiteTestFactory) AbstractPrerequisiteTest(pcgen.core.prereq.AbstractPrerequisiteTest) PrerequisiteTest(pcgen.core.prereq.PrerequisiteTest) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 4 with PrerequisiteTestFactory

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

the class PreVariableTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.PlayerCharacter)
	 */
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) throws PrerequisiteException {
    String src = (source == null) ? Constants.EMPTY_STRING : source.getQualifiedKey();
    final float aVar = //$NON-NLS-1$
    character.getVariableValue(prereq.getKey(), src);
    final float aTarget = //$NON-NLS-1$
    character.getVariableValue(prereq.getOperand(), src);
    float runningTotal = prereq.getOperator().compare(aVar, aTarget);
    if (CoreUtility.doublesEqual(runningTotal, 0.0)) {
        return 0;
    }
    for (Prerequisite element : prereq.getPrerequisites()) {
        final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance();
        final PrerequisiteTest test = factory.getTest(element.getKind());
        if (test != null) {
            // all of the tests must pass, so just
            // assign the value here, don't add
            runningTotal = test.passes(element, character, source);
            if (CoreUtility.doublesEqual(runningTotal, 0.0)) {
                return 0;
            }
        }
    }
    // as the total could be negative, and isn't running...
    return countedTotal(prereq, 1);
}
Also used : PrerequisiteTestFactory(pcgen.core.prereq.PrerequisiteTestFactory) AbstractPrerequisiteTest(pcgen.core.prereq.AbstractPrerequisiteTest) PrerequisiteTest(pcgen.core.prereq.PrerequisiteTest) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

AbstractPrerequisiteTest (pcgen.core.prereq.AbstractPrerequisiteTest)4 Prerequisite (pcgen.core.prereq.Prerequisite)4 PrerequisiteTest (pcgen.core.prereq.PrerequisiteTest)4 PrerequisiteTestFactory (pcgen.core.prereq.PrerequisiteTestFactory)4