use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreHandsTester method passes.
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter display, CDOMObject source) throws PrerequisiteException {
int runningTotal;
try {
final int targetHands = Integer.parseInt(prereq.getOperand());
int hands = FacetLibrary.getFacet(HandsFacet.class).getHands(display.getCharID());
runningTotal = prereq.getOperator().compare(hands, targetHands);
} catch (NumberFormatException nfe) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreHands.error.badly_formed", //$NON-NLS-1$
prereq.getOperand()));
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreAgeSetTester 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 ageset = display.getAgeSetIndex();
int runningTotal = -1;
int anInt;
try {
anInt = Integer.parseInt(prereq.getKey());
} catch (NumberFormatException exc) {
anInt = display.getBioSet().getAgeSetNamed(prereq.getKey());
} catch (Exception e) {
//$NON-NLS-1$
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAgeSet.error.badly_formed_attribute", prereq.getOperand()));
}
if (anInt == -1) {
//$NON-NLS-1$
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAgeSet.error.badly_formed_attribute", prereq.getOperand()));
}
runningTotal = prereq.getOperator().compare(ageset, anInt);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreAlignTester method passes.
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
//
// If game mode doesn't support alignment, then pass the prereq
//
int runningTotal = 0;
if (Globals.getGameModeAlignmentText().isEmpty()) {
runningTotal = 1;
} else {
String desiredAlignment = prereq.getKey();
final PCAlignment charAlignment = display.getPCAlignment();
if (prereq.getOperator().equals(PrerequisiteOperator.EQ)) {
if (alignMatches(display, desiredAlignment, charAlignment)) {
runningTotal++;
}
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ)) {
if (!alignMatches(display, desiredAlignment, charAlignment)) {
runningTotal++;
}
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAlign.error.invalidComparison", prereq.getOperator().toString(), //$NON-NLS-1$
prereq.toString()));
}
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreWeaponProfTester method passes.
/**
* <b>Tag Name</b>: {@code PREWEAPONPROF:x,y,y}<br>
* <b>Variables Used (x)</b>: <i>Number</i> (The number of proficiencies that must match the specified requirements). <br>
* <b>Variables Used (y)</b>: <i>Text</i> (The name of a weapon proficiency). <br>
* <b>Variables Used (y)</b>: {@code TYPE.}<i>Text</i> (The name of a weaponprof type). <br>
* <b>Variables Used (y)</b>: {@code DEITYWEAPON} (The favored weapon of the character's deity). <br>
* <p>
* <b>What it does:</b><br>
* Sets weapon proficiency requirements.
* <p>
* <b>Examples</b>: <br>
* {@code PREWEAPONPROF:2,Kama,Katana}<br>
* Character must have both "Kama" and "Katana".
* <p>
* {@code PREWEAPONPROF:1,TYPE.Exotic} <br>
* Character must have proficiency with any one exotic weaponprof type.
* <p>
* {@code PREWEAPONPROF:1,TYPE.Martial,Chain (Spiked)} <br>
* Character must have proficiency with either the Chain (Spiked) or any martial weapon.
* <p>
* {@code PREWEAPONPROF:1,DEITYWEAPON} <br>
* Weapon Prof in question must be one of the chosen deity's favored weapons.
*
* @see pcgen.core.prereq.AbstractPrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.PlayerCharacter, CDOMObject)
*/
@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("PreFeat.error", //$NON-NLS-1$
prereq.toString()));
}
final String aString = prereq.getKey();
if (//$NON-NLS-1$
"DEITYWEAPON".equals(aString) && display.getDeity() != null) {
List<CDOMReference<WeaponProf>> dwp = display.getDeity().getSafeListFor(ListKey.DEITYWEAPON);
DEITYWPN: for (CDOMReference<WeaponProf> ref : dwp) {
for (WeaponProf wp : ref.getContainedObjects()) {
if (display.hasWeaponProf(wp)) {
runningTotal++;
break DEITYWPN;
}
}
}
} else if (//$NON-NLS-1$ //$NON-NLS-2$
aString.startsWith("TYPE.") || aString.startsWith("TYPE=")) {
final String requiredType = aString.substring(5);
for (WeaponProf wp : display.getWeaponProfSet()) {
if (wp.isType(requiredType)) {
runningTotal++;
} else {
final Equipment eq = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, wp.getKeyName());
if (eq != null) {
if (eq.isType(requiredType)) {
runningTotal++;
}
}
}
}
} else {
WeaponProf wp = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WeaponProf.class, aString);
if ((wp != null && display.hasWeaponProf(wp))) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreTemplateTester 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("PreTemplate.error", //$NON-NLS-1$
prereq.toString()));
}
if (display.hasTemplates()) {
String templateKey = prereq.getKey().toUpperCase();
final int wildCard = templateKey.indexOf('%');
//handle wildcards (always assume they end the line)
if (wildCard >= 0) {
templateKey = templateKey.substring(0, wildCard);
for (PCTemplate aTemplate : display.getTemplateSet()) {
if (aTemplate.getKeyName().toUpperCase().startsWith(templateKey)) {
runningTotal++;
}
}
} else {
PCTemplate template = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTEMPLATE_CLASS, templateKey);
if (display.hasTemplate(template)) {
runningTotal++;
}
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
Aggregations