use of pcgen.core.PlayerCharacter in project pcgen by PCGen.
the class PreCSkillTest method testCSkill.
/**
* Test that CSkill works
* @throws Exception
*/
public void testCSkill() throws Exception {
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, myClass, true);
myClass = character.getClassKeyed("My Class");
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PRECSKILL:1,Spot,Listen");
assertFalse("Character has no class skills", PrereqHandler.passes(prereq, character, null));
character.addLocalCost(myClass, spot, SkillCost.CLASS, myClass);
//Need to throw out the cache
character.setDirty(true);
assertTrue("Character has spot class skills", PrereqHandler.passes(prereq, character, null));
character.addLocalCost(myClass, spy1, SkillCost.CLASS, myClass);
//Need to throw out the cache
character.setDirty(true);
assertTrue("Character has spot class skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,TYPE.Spy");
assertFalse("Character has only one Spy Skill", PrereqHandler.passes(prereq, character, null));
character.addLocalCost(myClass, spy2, SkillCost.CLASS, myClass);
//Need to throw out the cache
character.setDirty(true);
assertTrue("Character has 2 Spy class skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:3,Spot,TYPE.Spy");
assertTrue("Character has 2 Spy and Spot class skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:3,Listen,TYPE.Spy");
assertFalse("Character has only 2 Spy Skills", PrereqHandler.passes(prereq, character, null));
character.addLocalCost(myClass, spy3, SkillCost.CLASS, myClass);
//Need to throw out the cache
character.setDirty(true);
prereq = factory.parse("PRECSKILL:3,Listen,TYPE.Spy");
assertTrue("Character has 3 Spy Skills", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.PlayerCharacter in project pcgen by PCGen.
the class PreCSkillTest method testCSkillServesAs.
public void testCSkillServesAs() throws Exception {
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, myClass, true);
myClass = character.getClassKeyed("My Class");
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
Skill bar = new Skill();
bar.setName("Bar");
bar.addToListFor(ListKey.TYPE, Type.getConstant("Bar"));
Globals.getContext().getReferenceContext().importObject(bar);
Skill foo = new Skill();
foo.setName("Foo");
foo.addToListFor(ListKey.SERVES_AS_SKILL, CDOMDirectSingleRef.getRef(bar));
foo.addToListFor(ListKey.TYPE, Type.getConstant("Foo"));
Globals.getContext().getReferenceContext().importObject(foo);
Skill baz = new Skill();
baz.setName("Baz");
baz.addToListFor(ListKey.TYPE, Type.getConstant("Baz"));
Globals.getContext().getReferenceContext().importObject(baz);
Skill fee = new Skill();
fee.setName("Fee");
fee.addToListFor(ListKey.TYPE, Type.getConstant("Bar"));
Globals.getContext().getReferenceContext().importObject(fee);
character.addLocalCost(myClass, fee, SkillCost.CLASS, myClass);
character.addLocalCost(myClass, foo, SkillCost.CLASS, myClass);
prereq = factory.parse("PRECSKILL:1,Bar");
assertTrue("Character has 1 Listen Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,Bar,Fee");
assertTrue("Character has a Bar Skill and a Fee Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,Baz,Fee");
assertFalse("Character does not have both Baz and Fee Skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:1,TYPE=Bar");
assertTrue("Character has 1 Bar Type Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,TYPE=Bar");
assertTrue("Character has 2 Bar Type Skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:3,TYPE=Bar");
assertFalse("Character has less than 3 Bar Type Skills", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.PlayerCharacter in project pcgen by PCGen.
the class PreClassTest method testSpellcasterTypeWrongCasePass.
/**
* Test to ensure that a spellcaster type check is case insensitive
* @throws Exception
*/
public void testSpellcasterTypeWrongCasePass() throws Exception {
LoadContext context = Globals.getContext();
final PCClass pcClass = context.getReferenceContext().constructCDOMObject(PCClass.class, "MyClass");
BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "CAST", "5,4");
context.unconditionallyProcess(pcClass, "SPELLSTAT", "CHA");
context.getReferenceContext().buildDerivedObjects();
context.getReferenceContext().resolveReferences(null);
context.loadCampaignFacets();
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, pcClass);
setPCStat(character, cha, 12);
final Prerequisite prereq = new Prerequisite();
prereq.setKind("class");
prereq.setKey("Spellcaster.Arcane");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.GTEQ);
final PreClassTester test = new PreClassTester();
final int passes = test.passes(prereq, character, null);
assertEquals(1, passes);
}
use of pcgen.core.PlayerCharacter in project pcgen by PCGen.
the class PreClassTest method testNamedClassServesAs.
/**
* Test to ensure that a character with a ServeAs class can be found
* @throws Exception
*/
public void testNamedClassServesAs() throws Exception {
final PCClass pcClass = new PCClass();
pcClass.setName("MyClass");
final PCClass warrior = new PCClass();
warrior.setName("Warrior");
final PCClass ranger = new PCClass();
ranger.setName("Ranger");
pcClass.addToListFor(ListKey.SERVES_AS_CLASS, CDOMDirectSingleRef.getRef(warrior));
pcClass.addToListFor(ListKey.SERVES_AS_CLASS, CDOMDirectSingleRef.getRef(ranger));
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(3, pcClass);
final Prerequisite prereq = new Prerequisite();
prereq.setKind("class");
prereq.setKey("Warrior");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.GTEQ);
final PreClassTester test = new PreClassTester();
final int passes = test.passes(prereq, character, null);
assertEquals(1, passes);
}
use of pcgen.core.PlayerCharacter in project pcgen by PCGen.
the class PreClassTest method testLevelsTwoClasses.
public void testLevelsTwoClasses() throws Exception {
final PCClass pcClass = new PCClass();
pcClass.setName("MyClass");
BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
final PCClass pcClass2 = new PCClass();
pcClass2.setName("MyClass2");
BuildUtilities.setFact(pcClass2, "SpellType", "Divine");
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, pcClass);
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite prereq = factory.parse("PRECLASS:2,MyClass=1,MyClass2=2");
assertEquals(false, PrereqHandler.passes(prereq, character, null));
character.incrementClassLevel(1, pcClass2);
assertEquals(false, PrereqHandler.passes(prereq, character, null));
character.incrementClassLevel(1, pcClass2);
assertEquals(true, PrereqHandler.passes(prereq, character, null));
}
Aggregations