use of pcgen.persistence.lst.PCClassLoader in project pcgen by PCGen.
the class SubstitutionLevelSupport method levelArrayQualifies.
private static boolean levelArrayQualifies(int level, final PlayerCharacter pc, final String aLine, final SourceEntry tempSource, CDOMObject source) {
final PCClassLoader classLoader = new PCClassLoader();
PCClass dummyClass = new PCClass();
try {
classLoader.parseLine(Globals.getContext(), dummyClass, aLine, tempSource);
} catch (PersistenceLayerException e) {
Logging.errorPrint("Unable to parse line from levelArray: " + aLine);
}
return dummyClass.getOriginalClassLevel(level).qualifies(pc, source);
}
use of pcgen.persistence.lst.PCClassLoader in project pcgen by PCGen.
the class PCClassTest 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 {
FactKey.getConstant("Abb", new StringManager());
// Test a basic class
String classPCCText = humanoidClass.getPCCText();
assertNotNull("PCC Text for race should not be null", classPCCText);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
PCClass reconstClass = null;
System.out.println("Got text:" + classPCCText);
reconstClass = parsePCClassText(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.", humanoidClass.getAbbrev(), reconstClass.getAbbrev());
// Test a class with some innate spells
String b = "1" + "\t" + "SPELLS:" + "Humanoid|TIMES=1|CASTERLEVEL=var(\"TCL\")|Create undead,11+WIS";
PCClassLoader classLoader = new PCClassLoader();
classLoader.parseLine(Globals.getContext(), humanoidClass, b, source);
classPCCText = humanoidClass.getPCCText();
assertNotNull("PCC Text for race should not be null", classPCCText);
reconstClass = null;
System.out.println("Got text:" + classPCCText);
reconstClass = parsePCClassText(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.", humanoidClass.getAbbrev(), reconstClass.getAbbrev());
Collection<CDOMReference<Spell>> startSpells = humanoidClass.getOriginalClassLevel(1).getListMods(Spell.SPELLS);
Collection<CDOMReference<Spell>> reconstSpells = reconstClass.getOriginalClassLevel(1).getListMods(Spell.SPELLS);
assertEquals("All spell should have been reconstituted.", startSpells.size(), reconstSpells.size());
assertEquals("Spell names should been preserved.", startSpells, reconstSpells);
}
use of pcgen.persistence.lst.PCClassLoader 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.PCClassLoader in project pcgen by PCGen.
the class AddClassSkillsTest method parsePCClassText.
private static 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 PreVarTest method test2857848c.
public void test2857848c() {
final PCClass warrior = new PCClass();
warrior.setName("Warrior");
LoadContext context = Globals.getContext();
context.unconditionallyProcess(warrior, "DEFINE", "MyVar|0");
context.unconditionallyProcess(warrior, "BONUS", "VAR|MyVar|2");
final PCClass notawarrior = new PCClass();
notawarrior.setName("NotAWarrior");
context.unconditionallyProcess(notawarrior, "PREVARGTEQ", "MyVar,1");
Skill concentration = context.getReferenceContext().constructCDOMObject(Skill.class, "Concentration");
context.unconditionallyProcess(notawarrior, "CSKILL", "Concentration");
context.unconditionallyProcess(notawarrior, "BONUS", "SKILL|Concentration|5");
assertTrue(context.getReferenceContext().resolveReferences(null));
PCClassLoader loader = new PCClassLoader();
try {
SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
loader.completeObject(context, se, warrior);
loader.completeObject(context, se, notawarrior);
PlayerCharacter character = this.getCharacter();
assertFalse(notawarrior.qualifies(character, notawarrior));
//Fails
character.incrementClassLevel(1, notawarrior);
assertEquals(0, SkillModifier.modifier(concentration, character).intValue());
character.incrementClassLevel(1, warrior);
assertEquals(0, SkillModifier.modifier(concentration, character).intValue());
assertTrue(notawarrior.qualifies(character, notawarrior));
character.incrementClassLevel(1, notawarrior);
assertEquals(5, SkillModifier.modifier(concentration, character).intValue());
} catch (URISyntaxException | PersistenceLayerException e) {
fail(e.getMessage());
}
}
Aggregations