Search in sources :

Example 1 with DomainSpellList

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

the class AbstractReferenceContext method buildDerivedObjects.

public void buildDerivedObjects() {
    Collection<Domain> domains = getConstructedCDOMObjects(Domain.class);
    for (Domain d : domains) {
        DomainSpellList dsl = constructCDOMObject(DOMAINSPELLLIST_CLASS, d.getKeyName());
        dsl.addType(Type.DIVINE);
        d.put(ObjectKey.DOMAIN_SPELLLIST, dsl);
    }
    Collection<PCClass> classes = getConstructedCDOMObjects(PCClass.class);
    for (PCClass pcc : classes) {
        String key = pcc.getKeyName();
        ClassSkillList skl = constructCDOMObject(CLASSSKILLLIST_CLASS, key);
        boolean isMonster = pcc.isMonster();
        if (isMonster) {
            skl.addType(Type.MONSTER);
        }
        pcc.put(ObjectKey.CLASS_SKILLLIST, skl);
        /*
			 * TODO Need to limit which are built to only spellcasters... If you
			 * do that, please see TO-DO in SpellListFacet
			 */
        ClassSpellList csl = constructCDOMObject(CLASSSPELLLIST_CLASS, key);
        FactKey<String> fk = FactKey.valueOf("SpellType");
        String spelltype = pcc.getResolved(fk);
        if (spelltype != null) {
            csl.addType(Type.getConstant(spelltype));
        }
        pcc.put(ObjectKey.CLASS_SPELLLIST, csl);
        // for (CDOMSubClass subcl : subclasses)
        if (pcc.containsListFor(ListKey.SUB_CLASS)) {
            SubClassCategory cat = SubClassCategory.getConstant(key);
            boolean needSelf = pcc.getSafe(ObjectKey.ALLOWBASECLASS).booleanValue();
            for (SubClass subcl : pcc.getListFor(ListKey.SUB_CLASS)) {
                String subKey = subcl.getKeyName();
                if (subKey.equalsIgnoreCase(key)) {
                    //Now an error to explicitly create this match, see CODE-1928
                    Logging.errorPrint("Cannot explicitly create a SUBCLASS that matches the parent class.  " + "Use ALLOWBASECLASS.  " + "Tokens on the offending SUBCLASS line will be ignored");
                    pcc.removeFromListFor(ListKey.SUB_CLASS, subcl);
                    continue;
                }
                skl = constructCDOMObject(CLASSSKILLLIST_CLASS, subKey);
                if (isMonster) {
                    skl.addType(Type.MONSTER);
                }
                subcl.put(ObjectKey.CLASS_SKILLLIST, skl);
                // TODO Need to limit which are built to only
                // spellcasters...
                csl = constructCDOMObject(CLASSSPELLLIST_CLASS, subKey);
                if (spelltype != null) {
                    csl.addType(Type.getConstant(spelltype));
                }
                subcl.put(ObjectKey.CLASS_SPELLLIST, csl);
                // constructCDOMObject(SPELLPROGRESSION_CLASS, subKey);
                /*
					 * CONSIDER For right now, this is easiest to do here, though
					 * doing this 'live' may be more appropriate in the end.
					 */
                subcl.setCDOMCategory(cat);
                importObject(subcl);
            }
            if (needSelf) {
                SubClass self = constructCDOMObject(SUBCLASS_CLASS, key);
                reassociateCategory(SUBCLASS_CLASS, self, null, cat);
            }
        }
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) SubClass(pcgen.core.SubClass) ClassSpellList(pcgen.cdom.list.ClassSpellList) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 2 with DomainSpellList

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

the class SpellLevel method isLevel.

/**
	 * isLevel(int aLevel)
	 *
	 * @param aLevel
	 *            level of the spell
	 * @param aPC
	 * @return true if the spell is of the given level in any spell list
	 */
public static boolean isLevel(Spell sp, int aLevel, PlayerCharacter aPC) {
    Integer levelKey = aLevel;
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    for (PCClass pcc : aPC.getClassSet()) {
        ClassSpellList csl = pcc.get(ObjectKey.CLASS_SPELLLIST);
        Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(csl, sp);
        if (assoc != null) {
            for (AssociatedPrereqObject apo : assoc) {
                if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
                    if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
                        return true;
                    }
                }
            }
        }
    }
    for (Domain domain : aPC.getDomainSet()) {
        DomainSpellList dsl = domain.get(ObjectKey.DOMAIN_SPELLLIST);
        Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(dsl, sp);
        if (assoc != null) {
            for (AssociatedPrereqObject apo : assoc) {
                if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
                    if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) MasterListInterface(pcgen.cdom.base.MasterListInterface) ClassSpellList(pcgen.cdom.list.ClassSpellList) PCClass(pcgen.core.PCClass) Domain(pcgen.core.Domain) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 3 with DomainSpellList

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

the class DomainApplication method removeDomain.

/**
	 * Remove a domain from the character.
	 * @param pc The character
	 * @param domain The domain.
	 */
public static void removeDomain(PlayerCharacter pc, Domain domain) {
    ClassSource source = pc.getDomainSource(domain);
    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) {
            removeSpellsFromClassForLevels(pc, domain, aClass);
        }
        if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
            DomainSpellList domainSpellList = domain.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.removeDomainSpellCount(aClass);
                    break;
                }
            }
        }
    }
    if (!pc.isImporting()) {
        BonusActivation.deactivateBonuses(domain, pc);
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) PCClass(pcgen.core.PCClass) ClassSource(pcgen.cdom.helper.ClassSource) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 4 with DomainSpellList

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

the class DomainSpellListFacet method dataAdded.

/**
	 * Adds Domain Spell Lists granted to the Player Character due to the Domain
	 * selections of the Player Character.
	 * 
	 * Triggered when one of the Facets to which DomainSpellListFacet listens
	 * fires a DataFacetChangeEvent to indicate a Domain was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, Domain> dfce) {
    DomainSpellList list = dfce.getCDOMObject().get(ObjectKey.DOMAIN_SPELLLIST);
    //list should never be null??
    spellListFacet.add(dfce.getCharID(), list, dfce.getCDOMObject());
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList)

Example 5 with DomainSpellList

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

the class SpellBuilderFacadeImpl method addSpellInfoToList.

private void addSpellInfoToList(final Spell aSpell, List<PCClass> classes, List<Domain> domains, String spellType) {
    Set<String> unfoundItems = new HashSet<>();
    final HashMapToList<CDOMList<Spell>, Integer> levelInfo = character.getSpellLevelInfo(aSpell);
    if ((levelInfo == null) || (levelInfo.isEmpty())) {
        return;
    }
    for (CDOMList<Spell> spellList : levelInfo.getKeySet()) {
        if (spellList instanceof ClassSpellList) {
            String key = spellList.getKeyName();
            final PCClass aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, key);
            if (aClass != null) {
                if (!("".equals(spellType)) && (!spellType.contains(aClass.getSpellType()))) {
                    continue;
                }
                if (!classes.contains(aClass)) {
                    classes.add(aClass);
                }
            } else {
                key = 'C' + key;
                if (!unfoundItems.contains(key)) {
                    unfoundItems.add(key);
                    Logging.errorPrint("Class " + key.substring(1) + " not found. Was used in spell " + aSpell);
                }
            }
        } else if (spellList instanceof DomainSpellList) {
            if (!("".equals(spellType)) && (!spellType.contains("Divine"))) {
                continue;
            }
            String key = spellList.getKeyName();
            final Domain aDomain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, key);
            if (aDomain != null) {
                if (!domains.contains(aDomain)) {
                    domains.add(aDomain);
                }
            } else {
                key = 'D' + key;
                if (!unfoundItems.contains(key)) {
                    unfoundItems.add(key);
                    Logging.errorPrint("Domain " + key.substring(1) + " not found. Was used in spell " + aSpell);
                }
            }
        } else {
            Logging.errorPrint("Unknown spell source: " + spellList);
        }
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) ClassSpellList(pcgen.cdom.list.ClassSpellList) CDOMList(pcgen.cdom.base.CDOMList) PCClass(pcgen.core.PCClass) Domain(pcgen.core.Domain) AvailableSpell(pcgen.cdom.helper.AvailableSpell) Spell(pcgen.core.spell.Spell) HashSet(java.util.HashSet)

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