Search in sources :

Example 16 with PrerequisiteException

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);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) CDOMObject(pcgen.cdom.base.CDOMObject) Reducible(pcgen.cdom.base.Reducible)

Example 17 with PrerequisiteException

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);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException)

Example 18 with PrerequisiteException

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;
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) LoadContext(pcgen.rules.context.LoadContext) SizeAdjustment(pcgen.core.SizeAdjustment) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 19 with PrerequisiteException

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;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PrerequisiteException(pcgen.core.prereq.PrerequisiteException) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 20 with PrerequisiteException

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;
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) LoadContext(pcgen.rules.context.LoadContext) SizeAdjustment(pcgen.core.SizeAdjustment) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

PrerequisiteException (pcgen.core.prereq.PrerequisiteException)35 Prerequisite (pcgen.core.prereq.Prerequisite)8 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)8 Equipment (pcgen.core.Equipment)4 Reducible (pcgen.cdom.base.Reducible)2 SizeAdjustment (pcgen.core.SizeAdjustment)2 LoadContext (pcgen.rules.context.LoadContext)2 StringTokenizer (java.util.StringTokenizer)1 ParsingSeparator (pcgen.base.text.ParsingSeparator)1 WrappedMapSet (pcgen.base.util.WrappedMapSet)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 HandsFacet (pcgen.cdom.facet.analysis.HandsFacet)1 ReachFacet (pcgen.cdom.facet.analysis.ReachFacet)1 ArmorProf (pcgen.core.ArmorProf)1 Deity (pcgen.core.Deity)1 Kit (pcgen.core.Kit)1 Language (pcgen.core.Language)1 PCAlignment (pcgen.core.PCAlignment)1 PCClass (pcgen.core.PCClass)1