Search in sources :

Example 81 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreItemTest method testType.

/**
	 * Test equipment type tests
	 * @throws Exception
	 */
public void testType() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Equipment longsword = new Equipment();
    longsword.setName("Longsword");
    character.addEquipment(longsword);
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("item");
    prereq.setKey("TYPE=Weapon");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    assertFalse("Equipment has no type", PrereqHandler.passes(prereq, character, null));
    longsword.addType(Type.WEAPON);
    assertTrue("Equipment is weapon", PrereqHandler.passes(prereq, character, null));
    prereq.setKey("TYPE.Armor");
    assertFalse("Equipment is not armor", PrereqHandler.passes(prereq, character, null));
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREITEM:2,TYPE=Armor,Longsword%");
    assertFalse("Doesn't have armor", PrereqHandler.passes(prereq, character, null));
    final Equipment leather = new Equipment();
    leather.setName("Leather");
    leather.addType(Type.getConstant("ARMOR"));
    character.addEquipment(leather);
    assertTrue("Armor and sword present", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) Equipment(pcgen.core.Equipment)

Example 82 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreEquipTest method testType.

/**
	 * Test equipment type tests
	 * @throws Exception
	 */
public void testType() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Equipment longsword = new Equipment();
    longsword.setName("Longsword");
    character.addEquipment(longsword);
    longsword.setIsEquipped(true, character);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equip");
    prereq.setKey("TYPE=Weapon");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    assertFalse("Equipment has no type", PrereqHandler.passes(prereq, character, null));
    longsword.addType(Type.WEAPON);
    assertTrue("Equipment is weapon", PrereqHandler.passes(prereq, character, null));
    prereq.setKey("TYPE.Armor");
    assertFalse("Equipment is not armor", PrereqHandler.passes(prereq, character, null));
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREEQUIP:2,TYPE=Armor,Longsword%");
    assertFalse("Doesn't have armor equipped", PrereqHandler.passes(prereq, character, null));
    final Equipment leather = new Equipment();
    leather.setName("Leather");
    leather.addType(Type.getConstant("ARMOR"));
    character.addEquipment(leather);
    leather.setIsEquipped(true, character);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    assertTrue("Armor and sword equipped", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) Equipment(pcgen.core.Equipment)

Example 83 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreLegsTest method testLegs.

/**
	 * Test the PRELEGS code
	 * @throws Exception
	 */
public void testLegs() throws Exception {
    final PlayerCharacter character = getCharacter();
    Race race = new Race();
    race.put(IntegerKey.LEGS, 2);
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRELEGSLT:2");
    assertFalse("Character has more than 1 leg", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEGSEQ:2");
    assertTrue("Character has 2 legs", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEGSGT:2");
    assertFalse("Character does not have more than 2 legs", PrereqHandler.passes(prereq, character, null));
    PCTemplate tmpl = new PCTemplate();
    tmpl.put(IntegerKey.LEGS, 3);
    character.addTemplate(tmpl);
    assertTrue("Character does have more than 2 legs", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate)

Example 84 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreLevelTest method testHD.

/**
	 * Test that HD are counted
	 * @throws Exception
	 */
public void testHD() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.incrementClassLevel(2, myClass, true);
    myClass = character.getClassKeyed("MY_CLASS");
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRELEVEL:MIN=4");
    assertFalse("Character doesn't have 4 levels", PrereqHandler.passes(prereq, character, null));
    character.setRace(race);
    assertTrue("Character has 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MIN=5");
    assertTrue("Character doesn't have 5 or more levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MAX=3");
    assertTrue("Character doesn't have 3 or more levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MIN=6,MAX=7");
    assertTrue("Character doesn't have between 6 and 7 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MIN=4,MAX=6");
    assertTrue("Character doesn't have 4-6 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MIN=6,MAX=7");
    assertFalse("Character doesn't have 6-7 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MAX=7");
    assertTrue("Character has no more than 5 levels", PrereqHandler.passes(prereq, character, null));
    character.incrementClassLevel(4, myClass, true);
    prereq = factory.parse("PRELEVEL:MAX=7");
    assertFalse("Character has no more than 7 levels", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 85 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreShieldProfTest method testInverse.

/**
	 * Test with negation.
	 * 
	 * @throws Exception the exception
	 */
public void testInverse() throws Exception {
    final PlayerCharacter character = getCharacter();
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("!PREPROFWITHSHIELD:1,Heavy Steel Shield");
    assertTrue("Character has no proficiencies", PrereqHandler.passes(prereq, character, null));
    final Ability martialProf = TestHelper.makeAbility("Shield Proficiency (Single)", "FEAT", "General");
    Globals.getContext().unconditionallyProcess(martialProf, "AUTO", "SHIELDPROF|Heavy Wooden Shield");
    Globals.getContext().unconditionallyProcess(martialProf, "AUTO", "SHIELDPROF|Heavy Steel Shield");
    assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
    AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, martialProf, null);
    assertFalse("Character has the Heavy Steel Shield proficiency.", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PREPROFWITHSHIELD:1,Light Wooden Shield");
    assertTrue("Character does not have the Light Wooden Shield proficiency", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PREPROFWITHSHIELD:1,Heavy Wooden Shield");
    assertFalse("Character has the Heavy Wooden Shield proficiency.", PrereqHandler.passes(prereq, character, null));
}
Also used : Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Aggregations

PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)107 PlayerCharacter (pcgen.core.PlayerCharacter)89 LoadContext (pcgen.rules.context.LoadContext)16 BonusObj (pcgen.core.bonus.BonusObj)13 Prerequisite (pcgen.core.prereq.Prerequisite)12 Ability (pcgen.core.Ability)11 PCClass (pcgen.core.PCClass)11 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 StringTokenizer (java.util.StringTokenizer)5 Domain (pcgen.core.Domain)5 PCTemplate (pcgen.core.PCTemplate)5 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)5 URI (java.net.URI)4 Equipment (pcgen.core.Equipment)4 PersistenceManager (pcgen.persistence.PersistenceManager)4 DamageReduction (pcgen.cdom.content.DamageReduction)3 ClassSource (pcgen.cdom.helper.ClassSource)3 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)3 QualifiedObject (pcgen.core.QualifiedObject)3