Search in sources :

Example 36 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class LoadContextTest method testCloneInMasterListsAssoc.

/**
	 * Test method for {@link pcgen.rules.context.LoadContext#cloneInMasterLists(pcgen.cdom.base.CDOMObject, java.lang.String)}.
	 * Verify that associations from other objects to the object being cloned 
	 * are copied over. 
	 */
public final void testCloneInMasterListsAssoc() {
    final LoadContext context = Globals.getContext();
    FactKey.getConstant("ClassType", new StringManager());
    FactKey.getConstant("SpellType", new StringManager());
    Spell testSpell = TestHelper.makeSpell("LoadContextTest");
    PCClass wiz = TestHelper.makeClass("Wizard");
    CDOMReference<ClassSpellList> ref = TokenUtilities.getTypeOrPrimitive(context, ClassSpellList.class, wiz.getKeyName());
    AssociatedPrereqObject edge = context.getListContext().addToMasterList("CLASSES", testSpell, ref, testSpell);
    edge.setAssociation(AssociationKey.SPELL_LEVEL, 1);
    context.getReferenceContext().buildDerivedObjects();
    assertTrue(context.getReferenceContext().resolveReferences(null));
    context.commit();
    Spell newSpell = context.performCopy(testSpell, "New Spell");
    context.commit();
    assertEquals("Old spell name incorrect", "LoadContextTest", testSpell.getDisplayName());
    assertEquals("New spell name incorrect", "New Spell", newSpell.getDisplayName());
    // Check associations
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, testSpell);
    assertEquals("Incorrect size of assoc list for orig spell", 1, assoc.size());
    AssociatedPrereqObject apo = assoc.iterator().next();
    assertEquals("Incorrect level", 1, apo.getAssociation(AssociationKey.SPELL_LEVEL).intValue());
    assoc = masterLists.getAssociations(ref, newSpell);
    assertEquals("Incorrect size of assoc list for new spell", 1, assoc.size());
    apo = assoc.iterator().next();
    assertEquals("Incorrect level", 1, apo.getAssociation(AssociationKey.SPELL_LEVEL).intValue());
}
Also used : MasterListInterface(pcgen.cdom.base.MasterListInterface) ClassSpellList(pcgen.cdom.list.ClassSpellList) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) StringManager(pcgen.base.format.StringManager) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 37 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class TestHelper method makeSpell.

/**
	 * Set the important info about a Spell
	 * @param name The spell name
	 * @return The spell (which has also been added to global storage)
	 */
public static Spell makeSpell(final String name) {
    final Spell aSpell = new Spell();
    aSpell.setName(name);
    aSpell.put(StringKey.KEY_NAME, ("KEY_" + name));
    Globals.getContext().getReferenceContext().importObject(aSpell);
    return aSpell;
}
Also used : Spell(pcgen.core.spell.Spell)

Example 38 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class PreSpellTypeTest method additionalSetUp.

/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void additionalSetUp() throws Exception {
    LoadContext context = Globals.getContext();
    wiz = context.getReferenceContext().constructCDOMObject(PCClass.class, "Wizard");
    BuildUtilities.setFact(wiz, "SpellType", "Arcane");
    context.unconditionallyProcess(wiz, "KNOWNSPELLS", "LEVEL=1|LEVEL=2");
    context.unconditionallyProcess(wiz.getOriginalClassLevel(1), "CAST", "1,1");
    context.unconditionallyProcess(wiz.getOriginalClassLevel(2), "CAST", "2,2,2");
    cle = context.getReferenceContext().constructCDOMObject(PCClass.class, "Cleric");
    BuildUtilities.setFact(cle, "SpellType", "Divine");
    context.unconditionallyProcess(cle, "KNOWNSPELLS", "LEVEL=1|LEVEL=2");
    context.unconditionallyProcess(cle.getOriginalClassLevel(1), "CAST", "1,1");
    context.unconditionallyProcess(cle.getOriginalClassLevel(2), "CAST", "1,1,1");
    Arcaneball = new Spell();
    Arcaneball.setName("Arcaneball");
    context.getReferenceContext().importObject(Arcaneball);
    context.unconditionallyProcess(Arcaneball, "CLASSES", "Wizard=2");
    context.unconditionallyProcess(Arcaneball, "TYPE", "Arcane");
    lightning = new Spell();
    lightning.setName("Lightning Bolt");
    context.getReferenceContext().importObject(lightning);
    context.unconditionallyProcess(lightning, "CLASSES", "Wizard=2");
    context.unconditionallyProcess(lightning, "TYPE", "Arcane");
    burning = new Spell();
    burning.setName("Burning Hands");
    context.getReferenceContext().importObject(burning);
    context.unconditionallyProcess(burning, "CLASSES", "Wizard=1");
    context.unconditionallyProcess(burning, "TYPE", "Arcane");
    heal = new Spell();
    heal.setName("Heal");
    context.getReferenceContext().importObject(heal);
    context.unconditionallyProcess(heal, "CLASSES", "Cleric=2");
    context.unconditionallyProcess(heal, "TYPE", "Divine");
    cure = new Spell();
    cure.setName("Cure Light Wounds");
    context.getReferenceContext().importObject(cure);
    context.unconditionallyProcess(cure, "CLASSES", "Cleric=1");
    context.unconditionallyProcess(cure, "TYPE", "Divine");
}
Also used : LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell)

Example 39 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class KnownspellsTokenTest method testUnparseTypeLevel.

@Test
public void testUnparseTypeLevel() throws PersistenceLayerException {
    CDOMGroupRef<Spell> cool = primaryContext.getReferenceContext().getCDOMTypeReference(Spell.class, "Cool");
    primaryProf.addToListFor(ListKey.KNOWN_SPELLS, new KnownSpellIdentifier(cool, 4));
    String[] sap = getToken().unparse(primaryContext, primaryProf);
    expectSingle(sap, "TYPE=Cool,LEVEL=4");
}
Also used : KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) Spell(pcgen.core.spell.Spell) Test(org.junit.Test)

Example 40 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class KnownspellsTokenTest method testRoundRobinComplex.

@Test
public void testRoundRobinComplex() throws PersistenceLayerException {
    construct(primaryContext, "TestWP1");
    construct(secondaryContext, "TestWP1");
    Spell a = construct(primaryContext, "TestWP2");
    a.addToListFor(ListKey.TYPE, Type.getConstant("SpellType"));
    Spell c = construct(secondaryContext, "TestWP2");
    c.addToListFor(ListKey.TYPE, Type.getConstant("SpellType"));
    Spell b = construct(primaryContext, "TestWP3");
    b.addToListFor(ListKey.TYPE, Type.getConstant("ZOther"));
    b.addToListFor(ListKey.TYPE, Type.getConstant("ZType"));
    Spell d = construct(secondaryContext, "TestWP3");
    d.addToListFor(ListKey.TYPE, Type.getConstant("ZOther"));
    d.addToListFor(ListKey.TYPE, Type.getConstant("ZType"));
    runRoundRobin("TYPE=SpellType,LEVEL=0|TYPE=SpellType,LEVEL=1|TYPE=ZOther.ZType,LEVEL=1");
}
Also used : Spell(pcgen.core.spell.Spell) Test(org.junit.Test)

Aggregations

Spell (pcgen.core.spell.Spell)87 CharacterSpell (pcgen.core.character.CharacterSpell)35 ArrayList (java.util.ArrayList)25 PCClass (pcgen.core.PCClass)24 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)16 CDOMReference (pcgen.cdom.base.CDOMReference)15 Ability (pcgen.core.Ability)15 LoadContext (pcgen.rules.context.LoadContext)13 CDOMList (pcgen.cdom.base.CDOMList)12 CDOMObject (pcgen.cdom.base.CDOMObject)11 Test (org.junit.Test)10 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)9 AvailableSpell (pcgen.cdom.helper.AvailableSpell)8 StringTokenizer (java.util.StringTokenizer)7 CNAbility (pcgen.cdom.content.CNAbility)7 ClassSpellList (pcgen.cdom.list.ClassSpellList)7 DomainSpellList (pcgen.cdom.list.DomainSpellList)7 Formula (pcgen.base.formula.Formula)6 Domain (pcgen.core.Domain)6 PObject (pcgen.core.PObject)6