Search in sources :

Example 81 with LoadContext

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());
}
Also used : ChallengeRating(pcgen.cdom.content.ChallengeRating) GenericLoader(pcgen.persistence.lst.GenericLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) StringManager(pcgen.base.format.StringManager) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) OrderedPairManager(pcgen.base.format.OrderedPairManager) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader)

Example 82 with LoadContext

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());
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) DamageReduction(pcgen.cdom.content.DamageReduction)

Example 83 with LoadContext

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());
}
Also used : Ability(pcgen.core.Ability) AbilityLoader(pcgen.persistence.lst.AbilityLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) PCClass(pcgen.core.PCClass) URI(java.net.URI) Spell(pcgen.core.spell.Spell) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader)

Example 84 with LoadContext

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());
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext)

Example 85 with LoadContext

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);
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext)

Aggregations

LoadContext (pcgen.rules.context.LoadContext)141 PlayerCharacter (pcgen.core.PlayerCharacter)58 BonusObj (pcgen.core.bonus.BonusObj)48 PCClass (pcgen.core.PCClass)32 URI (java.net.URI)25 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)25 URISyntaxException (java.net.URISyntaxException)20 Campaign (pcgen.core.Campaign)16 Race (pcgen.core.Race)16 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)16 Equipment (pcgen.core.Equipment)15 UnreachableError (pcgen.base.lang.UnreachableError)14 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)14 PCClassLoader (pcgen.persistence.lst.PCClassLoader)14 Spell (pcgen.core.spell.Spell)13 Ability (pcgen.core.Ability)12 PCTemplate (pcgen.core.PCTemplate)12 SizeAdjustment (pcgen.core.SizeAdjustment)10 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)9 Skill (pcgen.core.Skill)9