Search in sources :

Example 86 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class DomainApplication method applyDomain.

/**
	 * Sets the locked flag on a PC
	 * 
	 * @param pc
	 */
public static void applyDomain(PlayerCharacter pc, Domain d) {
    ClassSource source = pc.getDomainSource(d);
    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) {
            addSpellsToClassForLevels(pc, d, aClass, 0, maxLevel - 1);
        }
        if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
            DomainSpellList domainSpellList = d.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.setDomainSpellCount(aClass, 1);
                    break;
                }
            }
        }
    }
    Collection<CDOMReference<Spell>> mods = d.getSafeListMods(Spell.SPELLS);
    for (CDOMReference<Spell> ref : mods) {
        Collection<Spell> spells = ref.getContainedObjects();
        Collection<AssociatedPrereqObject> assoc = d.getListAssociations(Spell.SPELLS, ref);
        for (AssociatedPrereqObject apo : assoc) {
            if (!PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, d)) {
                continue;
            }
            for (Spell s : spells) {
                String book = apo.getAssociation(AssociationKey.SPELLBOOK);
                List<CharacterSpell> aList = pc.getCharacterSpells(aClass, s, book, -1);
                if (aList.isEmpty()) {
                    Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
                    CharacterSpell cs = new CharacterSpell(d, s);
                    int resolvedTimes = times.resolve(pc, d.getQualifiedKey()).intValue();
                    cs.addInfo(1, resolvedTimes, book);
                    pc.addCharacterSpell(aClass, cs);
                }
            }
        }
    }
}
Also used : PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) DomainSpellList(pcgen.cdom.list.DomainSpellList) Formula(pcgen.base.formula.Formula) CharacterSpell(pcgen.core.character.CharacterSpell) ClassSource(pcgen.cdom.helper.ClassSource) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 87 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class SpellMemTokenTest method additionalSetUp.

/*
	 * @see TestCase#setUp()
	 */
@Override
protected void additionalSetUp() throws Exception {
    LoadContext context = Globals.getContext();
    // Human
    human = new Race();
    final BonusObj bon = Bonus.newBonus(context, "FEAT|POOL|2");
    human.addToListFor(ListKey.BONUS, bon);
    testSpell = new Spell();
    testSpell.setName("Test Spell");
    testSpell.put(StringKey.KEY_NAME, "TEST_SPELL");
    context.unconditionallyProcess(testSpell, "CLASSES", "KEY_TEST_ARCANE=1");
    context.unconditionallyProcess(testSpell, "DOMAINS", "Fire=0");
    context.unconditionallyProcess(testSpell, "CLASSES", "KEY_TEST_DIVINE=1");
    arcaneClass = new PCClass();
    arcaneClass.setName("TestArcane");
    arcaneClass.put(StringKey.KEY_NAME, "KEY_TEST_ARCANE");
    BuildUtilities.setFact(arcaneClass, "SpellType", "Arcane");
    context.unconditionallyProcess(arcaneClass, "SPELLSTAT", "CHA");
    arcaneClass.put(ObjectKey.SPELLBOOK, false);
    arcaneClass.put(ObjectKey.MEMORIZE_SPELLS, false);
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "KNOWN", "4,2,1");
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "CAST", "3,1,0");
    context.getReferenceContext().importObject(arcaneClass);
    divineClass = new PCClass();
    divineClass.setName("TestDivine");
    divineClass.put(StringKey.KEY_NAME, "KEY_TEST_DIVINE");
    BuildUtilities.setFact(divineClass, "SpellType", "Divine");
    context.unconditionallyProcess(divineClass, "SPELLSTAT", "WIS");
    divineClass.put(ObjectKey.SPELLBOOK, false);
    divineClass.put(ObjectKey.MEMORIZE_SPELLS, true);
    context.unconditionallyProcess(divineClass.getOriginalClassLevel(1), "CAST", "3,1,0");
    context.getReferenceContext().constructCDOMObject(Domain.class, "Fire");
    context.getReferenceContext().importObject(divineClass);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) Race(pcgen.core.Race) LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Aggregations

Spell (pcgen.core.spell.Spell)87 CharacterSpell (pcgen.core.character.CharacterSpell)35 ArrayList (java.util.ArrayList)25 PCClass (pcgen.core.PCClass)24 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)16 CDOMReference (pcgen.cdom.base.CDOMReference)15 Ability (pcgen.core.Ability)15 LoadContext (pcgen.rules.context.LoadContext)13 CDOMList (pcgen.cdom.base.CDOMList)12 CDOMObject (pcgen.cdom.base.CDOMObject)11 Test (org.junit.Test)10 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)9 AvailableSpell (pcgen.cdom.helper.AvailableSpell)8 StringTokenizer (java.util.StringTokenizer)7 CNAbility (pcgen.cdom.content.CNAbility)7 ClassSpellList (pcgen.cdom.list.ClassSpellList)7 DomainSpellList (pcgen.cdom.list.DomainSpellList)7 Formula (pcgen.base.formula.Formula)6 Domain (pcgen.core.Domain)6 PObject (pcgen.core.PObject)6