Search in sources :

Example 1 with Domain

use of pcgen.core.Domain in project pcgen by PCGen.

the class LocalSkillCostFacet method dataAdded.

/**
	 * Adds the SkillCost objects granted by CDOMObjects, as applied directly to
	 * a PCClass, when a CDOMObject is added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which LocalSkillCostFacet listens
	 * fires a DataFacetChangeEvent to indicate a CDOMObject 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, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    CharID id = dfce.getCharID();
    PCClass owner;
    if (cdo instanceof Domain) {
        owner = domainFacet.getSource(id, (Domain) cdo).getPcclass();
    } else if (cdo instanceof PCClassLevel) {
        owner = (PCClass) cdo.get(ObjectKey.PARENT);
    } else if (cdo instanceof PCClass) {
        owner = (PCClass) cdo;
    } else {
        Logging.errorPrint(getClass().getSimpleName() + " was given " + cdo + " which is not an expected object type");
        return;
    }
    for (CDOMReference<Skill> ref : cdo.getSafeListFor(ListKey.LOCALCSKILL)) {
        for (Skill sk : ref.getContainedObjects()) {
            add(id, owner, SkillCost.CLASS, sk, cdo);
        }
    }
    for (CDOMReference<Skill> ref : cdo.getSafeListFor(ListKey.LOCALCCSKILL)) {
        for (Skill sk : ref.getContainedObjects()) {
            add(id, owner, SkillCost.CROSS_CLASS, sk, cdo);
        }
    }
}
Also used : Skill(pcgen.core.Skill) CDOMObject(pcgen.cdom.base.CDOMObject) PCClass(pcgen.core.PCClass) Domain(pcgen.core.Domain) CharID(pcgen.cdom.enumeration.CharID) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 2 with Domain

use of pcgen.core.Domain 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 Domain

use of pcgen.core.Domain in project pcgen by PCGen.

the class DomainSpellsFacet method dataAdded.

/**
	 * Adds Domain Spells allowed / granted to the Player Character due to the
	 * Domain selections of the Player Character.
	 * 
	 * Triggered when one of the Facets to which DomainSpellsFacet 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) {
    Domain domain = dfce.getCDOMObject();
    CharID id = dfce.getCharID();
    ClassSource source = domainFacet.getSource(id, domain);
    if (source != null) {
        String classKey = source.getPcclass().getKeyName();
        PCClass domainClass = getClassKeyed(id, classKey);
        if (domainClass != null) {
            PlayerCharacter pc = trackingFacet.getPC(id);
            final int maxLevel = pc.getSpellSupport(domainClass).getMaxCastLevel();
            DomainApplication.addSpellsToClassForLevels(pc, domain, domainClass, 0, maxLevel);
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) ClassSource(pcgen.cdom.helper.ClassSource)

Example 4 with Domain

use of pcgen.core.Domain in project pcgen by PCGen.

the class NPCGenerator method selectDomainSpell.

private void selectDomainSpell(final PlayerCharacter aPC, final PCClass aClass, final int aLevel) {
    if (!aPC.hasDomains()) {
        return;
    }
    final WeightedCollection<Domain> domains = new WeightedCollection<>();
    for (Domain d : aPC.getDomainSet()) {
        // and is a valid domain, add them
        if (aClass.equals(aPC.getDomainSource(d).getPcclass())) {
            domains.add(d);
        }
    }
    final Domain domain = domains.getRandomValue();
    final WeightedCollection<Spell> domainSpells = new WeightedCollection<>(aPC.getSpellsIn(domain.get(ObjectKey.DOMAIN_SPELLLIST), aLevel));
    //$NON-NLS-1$
    selectSpell(aPC, aClass, domain, "Prepared Spells", domainSpells, aLevel);
}
Also used : WeightedCollection(pcgen.base.util.WeightedCollection) Domain(pcgen.core.Domain) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 5 with Domain

use of pcgen.core.Domain in project pcgen by PCGen.

the class PrerequisiteUtilities method subKeyDomain.

/**
	 * Count the number of domains associated with the ability being tested of types cType.
	 *
	 * @param countMults Should multiple occurrences be counted?
	 * @param cType The type to check for.
	 * @param selectedList The list of domains associated with the ability being tested.
	 * @return int
	 */
private static int subKeyDomain(final boolean countMults, final String cType, final List<String> selectedList) {
    int returnTotal = 0;
    for (String domain : selectedList) {
        final Domain dom;
        dom = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, domain);
        if (dom == null) {
            continue;
        }
        if (dom.isType(cType)) {
            returnTotal++;
            if (!countMults) {
                break;
            }
        }
    }
    return returnTotal;
}
Also used : Domain(pcgen.core.Domain)

Aggregations

Domain (pcgen.core.Domain)79 PCClass (pcgen.core.PCClass)31 Test (org.junit.Test)19 ClassSource (pcgen.cdom.helper.ClassSource)18 ArrayList (java.util.ArrayList)11 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10 Prerequisite (pcgen.core.prereq.Prerequisite)10 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)8 CDOMReference (pcgen.cdom.base.CDOMReference)8 Deity (pcgen.core.Deity)7 Spell (pcgen.core.spell.Spell)7 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)7 StringTokenizer (java.util.StringTokenizer)6 Ability (pcgen.core.Ability)6 QualifiedObject (pcgen.core.QualifiedObject)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 TreeSet (java.util.TreeSet)5 PlayerCharacter (pcgen.core.PlayerCharacter)5 PCClassLevel (pcgen.cdom.inst.PCClassLevel)4 ClassSpellList (pcgen.cdom.list.ClassSpellList)4