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 ");
}
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");
}
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());
}
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);
}
}
}
}
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;
}
Aggregations