use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreSubClassTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
int runningTotal = 0;
int num;
try {
// number we must match
num = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException nfe) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreSubClass.error.badly_formed", //$NON-NLS-1$
prereq.toString()));
}
final String thisClass = prereq.getKey();
for (PCClass aClass : display.getClassSet()) {
final String subClassName = display.getSubClassName(aClass);
if (subClassName != null && !subClassName.isEmpty()) {
if (thisClass.equalsIgnoreCase(subClassName)) {
runningTotal++;
break;
}
}
}
runningTotal = prereq.getOperator().compare(runningTotal, num);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreTotalABTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) throws PrerequisiteException {
int runningTotal;
int att = character.baseAttackBonus();
att += character.getTotalBonusTo("COMBAT", "EPICAB");
try {
final int anInt = Integer.parseInt(prereq.getOperand());
runningTotal = prereq.getOperator().compare(att, anInt);
} catch (NumberFormatException exc) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAttack.error.badly_formed_attribute", //$NON-NLS-1$
prereq.getOperand()));
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreTypeTester 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, CharacterDisplay display) throws PrerequisiteException {
final String requiredType = prereq.getKey();
int runningTotal = 0;
if (prereq.getOperator().equals(PrerequisiteOperator.EQ)) {
if (equipment.isPreType(requiredType)) {
runningTotal++;
}
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ)) {
if (!equipment.isPreType(requiredType)) {
runningTotal++;
}
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreType.error.invalidComparison", prereq.getOperator().toString(), //$NON-NLS-1$
prereq.toString()));
}
runningTotal = countedTotal(prereq, runningTotal);
return runningTotal;
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreStatTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
final int targetNumber = Integer.parseInt(prereq.getOperand());
PCStat stat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCStat.class, prereq.getKey());
if (stat == null) {
throw new PrerequisiteException("PRESTAT refers to invalid stat '" + stat + ". Prereq was " + prereq);
}
final int statValue = display.getTotalStatFor(stat);
final int runningTotal = prereq.getOperator().compare(statValue, targetNumber);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreSpecialAbilityTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) throws PrerequisiteException {
int runningTotal = 0;
int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException exceptn) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreSpecialAbility.error.bad_operand", //$NON-NLS-1$
prereq.toString()));
}
final String aString = prereq.getKey().toUpperCase();
for (SpecialAbility sa : character.getSpecialAbilityList()) {
if (sa.getKeyName().toUpperCase().startsWith(aString)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
Aggregations