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;
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class PCMaxCastableDomainTermEvaluator method resolve.
@Override
public Float resolve(PlayerCharacter pc) {
Domain domain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, domainKey);
if (domain == null) {
return 0.0f;
}
ClassSource source = pc.getDomainSource(domain);
if (source == null) {
return 0.0f;
}
String classKey = source.getPcclass().getKeyName();
PCClass spClass = pc.getClassKeyed(classKey);
int cutoff = pc.getSpellSupport(spClass).getHighestLevelSpell();
Float max = 0.0f;
if (pc.getSpellSupport(spClass).hasCastList()) {
for (int i = 0; i < cutoff; i++) {
if (pc.getSpellSupport(spClass).getCastForLevel(i, pc) != 0) {
max = Math.max(max, i);
}
}
} else {
for (int i = 0; i < cutoff; i++) {
if (pc.getSpellSupport(spClass).getKnownForLevel(i, pc) != 0) {
max = Math.max(max, i);
}
}
}
return max;
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class PCClassLevelDomainTest method testSimple.
@Test
public void testSimple() throws PersistenceLayerException {
PCClass source = create(PCClass.class, "Source");
PCClassLevel pcl = source.getOriginalClassLevel(2);
Domain granted = create(Domain.class, "Granted");
ParseResult result = token.parseToken(context, pcl, "Granted");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
finishLoad();
assertEquals(0, domainFacet.getCount(id));
classFacet.addClass(id, source);
PCClass pcc = pc.getClassKeyed(source.getKeyName());
classFacet.setLevel(id, pcc, 1);
//TODO get rid of this using facets :)
DomainApplication.addDomainsUpToLevel(source, 1, pc);
assertEquals(0, domainFacet.getCount(id));
classFacet.setLevel(id, pcc, 2);
DomainApplication.addDomainsUpToLevel(source, 2, pc);
assertTrue(domainFacet.contains(id, granted));
assertEquals(1, domainFacet.getCount(id));
DomainApplication.removeDomainsForLevel(source, 2, pc);
DomainApplication.removeDomainsForLevel(source, 1, pc);
pc.validateCharacterDomains();
classFacet.removeClass(id, source);
assertEquals(0, domainFacet.getCount(id));
}
use of pcgen.core.Domain 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);
}
}
}
Aggregations