Search in sources :

Example 16 with ClassSpellList

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

the class SpellLevelLstTest method testRoundRobinSpellCaster.

@Test
public void testRoundRobinSpellCaster() throws PersistenceLayerException {
    ClassSpellList a = primaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
    a.addType(Type.getConstant("Arcane"));
    ClassSpellList b = secondaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
    b.addType(Type.getConstant("Arcane"));
    primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
    secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
    runRoundRobin("CLASS|SPELLCASTER.Arcane=2|Fireball|PRECLASS:1,Fighter=2");
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) Test(org.junit.Test)

Example 17 with ClassSpellList

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

the class SpellknownLstTest method testRoundRobinSpellCaster.

@Test
public void testRoundRobinSpellCaster() throws PersistenceLayerException {
    primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
    secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
    ClassSpellList a = primaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
    a.addType(Type.getConstant("Arcane"));
    ClassSpellList b = secondaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
    b.addType(Type.getConstant("Arcane"));
    runRoundRobin("CLASS|SPELLCASTER.Arcane=2|Fireball|PRECLASS:1,Fighter=2");
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) Test(org.junit.Test)

Example 18 with ClassSpellList

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

the class AvailableSpellFacet method getSpellLevelInfo.

/**
	 * Returns a non-null HashMapToList indicating the spell levels and sources
	 * of those spell levels available to a Player Character for a given Spell.
	 * 
	 * This may return multiple spell levels because it is possible for a spell
	 * to be accessible to a Player Character at multiple levels since it may be
	 * available from multiple sources. This also returns the spell lists
	 * associated with the given level, since it is possible for a multi-class
	 * character to have access to the same spell at different levels. By
	 * returning the source as well as the spell levels, such scenarios can be
	 * appropriately distinguished.
	 * 
	 * This method is value-semantic in that ownership of the returned
	 * HashMapToList is transferred to the class calling this method.
	 * Modification of the returned HashMapToList will not modify this
	 * AvailableSpellFacet and modification of this AvailableSpellFacet will not
	 * modify the returned HashMapToList. Modifications to the returned
	 * HashMapToList will also not modify any future or previous objects
	 * returned by this (or other) methods on AvailableSpellFacet. If you wish
	 * to modify the information stored in this AvailableSpellFacet, you must
	 * use the add*() and remove*() methods of AvailableSpellFacet.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            spell levels should be returned
	 * @param sp
	 *            The Spell for which the spell levels should be returned
	 * @return A non-null HashMapToList indicating the spell levels and sources
	 *         of those spell levels available to a Player Character for a given
	 *         Spell.
	 */
public HashMapToList<CDOMList<Spell>, Integer> getSpellLevelInfo(CharID id, Spell sp) {
    HashMapToList<CDOMList<Spell>, Integer> levelInfo = new HashMapToList<>();
    Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> listMap = (Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>>) getCache(id);
    if (listMap == null) {
        return levelInfo;
    }
    for (Entry<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> me : listMap.entrySet()) {
        CDOMList<Spell> list = me.getKey();
        //Check to ensure we don't use SPELLS:
        if (!(list instanceof ClassSpellList) && !(list instanceof DomainSpellList)) {
            continue;
        }
        Map<Integer, Map<Spell, Set<Object>>> levelMap = me.getValue();
        for (Map.Entry<Integer, Map<Spell, Set<Object>>> lme : levelMap.entrySet()) {
            Integer level = lme.getKey();
            Map<Spell, Set<Object>> spellMap = lme.getValue();
            if (spellMap.containsKey(sp)) {
                levelInfo.addToListFor(list, level);
            } else {
                for (Spell spell : spellMap.keySet()) {
                    if (spell.getKeyName().equals(sp.getKeyName())) {
                        if (Logging.isLoggable(Logging.INFO)) {
                            Logging.log(Logging.INFO, "Found alternate spell of same key: " + spell + " from " + spell.getSource() + " rather than " + sp.getSource());
                        }
                        levelInfo.addToListFor(list, level);
                    }
                }
            }
        }
    }
    return levelInfo;
}
Also used : Set(java.util.Set) ClassSpellList(pcgen.cdom.list.ClassSpellList) Spell(pcgen.core.spell.Spell) DomainSpellList(pcgen.cdom.list.DomainSpellList) HashMapToList(pcgen.base.util.HashMapToList) CDOMList(pcgen.cdom.base.CDOMList) Map(java.util.Map)

Example 19 with ClassSpellList

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

the class PCGVer2Parser method parseSpellListLines.

/*
	 * ###############################################################
	 * Spell List Information methods
	 * ###############################################################
	 */
/*
	 * #Spell List Information
	 * SPELLLIST:sourceclassname|spelllistentry|spelllistentry
	 */
private void parseSpellListLines(final String line) {
    final String subLine = line.substring(IOConstants.TAG_SPELLLIST.length() + 1);
    final StringTokenizer stok = new StringTokenizer(subLine, IOConstants.TAG_SEPARATOR, false);
    final String classKey = stok.nextToken();
    final PCClass aClass = thePC.getClassKeyed(classKey);
    AbstractReferenceContext refContext = Globals.getContext().getReferenceContext();
    while ((aClass != null) && stok.hasMoreTokens()) {
        final String tok = stok.nextToken();
        if (tok.startsWith("CLASS.")) {
            ClassSpellList csl = refContext.silentlyGetConstructedCDOMObject(ClassSpellList.class, tok.substring(6));
            thePC.addClassSpellList(csl, aClass);
        } else if (tok.startsWith("DOMAIN.")) {
            DomainSpellList dsl = refContext.silentlyGetConstructedCDOMObject(DomainSpellList.class, tok.substring(7));
            thePC.addClassSpellList(dsl, aClass);
        } else {
            /*
				 * This is 5.14-ish, but have to try anyway:
				 */
            ClassSpellList csl = refContext.silentlyGetConstructedCDOMObject(ClassSpellList.class, tok);
            if (csl == null) {
                DomainSpellList dsl = refContext.silentlyGetConstructedCDOMObject(DomainSpellList.class, tok);
                if (dsl != null) {
                    thePC.addClassSpellList(dsl, aClass);
                }
            } else {
                thePC.addClassSpellList(csl, aClass);
            }
        }
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) StringTokenizer(java.util.StringTokenizer) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) ClassSpellList(pcgen.cdom.list.ClassSpellList) PCClass(pcgen.core.PCClass)

Example 20 with ClassSpellList

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

the class MasterAvailableSpellFacet method initialize.

/**
	 * Initializes the global lists of ClassSkillLists. This method only needs
	 * to be called once for each set of sources that are loaded.
	 */
@Override
public synchronized void initialize(LoadContext lc) {
    DataSetID dsID = lc.getDataSetID();
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    List<CDOMReference<CDOMList<Spell>>> useLists = new ArrayList<>();
    for (CDOMReference ref : masterLists.getActiveLists()) {
        Collection<CDOMList<Spell>> lists = ref.getContainedObjects();
        for (CDOMList<Spell> list : lists) {
            if ((list instanceof ClassSpellList) || (list instanceof DomainSpellList)) {
                useLists.add(ref);
                break;
            }
        }
    }
    for (CDOMReference<CDOMList<Spell>> ref : useLists) {
        for (Spell spell : masterLists.getObjects(ref)) {
            Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, spell);
            for (AssociatedPrereqObject apo : assoc) {
                int lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
                for (CDOMList<Spell> list : ref.getContainedObjects()) {
                    AvailableSpell as = new AvailableSpell(list, spell, lvl);
                    if (apo.hasPrerequisites()) {
                        as.addAllPrerequisites(apo.getPrerequisiteList());
                    }
                    add(dsID, as);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ClassSpellList(pcgen.cdom.list.ClassSpellList) DataSetID(pcgen.cdom.enumeration.DataSetID) AvailableSpell(pcgen.cdom.helper.AvailableSpell) Spell(pcgen.core.spell.Spell) DomainSpellList(pcgen.cdom.list.DomainSpellList) AvailableSpell(pcgen.cdom.helper.AvailableSpell) MasterListInterface(pcgen.cdom.base.MasterListInterface) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

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