Search in sources :

Example 11 with PrerequisiteException

use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.

the class PreMoveTester method passes.

/*
	 * (non-Javadoc)
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.PlayerCharacter)
	 */
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
    int runningTotal = 0;
    int moveAmount = 0;
    if ((display != null) && display.hasMovement()) {
        final String moveType = prereq.getKey();
        try {
            moveAmount = Integer.parseInt(prereq.getOperand());
        } catch (NumberFormatException e) {
            throw new PrerequisiteException(LanguageBundle.getFormattedString("PreMove.error.bad_operand", //$NON-NLS-1$
            prereq.toString()));
        }
        int speed = (int) display.getMovementOfType(moveType);
        if (speed >= moveAmount) {
            runningTotal += speed;
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, moveAmount);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException)

Example 12 with PrerequisiteException

use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.

the class PreStatParser 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 {
        // PREMULT
        prereq.setKind(null);
        // Get the comparator type STATGTEQ, STAT, STATNEQ etc.
        String compType = kind.substring(4);
        if (compType.isEmpty()) {
            compType = "gteq";
        }
        String[] tokens = formula.split(",|\\|");
        int currToken = 0;
        // Get the minimum match count
        String aString = tokens[currToken++];
        try {
            prereq.setOperand(Integer.toString(Integer.parseInt(aString)));
        } catch (NumberFormatException e) {
            Logging.errorPrint("Badly formed PRESTAT attribute: " + aString);
            prereq.setOperand("1");
        }
        while (currToken < tokens.length) {
            aString = tokens[currToken++];
            final int idxEquals = aString.lastIndexOf('=');
            if (idxEquals < 3) {
                throw new PersistenceLayerException("PRE" + kindsHandled()[0] + " formula '" + formula + "' is not valid.");
            }
            final String stat = aString.substring(0, Math.min(3, idxEquals));
            Prerequisite statPrereq = new Prerequisite();
            statPrereq.setKind("stat");
            statPrereq.setKey(stat);
            statPrereq.setOperator(compType);
            statPrereq.setOperand(aString.substring(idxEquals + 1));
            prereq.addPrerequisite(statPrereq);
        }
        if ((prereq.getPrerequisiteCount() == 1) && (prereq.getOperator() == PrerequisiteOperator.GTEQ) && prereq.getOperand().equals("1")) {
            prereq = prereq.getPrerequisites().get(0);
        }
        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 13 with PrerequisiteException

use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.

the class PreCampaignTester 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 number;
    try {
        number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException exceptn) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreFeat.error", //$NON-NLS-1$
        prereq.toString()));
    }
    int runningTotal = 0;
    if (prereq.getKey().startsWith("BOOKTYPE=")) {
        runningTotal += countCampaignByBookType(prereq.getKey().substring(9), false);
    } else if (prereq.getKey().startsWith("INCLUDESBOOKTYPE=")) {
        runningTotal += countCampaignByBookType(prereq.getKey().substring(17), true);
    } else if (prereq.getKey().startsWith("INCLUDES=")) {
        runningTotal += countCampaignByName(prereq.getKey().substring(9), source, true);
    } else {
        runningTotal += countCampaignByName(prereq.getKey(), source, false);
    }
    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException)

Example 14 with PrerequisiteException

use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.

the class PreVariableParser 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);
    prereq.setKind("var");
    // Get the comparator type SIZEGTEQ, BSIZE, SIZENEQ etc.
    String compType = kind.substring(3);
    if (compType.isEmpty()) {
        compType = "gteq";
    }
    ParsingSeparator ps = new ParsingSeparator(formula, ',');
    ps.addGroupingPair('[', ']');
    ps.addGroupingPair('(', ')');
    try {
        int count = 0;
        while (ps.hasNext()) {
            String first = ps.next();
            if (!ps.hasNext()) {
                throw new PersistenceLayerException("Unable to parse prerequisite 'PRE" + kind + ':' + formula + "'. Incorrect parameter count (must be even)");
            }
            String second = ps.next();
            Prerequisite subreq;
            if (!ps.hasNext() && count == 0) {
                subreq = prereq;
            } else {
                // PREMULT
                prereq.setKind(null);
                subreq = new Prerequisite();
                subreq.setKind("var");
                prereq.addPrerequisite(subreq);
                count++;
            }
            subreq.setOperator(compType.intern());
            subreq.setKey(first.intern());
            subreq.setOperand(second.intern());
        }
        if (count > 0) {
            prereq.setOperand(Integer.toString(count));
        }
    } catch (PrerequisiteException pe) {
        throw new PersistenceLayerException("Unable to parse prerequisite 'PRE" + kind + ':' + formula + "'. " + pe.getLocalizedMessage());
    }
    if (invertResult) {
        prereq.setOperator(prereq.getOperator().invert());
    }
    prereq.setOverrideQualify(overrideQualify);
    return prereq;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PrerequisiteException(pcgen.core.prereq.PrerequisiteException) ParsingSeparator(pcgen.base.text.ParsingSeparator) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 15 with PrerequisiteException

use of pcgen.core.prereq.PrerequisiteException in project pcgen by PCGen.

the class PreAbilityTester method passes.

@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) throws PrerequisiteException {
    final int number;
    try {
        number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException exception) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAbility.error", //$NON-NLS-1$
        prereq.toString()));
    }
    String categoryName = prereq.getCategoryName();
    int runningTotal = PrerequisiteUtilities.passesAbilityTest(prereq, character, number, categoryName);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException)

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