use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreRegionTester 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 String requiredRegion = prereq.getKey().toUpperCase();
final String characterRegion = display.getFullRegion().toUpperCase();
final boolean sameRegion = characterRegion.startsWith(requiredRegion);
int runningTotal;
if (prereq.getOperator().equals(PrerequisiteOperator.EQ)) {
runningTotal = sameRegion ? 1 : 0;
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ)) {
runningTotal = sameRegion ? 0 : 1;
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreRegion.error.invalid_comparator", //$NON-NLS-1$
prereq.toString()));
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreAttackTester 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;
final int att = character.baseAttackBonus();
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 PreKitTester 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;
final int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException exceptn) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreKit.error", //$NON-NLS-1$
prereq.toString()));
}
String kitKey = prereq.getKey().toUpperCase();
final int wildCard = kitKey.indexOf('%');
//handle wildcards (always assume they end the line)
if (wildCard >= 0) {
kitKey = kitKey.substring(0, wildCard);
for (Kit kit : display.getKitInfo()) {
if (kit.getKeyName().toUpperCase().startsWith(kitKey)) {
runningTotal++;
}
}
} else {
Kit kit = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(KIT_CLASS, kitKey);
if (display.hasKit(kit)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreLegsTester 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;
try {
final int targetLegs = Integer.parseInt(prereq.getOperand());
runningTotal = prereq.getOperator().compare(display.getPreFormulaLegs(), targetLegs);
} catch (NumberFormatException nfe) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreLegs.error.bad_operand", //$NON-NLS-1$
prereq.getOperand()));
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreHDTester 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;
try {
final int targetHD = Integer.parseInt(prereq.getOperand());
runningTotal = prereq.getOperator().compare(display.totalHitDice(), targetHD);
} catch (NumberFormatException nfe) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreHD.error.bad_operand", //$NON-NLS-1$
prereq.getOperand()));
}
return countedTotal(prereq, runningTotal);
}
Aggregations