use of pcgen.core.prereq.PrerequisiteTest 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));
}
use of pcgen.core.prereq.PrerequisiteTest 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);
}
use of pcgen.core.prereq.PrerequisiteTest 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));
}
use of pcgen.core.prereq.PrerequisiteTest 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);
}
Aggregations