Search in sources :

Example 71 with Spell

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

the class KnownspellsTokenTest method testUnparseLevel.

@Test
public void testUnparseLevel() throws PersistenceLayerException {
    CDOMGroupRef<Spell> all = primaryContext.getReferenceContext().getCDOMAllReference(Spell.class);
    primaryProf.addToListFor(ListKey.KNOWN_SPELLS, new KnownSpellIdentifier(all, 4));
    String[] sap = getToken().unparse(primaryContext, primaryProf);
    expectSingle(sap, "LEVEL=4");
}
Also used : KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) Spell(pcgen.core.spell.Spell) Test(org.junit.Test)

Example 72 with Spell

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

the class KnownspellsTokenTest method testRoundRobinTypeLevel.

@Test
public void testRoundRobinTypeLevel() throws PersistenceLayerException {
    construct(primaryContext, "TestWP1");
    construct(primaryContext, "TestWP2");
    construct(primaryContext, "TestWP3");
    construct(secondaryContext, "TestWP1");
    construct(secondaryContext, "TestWP2");
    construct(secondaryContext, "TestWP3");
    Spell a = construct(primaryContext, "TestWP2");
    a.addToListFor(ListKey.TYPE, Type.getConstant("SpellType"));
    Spell c = construct(secondaryContext, "TestWP2");
    c.addToListFor(ListKey.TYPE, Type.getConstant("SpellType"));
    runRoundRobin("TestWP1" + getJoinCharacter() + "TYPE=SpellType,LEVEL=1");
}
Also used : Spell(pcgen.core.spell.Spell) Test(org.junit.Test)

Example 73 with Spell

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

the class PlayerCharacter method getCasterLevelForClass.

/**
	 * Computes the Caster Level for a Class
	 *
	 * @param aClass
	 * @return caster level for class
	 */
public int getCasterLevelForClass(final PCClass aClass) {
    final Spell sp = new Spell();
    final CharacterSpell cs = new CharacterSpell(aClass, sp);
    final String aSpellClass = "CLASS:" + aClass.getKeyName();
    return getVariableValue(cs, "CASTERLEVEL", aSpellClass).intValue();
}
Also used : CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 74 with Spell

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

the class PlayerCharacter method removeKnownSpellsForClassLevel.

public void removeKnownSpellsForClassLevel(PCClass pcc) {
    if (!pcc.containsListFor(ListKey.KNOWN_SPELLS) || importing || !autoKnownSpells) {
        return;
    }
    if (!hasCharacterSpells(pcc)) {
        return;
    }
    SpellSupportForPCClass spellSupport = getSpellSupport(pcc);
    List<? extends CDOMList<Spell>> lists = getSpellLists(pcc);
    List<CharacterSpell> spellsToBeRemoved = new ArrayList<>();
    for (final CharacterSpell charSpell : getCharacterSpells(pcc)) {
        final Spell aSpell = charSpell.getSpell();
        // Check that the character can still cast spells of this level.
        final Integer[] spellLevels = SpellLevel.levelForKey(aSpell, lists, this);
        for (final Integer spellLevel : spellLevels) {
            if (spellLevel == -1) {
                continue;
            }
            final boolean isKnownAtThisLevel = spellSupport.isAutoKnownSpell(aSpell, spellLevel, true, this);
            if (!isKnownAtThisLevel) {
                spellsToBeRemoved.add(charSpell);
            }
        }
    }
    for (CharacterSpell characterSpell : spellsToBeRemoved) {
        removeCharacterSpell(pcc, characterSpell);
    }
}
Also used : ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 75 with Spell

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

the class DomainApplication method addSpellsToClassForLevels.

public static void addSpellsToClassForLevels(PlayerCharacter pc, Domain d, PCClass aClass, int minLevel, int maxLevel) {
    if (aClass == null) {
        return;
    }
    for (int aLevel = minLevel; aLevel <= maxLevel; aLevel++) {
        Collection<Spell> domainSpells = pc.getSpellsIn(d.get(ObjectKey.DOMAIN_SPELLLIST), aLevel);
        for (Spell spell : domainSpells) {
            List<CharacterSpell> slist = pc.getCharacterSpells(aClass, spell, Globals.getDefaultSpellBook(), aLevel);
            boolean flag = true;
            for (CharacterSpell cs1 : slist) {
                flag = !(cs1.getOwner().equals(d));
                if (!flag) {
                    break;
                }
            }
            if (flag) {
                CharacterSpell cs = new CharacterSpell(d, spell);
                cs.addInfo(aLevel, 1, Globals.getDefaultSpellBook());
                pc.addCharacterSpell(aClass, cs);
            }
        }
    }
}
Also used : CharacterSpell(pcgen.core.character.CharacterSpell) 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