Search in sources :

Example 86 with LoadContext

use of pcgen.rules.context.LoadContext 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();
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) ClassSpellList(pcgen.cdom.list.ClassSpellList) LoadContext(pcgen.rules.context.LoadContext) GenericLoader(pcgen.persistence.lst.GenericLoader) PCClassLoader(pcgen.persistence.lst.PCClassLoader) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 87 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PObjectUtilitiesTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    LoadContext context = Globals.getContext();
    arcaneClass = new PCClass();
    arcaneClass.setName("TestArcane");
    BuildUtilities.setFact(arcaneClass, "SpellType", "Arcane");
    context.unconditionallyProcess(arcaneClass, "SPELLSTAT", "CHA");
    arcaneClass.put(ObjectKey.SPELLBOOK, false);
    arcaneClass.put(ObjectKey.MEMORIZE_SPELLS, false);
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "KNOWN", "4,2");
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "CAST", "3,1");
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(2), "KNOWN", "4,3,1");
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(2), "CAST", "3,2,1");
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(3), "KNOWN", "5,5,2,1");
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(3), "CAST", "5,5,3,1");
    Globals.getContext().getReferenceContext().importObject(arcaneClass);
    divineClass = new PCClass();
    divineClass.setName("TestDivine");
    BuildUtilities.setFact(divineClass, "SpellType", "Divine");
    context.unconditionallyProcess(divineClass, "SPELLSTAT", "WIS");
    divineClass.put(ObjectKey.SPELLBOOK, false);
    divineClass.put(ObjectKey.MEMORIZE_SPELLS, true);
    context.unconditionallyProcess(divineClass.getOriginalClassLevel(3), "CAST", "3,1,0");
    Globals.getContext().getReferenceContext().importObject(divineClass);
    psionicClass = new PCClass();
    psionicClass.setName("TestPsion");
    BuildUtilities.setFact(psionicClass, "SpellType", "Psionic");
    context.unconditionallyProcess(psionicClass, "SPELLSTAT", "CHA");
    psionicClass.put(ObjectKey.SPELLBOOK, false);
    psionicClass.put(ObjectKey.MEMORIZE_SPELLS, false);
    context.unconditionallyProcess(psionicClass.getOriginalClassLevel(1), "KNOWN", "0,3");
    context.unconditionallyProcess(psionicClass.getOriginalClassLevel(2), "KNOWN", "0,5");
    context.unconditionallyProcess(psionicClass.getOriginalClassLevel(3), "KNOWN", "0,5,2");
    context.unconditionallyProcess(psionicClass.getOriginalClassLevel(4), "KNOWN", "0,5,4");
    context.unconditionallyProcess(psionicClass.getOriginalClassLevel(5), "KNOWN", "0,5,4,2");
    Globals.getContext().getReferenceContext().importObject(psionicClass);
    super.setUp();
}
Also used : LoadContext(pcgen.rules.context.LoadContext)

Example 88 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PlayerCharacterTest method testGetPartialStatFor.

public void testGetPartialStatFor() {
    readyToRun();
    PlayerCharacter pc = getCharacter();
    LoadContext context = Globals.getContext();
    setPCStat(pc, str, 14);
    Ability strBonusAbility = TestHelper.makeAbility("Strength power up", AbilityCategory.FEAT, "General.Fighter");
    final BonusObj strBonus = Bonus.newBonus(context, "STAT|STR|2");
    strBonusAbility.addToListFor(ListKey.BONUS, strBonus);
    assertEquals("Before bonus, no temp no equip", 14, pc.getPartialStatFor(str, false, false));
    assertEquals("Before bonus, temp no equip", 14, pc.getPartialStatFor(str, true, false));
    AbstractCharacterTestCase.applyAbility(pc, AbilityCategory.FEAT, strBonusAbility, null);
    pc.calcActiveBonuses();
    assertEquals("After bonus, no temp no equip", 16, pc.getPartialStatFor(str, false, false));
    assertEquals("After bonus, temp no equip", 16, pc.getPartialStatFor(str, true, false));
//		final BonusObj strBonusViaList = Bonus.newBonus("STAT|%LIST|3");
//		strBonusAbility.addBonusList(strBonusViaList);
//		strBonusAbility.addAssociated("STR");
//		strBonusAbility.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
//		pc.calcActiveBonuses();
//
//		assertEquals("After list bonus, no temp no equip", 3, pc.getPartialStatBonusFor("STR", false, false));
//		assertEquals("After list bonus, temp no equip", 3, pc.getPartialStatBonusFor("STR", true, false));
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

Example 89 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PlayerCharacterTest method readyToRun.

private void readyToRun() {
    LoadContext context = Globals.getContext();
    context.resolveDeferredTokens();
    assertTrue(context.getReferenceContext().resolveReferences(null));
}
Also used : LoadContext(pcgen.rules.context.LoadContext)

Example 90 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PlayerCharacterTest method testNestedAbilities.

/**
	 * Verify that bested abilities are processed correctly.
	 */
public void testNestedAbilities() {
    PlayerCharacter pc = getCharacter();
    Ability resToAcid = TestHelper.makeAbility("Resistance To Acid", specialAbilityCat, "Foo");
    Ability resToAcidOutputVirt = TestHelper.makeAbility("Resistance To Acid Output Virt", specialAbilityCat, "Foo");
    Ability resToAcidOutputAuto = TestHelper.makeAbility("Resistance To Acid Output Auto", specialAbilityCat, "Foo");
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(human, "ABILITY", specialAbilityCat.getKeyName() + "|AUTOMATIC|" + resToAcid.getKeyName());
    context.unconditionallyProcess(resToAcid, "ABILITY", specialAbilityCat.getKeyName() + "|VIRTUAL|" + resToAcidOutputVirt.getKeyName());
    context.unconditionallyProcess(resToAcid, "ABILITY", specialAbilityCat.getKeyName() + "|AUTOMATIC|" + resToAcidOutputAuto.getKeyName());
    readyToRun();
    pc.setRace(human);
    assertEquals("PC should now have a race of human", human, pc.getRace());
    assertFalse("Character should have the first feat", pc.getMatchingCNAbilities(resToAcid).isEmpty());
    assertFalse("Character should have the second feat", pc.getMatchingCNAbilities(resToAcidOutputVirt).isEmpty());
    assertFalse("Character should have the third feat", pc.getMatchingCNAbilities(resToAcidOutputAuto).isEmpty());
}
Also used : 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