use of pcgen.cdom.formula.FixedSizeFormula in project pcgen by PCGen.
the class PreEquipPrimaryTest method testWield.
/**
* Test wield category tests
* @throws Exception
*/
public void testWield() throws Exception {
final PlayerCharacter character = getCharacter();
final Race race = new Race();
race.setName("Test Race");
CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
character.setRace(race);
LoadContext context = Globals.getContext();
final Equipment longsword = new Equipment();
longsword.setName("Dagger");
character.addEquipment(longsword);
longsword.setIsEquipped(true, character);
longsword.setLocation(EquipmentLocation.EQUIPPED_PRIMARY);
character.doAfavorForAunitTestThatIgnoresEquippingRules();
Prerequisite prereq = new Prerequisite();
prereq.setKind("equipprimary");
prereq.setKey("WIELDCATEGORY=OneHanded");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.EQ);
// Test 3.0 Style
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
assertTrue("Weapon is M therefore OneHanded", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.SIZE, largeRef);
longsword.put(ObjectKey.BASESIZE, largeRef);
assertFalse("Weapon is L therefore TwoHanded", PrereqHandler.passes(prereq, character, null));
// Test 3.5 style
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
assertFalse("Weapon is TwoHanded", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
assertTrue("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.cdom.formula.FixedSizeFormula in project pcgen by PCGen.
the class PreHDTest method testClassLevels.
/**
* Tests using monster class levels
* @throws Exception
*/
public void testClassLevels() throws Exception {
monClass.setName("Humanoid");
monClass.put(ObjectKey.IS_MONSTER, true);
Globals.getContext().getReferenceContext().importObject(monClass);
race1.setName("Bugbear");
CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
race1.put(FormulaKey.SIZE, new FixedSizeFormula(largeRef));
race1.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(monClass), FormulaFactory.getFormulaFor(3)));
Globals.getContext().getReferenceContext().importObject(race1);
final PlayerCharacter character = new PlayerCharacter();
character.setRace(race1);
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREHD:MIN=4");
assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=3");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=1,MAX=3");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=3,MAX=6");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=4,MAX=7");
assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=1,MAX=2");
assertFalse("Character doesn't have 2 or less HD", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.cdom.formula.FixedSizeFormula in project pcgen by PCGen.
the class PreEquipSecondaryTest method testWield.
/**
* Test wield category tests
* @throws Exception
*/
public void testWield() throws Exception {
final PlayerCharacter character = getCharacter();
final Race race = new Race();
race.setName("Test Race");
CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
CDOMDirectSingleRef<SizeAdjustment> smallRef = CDOMDirectSingleRef.getRef(small);
race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
character.setRace(race);
LoadContext context = Globals.getContext();
final Equipment longsword = new Equipment();
longsword.setName("Longsword");
character.addEquipment(longsword);
longsword.setIsEquipped(true, character);
longsword.setLocation(EquipmentLocation.EQUIPPED_SECONDARY);
character.doAfavorForAunitTestThatIgnoresEquippingRules();
Prerequisite prereq = new Prerequisite();
prereq.setKind("equipsecondary");
prereq.setKey("WIELDCATEGORY=Light");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.EQ);
// Test 3.0 Style
longsword.put(ObjectKey.SIZE, smallRef);
longsword.put(ObjectKey.BASESIZE, smallRef);
assertTrue("Weapon is S therefore Light", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
assertFalse("Weapon is M therefore OneHanded", PrereqHandler.passes(prereq, character, null));
// Test 3.5 style
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
assertFalse("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "Light"));
assertTrue("Weapon is Light", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.cdom.formula.FixedSizeFormula in project pcgen by PCGen.
the class PreEquipTest method testWield.
/**
* Test wield category tests
* @throws Exception
*/
public void testWield() throws Exception {
final PlayerCharacter character = getCharacter();
final Race race = new Race();
race.setName("Test Race");
CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
character.setRace(race);
LoadContext context = Globals.getContext();
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("WIELDCATEGORY=OneHanded");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.EQ);
// Test 3.0 Style
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
assertTrue("Weapon is M therefore OneHanded", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.SIZE, largeRef);
longsword.put(ObjectKey.BASESIZE, largeRef);
assertFalse("Weapon is L therefore TwoHanded", PrereqHandler.passes(prereq, character, null));
// Test 3.5 style
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
assertFalse("Weapon is TwoHanded", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
assertTrue("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.cdom.formula.FixedSizeFormula in project pcgen by PCGen.
the class PreHDTest method testHD.
/**
* Test the PREHD code
* @throws Exception
*/
public void testHD() throws Exception {
race.setName("Human");
CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
Globals.getContext().getReferenceContext().importObject(race);
PCClass raceClass = new PCClass();
raceClass.setName("Race Class");
raceClass.put(StringKey.KEY_NAME, "RaceClass");
raceClass.put(ObjectKey.IS_MONSTER, true);
Globals.getContext().getReferenceContext().importObject(raceClass);
race.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(raceClass), FormulaFactory.getFormulaFor(3)));
final PlayerCharacter character = getCharacter();
character.setRace(race);
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREHD:MIN=4");
assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=3");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=1,MAX=3");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=3,MAX=6");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=4,MAX=7");
assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=1,MAX=2");
assertFalse("Character doesn't have 2 or less HD", PrereqHandler.passes(prereq, character, null));
}
Aggregations