Search in sources :

Example 21 with PrerequisiteException

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

Example 22 with PrerequisiteException

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

Example 23 with PrerequisiteException

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

Example 24 with PrerequisiteException

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);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment) CharacterDisplay(pcgen.core.display.CharacterDisplay) WieldCategory(pcgen.core.character.WieldCategory)

Example 25 with PrerequisiteException

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

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