Search in sources :

Example 6 with ClassSpellList

use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.

the class EvaluatorFactoryTest method testGetTermEvaluator052.

/**
	 * Method: getTermEvaluator(String term, String source)
	 */
public void testGetTermEvaluator052() {
    EvaluatorFactoryTest.loadAll();
    String term = "MAXCASTABLE";
    Globals.getContext().getReferenceContext().constructCDOMObject(ClassSpellList.class, "Bard");
    TermEvaluator t = EvaluatorFactory.PC.getTermEvaluator(term, "CLASS:Bard");
    is(t instanceof PCMaxCastableClassTermEvaluator, eq(true), "GetTermEvaluator052 evaluator correct for " + term);
    Class<?> uClass = PCMaxCastableClassTermEvaluator.class;
    Field pF0 = (Field) TestHelper.findField(uClass, "originalText");
    Field pF1 = (Field) TestHelper.findField(uClass, "spellList");
    String field0 = "";
    ClassSpellList field1 = null;
    boolean ok;
    try {
        ok = true;
        field0 = (String) pF0.get(t);
        field1 = (ClassSpellList) pF1.get(t);
    } catch (ClassCastException e) {
        ok = false;
    } catch (IllegalAccessException e) {
        ok = false;
    }
    is(ok, eq(true), "No illegal access in getTermEvaluator052");
    is(field0, strEq(term), "GetTermEvaluator052 stored term is correct " + term);
    is(field1.getKeyName(), strEq("Bard"), "GetTermEvaluator052 field spellList is correct ");
}
Also used : Field(java.lang.reflect.Field) ClassSpellList(pcgen.cdom.list.ClassSpellList)

Example 7 with ClassSpellList

use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.

the class SpellListTokenTest method testUnparseMultiple.

/*
	 * TODO Need to figure out who's responsibility this is!
	 */
// @Test
// public void testUnparseBadList() throws PersistenceLayerException
// {
// Language wp1 = construct(primaryContext, "TestWP1");
// ReferenceChoiceSet<Language> rcs = buildRCS(CDOMDirectSingleRef
// .getRef(wp1), primaryContext.ref
// .getCDOMAllReference(getTargetClass()));
// assertFalse(rcs.getGroupingState().isValid());
// PersistentTransitionChoice<Language> tc = buildTC(rcs);
// tc.setChoiceActor(subtoken);
// primaryProf.put(ObjectKey.CHOOSE_LANGAUTO, tc);
// assertBadUnparse();
// }
@Test
public void testUnparseMultiple() throws PersistenceLayerException {
    ClassSpellList wp1 = construct(primaryContext, "TestWP1");
    ClassSpellList wp2 = construct(primaryContext, "TestWP2");
    PersistentTransitionChoice<CDOMListObject<Spell>> tc = buildChoice(CDOMDirectSingleRef.getRef(wp1), CDOMDirectSingleRef.getRef(wp2));
    primaryProf.put(ObjectKey.SPELLLIST_CHOICE, tc);
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, "1|TestWP1|TestWP2");
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) CDOMListObject(pcgen.cdom.base.CDOMListObject) Test(org.junit.Test)

Example 8 with ClassSpellList

use of pcgen.cdom.list.ClassSpellList 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 9 with ClassSpellList

use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.

the class PlayerCharacter method addBonusKnownSpellsToList.

/**
	 * Adds to the provided list any spells that have been granted to the character's class by abilities
	 * through the use of SPELLKNOWN:CLASS tags.
	 *
	 * @param aClass The character class owning the spell list.
	 * @param cSpells The list of spells to be updated.
	 */
public void addBonusKnownSpellsToList(CDOMObject aClass, List<CharacterSpell> cSpells) {
    if (!(aClass instanceof PCClass)) {
        return;
    }
    ClassSpellList classSpellList = aClass.get(ObjectKey.CLASS_SPELLLIST);
    for (Integer spellLevel : knownSpellFacet.getScopes2(id, classSpellList)) {
        for (Spell spell : knownSpellFacet.getSet(id, classSpellList, spellLevel)) {
            CharacterSpell acs = null;
            Collection<? extends CharacterSpell> characterSpells = getCharacterSpells(grantedSpellCache);
            for (CharacterSpell cs : characterSpells) {
                Spell sp = cs.getSpell();
                if (spell.equals(sp) && (cs.getOwner().equals(aClass))) {
                    acs = cs;
                    break;
                }
            }
            if (acs == null) {
                acs = new CharacterSpell(aClass, spell);
                acs.addInfo(spellLevel, 1, Globals.getDefaultSpellBook());
                addCharacterSpell(grantedSpellCache, acs);
            }
            if (!cSpells.contains(acs)) {
                cSpells.add(acs);
            }
        }
    }
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 10 with ClassSpellList

use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.

the class ClassListToken method allow.

@Override
public boolean allow(PlayerCharacter pc, Spell spell) {
    ClassSpellList list = spelllist.get();
    DataSetID datasetID = pc.getCharID().getDatasetID();
    for (AvailableSpell availSpell : masterAvailableSpellFacet.getMatchingSpellsInList(list, datasetID, spell)) {
        int level = availSpell.getLevel();
        if (level >= 0 && allow(pc, level, "", spell, list)) {
            return true;
        }
    }
    return false;
}
Also used : AvailableSpell(pcgen.cdom.helper.AvailableSpell) ClassSpellList(pcgen.cdom.list.ClassSpellList) DataSetID(pcgen.cdom.enumeration.DataSetID)

Aggregations

ClassSpellList (pcgen.cdom.list.ClassSpellList)21 Test (org.junit.Test)7 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)7 Spell (pcgen.core.spell.Spell)7 DomainSpellList (pcgen.cdom.list.DomainSpellList)6 PCClass (pcgen.core.PCClass)6 CDOMListObject (pcgen.cdom.base.CDOMListObject)4 Domain (pcgen.core.Domain)4 ArrayList (java.util.ArrayList)3 CDOMList (pcgen.cdom.base.CDOMList)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 MasterListInterface (pcgen.cdom.base.MasterListInterface)3 AvailableSpell (pcgen.cdom.helper.AvailableSpell)3 StringTokenizer (java.util.StringTokenizer)2 DataSetID (pcgen.cdom.enumeration.DataSetID)2 CharacterSpell (pcgen.core.character.CharacterSpell)2 Prerequisite (pcgen.core.prereq.Prerequisite)2 StringWriter (java.io.StringWriter)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1