use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreFactTester 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("PreFact.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[] factinfo = prereq.getKey().split("=");
FactKey<?> fk = FactKey.valueOf(factinfo[0]);
Object targetVal = fk.getFormatManager().convertIndirect(factinfo[1]);
int runningTotal = 0;
for (Reducible r : objModel) {
Indirect<?> cdoVal = r.getCDOMObject().get(fk);
if (targetVal.equals(cdoVal)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.
the class PreHPTester 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;
try {
final int targetHP = Integer.parseInt(prereq.getOperand());
runningTotal = prereq.getOperator().compare(character.hitPoints(), targetHP);
} catch (NumberFormatException nfe) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreHP.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 PreBaseSizeParser 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("basesize");
// Get the comparator type BASESIZEGTEQ, BASESIZE, BASESIZENEQ etc.
String compType = kind.substring(8);
if (compType.isEmpty()) {
compType = "gteq";
}
prereq.setOperator(compType);
String abb = formula.substring(0, 1);
LoadContext context = Globals.getContext();
CDOMSingleRef<SizeAdjustment> ref = context.getReferenceContext().getCDOMReference(SizeAdjustment.class, abb);
context.forgetMeNot(ref);
prereq.setOperand(abb);
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 PreReachParser 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.PCREACH)) {
throw new PersistenceLayerException("PREREACH is disabled when CREATEUREREACH control is used");
}
Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
try {
prereq.setKind("reach");
// 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 PreSizeParser 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("size");
// Get the comparator type SIZEGTEQ, BSIZE, SIZENEQ etc.
String compType = kind.substring(4);
if (compType.isEmpty()) {
compType = "gteq";
}
prereq.setOperator(compType);
String abb = formula.substring(0, 1);
LoadContext context = Globals.getContext();
CDOMSingleRef<SizeAdjustment> ref = context.getReferenceContext().getCDOMReference(SizeAdjustment.class, abb);
context.forgetMeNot(ref);
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;
}
Aggregations