use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.
the class PCClassTest method testBypassClassPrereqsDeprecated.
/**
* Test the interaction of prerequisites on PCClasses and bonuses and the
* Bypass Class Prereqs flag.
* @throws Exception
*/
public void testBypassClassPrereqsDeprecated() throws Exception {
LoadContext context = Globals.getContext();
// Setup class with prereqs and var based abilities with prereqs.
final PreVariableParser parser = new PreVariableParser();
final Prerequisite aPrereq = parser.parse("VARGTEQ", "Foo,1", false, false);
final GameMode gameMode = SettingsHandler.getGame();
RuleCheck aClassPreRule = gameMode.getModeContext().getReferenceContext().silentlyGetConstructedCDOMObject(RuleCheck.class, "CLASSPRE");
if (aClassPreRule == null) {
aClassPreRule = new RuleCheck();
aClassPreRule.setName("CLASSPRE");
gameMode.getModeContext().getReferenceContext().importObject(aClassPreRule);
}
aClassPreRule.setDefault(false);
final PCClass aPrClass = new PCClass();
aPrClass.setName("PreReqClass");
aPrClass.put(StringKey.KEY_NAME, "KEY_PreReqClass");
final BonusObj aBonus = Bonus.newBonus(context, "MISC|SR|10|PREVARGTEQ:Foo,2");
if (aBonus != null) {
aPrClass.addToListFor(ListKey.BONUS, aBonus);
}
aPrClass.addPrerequisite(aPrereq);
final PCClass aQClass = new PCClass();
aQClass.setName("QualClass");
aQClass.put(StringKey.KEY_NAME, "KEY_QualClass");
CDOMDirectSingleRef<PCClass> ref = CDOMDirectSingleRef.getRef(aPrClass);
aQClass.addToListFor(ListKey.QUALIFY, new Qualifier(PCClass.class, ref));
final PCClass aNqClass = new PCClass();
aNqClass.setName("NonQualClass");
aNqClass.put(StringKey.KEY_NAME, "KEY_NonQualClass");
aNqClass.put(VariableKey.getConstant("Foo"), FormulaFactory.ONE);
aNqClass.getOriginalClassLevel(2).put(VariableKey.getConstant("Foo"), FormulaFactory.getFormulaFor(2));
// Setup character without prereqs
final PlayerCharacter character = getCharacter();
// Test no prereqs and no bypass fails class and var
assertFalse("PC with no prereqs should fail class qual test.", aPrClass.qualifies(character, aPrClass));
assertEquals("PC with no prereqs should fail var qual test.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
// Test no prereqs and bypass passes class and fails var
aClassPreRule.setDefault(true);
assertTrue("PC with no prereqs should pass class qual test when bypassing prereqs is on.", aPrClass.qualifies(character, aPrClass));
assertEquals("PC with no prereqs should fail var qual test when bypass prereqs is on.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
// Test prereqs and bypass pass class and var
character.incrementClassLevel(1, aNqClass);
assertTrue("PC with prereqs and bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
character.incrementClassLevel(1, aNqClass);
assertEquals("PC with prereqs and bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
// Test prereqs and no bypass passes class and var
aClassPreRule.setDefault(false);
assertTrue("PC with prereqs and no bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
assertEquals("PC with prereqs and no bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
}
use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.
the class GlobalSpellKnownTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
knownSpellFacet = FacetLibrary.getFacet(KnownSpellFacet.class);
wizardSpellList = context.getReferenceContext().constructNowIfNecessary(ClassSpellList.class, "Wizard");
fb = context.getReferenceContext().constructNowIfNecessary(Spell.class, "Fireball");
TokenRegistration.register(new PreVariableParser());
classSetUp();
}
use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.
the class WeildIntegrationTest method setUp.
@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
super.setUp();
TokenRegistration.register(new PreVariableParser());
TokenRegistration.register(new PreVariableWriter());
GameModeFileLoader.addDefaultWieldCategories(primaryContext);
GameModeFileLoader.addDefaultWieldCategories(secondaryContext);
}
use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.
the class PreVarTest method testMutiplePositive.
public void testMutiplePositive() throws Exception {
final PlayerCharacter character = getCharacter();
setPCStat(character, str, 10);
setPCStat(character, dex, 14);
character.calcActiveBonuses();
PreVariableParser parser = new PreVariableParser();
Prerequisite prereq = parser.parse("VAR", "abs(STR),1,abs(DEX),3", false, false);
assertFalse("Test matches with no stats passing", PrereqHandler.passes(prereq, character, null));
setPCStat(character, str, 12);
character.calcActiveBonuses();
assertFalse("Test matches with no stats passing", PrereqHandler.passes(prereq, character, null));
setPCStat(character, dex, 16);
character.calcActiveBonuses();
assertTrue("Test should match now both stats pass", PrereqHandler.passes(prereq, character, null));
}
use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.
the class PreVarTest method testVarPass.
/**
* @throws Exception
*/
public void testVarPass() throws Exception {
final PlayerCharacter character = getCharacter();
PreVariableParser parser = new PreVariableParser();
Prerequisite prereq = parser.parse("vareq", "1,count(\"ABILITIES\",\"CATEGORY=BARDIC\",\"NAME=Dancer\")", false, false);
assertFalse("Test matches with no abilities.", PrereqHandler.passes(prereq, character, null));
Ability ab2 = TestHelper.makeAbility("Dancer", "BARDIC", "General.Bardic");
ab2.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
addAbility(TestHelper.getAbilityCategory(ab2), ab2);
assertTrue("Test fails with ability present.", PrereqHandler.passes(prereq, character, null));
}
Aggregations