use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreHandsParser method parse.
/**
* Parse the pre req list
*
* @param kind The kind of the prerequisite (less the "PRE" prefix)
* @param formula The body of the prerequisite.
* @param invertResult Whether the prerequisite should invert the result.
* @param overrideQualify
* if set true, this prerequisite will be enforced in spite
* of any "QUALIFY" tag that may be present.
* @return PreReq
* @throws PersistenceLayerException
*/
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
if (ControlUtilities.hasControlToken(Globals.getContext(), CControl.CREATUREHANDS)) {
throw new PersistenceLayerException("PREHANDS is disabled when CREATUREHANDS CodeControl is used");
}
Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
try {
prereq.setKind("hands");
// Get the comparator type SIZEGTEQ, BSIZE, SIZENEQ etc.
String compType = kind.substring(5);
if (compType.isEmpty()) {
compType = "gteq";
}
prereq.setOperator(compType);
prereq.setOperand(formula);
if (invertResult) {
prereq.setOperator(prereq.getOperator().invert());
}
} catch (PrerequisiteException pe) {
throw new PersistenceLayerException("Unable to parse the prerequisite :'" + kind + ':' + formula + "'. " + pe.getLocalizedMessage());
}
return prereq;
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreLegsParser method parse.
/**
* Parse the pre req list
*
* @param kind The kind of the prerequisite (less the "PRE" prefix)
* @param formula The body of the prerequisite.
* @param invertResult Whether the prerequisite should invert the result.
* @param overrideQualify
* if set true, this prerequisite will be enforced in spite
* of any "QUALIFY" tag that may be present.
* @return PreReq
* @throws PersistenceLayerException
*/
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
if (ControlUtilities.hasControlToken(Globals.getContext(), CControl.LEGS)) {
throw new PersistenceLayerException("PRELEGS is deprecated (does not function) when LEGS CodeControl is used");
}
Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
try {
prereq.setKind("legs");
// Get the comparator type SIZEGTEQ, BSIZE, SIZENEQ etc.
String compType = kind.substring(4);
if (compType.isEmpty()) {
compType = "gteq";
}
prereq.setOperator(compType);
prereq.setOperand(formula);
if (invertResult) {
prereq.setOperator(prereq.getOperator().invert());
}
} catch (PrerequisiteException pe) {
throw new PersistenceLayerException("Unable to parse the prerequisite :'" + kind + ':' + formula + "'. " + pe.getLocalizedMessage());
}
return prereq;
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreSpellResistanceParser method parse.
/**
* Parse the pre req list
*
* @param kind The kind of the prerequisite (less the "PRE" prefix)
* @param formula The body of the prerequisite.
* @param invertResult Whether the prerequisite should invert the result.
* @param overrideQualify
* if set true, this prerequisite will be enforced in spite
* of any "QUALIFY" tag that may be present.
* @return PreReq
* @throws PersistenceLayerException
*/
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
try {
prereq.setKind("sr");
// Get the comparator type SRGTEQ, SR, SRNEQ etc.
String compType = kind.substring(2);
if (compType.isEmpty()) {
compType = "gteq";
}
prereq.setOperator(compType);
if (invertResult) {
prereq.setOperator(prereq.getOperator().invert());
}
} catch (PrerequisiteException pe) {
throw new PersistenceLayerException("Unable to parse the prerequisite :'" + kind + ':' + formula + "'. " + pe.getLocalizedMessage());
}
return prereq;
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreEquipTester method passes.
/*
* (non-Javadoc)
*
* @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;
final int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException exceptn) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreFeat.error", //$NON-NLS-1$
prereq.toString()));
}
CharacterDisplay display = character.getDisplay();
if (display.hasEquipment()) {
String targetEquip = prereq.getKey();
for (Equipment eq : display.getEquippedEquipmentSet()) {
if (targetEquip.startsWith("WIELDCATEGORY=") || targetEquip.startsWith("WIELDCATEGORY.")) {
final WieldCategory wCat = eq.getEffectiveWieldCategory(character);
if ((wCat != null) && wCat.getKeyName().equalsIgnoreCase(targetEquip.substring(14))) {
++runningTotal;
break;
}
} else if (//$NON-NLS-1$ //$NON-NLS-2$
targetEquip.startsWith("TYPE=") || targetEquip.startsWith("TYPE.")) {
StringTokenizer tok = new StringTokenizer(targetEquip.substring(5).toUpperCase(), ".");
boolean match = false;
if (tok.hasMoreTokens()) {
match = true;
}
//
while (tok.hasMoreTokens()) {
final String type = tok.nextToken();
if (!eq.isType(type)) {
match = false;
break;
}
}
if (match) {
++runningTotal;
break;
}
} else //not a TYPE string
{
String eqName;
if (//$NON-NLS-1$ //$NON-NLS-2$
targetEquip.startsWith("BASEITEM=")) {
eqName = eq.getBaseItemName().toUpperCase();
targetEquip = targetEquip.substring(targetEquip.indexOf(Constants.EQUALS) + 1);
} else {
eqName = eq.getName().toUpperCase();
}
if (targetEquip.indexOf('%') >= 0) {
//handle wildcards (always assume
// they end the line)
final int percentPos = targetEquip.indexOf('%');
final String substring = targetEquip.substring(0, percentPos).toUpperCase();
if ((eqName.startsWith(substring))) {
++runningTotal;
break;
}
} else if (eqName.equalsIgnoreCase(targetEquip)) {
//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 PreReachTester 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 targetReach = Integer.parseInt(prereq.getOperand());
int pcReach = FacetLibrary.getFacet(ReachFacet.class).getReach(display.getCharID());
runningTotal = prereq.getOperator().compare(pcReach, targetReach);
} catch (NumberFormatException nfe) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreReach.error.badly_formed", //$NON-NLS-1$
prereq.getOperand()));
}
return countedTotal(prereq, runningTotal);
}
Aggregations