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