use of pcgen.cdom.base.Reducible in project pcgen by PCGen.
the class PreFactSetTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter aPC, CDOMObject source) throws PrerequisiteException {
final int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException exceptn) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreFactSet.error", //$NON-NLS-1$
prereq.toString()));
}
String location = prereq.getCategoryName();
String[] locationElements = location.split("\\.");
Iterable<Reducible> objModel = (Iterable<Reducible>) OutputDB.getIterable(aPC.getCharID(), locationElements);
if (objModel == null) {
throw new PrerequisiteException("Output System does not have model for: " + location);
}
String test = prereq.getKey();
String[] factinfo = test.split("=");
String factid = factinfo[0];
String factval = factinfo[1];
FactSetKey<?> fk = FactSetKey.valueOf(factid);
int runningTotal = getRunningTotal(prereq, number, objModel, factval, fk);
return countedTotal(prereq, runningTotal);
}
use of pcgen.cdom.base.Reducible in project pcgen by PCGen.
the class PreFactTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter aPC, CDOMObject source) throws PrerequisiteException {
final int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException exceptn) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreFact.error", //$NON-NLS-1$
prereq.toString()));
}
String location = prereq.getCategoryName();
String[] locationElements = location.split("\\.");
Iterable<Reducible> objModel = (Iterable<Reducible>) OutputDB.getIterable(aPC.getCharID(), locationElements);
if (objModel == null) {
throw new PrerequisiteException("Output System does not have model for: " + location);
}
String[] factinfo = prereq.getKey().split("=");
FactKey<?> fk = FactKey.valueOf(factinfo[0]);
Object targetVal = fk.getFormatManager().convertIndirect(factinfo[1]);
int runningTotal = 0;
for (Reducible r : objModel) {
Indirect<?> cdoVal = r.getCDOMObject().get(fk);
if (targetVal.equals(cdoVal)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
Aggregations