use of pcgen.persistence.lst.GenericLoader in project pcgen by PCGen.
the class ChallengeRatingPathfinderTest method additionalSetUp.
@Override
protected void additionalSetUp() throws Exception {
SettingsHandler.getGame().setCRSteps("1/2|1/3|1/4|1/6|1/8");
SettingsHandler.getGame().setCRThreshold("BASECR");
SettingsHandler.getGame().setMonsterRoleList(new ArrayList<>(Arrays.asList("Combat", "Skill", "Druid")));
SettingsHandler.getGame().addClassType("PC CRFORMULA:CL ISMONSTER:NO CRMOD:-1 CRMODPRIORITY:1");
SettingsHandler.getGame().addClassType("NPC CRFORMULA:CL ISMONSTER:NO CRMOD:-2 CRMODPRIORITY:2");
SettingsHandler.getGame().addClassType("Monster CRFORMULA:0 ISMONSTER:YES");
SettingsHandler.getGame().addClassType("Companion CRFORMULA:NONE ISMONSTER:YES");
LoadContext context = Globals.getContext();
BuildUtilities.createFact(context, "ClassType", PCClass.class);
SourceFileLoader.processFactDefinitions(context);
CampaignSourceEntry source = TestHelper.createSource(getClass());
GenericLoader<Race> raceLoader = new GenericLoader<>(Race.class);
PCClassLoader classLoader = new PCClassLoader();
final String standardRaceLine = "Standard Race";
raceLoader.parseLine(context, null, standardRaceLine, source);
standardRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Standard Race");
final String koboldRaceLine = "Kobold CRMOD:NPC|-3";
raceLoader.parseLine(context, null, koboldRaceLine, source);
koboldRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Kobold");
final String drowNobleLine = "Drow Noble CRMOD:PC.NPC|0";
raceLoader.parseLine(context, null, drowNobleLine, source);
drowNobleRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Drow Noble");
final String babauLine = "Babau MONSTERCLASS:TestMonsterClass:7 CR:6 ROLE:Combat.Skill";
raceLoader.parseLine(context, null, babauLine, source);
babauRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Babau");
final String dryadLine = "Dryad MONSTERCLASS:TestMonsterClass:8 CR:7 ROLE:Druid";
raceLoader.parseLine(context, null, dryadLine, source);
dryadRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Dryad");
final String companionLine = "TestCompanion MONSTERCLASS:TestCompanionClass:4";
raceLoader.parseLine(context, null, companionLine, source);
companionRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "TestCompanion");
final String zombieLine = "Zombie MONSTERCLASS:TestMonsterClass:1 CR:1/2 ROLE:Combat";
raceLoader.parseLine(context, null, zombieLine, source);
zombieRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Zombie");
final String direRatLine = "Dire Rat MONSTERCLASS:TestMonsterClass:1 CR:1/3 ROLE:Combat";
raceLoader.parseLine(context, null, direRatLine, source);
direRatRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Dire rat");
final String miteLine = "Mite MONSTERCLASS:TestMonsterClass:1 CR:1/4 ROLE:Combat";
raceLoader.parseLine(context, null, miteLine, source);
miteRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Mite");
final String beetleLine = "Beetle MONSTERCLASS:TestMonsterClass:1 CR:1/6 ROLE:Combat";
raceLoader.parseLine(context, null, beetleLine, source);
beetleRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Beetle");
final String centipedeLine = "Centipede MONSTERCLASS:TestMonsterClass:1 CR:1/8 Centipede";
raceLoader.parseLine(context, null, centipedeLine, source);
centipedeRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Centipede");
final String pcClassLine = "CLASS:TestPCClass TYPE:PC ROLE:Combat";
pcClass = classLoader.parseLine(context, null, pcClassLine, source);
context.getReferenceContext().importObject(pcClass);
final String pcClassLine2 = "CLASS:TestPCClass2 TYPE:PC ROLE:Druid";
pcClass2 = classLoader.parseLine(context, null, pcClassLine2, source);
context.getReferenceContext().importObject(pcClass2);
final String npcClassLine = "CLASS:TestNPCClass2 TYPE:NPC";
npcClass = classLoader.parseLine(context, null, npcClassLine, source);
context.getReferenceContext().importObject(npcClass);
final String npcClassLine2 = "CLASS:TestNPCClass2 TYPE:NPC";
npcClass2 = classLoader.parseLine(context, null, npcClassLine2, source);
context.getReferenceContext().importObject(npcClass2);
final String monsterClassLine = "CLASS:TestMonsterClass HD:8 CLASSTYPE:Monster";
monsterClass = classLoader.parseLine(context, null, monsterClassLine, source);
context.getReferenceContext().importObject(monsterClass);
final String companionClassLine = "CLASS:TestCompanionClass HD:8 CLASSTYPE:Companion";
companionClass = classLoader.parseLine(context, null, companionClassLine, source);
context.getReferenceContext().importObject(companionClass);
context.commit();
BuildUtilities.createFact(context, "ClassType", PCClass.class);
FactDefinition<?, String> fd = BuildUtilities.createFact(context, "SpellType", PCClass.class);
fd.setSelectable(true);
SourceFileLoader.processFactDefinitions(context);
context.getReferenceContext().buildDerivedObjects();
context.resolveDeferredTokens();
}
use of pcgen.persistence.lst.GenericLoader in project pcgen by PCGen.
the class PObjectTest method testAddAbility.
/**
* Test the definition and application of abilities.
* @throws PersistenceLayerException
*/
public void testAddAbility() throws PersistenceLayerException {
// Create some abilities to be added
LoadContext context = Globals.getContext();
AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
new AbilityCategoryLoader().parseLine(context, "TestCat\tCATEGORY:TestCat", null);
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(SettingsHandler.getGame().getAbilityCategory("TestCat"));
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(SettingsHandler.getGame().getAbilityCategory("TestCat"));
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
// Link them to a template
Race race = new Race();
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
GenericLoader<Race> loader = new GenericLoader<>(Race.class);
loader.parseLine(context, race, "Race1 ABILITY:TestCat|AUTOMATIC|Ability1 ABILITY:TestCat|AUTOMATIC|Ability2", source);
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "TestCat");
assertTrue(context.getReferenceContext().resolveReferences(null));
CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
Collection<CDOMReference<Ability>> listMods = race.getListMods(autoList);
assertEquals(2, listMods.size());
Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
CDOMReference<Ability> ref1 = iterator.next();
CDOMReference<Ability> ref2 = iterator.next();
Collection<Ability> contained1 = ref1.getContainedObjects();
Collection<Ability> contained2 = ref2.getContainedObjects();
assertEquals(1, contained1.size());
assertEquals(1, contained2.size());
assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
// Add the template to the character
PlayerCharacter pc = getCharacter();
pc.setRace(race);
assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
}
use of pcgen.persistence.lst.GenericLoader in project pcgen by PCGen.
the class EquipmentTest method additionalSetUp.
@Override
public void additionalSetUp() throws PersistenceLayerException {
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
GenericLoader<Equipment> eqLoader = new GenericLoader<>(Equipment.class);
eq = eqLoader.parseLine(Globals.getContext(), null, "Dummy SIZE:M KEY:OrigKey TYPE:Weapon", source);
eq = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, OriginalKey);
eqDouble = eqLoader.parseLine(Globals.getContext(), null, "Double SIZE:M KEY:DoubleKey TYPE:Weapon.Double", source);
eqDouble = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, "DoubleKey");
GenericLoader<EquipmentModifier> loader = new GenericLoader<>(EquipmentModifier.class);
loader.parseLine(Globals.getContext(), null, "+1 (Enhancement to Weapon or Ammunition) KEY:PLUS1W FORMATCAT:MIDDLE NAMEOPT:TEXT=+1 TYPE:Ammunition.Weapon PLUS:1 VISIBLE:QUALIFY ITYPE:Masterwork.Enhancement.Magic.Plus1 SOURCEPAGE:RSRD SpecialMaterials.rtf BONUS:WEAPON|DAMAGE,TOHIT|1|TYPE=Enhancement ASSIGNTOALL:NO", source);
loader.parseLine(Globals.getContext(), null, "Masterwork KEY:MWORKW FORMATCAT:FRONT NAMEOPT:NORMAL TYPE:MasterworkQuality.Ammunition.Weapon COST:0 VISIBLE:QUALIFY ITYPE:Masterwork SOURCEPAGE:SRDEquipmentI.rtf BONUS:ITEMCOST|TYPE=Ammunition|6 BONUS:ITEMCOST|TYPE=Weapon|300 BONUS:WEAPON|TOHIT|1|TYPE=Enhancement ASSIGNTOALL:YES", source);
SettingsHandler.getGame().addPlusCalculation("WEAPON|(2000*PLUS*PLUS)+(2000*ALTPLUS*ALTPLUS)");
}
use of pcgen.persistence.lst.GenericLoader 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.GenericLoader 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