use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreDeityTester 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;
if (//$NON-NLS-1$
prereq.getKey().startsWith("PANTHEON.")) {
try {
String pantheon = prereq.getKey().substring(9);
Deity deity = display.getDeity();
Set<String> charDeityPantheon = new WrappedMapSet<>(CaseInsensitiveMap.class);
if (deity != null) {
FactSetKey<String> fk = FactSetKey.valueOf("Pantheon");
for (Indirect<String> indirect : deity.getSafeSetFor(fk)) {
charDeityPantheon.add(indirect.get());
}
}
if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
runningTotal = (charDeityPantheon.contains(pantheon)) ? 1 : 0;
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
runningTotal = (charDeityPantheon.contains(pantheon)) ? 0 : 1;
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
prereq.toString()));
}
} catch (IllegalArgumentException e) {
//This is okay, just indicates the Pantheon asked for can't exist in any PC
if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
runningTotal = 0;
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
runningTotal = 1;
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
prereq.toString()));
}
}
} else {
final String charDeity = display.getDeity() != null ? display.getDeity().getKeyName() : //$NON-NLS-1$
"";
if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
runningTotal = (charDeity.equalsIgnoreCase(prereq.getKey())) ? 1 : 0;
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
runningTotal = (charDeity.equalsIgnoreCase(prereq.getKey())) ? 0 : 1;
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
prereq.toString()));
}
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException 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.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreArmorProfTester 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("Prereq.error", "PREARMOR", //$NON-NLS-1$ //$NON-NLS-2$
prereq.toString()));
}
final String aString = prereq.getKey();
Equipment keyEquip = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, aString);
final boolean isType = aString.startsWith("TYPE") && aString.length() > 5;
final boolean isArmorType = aString.startsWith("ARMORTYPE") && aString.length() > 11;
String typeString = null;
if (isType) {
typeString = "ARMOR." + aString.substring(5);
} else if (isArmorType) {
typeString = "ARMOR." + aString.substring(10);
}
for (ProfProvider<ArmorProf> spp : display.getArmorProfList()) {
if (keyEquip != null && spp.providesProficiency(keyEquip.getArmorProf())) {
runningTotal++;
} else if (keyEquip != null && spp.providesEquipmentType(keyEquip.getType())) {
runningTotal++;
} else if (isType && spp.providesEquipmentType(typeString)) {
runningTotal++;
} else if (isArmorType && spp.providesEquipmentType(typeString)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreItemTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
// TODO Refactor this with all the equipment tests.
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
final int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException e) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreItem.error.bad_operand", //$NON-NLS-1$
prereq.toString()));
}
int runningTotal = 0;
if (display.hasEquipment()) {
// Work out exactlywhat we are going to test.
final String aString = prereq.getKey();
List<String> typeList = null;
if (aString.startsWith(Constants.LST_TYPE_EQUAL) || aString.startsWith(Constants.LST_TYPE_DOT)) {
String stripped = aString.substring(Constants.SUBSTRING_LENGTH_FIVE);
typeList = CoreUtility.split(stripped, '.');
}
for (Equipment eq : display.getEquipmentSet()) {
if (typeList != null) {
// Check to see if the equipment matches
// all of the types in the requested list;
boolean bMatches = true;
for (int i = 0, x = typeList.size(); i < x; ++i) {
if (!eq.isType(typeList.get(i))) {
bMatches = false;
break;
}
}
if (bMatches) {
runningTotal++;
}
} else {
//not a TYPE string
final String eqName = eq.getName().toUpperCase();
if (aString.indexOf('%') >= 0) {
//handle wildcards (always assume
// they end the line)
final int percentPos = aString.indexOf('%');
final String substring = aString.substring(0, percentPos).toUpperCase();
if ((eqName.startsWith(substring))) {
++runningTotal;
break;
}
} else if (eqName.equalsIgnoreCase(aString)) {
//just a straight String compare
++runningTotal;
break;
}
}
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreLanguageTester 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 requiredLang = prereq.getKey();
final int requiredNumber = Integer.parseInt(prereq.getOperand());
int runningTotal = 0;
if (prereq.getKey().equalsIgnoreCase("ANY")) {
//$NON-NLS-1$
runningTotal = display.getLanguageCount();
} else {
final Language aLang = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Language.class, requiredLang);
if (aLang != null) {
if (display.hasLanguage(aLang)) {
runningTotal = 1;
}
} else if (//$NON-NLS-1$
!requiredLang.equals("ANY")) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreLanguage.error.no_such_language", //$NON-NLS-1$
requiredLang));
}
}
runningTotal = prereq.getOperator().compare(runningTotal, requiredNumber);
return countedTotal(prereq, runningTotal);
}
Aggregations