use of pcgen.persistence.lst.PCClassLoader 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));
}
use of pcgen.persistence.lst.PCClassLoader in project pcgen by PCGen.
the class PCClassTest method parsePCClassText.
/**
* Parse a class definition and return the populated PCClass object.
*
* @param classPCCText The textual definition of the class.
* @param source The source that the class is from.
* @return The populated class.
* @throws PersistenceLayerException
*/
private PCClass parsePCClassText(String classPCCText, CampaignSourceEntry source) throws PersistenceLayerException {
PCClassLoader pcClassLoader = new PCClassLoader();
PCClass reconstClass = null;
StringTokenizer tok = new StringTokenizer(classPCCText, "\n");
while (tok.hasMoreTokens()) {
String line = tok.nextToken();
if (!line.trim().isEmpty()) {
System.out.println("Processing line:'" + line + "'.");
reconstClass = pcClassLoader.parseLine(Globals.getContext(), reconstClass, line, source);
}
}
return reconstClass;
}
use of pcgen.persistence.lst.PCClassLoader in project pcgen by PCGen.
the class PObjectTest method testGetPCCText.
/**
* Test the processing of getPCCText to ensure that it correctly produces
* an LST representation of an object and that the LST can then be reloaded
* to recrete the object.
*
* @throws PersistenceLayerException
*/
public void testGetPCCText() throws PersistenceLayerException {
OrderedPairManager opManager = new OrderedPairManager();
LoadContext context = Globals.getContext();
context.getVariableContext().assertLegalVariableID(context.getActiveScope().getLegalScope(), opManager, "Face");
Race race = new Race();
race.setName("TestRace");
race.put(ObjectKey.CHALLENGE_RATING, new ChallengeRating(FormulaFactory.getFormulaFor(5)));
String racePCCText = race.getPCCText();
assertNotNull("PCC Text for race should not be null", racePCCText);
GenericLoader<Race> raceLoader = new GenericLoader<>(Race.class);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
raceLoader.parseLine(context, null, racePCCText, source);
Race reconstRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "TestRace");
assertEquals("getPCCText should be the same after being encoded and reloaded", racePCCText, reconstRace.getPCCText());
assertEquals("Racial CR was not restored after saving and reloading.", race.get(ObjectKey.CHALLENGE_RATING), reconstRace.get(ObjectKey.CHALLENGE_RATING));
FactKey.getConstant("Abb", new StringManager());
PCClass aClass = new PCClass();
aClass.setName("TestClass");
String classPCCText = aClass.getPCCText();
assertNotNull("PCC Text for race should not be null", racePCCText);
PCClassLoader classLoader = new PCClassLoader();
PCClass reconstClass = classLoader.parseLine(context, null, classPCCText, source);
assertEquals("getPCCText should be the same after being encoded and reloaded", classPCCText, reconstClass.getPCCText());
assertEquals("Class abbrev was not restored after saving and reloading.", aClass.getAbbrev(), reconstClass.getAbbrev());
}
use of pcgen.persistence.lst.PCClassLoader in project pcgen by PCGen.
the class SpellLevelTest method testGetPCBasedBonusKnownSpells.
/**
* Test method for {@link pcgen.core.analysis.SpellLevel#getPCBasedBonusKnownSpells(pcgen.core.PlayerCharacter, pcgen.core.PCClass)}.
* @throws Exception
*/
public void testGetPCBasedBonusKnownSpells() throws Exception {
LoadContext context = Globals.getContext();
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
final String classLine = "CLASS:Sorcerer TYPE:Base.PC SPELLSTAT:CHA SPELLTYPE:Arcane MEMORIZE:NO BONUS:CASTERLEVEL|Sorcerer|CL";
PCClassLoader classLoader = new PCClassLoader();
PCClass pcc = classLoader.parseLine(context, null, classLine, source);
Spell spell = TestHelper.makeSpell("Bless");
String abilityLine = "Spell bonanza CATEGORY:FEAT SPELLKNOWN:CLASS|Sorcerer=3|KEY_Bless";
AbilityLoader abilityLoader = new AbilityLoader();
abilityLoader.parseLine(context, null, abilityLine, source);
Ability ab1 = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, "Spell bonanza");
// Do the post parsing cleanup
context.resolveDeferredTokens();
context.getReferenceContext().buildDeferredObjects();
context.getReferenceContext().buildDerivedObjects();
context.getReferenceContext().validate(null);
assertTrue(context.getReferenceContext().resolveReferences(null));
PlayerCharacter aPC = getCharacter();
Collection<Integer> levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
assertEquals("Initial number of spell levels incorrect", 0, levels.size());
addAbility(AbilityCategory.FEAT, ab1);
// Now for the tests
levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
assertEquals("Incorrect number of spell levels returned", 1, levels.size());
assertEquals("Incorrect spell level returned", Integer.valueOf(3), levels.iterator().next());
Collection<Spell> result = listManagerFacet.getSet(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST), 3);
assertEquals("Incorrect number of spells returned", 1, result.size());
assertEquals("Incorrect spell returned", spell, result.iterator().next());
}
use of pcgen.persistence.lst.PCClassLoader in project pcgen by PCGen.
the class PlayerCharacterSpellTest method additionalSetUp.
@Override
protected void additionalSetUp() throws Exception {
LoadContext context = Globals.getContext();
CampaignSourceEntry source = TestHelper.createSource(getClass());
// Spells
classSpell = TestHelper.makeSpell("classSpell");
domainSpell = TestHelper.makeSpell("domainSpell");
final String classLine = "CLASS:MyClass TYPE:Base.PC SPELLSTAT:CHA MEMORIZE:YES SPELLBOOK:NO";
PCClassLoader classLoader = new PCClassLoader();
divineClass = classLoader.parseLine(context, null, classLine, source);
BuildUtilities.setFact(divineClass, "SpellType", "Divine");
classLoader.parseLine(context, divineClass, "CLASS:MyClass KNOWNSPELLS:LEVEL=0|LEVEL=1|LEVEL=2|LEVEL=3|LEVEL=4|LEVEL=5|LEVEL=6|LEVEL=7|LEVEL=8|LEVEL=9 BONUS:CASTERLEVEL|Cleric|CL", source);
classLoader.parseClassLevelLine(context, divineClass, 1, source, "CAST:5,4 BONUS:DOMAIN|NUMBER|2 BONUS:VAR|DomainLVL|CL");
context.getReferenceContext().importObject(divineClass);
final String domainLine = "Sun SPELLLEVEL:DOMAIN|Sun=1|KEY_domainSpell";
GenericLoader<Domain> domainLoader = new GenericLoader<>(Domain.class);
domainLoader.parseLine(context, null, domainLine, source);
sunDomain = context.getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, "Sun");
CDOMReference<ClassSpellList> ref = TokenUtilities.getTypeOrPrimitive(context, ClassSpellList.class, divineClass.getKeyName());
AssociatedPrereqObject edge = context.getListContext().addToMasterList("CLASSES", classSpell, ref, classSpell);
edge.setAssociation(AssociationKey.SPELL_LEVEL, 1);
context.commit();
}
Aggregations