Search in sources :

Example 1 with PrerequisiteException

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

the class PreSubClassTester 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 = 0;
    int num;
    try {
        // number we must match
        num = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException nfe) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreSubClass.error.badly_formed", //$NON-NLS-1$
        prereq.toString()));
    }
    final String thisClass = prereq.getKey();
    for (PCClass aClass : display.getClassSet()) {
        final String subClassName = display.getSubClassName(aClass);
        if (subClassName != null && !subClassName.isEmpty()) {
            if (thisClass.equalsIgnoreCase(subClassName)) {
                runningTotal++;
                break;
            }
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, num);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) PCClass(pcgen.core.PCClass)

Example 2 with PrerequisiteException

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

the class PreTotalABTester 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;
    int att = character.baseAttackBonus();
    att += character.getTotalBonusTo("COMBAT", "EPICAB");
    try {
        final int anInt = Integer.parseInt(prereq.getOperand());
        runningTotal = prereq.getOperator().compare(att, anInt);
    } catch (NumberFormatException exc) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAttack.error.badly_formed_attribute", //$NON-NLS-1$
        prereq.getOperand()));
    }
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException)

Example 3 with PrerequisiteException

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

the class PreTypeTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.Equipment)
	 */
@Override
public int passes(final Prerequisite prereq, final Equipment equipment, CharacterDisplay display) throws PrerequisiteException {
    final String requiredType = prereq.getKey();
    int runningTotal = 0;
    if (prereq.getOperator().equals(PrerequisiteOperator.EQ)) {
        if (equipment.isPreType(requiredType)) {
            runningTotal++;
        }
    } else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ)) {
        if (!equipment.isPreType(requiredType)) {
            runningTotal++;
        }
    } else {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreType.error.invalidComparison", prereq.getOperator().toString(), //$NON-NLS-1$
        prereq.toString()));
    }
    runningTotal = countedTotal(prereq, runningTotal);
    return runningTotal;
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException)

Example 4 with PrerequisiteException

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

the class PreStatTester 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 targetNumber = Integer.parseInt(prereq.getOperand());
    PCStat stat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCStat.class, prereq.getKey());
    if (stat == null) {
        throw new PrerequisiteException("PRESTAT refers to invalid stat '" + stat + ". Prereq was " + prereq);
    }
    final int statValue = display.getTotalStatFor(stat);
    final int runningTotal = prereq.getOperator().compare(statValue, targetNumber);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) PCStat(pcgen.core.PCStat)

Example 5 with PrerequisiteException

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

the class PreSpecialAbilityTester 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 = 0;
    int number;
    try {
        number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException exceptn) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreSpecialAbility.error.bad_operand", //$NON-NLS-1$
        prereq.toString()));
    }
    final String aString = prereq.getKey().toUpperCase();
    for (SpecialAbility sa : character.getSpecialAbilityList()) {
        if (sa.getKeyName().toUpperCase().startsWith(aString)) {
            runningTotal++;
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) SpecialAbility(pcgen.core.SpecialAbility)

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