Search in sources :

Example 16 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 17 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)

Example 18 with Domain

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;
}
Also used : Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) ClassSource(pcgen.cdom.helper.ClassSource)

Example 19 with Domain

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));
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) PCClass(pcgen.core.PCClass) Domain(pcgen.core.Domain) PCClassLevel(pcgen.cdom.inst.PCClassLevel) Test(org.junit.Test) AbstractTokenModelTest(tokenmodel.testsupport.AbstractTokenModelTest)

Example 20 with Domain

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

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