use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PreClassTest method testFromParserCharWithMultipleSpellClasses.
/**
* Test to ensure that a character will fail a test
* if it does not have the correct number of levels
* in the class.
* @throws Exception
*/
public void testFromParserCharWithMultipleSpellClasses() throws Exception {
LoadContext context = Globals.getContext();
final PCClass pcClass = context.getReferenceContext().constructCDOMObject(PCClass.class, "MyClass");
context.unconditionallyProcess(pcClass, "SPELLSTAT", "CHA");
BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "CAST", "5,4");
final PCClass pcClass2 = context.getReferenceContext().constructCDOMObject(PCClass.class, "Other Class");
context.unconditionallyProcess(pcClass2, "SPELLSTAT", "INT");
BuildUtilities.setFact(pcClass2, "SpellType", "Arcane");
context.unconditionallyProcess(pcClass2.getOriginalClassLevel(1), "CAST", "5,4");
context.getReferenceContext().buildDerivedObjects();
context.getReferenceContext().resolveReferences(null);
context.loadCampaignFacets();
final PlayerCharacter character = getCharacter();
setPCStat(character, cha, 12);
setPCStat(character, intel, 12);
character.incrementClassLevel(1, pcClass);
character.incrementClassLevel(2, pcClass2);
final PreParserFactory factory = PreParserFactory.getInstance();
final Prerequisite prereq = factory.parse("PRECLASS:1,SPELLCASTER.ARCANE=3");
final PreClassTester test = new PreClassTester();
int passes = test.passes(prereq, character, null);
// Doens't pass - levels not summed...
assertEquals(0, passes);
character.incrementClassLevel(1, pcClass2);
passes = test.passes(prereq, character, null);
assertEquals(1, passes);
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PreCheckBaseTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
LoadContext context = Globals.getContext();
PCCheck obj = new PCCheck();
obj.setName("Fortitude");
Globals.getContext().getReferenceContext().importObject(obj);
obj = new PCCheck();
obj.setName("Reflex");
Globals.getContext().getReferenceContext().importObject(obj);
obj = new PCCheck();
obj.setName("Will");
Globals.getContext().getReferenceContext().importObject(obj);
myClass.setName("My Class");
myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
final BonusObj fortRefBonus = Bonus.newBonus(context, "SAVE|BASE.Fortitude,BASE.Reflex|CL/3");
myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, fortRefBonus);
final BonusObj willBonus = Bonus.newBonus(context, "SAVE|BASE.Will|CL/2+2");
myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, willBonus);
Globals.getContext().getReferenceContext().importObject(myClass);
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class ModifyOtherLst method parseTokenWithSeparator.
//MODIFYOTHER:EQUIPMENT|GROUP=Martial|EqCritRange|ADD|1
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Campaign) {
return new ParseResult.Fail(getTokenName() + " may not be used in Campaign Files. " + "Please use the Global Modifier file", context);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String scopeName = sep.next();
/*
* Note lvs is implicitly defined as "not global" since the global scope
* is "" and thus would have failed the tests imposed by
* AbstractTokenWithSeparator
*/
final LegalScope lvs = context.getVariableContext().getScope(scopeName);
if (lvs == null) {
return new ParseResult.Fail(getTokenName() + " found illegal variable scope: " + scopeName + " as first argument: " + value, context);
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " needed 2nd argument: " + value, context);
}
LoadContext subContext = context.dropIntoContext(lvs.getName());
return continueParsing(subContext, obj, value, sep);
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class AbstractCharacterTestCase method setUp.
/**
* Sets up the absolute minimum amount of data to create a PlayerCharacter
* Object.
* @throws Exception
*/
@Override
protected void setUp() throws Exception {
super.setUp();
TestHelper.loadPlugins();
Globals.setUseGUI(false);
Globals.emptyLists();
final GameMode gamemode = SettingsHandler.getGame();
LoadContext context = Globals.getContext();
str = BuildUtilities.createStat("Strength", "STR");
str.put(VariableKey.getConstant("LOADSCORE"), FormulaFactory.getFormulaFor("STRSCORE"));
str.put(VariableKey.getConstant("OFFHANDLIGHTBONUS"), FormulaFactory.getFormulaFor(2));
str.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
str.put(VariableKey.getConstant("MAXLEVELSTAT=" + str.getKeyName()), FormulaFactory.getFormulaFor(str.getKeyName() + "SCORE-10"));
dex = BuildUtilities.createStat("Dexterity", "DEX");
dex.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
dex.put(VariableKey.getConstant("MAXLEVELSTAT=" + dex.getKeyName()), FormulaFactory.getFormulaFor(dex.getKeyName() + "SCORE-10"));
PCStat con = BuildUtilities.createStat("Constitution", "CON");
con.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
con.put(VariableKey.getConstant("MAXLEVELSTAT=" + con.getKeyName()), FormulaFactory.getFormulaFor(con.getKeyName() + "SCORE-10"));
intel = BuildUtilities.createStat("Intelligence", "INT");
intel.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
intel.put(VariableKey.getConstant("MAXLEVELSTAT=" + intel.getKeyName()), FormulaFactory.getFormulaFor(intel.getKeyName() + "SCORE-10"));
wis = BuildUtilities.createStat("Wisdom", "WIS");
wis.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
wis.put(VariableKey.getConstant("MAXLEVELSTAT=" + wis.getKeyName()), FormulaFactory.getFormulaFor(wis.getKeyName() + "SCORE-10"));
cha = BuildUtilities.createStat("Charisma", "CHA");
cha.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
cha.put(VariableKey.getConstant("MAXLEVELSTAT=" + cha.getKeyName()), FormulaFactory.getFormulaFor(cha.getKeyName() + "SCORE-10"));
gamemode.setBonusFeatLevels("3|3");
SettingsHandler.setGame("3.5");
AbstractReferenceContext ref = context.getReferenceContext();
lg = BuildUtilities.createAlignment("Lawful Good", "LG");
ref.importObject(lg);
ln = BuildUtilities.createAlignment("Lawful Neutral", "LN");
ref.importObject(ln);
le = BuildUtilities.createAlignment("Lawful Evil", "LE");
ref.importObject(le);
ng = BuildUtilities.createAlignment("Neutral Good", "NG");
ref.importObject(ng);
tn = BuildUtilities.createAlignment("True Neutral", "TN");
ref.importObject(tn);
ne = BuildUtilities.createAlignment("Neutral Evil", "NE");
ref.importObject(ne);
cg = BuildUtilities.createAlignment("Chaotic Good", "CG");
ref.importObject(cg);
cn = BuildUtilities.createAlignment("Chaotic Neutral", "CN");
ref.importObject(cn);
ce = BuildUtilities.createAlignment("Chaotic Evil", "CE");
ref.importObject(ce);
ref.importObject(BuildUtilities.createAlignment("None", "NONE"));
ref.importObject(BuildUtilities.createAlignment("Deity's", "Deity"));
GameModeFileLoader.addDefaultWieldCategories(context);
ref.importObject(str);
ref.importObject(dex);
ref.importObject(con);
ref.importObject(intel);
ref.importObject(wis);
ref.importObject(cha);
ref.constructCDOMObject(Language.class, "All Language For Test");
BuildUtilities.createFact(context, "ClassType", PCClass.class);
FactDefinition<?, String> fd = BuildUtilities.createFact(context, "SpellType", PCClass.class);
fd.setSelectable(true);
SourceFileLoader.processFactDefinitions(context);
fine = BuildUtilities.createSize("Fine", 0);
diminutive = BuildUtilities.createSize("Diminutive", 1);
tiny = BuildUtilities.createSize("Tiny", 2);
small = BuildUtilities.createSize("Small", 3);
medium = BuildUtilities.createSize("Medium", 4);
medium.put(ObjectKey.IS_DEFAULT_SIZE, true);
large = BuildUtilities.createSize("Large", 5);
huge = BuildUtilities.createSize("Huge", 6);
gargantuan = BuildUtilities.createSize("Gargantuan", 7);
colossal = BuildUtilities.createSize("Colossal", 8);
SourceFileLoader.createLangBonusObject(context);
GameModeFileLoader.addDefaultUnitSet(SettingsHandler.getGame());
SettingsHandler.getGame().selectDefaultUnitSet();
ref.importObject(AbilityCategory.FEAT);
additionalSetUp();
context.getReferenceContext().buildDerivedObjects();
context.resolveDeferredTokens();
assertTrue(ref.resolveReferences(null));
context.loadCampaignFacets();
character = new PlayerCharacter();
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class AbstractJunit4CharacterTestCase method setUp.
/**
* Sets up the absolute minimum amount of data to create a PlayerCharacter
* Object.
* @throws Exception
*/
@Before
public void setUp() throws Exception {
TestHelper.loadPlugins();
final GameMode gamemode = new GameMode("3.5");
gamemode.setBonusFeatLevels("3|3");
gamemode.setAlignmentText("Alignment");
final LevelInfo levelInfo = new LevelInfo();
levelInfo.setLevelString("LEVEL");
levelInfo.setMaxClassSkillString("LEVEL+3");
levelInfo.setMaxCrossClassSkillString("(LEVEL+3)/2");
gamemode.addLevelInfo("Normal", levelInfo);
gamemode.addXPTableName("Normal");
gamemode.setDefaultXPTableName("Normal");
LoadInfo loadable = gamemode.getModeContext().getReferenceContext().constructNowIfNecessary(LoadInfo.class, gamemode.getName());
loadable.addLoadScoreValue(0, BigDecimal.ONE);
GameModeFileLoader.addDefaultTabInfo(gamemode);
SystemCollections.addToGameModeList(gamemode);
SettingsHandler.setGame("3.5");
Globals.setUseGUI(false);
Globals.emptyLists();
str = BuildUtilities.createStat("Strength", "STR");
str.put(VariableKey.getConstant("LOADSCORE"), FormulaFactory.getFormulaFor("STRSCORE"));
str.put(VariableKey.getConstant("OFFHANDLIGHTBONUS"), FormulaFactory.getFormulaFor(2));
str.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
str.put(VariableKey.getConstant("MAXLEVELSTAT=" + str.getKeyName()), FormulaFactory.getFormulaFor(str.getKeyName() + "SCORE-10"));
dex = BuildUtilities.createStat("Dexterity", "DEX");
dex.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
dex.put(VariableKey.getConstant("MAXLEVELSTAT=" + dex.getKeyName()), FormulaFactory.getFormulaFor(dex.getKeyName() + "SCORE-10"));
PCStat con = BuildUtilities.createStat("Constitution", "CON");
con.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
con.put(VariableKey.getConstant("MAXLEVELSTAT=" + con.getKeyName()), FormulaFactory.getFormulaFor(con.getKeyName() + "SCORE-10"));
intel = BuildUtilities.createStat("Intelligence", "INT");
intel.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
intel.put(VariableKey.getConstant("MAXLEVELSTAT=" + intel.getKeyName()), FormulaFactory.getFormulaFor(intel.getKeyName() + "SCORE-10"));
wis = BuildUtilities.createStat("Wisdom", "WIS");
wis.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
wis.put(VariableKey.getConstant("MAXLEVELSTAT=" + wis.getKeyName()), FormulaFactory.getFormulaFor(wis.getKeyName() + "SCORE-10"));
cha = BuildUtilities.createStat("Charisma", "CHA");
cha.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
cha.put(VariableKey.getConstant("MAXLEVELSTAT=" + cha.getKeyName()), FormulaFactory.getFormulaFor(cha.getKeyName() + "SCORE-10"));
gamemode.setBonusFeatLevels("3|3");
SettingsHandler.setGame("3.5");
LoadContext context = Globals.getContext();
AbstractReferenceContext ref = context.getReferenceContext();
lg = BuildUtilities.createAlignment("Lawful Good", "LG");
ref.importObject(lg);
ln = BuildUtilities.createAlignment("Lawful Neutral", "LN");
ref.importObject(ln);
le = BuildUtilities.createAlignment("Lawful Evil", "LE");
ref.importObject(le);
ng = BuildUtilities.createAlignment("Neutral Good", "NG");
ref.importObject(ng);
tn = BuildUtilities.createAlignment("True Neutral", "TN");
ref.importObject(tn);
ne = BuildUtilities.createAlignment("Neutral Evil", "NE");
ref.importObject(ne);
cg = BuildUtilities.createAlignment("Chaotic Good", "CG");
ref.importObject(cg);
cn = BuildUtilities.createAlignment("Chaotic Neutral", "CN");
ref.importObject(cn);
ce = BuildUtilities.createAlignment("Chaotic Evil", "CE");
ref.importObject(ce);
ref.importObject(BuildUtilities.createAlignment("None", "NONE"));
ref.importObject(BuildUtilities.createAlignment("Deity's", "Deity"));
GameModeFileLoader.addDefaultWieldCategories(context);
ref.importObject(str);
ref.importObject(dex);
ref.importObject(con);
ref.importObject(intel);
ref.importObject(wis);
ref.importObject(cha);
ref.constructCDOMObject(Language.class, "All Language For Test");
BuildUtilities.createFact(context, "ClassType", PCClass.class);
FactDefinition<?, String> fd = BuildUtilities.createFact(context, "SpellType", PCClass.class);
fd.setSelectable(true);
fine = BuildUtilities.createSize("Fine", 0);
diminutive = BuildUtilities.createSize("Diminutive", 1);
tiny = BuildUtilities.createSize("Tiny", 2);
small = BuildUtilities.createSize("Small", 3);
medium = BuildUtilities.createSize("Medium", 4);
medium.put(ObjectKey.IS_DEFAULT_SIZE, true);
large = BuildUtilities.createSize("Large", 5);
huge = BuildUtilities.createSize("Huge", 6);
gargantuan = BuildUtilities.createSize("Gargantuan", 7);
colossal = BuildUtilities.createSize("Colossal", 8);
SourceFileLoader.createLangBonusObject(context);
GameModeFileLoader.addDefaultUnitSet(SettingsHandler.getGame());
SettingsHandler.getGame().selectDefaultUnitSet();
ref.importObject(AbilityCategory.FEAT);
SourceFileLoader.processFactDefinitions(context);
additionalSetUp();
if (!ref.resolveReferences(null)) {
fail("Unconstructed References");
}
context.resolvePostValidationTokens();
context.resolvePostDeferredTokens();
context.loadCampaignFacets();
character = new PlayerCharacter();
}
Aggregations