use of pcgen.rules.context.LoadContext 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.rules.context.LoadContext in project pcgen by PCGen.
the class PObjectTest method testDR.
/**
* Test DR
* @throws Exception
*/
public void testDR() throws Exception {
Race race = new Race();
LoadContext context = Globals.getContext();
race.setName("Race");
PCTemplate template = new PCTemplate();
race.setName("Template");
// race.setDR("5/Good");
race.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(5), "Good"));
assertEquals("Basic DR set.", "5/Good", race.getListFor(ListKey.DAMAGE_REDUCTION).get(0).toString());
race.removeListFor(ListKey.DAMAGE_REDUCTION);
// race.setDR("0/-");
race.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(0), "-"));
assertEquals("Basic DR set.", "0/-", race.getListFor(ListKey.DAMAGE_REDUCTION).get(0).toString());
// template.setDR("0/-");
template.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(0), "-"));
final BonusObj aBonus = Bonus.newBonus(context, "DR|-|1");
if (aBonus != null) {
template.addToListFor(ListKey.BONUS, aBonus);
}
PlayerCharacter pc = getCharacter();
pc.setRace(race);
pc.addTemplate(template);
pc.calcActiveBonuses();
assertEquals("Basic DR set.", "1/-", pc.getDisplay().calcDR());
}
use of pcgen.rules.context.LoadContext 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.rules.context.LoadContext in project pcgen by PCGen.
the class BonusTest method testBonuswithLISTValue.
/**
* Test to make sure that fix for replacing %LIST within a
* bonuses value will work.
*/
public void testBonuswithLISTValue() {
final PlayerCharacter character = getCharacter();
LoadContext context = Globals.getContext();
setPCStat(character, intel, 18);
BonusObj bonus = Bonus.newBonus(context, "VISION|Darkvision|%LIST+10|TYPE=Magical Boon");
List<BonusObj> bonusList = new ArrayList<>();
bonusList.add(bonus);
Ability testBonus = new Ability();
testBonus.setName("TB1Assoc");
testBonus.setCDOMCategory(AbilityCategory.FEAT);
testBonus.addToListFor(ListKey.BONUS, bonus);
Globals.getContext().unconditionallyProcess(testBonus, "CHOOSE", "PCSTAT|ALL");
Globals.getContext().unconditionallyProcess(testBonus, "MULT", "YES");
CNAbility cna = AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, testBonus, "INT");
testBonus = cna.getAbility();
character.calcActiveBonuses();
bonus = testBonus.getSafeListFor(ListKey.BONUS).get(0);
List<BonusPair> bonusPairs = character.getStringListFromBonus(bonus);
assertEquals(1, bonusPairs.size());
BonusPair bp = bonusPairs.get(0);
assertEquals("VISION.DARKVISION:MAGICAL BOON", bp.fullyQualifiedBonusType);
assertEquals(14, bp.resolve(character).intValue());
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class BonusTest method testSpellKnownBonusWithLISTValue.
/**
* Test to make sure that fix for replacing %LIST within a
* bonuses value will work.
*/
public void testSpellKnownBonusWithLISTValue() {
final PlayerCharacter character = getCharacter();
LoadContext context = Globals.getContext();
context.getReferenceContext().constructNowIfNecessary(PCClass.class, "Wizard");
BonusObj bonus = Bonus.newBonus(context, "SPELLKNOWN|%LIST|1");
List<BonusObj> bonusList = new ArrayList<>();
bonusList.add(bonus);
Ability testBonus = new Ability();
testBonus.setName("TB1Assoc");
testBonus.setCDOMCategory(AbilityCategory.FEAT);
testBonus.addToListFor(ListKey.BONUS, bonus);
Globals.getContext().unconditionallyProcess(testBonus, "CHOOSE", "SPELLLEVEL|Wizard|1|5");
Globals.getContext().unconditionallyProcess(testBonus, "MULT", "YES");
CNAbility cna = AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, testBonus, "CLASS.Wizard;LEVEL.1");
testBonus = cna.getAbility();
character.calcActiveBonuses();
bonus = testBonus.getSafeListFor(ListKey.BONUS).get(0);
List<BonusPair> bonusPairs = character.getStringListFromBonus(bonus);
assertEquals(1, bonusPairs.size());
BonusPair bp = bonusPairs.get(0);
assertEquals("SPELLKNOWN.CLASS.Wizard;LEVEL.1", bp.fullyQualifiedBonusType);
}
Aggregations