Search in sources :

Example 56 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreLangTest method testLang.

/**
	 * Test the PRELANG code
	 * @throws Exception
	 */
public void testLang() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.addFreeLanguage(elven, elven);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRELANG:1,KEY_Elven");
    assertTrue("Character should have elven", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELANG:1,KEY_Elven,KEY_Dwarven");
    assertTrue("Character should have elven", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELANG:2,KEY_Elven,KEY_Dwarven");
    assertFalse("Character doesn't have Dwarven", PrereqHandler.passes(prereq, character, null));
    character.addFreeLanguage(dwarven, dwarven);
    assertTrue("Character has Elven and Dwarven", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELANG:3,ANY");
    assertFalse("Character doesn't have 3 langs", PrereqHandler.passes(prereq, character, null));
    character.addFreeLanguage(halfling, halfling);
    assertTrue("Character has Elven, Dwarven, and Halfling", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELANG:3,Elven");
    assertFalse("PRE test should look at keys", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 57 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreRaceTest method testPassServesAsRaceSubType.

/**
	 * Test to make sure that we return true when races RACESUBTYPE are equal using ServesAs.
	 * 
	 * @throws Exception
	 */
public void testPassServesAsRaceSubType() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Race race = new Race();
    race.setName("Human");
    race.addToListFor(ListKey.TYPE, Type.getConstant("Outsider"));
    race.addToListFor(ListKey.RACESUBTYPE, RaceSubType.getConstant("aquatic"));
    race.addToListFor(ListKey.RACESUBTYPE, RaceSubType.getConstant("foo"));
    Globals.getContext().getReferenceContext().importObject(race);
    final Race fake = new Race();
    fake.setName("NotHuman");
    fake.addToListFor(ListKey.TYPE, Type.getConstant("Humanoid"));
    fake.addToListFor(ListKey.RACESUBTYPE, RaceSubType.getConstant("desert"));
    fake.addToListFor(ListKey.RACESUBTYPE, RaceSubType.getConstant("none"));
    Globals.getContext().getReferenceContext().importObject(fake);
    fake.addToListFor(ListKey.SERVES_AS_RACE, CDOMDirectSingleRef.getRef(race));
    final Race gnome = new Race();
    gnome.setName("Gnome");
    gnome.addToListFor(ListKey.RACESUBTYPE, RaceSubType.getConstant("SpikyHair"));
    Globals.getContext().getReferenceContext().importObject(gnome);
    final Race bugbear = new Race();
    bugbear.setName("Bugbear");
    bugbear.addToListFor(ListKey.RACESUBTYPE, RaceSubType.getConstant("SpikyClub"));
    Globals.getContext().getReferenceContext().importObject(bugbear);
    bugbear.addToListFor(ListKey.SERVES_AS_RACE, CDOMDirectSingleRef.getRef(gnome));
    character.setRace(fake);
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("race");
    prereq.setKey("RACESUBTYPE=aquatic");
    prereq.setOperator(PrerequisiteOperator.EQ);
    boolean passes = PrereqHandler.passes(prereq, character, null);
    assertTrue(passes);
    final Prerequisite prereq2 = new Prerequisite();
    prereq2.setKind("race");
    prereq2.setKey("RACESUBTYPE=foo");
    prereq2.setOperator(PrerequisiteOperator.EQ);
    passes = PrereqHandler.passes(prereq2, character, null);
    assertTrue(passes);
    prereq.setKey("RACESUBTYPE=SpikyHair");
    passes = PrereqHandler.passes(prereq, character, null);
    assertFalse("Prereq " + prereq + " should not be passed by character without a " + "race or servesas link.", passes);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Race(pcgen.core.Race)

Example 58 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreRaceTest method testNeqFails.

/**
	 * Test to make sure we return false when race is equal but NOT is specificed.
	 * 
	 * @throws Exception
	 */
public void testNeqFails() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Race race = new Race();
    race.setName("Human");
    Globals.getContext().getReferenceContext().importObject(race);
    character.setRace(race);
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("race");
    prereq.setKey("Human");
    prereq.setOperator(PrerequisiteOperator.NEQ);
    final boolean passes = PrereqHandler.passes(prereq, character, null);
    assertFalse(passes);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Race(pcgen.core.Race)

Example 59 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreRaceTest method testPass.

/**
	 * Test to make sure that we return true when races are equal.
	 * 
	 * @throws Exception
	 */
public void testPass() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Race race = new Race();
    race.setName("Human");
    Globals.getContext().getReferenceContext().importObject(race);
    character.setRace(race);
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("race");
    prereq.setKey("human");
    prereq.setOperator(PrerequisiteOperator.EQ);
    final boolean passes = PrereqHandler.passes(prereq, character, null);
    assertTrue(passes);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Race(pcgen.core.Race)

Example 60 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreRaceTest method testRaceTypeEq.

public void testRaceTypeEq() {
    final PlayerCharacter character = getCharacter();
    final Race race = new Race();
    race.setName("Human");
    race.put(ObjectKey.RACETYPE, RaceType.getConstant("Humanoid"));
    Globals.getContext().getReferenceContext().importObject(race);
    character.setRace(race);
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("race");
    prereq.setKey("RACETYPE=Humanoid");
    prereq.setOperator(PrerequisiteOperator.EQ);
    final boolean passes = PrereqHandler.passes(prereq, character, null);
    assertTrue(prereq + " should pass", passes);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Race(pcgen.core.Race)

Aggregations

PlayerCharacter (pcgen.core.PlayerCharacter)438 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)89 PCClass (pcgen.core.PCClass)61 LoadContext (pcgen.rules.context.LoadContext)58 Ability (pcgen.core.Ability)54 Equipment (pcgen.core.Equipment)41 PCTemplate (pcgen.core.PCTemplate)38 EquipSet (pcgen.core.character.EquipSet)32 BonusObj (pcgen.core.bonus.BonusObj)29 Race (pcgen.core.Race)28 CharID (pcgen.cdom.enumeration.CharID)25 ExportHandler (pcgen.io.ExportHandler)24 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)16 PreClassTester (plugin.pretokens.test.PreClassTester)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 Skill (pcgen.core.Skill)14 CNAbility (pcgen.cdom.content.CNAbility)13 URI (java.net.URI)11 URISyntaxException (java.net.URISyntaxException)11