Search in sources :

Example 81 with Prerequisite

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

the class PreLevelWriter method specialCase.

/**
	 * @see pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter#specialCase(java.io.Writer writer, pcgen.core.prereq.Prerequisite prereq)
	 */
@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
    //
    if (prereq.getKind() == null) {
        //
        // ...with exactly 2 entries...
        //
        List<Prerequisite> prereqList = prereq.getPrerequisites();
        if (prereqList.size() == 2) {
            //
            // ...both of which are PREHD. The first must specify >= and the second <=
            //
            final Prerequisite elementGTEQ = prereqList.get(0);
            final Prerequisite elementLTEQ = prereqList.get(1);
            if ("level".equalsIgnoreCase(elementGTEQ.getKind()) && elementGTEQ.getOperator().equals(PrerequisiteOperator.GTEQ) && "level".equalsIgnoreCase(elementLTEQ.getKind()) && elementLTEQ.getOperator().equals(PrerequisiteOperator.LTEQ)) {
                if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
                    writer.write('!');
                }
                writer.write("PRELEVEL:" + (prereq.isOverrideQualify() ? "Q:" : ""));
                writer.write("MIN=");
                writer.write(elementGTEQ.getOperand());
                writer.write(",MAX=");
                writer.write(elementLTEQ.getOperand());
                return true;
            }
        }
    }
    return false;
}
Also used : Prerequisite(pcgen.core.prereq.Prerequisite)

Example 82 with Prerequisite

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

the class PrereqHandlerTest method testFeatPasses.

/**
	 * Tests PREFEAT
	 * @throws PersistenceLayerException
	 */
public void testFeatPasses() throws PersistenceLayerException {
    final PreParserFactory factory = PreParserFactory.getInstance();
    final Prerequisite prereq = factory.parse("!PREFEAT:1,Uncanny Dodge");
    final PlayerCharacter pc = getCharacter();
    final Race human = new Race();
    human.setName("Human");
    pc.setRace(human);
    assertTrue("No feat should return true", PrereqHandler.passes(prereq, pc, null));
    final Ability ud = new Ability();
    ud.setName("Uncanny Dodge");
    ud.setCDOMCategory(AbilityCategory.FEAT);
    ud.put(StringKey.KEY_NAME, "Uncanny Dodge");
    addAbility(AbilityCategory.FEAT, ud);
    assertFalse("Feat should return false", PrereqHandler.passes(prereq, pc, null));
}
Also used : PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 83 with Prerequisite

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

the class PreTypeParserTest method testNewStyle.

/**
	 * @throws Exception
	 */
@Test
public void testNewStyle() throws Exception {
    PreTypeParser producer = new PreTypeParser();
    Prerequisite prereq = producer.parse("TYPE", "1,Mithral,Adamantine,Darkwood", false, false);
    System.out.println(prereq.toString());
    assertEquals("<prereq operator=\"GTEQ\" operand=\"1\" >\n" + "<prereq kind=\"type\" key=\"Mithral\" operator=\"EQ\" operand=\"1\" >\n" + "</prereq>\n" + "<prereq kind=\"type\" key=\"Adamantine\" operator=\"EQ\" operand=\"1\" >\n" + "</prereq>\n" + "<prereq kind=\"type\" key=\"Darkwood\" operator=\"EQ\" operand=\"1\" >\n" + "</prereq>\n" + "</prereq>\n", prereq.toString());
}
Also used : PreTypeParser(plugin.pretokens.parser.PreTypeParser) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 84 with Prerequisite

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

the class PreVariableParserTest method testNotEqual.

/**
	 * @throws Exception
	 */
@Test
public void testNotEqual() throws Exception {
    PreVariableParser parser = new PreVariableParser();
    Prerequisite prereq = parser.parse("VARNEQ", "Enraged,1", false, false);
    assertEquals("<prereq kind=\"var\" key=\"Enraged\" operator=\"NEQ\" operand=\"1\" >\n</prereq>\n", prereq.toString());
}
Also used : PreVariableParser(plugin.pretokens.parser.PreVariableParser) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 85 with Prerequisite

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

the class PreMoveParserTest method testFly1.

/**
	 * @throws Exception
	 */
@Test
public void testFly1() throws Exception {
    PreMoveParser parser = new PreMoveParser();
    Prerequisite prereq = parser.parse("MOVE", "1,Fly=1", false, false);
    assertEquals("<prereq kind=\"move\" key=\"Fly\" operator=\"GTEQ\" operand=\"1\" >\n</prereq>\n", prereq.toString());
}
Also used : PreMoveParser(plugin.pretokens.parser.PreMoveParser) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Aggregations

Prerequisite (pcgen.core.prereq.Prerequisite)267 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)62 Test (org.junit.Test)61 PrerequisiteOperator (pcgen.core.prereq.PrerequisiteOperator)50 StringTokenizer (java.util.StringTokenizer)36 ArrayList (java.util.ArrayList)35 StringWriter (java.io.StringWriter)19 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)19 CDOMReference (pcgen.cdom.base.CDOMReference)18 ParseResult (pcgen.rules.persistence.token.ParseResult)18 BonusObj (pcgen.core.bonus.BonusObj)13 TreeSet (java.util.TreeSet)12 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)12 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10 Domain (pcgen.core.Domain)10 QualifiedObject (pcgen.core.QualifiedObject)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 PrerequisiteWriter (pcgen.persistence.lst.output.prereq.PrerequisiteWriter)9 Ungranted (pcgen.cdom.base.Ungranted)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8