Search in sources :

Example 26 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class PlayerCharacterTest method testAddSpells.

/**
	 * Tests adding a spell.
	 */
public void testAddSpells() {
    readyToRun();
    final PlayerCharacter character = new PlayerCharacter();
    character.setRace(human);
    character.incrementClassLevel(1, pcClass, true);
    final List<Ability> none = Collections.emptyList();
    String response = character.addSpell(null, none, pcClass.getKeyName(), null, 1, 1);
    assertEquals("Add spell should be rejected due to no spell", "Invalid parameter to add spell", response);
    Spell spell = new Spell();
    spell.setName("test spell 1");
    CharacterSpell charSpell = new CharacterSpell(pcClass, spell);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), null, 1, 1);
    assertEquals("Add spell should be rejected due to no book", "Invalid spell list/book name.", response);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), "", 1, 1);
    assertEquals("Add spell should be rejected due to no book", "Invalid spell list/book name.", response);
    // Add a non existant spell to a non existent spellbook
    String spellBookName = "Test book";
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to book not existing", "Could not find spell list/book Test book", response);
    character.addSpellBook(spellBookName);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to no levels.", "You can only prepare 0 spells for level 1 \nand there are no higher-level slots available.", response);
    response = character.addSpell(charSpell, none, "noclass", spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to no matching class", "No class keyed noclass", response);
    SpellBook book = character.getSpellBookByName(spellBookName);
    book.setType(SpellBook.TYPE_PREPARED_LIST);
    character.addSpellBook(spellBookName);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to no levels.", "You can only prepare 0 spells for level 1 \nand there are no higher-level slots available.", response);
    book.setType(SpellBook.TYPE_SPELL_BOOK);
    book.setPageFormula(FormulaFactory.getFormulaFor("SPELLLEVEL"));
    book.setNumPages(3);
    character.addSpellBook(spellBookName);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should not be rejected.", "", response);
    // Add a second time to cover multiples
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should not be rejected.", "", response);
    response = character.addSpell(charSpell, none, giantClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should not be rejected.", "", response);
    response = character.addSpell(charSpell, none, giantClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to the book being full.", "There are not enough pages left to add this spell to the spell book.", response);
    PCClass c = character.getClassKeyed(pcClass.getKeyName());
    List<CharacterSpell> aList = character.getCharacterSpells(c, null, spellBookName, 1);
    CharacterSpell addedSpell = aList.get(0);
    response = character.delSpell(addedSpell.getSpellInfoFor(spellBookName, 1, none), pcClass, spellBookName);
    assertEquals("Delete spell should not be rejected.", "", response);
    aList = character.getCharacterSpells(giantClass, null, spellBookName, 1);
    addedSpell = aList.get(0);
    response = character.delSpell(addedSpell.getSpellInfoFor(spellBookName, 1), giantClass, spellBookName);
    assertEquals("Delete spell should not be rejected.", "", response);
}
Also used : SpellBook(pcgen.core.character.SpellBook) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 27 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class AbstractRestrictedSpellPrimitive method allow.

public boolean allow(PlayerCharacter pc, int level, String source, Spell spell, CDOMList<Spell> optionalList) {
    if (restriction != null) {
        Formula maxLevel = restriction.maxLevel;
        if (maxLevel != null && (level > maxLevel.resolve(pc, source).intValue())) {
            return false;
        }
        Formula minLevel = restriction.minLevel;
        if (minLevel != null && (level < minLevel.resolve(pc, source).intValue())) {
            return false;
        }
        if (restriction.knownRequired != null) {
            String defaultbook = Globals.getDefaultSpellBook();
            boolean known = restriction.knownRequired.booleanValue();
            boolean found = false;
            for (PCClass cl : pc.getClassSet()) {
                if (optionalList != null) {
                    /*
						 * This may not be a precise test of intent, but given
						 * the weirdness we have on lists and the use of
						 * SPELLLIST tag in data to share lists between classes,
						 * this is probably the closest we can get
						 */
                    if (!pc.hasSpellList(cl, optionalList)) {
                        continue;
                    }
                }
                List<CharacterSpell> csl = pc.getCharacterSpells(cl, spell, defaultbook, -1);
                if (csl != null && !csl.isEmpty()) {
                    /*
						 * Going to assume here that the level doesn't need to
						 * be rechecked... ?? - thpr Feb 26, 08
						 */
                    found = true;
                }
            }
            if (found != known) {
                return false;
            }
        }
    }
    return true;
}
Also used : Formula(pcgen.base.formula.Formula) CharacterSpell(pcgen.core.character.CharacterSpell) PCClass(pcgen.core.PCClass)

Example 28 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class PCCountSpellTimesTermEvaluator method resolve.

@Override
public Float resolve(PlayerCharacter pc) {
    String bookName = (classNum == -1) ? Globals.getDefaultSpellBook() : (bookNum > 0) ? pc.getDisplay().getSpellBookNames().get(bookNum) : Globals.getDefaultSpellBook();
    if (!"".equals(bookName)) {
        List<CharacterSpell> csList = new ArrayList<>();
        if (classNum == -1) {
            csList = new ArrayList<>();
            for (PObject cl : pc.getDisplay().getClassSet()) {
                for (CharacterSpell cs : pc.getCharacterSpells(cl, bookName)) {
                    if (!csList.contains(cs)) {
                        csList.add(cs);
                    }
                }
            }
            Collections.sort(csList);
        } else {
            final PObject pcClass = pc.getSpellClassAtIndex(classNum);
            if (pcClass != null) {
                csList = pc.getCharacterSpells(pcClass, null, bookName, spellLevel);
            }
        }
        boolean found = false;
        SpellInfo si = null;
        if (spellNumber < csList.size()) {
            final CharacterSpell cs = csList.get(spellNumber);
            si = cs.getSpellInfoFor(bookName, spellLevel);
            found = true;
        }
        if (found && (si != null)) {
            return (float) si.getTimes();
        }
    }
    return 0.0f;
}
Also used : PObject(pcgen.core.PObject) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 29 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class PCCountSpellsLevelsInBookTermEvaluator method resolve.

@Override
public Float resolve(PlayerCharacter pc) {
    String bookName = Globals.getDefaultSpellBook();
    if (sbookNum > 0) {
        bookName = pc.getDisplay().getSpellBookNames().get(sbookNum);
    }
    final PObject pObj = pc.getSpellClassAtIndex(classNum);
    int levelNum = 0;
    if (pObj != null) {
        for (; levelNum >= 0; ++levelNum) {
            final List<CharacterSpell> aList = pc.getCharacterSpells(pObj, null, bookName, levelNum);
            if (aList.size() < 1) {
                break;
            }
        }
    }
    return (float) levelNum;
}
Also used : PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 30 with CharacterSpell

use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.

the class ExportHandler method replaceTokenSpellListBook.

/**
	 * Helper method to deal with the SpellListBook token
	 * 
	 * @param aString
	 * @param aPC
	 * @return 0
	 */
private int replaceTokenSpellListBook(String aString, PlayerCharacter aPC) {
    int sbookNum = 0;
    final StringTokenizer aTok = new StringTokenizer(aString, ".");
    final int classNum = Integer.parseInt(aTok.nextToken());
    final int levelNum = Integer.parseInt(aTok.nextToken());
    // Get the spell book number
    if (aTok.hasMoreTokens()) {
        sbookNum = Integer.parseInt(aTok.nextToken());
    }
    // Set the spell book name
    String bookName = Globals.getDefaultSpellBook();
    if (sbookNum > 0) {
        bookName = aPC.getDisplay().getSpellBookNames().get(sbookNum);
    }
    canWrite = false;
    final PObject aObject = aPC.getSpellClassAtIndex(classNum);
    if (aObject != null) {
        final List<CharacterSpell> aList = aPC.getCharacterSpells(aObject, null, bookName, levelNum);
        canWrite = !aList.isEmpty();
    }
    return 0;
}
Also used : StringTokenizer(java.util.StringTokenizer) PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell)

Aggregations

CharacterSpell (pcgen.core.character.CharacterSpell)41 Spell (pcgen.core.spell.Spell)22 ArrayList (java.util.ArrayList)16 PCClass (pcgen.core.PCClass)12 SpellInfo (pcgen.core.character.SpellInfo)12 PObject (pcgen.core.PObject)7 SpellBook (pcgen.core.character.SpellBook)6 Ability (pcgen.core.Ability)5 StringTokenizer (java.util.StringTokenizer)4 CNAbility (pcgen.cdom.content.CNAbility)4 Formula (pcgen.base.formula.Formula)3 CDOMList (pcgen.cdom.base.CDOMList)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 PlayerCharacter (pcgen.core.PlayerCharacter)3 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)2 CDOMReference (pcgen.cdom.base.CDOMReference)2 ClassSource (pcgen.cdom.helper.ClassSource)2 SpellSchool (pcgen.cdom.identifier.SpellSchool)2 ClassSpellList (pcgen.cdom.list.ClassSpellList)2 DomainSpellList (pcgen.cdom.list.DomainSpellList)2