Search in sources :

Example 6 with PrerequisiteException

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

the class PreDeityTester 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;
    if (//$NON-NLS-1$
    prereq.getKey().startsWith("PANTHEON.")) {
        try {
            String pantheon = prereq.getKey().substring(9);
            Deity deity = display.getDeity();
            Set<String> charDeityPantheon = new WrappedMapSet<>(CaseInsensitiveMap.class);
            if (deity != null) {
                FactSetKey<String> fk = FactSetKey.valueOf("Pantheon");
                for (Indirect<String> indirect : deity.getSafeSetFor(fk)) {
                    charDeityPantheon.add(indirect.get());
                }
            }
            if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
                runningTotal = (charDeityPantheon.contains(pantheon)) ? 1 : 0;
            } else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
                runningTotal = (charDeityPantheon.contains(pantheon)) ? 0 : 1;
            } else {
                throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
                prereq.toString()));
            }
        } catch (IllegalArgumentException e) {
            //This is okay, just indicates the Pantheon asked for can't exist in any PC
            if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
                runningTotal = 0;
            } else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
                runningTotal = 1;
            } else {
                throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
                prereq.toString()));
            }
        }
    } else {
        final String charDeity = display.getDeity() != null ? display.getDeity().getKeyName() : //$NON-NLS-1$
        "";
        if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
            runningTotal = (charDeity.equalsIgnoreCase(prereq.getKey())) ? 1 : 0;
        } else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
            runningTotal = (charDeity.equalsIgnoreCase(prereq.getKey())) ? 0 : 1;
        } else {
            throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
            prereq.toString()));
        }
    }
    return countedTotal(prereq, runningTotal);
}
Also used : Deity(pcgen.core.Deity) PrerequisiteException(pcgen.core.prereq.PrerequisiteException) WrappedMapSet(pcgen.base.util.WrappedMapSet)

Example 7 with PrerequisiteException

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

the class PreFactSetTester 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("PreFactSet.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 test = prereq.getKey();
    String[] factinfo = test.split("=");
    String factid = factinfo[0];
    String factval = factinfo[1];
    FactSetKey<?> fk = FactSetKey.valueOf(factid);
    int runningTotal = getRunningTotal(prereq, number, objModel, factval, fk);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) Reducible(pcgen.cdom.base.Reducible)

Example 8 with PrerequisiteException

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

the class PreArmorProfTester 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("Prereq.error", "PREARMOR", //$NON-NLS-1$ //$NON-NLS-2$
        prereq.toString()));
    }
    final String aString = prereq.getKey();
    Equipment keyEquip = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, aString);
    final boolean isType = aString.startsWith("TYPE") && aString.length() > 5;
    final boolean isArmorType = aString.startsWith("ARMORTYPE") && aString.length() > 11;
    String typeString = null;
    if (isType) {
        typeString = "ARMOR." + aString.substring(5);
    } else if (isArmorType) {
        typeString = "ARMOR." + aString.substring(10);
    }
    for (ProfProvider<ArmorProf> spp : display.getArmorProfList()) {
        if (keyEquip != null && spp.providesProficiency(keyEquip.getArmorProf())) {
            runningTotal++;
        } else if (keyEquip != null && spp.providesEquipmentType(keyEquip.getType())) {
            runningTotal++;
        } else if (isType && spp.providesEquipmentType(typeString)) {
            runningTotal++;
        } else if (isArmorType && spp.providesEquipmentType(typeString)) {
            runningTotal++;
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) Equipment(pcgen.core.Equipment) ArmorProf(pcgen.core.ArmorProf)

Example 9 with PrerequisiteException

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

the class PreItemTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
	 */
// TODO Refactor this with all the equipment tests.
@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 e) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreItem.error.bad_operand", //$NON-NLS-1$
        prereq.toString()));
    }
    int runningTotal = 0;
    if (display.hasEquipment()) {
        // Work out exactlywhat we are going to test.
        final String aString = prereq.getKey();
        List<String> typeList = null;
        if (aString.startsWith(Constants.LST_TYPE_EQUAL) || aString.startsWith(Constants.LST_TYPE_DOT)) {
            String stripped = aString.substring(Constants.SUBSTRING_LENGTH_FIVE);
            typeList = CoreUtility.split(stripped, '.');
        }
        for (Equipment eq : display.getEquipmentSet()) {
            if (typeList != null) {
                // Check to see if the equipment matches
                // all of the types in the requested list;
                boolean bMatches = true;
                for (int i = 0, x = typeList.size(); i < x; ++i) {
                    if (!eq.isType(typeList.get(i))) {
                        bMatches = false;
                        break;
                    }
                }
                if (bMatches) {
                    runningTotal++;
                }
            } else {
                //not a TYPE string
                final String eqName = eq.getName().toUpperCase();
                if (aString.indexOf('%') >= 0) {
                    //handle wildcards (always assume
                    // they end the line)
                    final int percentPos = aString.indexOf('%');
                    final String substring = aString.substring(0, percentPos).toUpperCase();
                    if ((eqName.startsWith(substring))) {
                        ++runningTotal;
                        break;
                    }
                } else if (eqName.equalsIgnoreCase(aString)) {
                    //just a straight String compare
                    ++runningTotal;
                    break;
                }
            }
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) Equipment(pcgen.core.Equipment)

Example 10 with PrerequisiteException

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

the class PreLanguageTester 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 String requiredLang = prereq.getKey();
    final int requiredNumber = Integer.parseInt(prereq.getOperand());
    int runningTotal = 0;
    if (prereq.getKey().equalsIgnoreCase("ANY")) {
        //$NON-NLS-1$
        runningTotal = display.getLanguageCount();
    } else {
        final Language aLang = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Language.class, requiredLang);
        if (aLang != null) {
            if (display.hasLanguage(aLang)) {
                runningTotal = 1;
            }
        } else if (//$NON-NLS-1$
        !requiredLang.equals("ANY")) {
            throw new PrerequisiteException(LanguageBundle.getFormattedString("PreLanguage.error.no_such_language", //$NON-NLS-1$
            requiredLang));
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, requiredNumber);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) Language(pcgen.core.Language)

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