Search in sources :

Example 31 with PrerequisiteException

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

the class PreHandsTester method passes.

@Override
public int passes(final Prerequisite prereq, final PlayerCharacter display, CDOMObject source) throws PrerequisiteException {
    int runningTotal;
    try {
        final int targetHands = Integer.parseInt(prereq.getOperand());
        int hands = FacetLibrary.getFacet(HandsFacet.class).getHands(display.getCharID());
        runningTotal = prereq.getOperator().compare(hands, targetHands);
    } catch (NumberFormatException nfe) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreHands.error.badly_formed", //$NON-NLS-1$
        prereq.getOperand()));
    }
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) HandsFacet(pcgen.cdom.facet.analysis.HandsFacet)

Example 32 with PrerequisiteException

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

the class PreAgeSetTester 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 ageset = display.getAgeSetIndex();
    int runningTotal = -1;
    int anInt;
    try {
        anInt = Integer.parseInt(prereq.getKey());
    } catch (NumberFormatException exc) {
        anInt = display.getBioSet().getAgeSetNamed(prereq.getKey());
    } catch (Exception e) {
        //$NON-NLS-1$
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAgeSet.error.badly_formed_attribute", prereq.getOperand()));
    }
    if (anInt == -1) {
        //$NON-NLS-1$
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAgeSet.error.badly_formed_attribute", prereq.getOperand()));
    }
    runningTotal = prereq.getOperator().compare(ageset, anInt);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) PrerequisiteException(pcgen.core.prereq.PrerequisiteException)

Example 33 with PrerequisiteException

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

the class PreAlignTester method passes.

@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
    //
    // If game mode doesn't support alignment, then pass the prereq
    //
    int runningTotal = 0;
    if (Globals.getGameModeAlignmentText().isEmpty()) {
        runningTotal = 1;
    } else {
        String desiredAlignment = prereq.getKey();
        final PCAlignment charAlignment = display.getPCAlignment();
        if (prereq.getOperator().equals(PrerequisiteOperator.EQ)) {
            if (alignMatches(display, desiredAlignment, charAlignment)) {
                runningTotal++;
            }
        } else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ)) {
            if (!alignMatches(display, desiredAlignment, charAlignment)) {
                runningTotal++;
            }
        } else {
            throw new PrerequisiteException(LanguageBundle.getFormattedString("PreAlign.error.invalidComparison", prereq.getOperator().toString(), //$NON-NLS-1$
            prereq.toString()));
        }
    }
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) PCAlignment(pcgen.core.PCAlignment)

Example 34 with PrerequisiteException

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

the class PreWeaponProfTester method passes.

/**
	 * <b>Tag Name</b>: {@code PREWEAPONPROF:x,y,y}<br>
	 * &nbsp; <b>Variables Used (x)</b>: <i>Number</i> (The number of proficiencies that must match the specified requirements). <br>
	 * &nbsp; <b>Variables Used (y)</b>: <i>Text</i> (The name of a weapon proficiency). <br>
	 * &nbsp; <b>Variables Used (y)</b>: {@code TYPE.}<i>Text</i> (The name of a weaponprof type). <br>
	 * &nbsp; <b>Variables Used (y)</b>: {@code DEITYWEAPON} (The favored weapon of the character's deity). <br>
	 * <p>
	 * <b>What it does:</b><br>
	 * &nbsp; Sets weapon proficiency requirements.
	 * <p>
	 * <b>Examples</b>: <br>
	 * &nbsp; {@code PREWEAPONPROF:2,Kama,Katana}<br>
	 * &nbsp; &nbsp; Character must have both "Kama" and "Katana".
	 * <p>
	 * &nbsp; {@code PREWEAPONPROF:1,TYPE.Exotic} <br>
	 * &nbsp; &nbsp; Character must have proficiency with any one exotic weaponprof type.
	 * <p>
	 * &nbsp; {@code PREWEAPONPROF:1,TYPE.Martial,Chain (Spiked)} <br>
	 * &nbsp; &nbsp; Character must have proficiency with either the Chain (Spiked) or any martial weapon.
	 * <p>
	 * &nbsp; {@code PREWEAPONPROF:1,DEITYWEAPON} <br>
	 * &nbsp; &nbsp; Weapon Prof in question must be one of the chosen deity's favored weapons.
	 * 
	 * @see pcgen.core.prereq.AbstractPrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.PlayerCharacter, CDOMObject)
	 */
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, 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()));
    }
    final String aString = prereq.getKey();
    if (//$NON-NLS-1$
    "DEITYWEAPON".equals(aString) && display.getDeity() != null) {
        List<CDOMReference<WeaponProf>> dwp = display.getDeity().getSafeListFor(ListKey.DEITYWEAPON);
        DEITYWPN: for (CDOMReference<WeaponProf> ref : dwp) {
            for (WeaponProf wp : ref.getContainedObjects()) {
                if (display.hasWeaponProf(wp)) {
                    runningTotal++;
                    break DEITYWPN;
                }
            }
        }
    } else if (//$NON-NLS-1$ //$NON-NLS-2$
    aString.startsWith("TYPE.") || aString.startsWith("TYPE=")) {
        final String requiredType = aString.substring(5);
        for (WeaponProf wp : display.getWeaponProfSet()) {
            if (wp.isType(requiredType)) {
                runningTotal++;
            } else {
                final Equipment eq = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, wp.getKeyName());
                if (eq != null) {
                    if (eq.isType(requiredType)) {
                        runningTotal++;
                    }
                }
            }
        }
    } else {
        WeaponProf wp = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WeaponProf.class, aString);
        if ((wp != null && display.hasWeaponProf(wp))) {
            runningTotal++;
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) Equipment(pcgen.core.Equipment) WeaponProf(pcgen.core.WeaponProf) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 35 with PrerequisiteException

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

the class PreTemplateTester 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;
    final int number;
    try {
        number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException exceptn) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreTemplate.error", //$NON-NLS-1$
        prereq.toString()));
    }
    if (display.hasTemplates()) {
        String templateKey = prereq.getKey().toUpperCase();
        final int wildCard = templateKey.indexOf('%');
        //handle wildcards (always assume they end the line)
        if (wildCard >= 0) {
            templateKey = templateKey.substring(0, wildCard);
            for (PCTemplate aTemplate : display.getTemplateSet()) {
                if (aTemplate.getKeyName().toUpperCase().startsWith(templateKey)) {
                    runningTotal++;
                }
            }
        } else {
            PCTemplate template = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTEMPLATE_CLASS, templateKey);
            if (display.hasTemplate(template)) {
                runningTotal++;
            }
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) PCTemplate(pcgen.core.PCTemplate)

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