Search in sources :

Example 11 with DomainSpellList

use of pcgen.cdom.list.DomainSpellList 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 12 with DomainSpellList

use of pcgen.cdom.list.DomainSpellList 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)

Example 13 with DomainSpellList

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

the class DomainApplication method applyDomain.

/**
	 * Sets the locked flag on a PC
	 * 
	 * @param pc
	 */
public static void applyDomain(PlayerCharacter pc, Domain d) {
    ClassSource source = pc.getDomainSource(d);
    PCClass aClass = pc.getClassKeyed(source.getPcclass().getKeyName());
    if (aClass != null) {
        int maxLevel;
        for (maxLevel = 0; maxLevel < 10; maxLevel++) {
            if (pc.getSpellSupport(aClass).getCastForLevel(maxLevel, pc) == 0) {
                break;
            }
        }
        if (maxLevel > 0) {
            addSpellsToClassForLevels(pc, d, aClass, 0, maxLevel - 1);
        }
        if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
            DomainSpellList domainSpellList = d.get(ObjectKey.DOMAIN_SPELLLIST);
            final List<Spell> aList = pc.getAllSpellsInLists(Collections.singletonList(domainSpellList));
            for (Spell gcs : aList) {
                if (SpellLevel.getFirstLvlForKey(gcs, domainSpellList, pc) < maxLevel) {
                    pc.setDomainSpellCount(aClass, 1);
                    break;
                }
            }
        }
    }
    Collection<CDOMReference<Spell>> mods = d.getSafeListMods(Spell.SPELLS);
    for (CDOMReference<Spell> ref : mods) {
        Collection<Spell> spells = ref.getContainedObjects();
        Collection<AssociatedPrereqObject> assoc = d.getListAssociations(Spell.SPELLS, ref);
        for (AssociatedPrereqObject apo : assoc) {
            if (!PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, d)) {
                continue;
            }
            for (Spell s : spells) {
                String book = apo.getAssociation(AssociationKey.SPELLBOOK);
                List<CharacterSpell> aList = pc.getCharacterSpells(aClass, s, book, -1);
                if (aList.isEmpty()) {
                    Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
                    CharacterSpell cs = new CharacterSpell(d, s);
                    int resolvedTimes = times.resolve(pc, d.getQualifiedKey()).intValue();
                    cs.addInfo(1, resolvedTimes, book);
                    pc.addCharacterSpell(aClass, cs);
                }
            }
        }
    }
}
Also used : PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) DomainSpellList(pcgen.cdom.list.DomainSpellList) Formula(pcgen.base.formula.Formula) CharacterSpell(pcgen.core.character.CharacterSpell) ClassSource(pcgen.cdom.helper.ClassSource) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

DomainSpellList (pcgen.cdom.list.DomainSpellList)13 Spell (pcgen.core.spell.Spell)7 ClassSpellList (pcgen.cdom.list.ClassSpellList)6 PCClass (pcgen.core.PCClass)6 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)5 CDOMList (pcgen.cdom.base.CDOMList)4 ArrayList (java.util.ArrayList)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 AvailableSpell (pcgen.cdom.helper.AvailableSpell)3 Domain (pcgen.core.Domain)3 CharacterSpell (pcgen.core.character.CharacterSpell)3 StringTokenizer (java.util.StringTokenizer)2 TreeSet (java.util.TreeSet)2 MasterListInterface (pcgen.cdom.base.MasterListInterface)2 DataSetID (pcgen.cdom.enumeration.DataSetID)2 ClassSource (pcgen.cdom.helper.ClassSource)2 Prerequisite (pcgen.core.prereq.Prerequisite)2 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1