use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCRacialHDSizeTermEvaluatorTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Campaign customCampaign = new Campaign();
customCampaign.setName("Unit Test");
customCampaign.setName("KEY_Unit Test");
customCampaign.addToListFor(ListKey.DESCRIPTION, new Description("Unit Test data"));
CampaignSourceEntry source = new CampaignSourceEntry(customCampaign, new URI("file:/" + getClass().getName() + ".java"));
LoadContext context = Globals.getContext();
PCClassLoader classLoader = new PCClassLoader();
// Create the humanoid monster class
final String humanoidClassLine = "CLASS:Humanoid KEY:KEY_Humanoid HD:8 TYPE:Monster CLASSTYPE:Monster " + "STARTSKILLPTS:2 MODTOSKILLS:YES";
humanoidClass = classLoader.parseLine(context, null, humanoidClassLine, source);
context.getReferenceContext().importObject(humanoidClass);
// Create the pc class
final String pcClassLine = "CLASS:TestPCClass TYPE:PC HD:10";
pcClass = classLoader.parseLine(context, null, pcClassLine, source);
context.getReferenceContext().importObject(pcClass);
CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
// Create the BugBear race
bugbearRace.setName("Bugbear");
bugbearRace.put(StringKey.KEY_NAME, "KEY_Bugbear");
bugbearRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
bugbearRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
bugbearRace.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(humanoidClass), FormulaFactory.getFormulaFor(3)));
context.getReferenceContext().importObject(bugbearRace);
// Create the human race
humanRace.setName("Human");
humanRace.put(StringKey.KEY_NAME, "KEY_Human");
humanRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
context.getReferenceContext().importObject(humanRace);
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class DropIntoContextFunctionTest method testDynamic.
@Test
public void testDynamic() {
VariableLibrary vl = getVariableLibrary();
LegalScope equipScope = getScopeLibrary().getScope("EQUIPMENT");
LegalScope globalScope = getScopeLibrary().getScope("Global");
vl.assertLegalVariableID("LocalVar", equipScope, numberManager);
vl.assertLegalVariableID("EquipVar", globalScope, stringManager);
String formula = "dropIntoContext(\"EQUIPMENT\",EquipVar,LocalVar)";
SimpleNode node = TestUtilities.doParse(formula);
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
semanticsVisitor.visit(node, semantics);
if (!semantics.isValid()) {
TestCase.fail("Expected Valid Formula: " + formula + " but was told: " + semantics.getReport());
}
isStatic(formula, node, false);
Equipment equip = new Equipment();
equip.setName("EquipKey");
Equipment equipalt = new Equipment();
equipalt.setName("EquipAlt");
ScopeInstance scopeInste = getInstanceFactory().get("EQUIPMENT", equip);
VariableID varIDe = vl.getVariableID(scopeInste, "LocalVar");
getVariableStore().put(varIDe, 2);
ScopeInstance scopeInsta = getInstanceFactory().get("EQUIPMENT", equipalt);
VariableID varIDa = vl.getVariableID(scopeInsta, "LocalVar");
getVariableStore().put(varIDa, 3);
ScopeInstance globalInst = getInstanceFactory().getGlobalInstance("Global");
VariableID varIDq = vl.getVariableID(globalInst, "EquipVar");
getVariableStore().put(varIDq, "EquipKey");
LoadContext context = new RuntimeLoadContext(new RuntimeReferenceContext(), new ConsolidatedListCommitStrategy());
context.getReferenceContext().importObject(equip);
context.getReferenceContext().importObject(equipalt);
evaluatesTo(formula, node, 2, context);
Object rv = new ReconstructionVisitor().visit(node, new StringBuilder());
assertEquals(rv.toString(), formula);
getVariableStore().put(varIDq, "EquipAlt");
evaluatesTo(formula, node, 3, context);
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class DropIntoContextFunctionTest method testBasic.
@Test
public void testBasic() {
VariableLibrary vl = getVariableLibrary();
LegalScope equipScope = getScopeLibrary().getScope("EQUIPMENT");
vl.assertLegalVariableID("LocalVar", equipScope, numberManager);
String formula = "dropIntoContext(\"EQUIPMENT\",\"EquipKey\",LocalVar)";
SimpleNode node = TestUtilities.doParse(formula);
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
semanticsVisitor.visit(node, semantics);
if (!semantics.isValid()) {
TestCase.fail("Expected Valid Formula: " + formula + " but was told: " + semantics.getReport());
}
isStatic(formula, node, false);
Equipment equip = new Equipment();
equip.setName("EquipKey");
ScopeInstance scopeInst = getInstanceFactory().get("EQUIPMENT", equip);
VariableID varID = vl.getVariableID(scopeInst, "LocalVar");
getVariableStore().put(varID, 2);
LoadContext context = new RuntimeLoadContext(new RuntimeReferenceContext(), new ConsolidatedListCommitStrategy());
context.getReferenceContext().importObject(equip);
evaluatesTo(formula, node, 2, context);
Object rv = new ReconstructionVisitor().visit(node, new StringBuilder());
assertEquals(rv.toString(), formula);
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCClassTest method testBypassClassPrereqs.
/**
* Test the interaction of prerequisites on PCClasses and bonuses and the
* Bypass Class Prereqs flag.
* @throws Exception
*/
public void testBypassClassPrereqs() 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));
//aQClass.setQualifyString("KEY_PreReqClass|PreReqVar");
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 pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCClassTest method setUp.
/**
* @see pcgen.AbstractCharacterTestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
Campaign customCampaign = new Campaign();
customCampaign.setName("Unit Test");
customCampaign.setName("KEY_Unit Test");
customCampaign.addToListFor(ListKey.DESCRIPTION, new Description("Unit Test data"));
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(customCampaign, new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
// Create the monseter class type
GameMode gamemode = SettingsHandler.getGame();
gamemode.addClassType("Monster CRFORMULA:0 ISMONSTER:YES XPPENALTY:NO");
gamemode.setSkillMultiplierLevels("4");
// Create the humanoid class
String classDef = "CLASS:Humanoid KEY:KEY_Humanoid HD:8 CLASSTYPE:Monster STARTSKILLPTS:1 " + "MODTOSKILLS:NO MONSKILL:6+INT MONNONSKILLHD:1|PRESIZELTEQ:M " + "MONNONSKILLHD:2|PRESIZEEQ:L";
PCClassLoader classLoader = new PCClassLoader();
LoadContext context = Globals.getContext();
humanoidClass = classLoader.parseLine(context, null, classDef, source);
Globals.getContext().getReferenceContext().importObject(humanoidClass);
classDef = "CLASS:Nymph KEY:KEY_Nymph CLASSTYPE:Monster HD:6 STARTSKILLPTS:6 MODTOSKILLS:YES ";
classLoader = new PCClassLoader();
nymphClass = classLoader.parseLine(context, null, classDef, source);
Globals.getContext().getReferenceContext().importObject(nymphClass);
CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
// Create the large size mod
// Create the BugBear race
bugbearRace = new Race();
bugbearRace.setName("Bugbear");
bugbearRace.put(StringKey.KEY_NAME, "KEY_Bugbear");
bugbearRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
bugbearRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
bugbearRace.put(IntegerKey.INITIAL_SKILL_MULT, 1);
Globals.getContext().getReferenceContext().importObject(bugbearRace);
bigBugbearRace = new Race();
bigBugbearRace.setName("BigBugbear");
bigBugbearRace.put(StringKey.KEY_NAME, "KEY_BigBugbear");
bigBugbearRace.put(FormulaKey.SIZE, new FixedSizeFormula(largeRef));
bigBugbearRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
bigBugbearRace.put(IntegerKey.INITIAL_SKILL_MULT, 1);
Globals.getContext().getReferenceContext().importObject(bigBugbearRace);
// Create the Nymph race
nymphRace = new Race();
nymphRace.setName("Nymph");
nymphRace.put(StringKey.KEY_NAME, "KEY_Nymph");
nymphRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
nymphRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
nymphRace.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(nymphClass), FormulaFactory.getFormulaFor(0)));
Globals.getContext().getReferenceContext().importObject(nymphRace);
// Setup class with prereqs and var based abilities with prereqs.
PreVariableParser parser = new PreVariableParser();
prereq = parser.parse("VARGTEQ", "Foo,1", false, false);
classPreRule = new RuleCheck();
classPreRule.setName("CLASSPRE");
classPreRule.setDefault(false);
gamemode.getModeContext().getReferenceContext().importObject(classPreRule);
prClass = new PCClass();
prClass.setName("PreReqClass");
prClass.put(StringKey.KEY_NAME, "KEY_PreReqClass");
final BonusObj aBonus = Bonus.newBonus(context, "MISC|SR|10|PREVARGTEQ:Foo,2");
if (aBonus != null) {
prClass.addToListFor(ListKey.BONUS, aBonus);
}
prClass.addPrerequisite(prereq);
qClass = new PCClass();
qClass.setName("QualClass");
qClass.put(StringKey.KEY_NAME, "KEY_QualClass");
CDOMDirectSingleRef<PCClass> ref = CDOMDirectSingleRef.getRef(prClass);
qClass.addToListFor(ListKey.QUALIFY, new Qualifier(PCClass.class, ref));
nqClass = new PCClass();
nqClass.setName("NonQualClass");
nqClass.put(StringKey.KEY_NAME, "KEY_NonQualClass");
nqClass.put(VariableKey.getConstant("Foo"), FormulaFactory.ONE);
nqClass.getOriginalClassLevel(2).put(VariableKey.getConstant("Foo"), FormulaFactory.getFormulaFor(2));
}
Aggregations