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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations