Search in sources :

Example 41 with Spell

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

the class SpellMemToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter aPC, ExportHandler eh) {
    StringBuilder retValue = new StringBuilder();
    // New Token syntax - SPELLMEM.x instead of SPELLMEMx
    final StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    aTok.nextToken();
    final int classNum;
    classNum = Integer.parseInt(aTok.nextToken());
    final int bookNum = Integer.parseInt(aTok.nextToken());
    final int spellLevel = Integer.parseInt(aTok.nextToken());
    final int spellNumber = Integer.parseInt(aTok.nextToken());
    boolean found = false;
    String aLabel = "NAME";
    if (aTok.hasMoreTokens()) {
        aLabel = aTok.nextToken();
    }
    String altLabel = "";
    if (aTok.hasMoreTokens()) {
        altLabel = aTok.nextToken();
    }
    final PObject aObject = aPC.getSpellClassAtIndex(classNum);
    if ((aObject == null) && eh != null && eh.getExistsOnly() && (classNum != -1)) {
        eh.setNoMoreItems(true);
    }
    String bookName = Globals.getDefaultSpellBook();
    if (bookNum > 0) {
        bookName = aPC.getDisplay().getSpellBookNames().get(bookNum);
    }
    if ((aObject != null) || (classNum == -1)) {
        if (classNum == -1) {
            bookName = Globals.getDefaultSpellBook();
        }
        CharacterSpell selectedCSpell = null;
        if (!"".equals(bookName)) {
            Spell aSpell = null;
            if (classNum == -1) {
                // List of all the character's spells (including SLAs)
                final List<CharacterSpell> charSpellList = new ArrayList<>();
                // For each class
                for (PCClass pcClass : aPC.getDisplay().getClassSet()) {
                    // Get the spells provided by the class
                    List<CharacterSpell> aList = aPC.getCharacterSpells(pcClass, null, bookName, spellLevel);
                    for (CharacterSpell cs : aList) {
                        // Add to the list if they are not there already
                        if (!charSpellList.contains(cs)) {
                            charSpellList.add(cs);
                        }
                    }
                }
                // Sort the list
                Collections.sort(charSpellList);
                // Set cs to the spell asked for
                if (spellNumber < charSpellList.size()) {
                    selectedCSpell = charSpellList.get(spellNumber);
                    aSpell = selectedCSpell.getSpell();
                    found = true;
                }
            } else if (aObject != null) {
                // List of spells provided by this PObject
                final List<CharacterSpell> charSpells = aPC.getCharacterSpells(aObject, null, bookName, spellLevel);
                if (spellNumber < charSpells.size()) {
                    selectedCSpell = charSpells.get(spellNumber);
                    aSpell = selectedCSpell.getSpell();
                    found = true;
                }
            } else if (eh != null && eh.getInLabel() && eh.getCheckBefore()) {
                eh.setCanWrite(false);
            }
            // We never found the requested spell
            if (selectedCSpell == null) {
                if (eh != null && eh.getExistsOnly()) {
                    eh.setNoMoreItems(true);
                }
                return retValue.toString();
            }
            // Get the SpellInfo for the selected spell
            final SpellInfo si = selectedCSpell.getSpellInfoFor(bookName, spellLevel);
            if (found && (aSpell != null) && (si != null)) {
                if ("NAME".equals(aLabel) || "OUTPUTNAME".equals(aLabel)) {
                    retValue.append(OutputNameFormatting.getOutputName(aSpell) + si.toString());
                } else if ("BASENAME".equals(aLabel)) {
                    retValue.append(OutputNameFormatting.getOutputName(aSpell));
                } else if ("APPLIEDNAME".equals(aLabel)) {
                    retValue.append(getAppliedName(si));
                } else if ("PPCOST".equals(aLabel)) {
                    if (si.getActualPPCost() != -1) {
                        retValue.append(si.getActualPPCost());
                    }
                } else if ("TIMES".equals(aLabel)) {
                    if (si.getTimes() == SpellInfo.TIMES_AT_WILL) {
                        retValue.append("At Will");
                    } else {
                        retValue.append(String.valueOf(si.getTimes()));
                    }
                } else if ("TIMEUNIT".equals(aLabel)) {
                    retValue.append(String.valueOf(si.getTimeUnit()));
                } else // if (aSpell != null) can't be null
                {
                    if ("RANGE".equals(aLabel)) {
                        retValue.append(aPC.getSpellRange(selectedCSpell, si));
                    } else if ("CASTERLEVEL".equals(aLabel)) {
                        retValue.append(aPC.getCasterLevelForSpell(selectedCSpell));
                    } else if ("CASTINGTIME".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.CASTTIME));
                    } else if ("COMPONENTS".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.COMPONENTS));
                    } else if ("CONCENTRATION".equals(aLabel)) {
                        if (SettingsHandler.getGame().getSpellBaseConcentration() != "") {
                            int concentration = aPC.getConcentration(aSpell, selectedCSpell, si);
                            retValue.append(Delta.toString(concentration));
                        }
                    } else if ("COST".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(ObjectKey.COST).toString());
                    } else if ("DC".equals(aLabel)) {
                        String SaveInfo = aSpell.getListAsString(ListKey.SAVE_INFO);
                        if (!"".equals(SaveInfo) && !"None".equals(SaveInfo) && !"No".equals(SaveInfo)) {
                            int dc = aPC.getDC(aSpell, selectedCSpell, si);
                            retValue.append(String.valueOf(dc));
                        }
                    } else if ("DURATION".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aSpell.getListAsString(ListKey.DURATION));
                        retValue.append(mString);
                    } else if ("DESC".equals(aLabel) || "EFFECT".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aPC.getDescription(aSpell));
                        retValue.append(mString);
                    } else if ("TARGET".equals(aLabel) || "EFFECTYPE".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aSpell.getSafe(StringKey.TARGET_AREA));
                        retValue.append(mString);
                    } else if ("SAVEINFO".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SAVE_INFO));
                    } else if ("SCHOOL".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_SCHOOL));
                    } else if ("SOURCELEVEL".equals(aLabel)) {
                        retValue.append(replaceTokenSpellMemSourceLevel(aSpell, aPC));
                    } else if ("SOURCE".equals(aLabel)) {
                        retValue.append(SourceFormat.getFormattedString(aSpell, Globals.getSourceDisplay(), true));
                    } else if ("SOURCESHORT".equals(aLabel)) {
                        retValue.append(SourceFormat.formatShort(aSpell, 8));
                    } else if ("SOURCEPAGE".equals(aLabel)) {
                        retValue.append(aSpell.get(StringKey.SOURCE_PAGE));
                    } else if ("SOURCEWEB".equals(aLabel)) {
                        String aTemp = aSpell.get(StringKey.SOURCE_WEB);
                        if (aTemp != null && !aTemp.isEmpty()) {
                            retValue.append(aTemp);
                        }
                    } else if ("SOURCELINK".equals(aLabel)) {
                        String aTemp = aSpell.get(StringKey.SOURCE_LINK);
                        if (aTemp != null && !aTemp.isEmpty()) {
                            retValue.append(aTemp);
                        }
                    } else if ("SUBSCHOOL".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL));
                    } else if ("DESCRIPTOR".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR));
                    } else if ("FULLSCHOOL".equals(aLabel)) {
                        String aTemp = aSpell.getListAsString(ListKey.SPELL_SCHOOL);
                        if ((!aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL).isEmpty()) && (!"NONE".equalsIgnoreCase(aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL).trim()))) {
                            aTemp += (" (" + aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL) + ')');
                        }
                        if (!aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR).isEmpty()) {
                            aTemp += (" [" + aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR) + ']');
                        }
                        retValue.append(aTemp);
                    } else if ("SR".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_RESISTANCE));
                    } else if ("SRSHORT".equals(aLabel)) {
                        if ("No".equals(aSpell.getListAsString(ListKey.SPELL_RESISTANCE))) {
                            retValue.append('N');
                        } else {
                            retValue.append('Y');
                        }
                    } else if ("CLASS".equals(aLabel)) {
                        retValue.append(OutputNameFormatting.getOutputName(aObject));
                    } else if ("DCSTAT".equals(aLabel)) {
                        if (aObject instanceof PCClass) {
                            PCClass aClass = (PCClass) aObject;
                            retValue.append(aClass.getSpellBaseStat());
                        }
                    } else if ("TYPE".equals(aLabel)) {
                        PCClass aClass = null;
                        if (aObject instanceof PCClass) {
                            aClass = (PCClass) aObject;
                        }
                        if (aClass != null) {
                            retValue.append(aClass.getSpellType());
                        }
                    } else if (aLabel.startsWith("DESCRIPTION")) {
                        final String sString = getItemDescription("SPELL", aSpell.getKeyName(), aPC.getDescription(aSpell), aPC);
                        if (!altLabel.isEmpty()) {
                            retValue.append(sString.replaceAll("\r?\n", altLabel));
                        } else {
                            retValue.append(sString);
                        }
                    } else if (aLabel.startsWith("BONUSSPELL")) {
                        String sString = "*";
                        if (aLabel.length() > 10) {
                            sString = aLabel.substring(10);
                        }
                        retValue.append(getBonusSpellValue(aPC, spellLevel, sString, altLabel, aObject, bookName, selectedCSpell, aSpell));
                    } else if ("XPCOST".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(IntegerKey.XP_COST));
                    } else if ("CT".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(IntegerKey.CASTING_THRESHOLD));
                    }
                }
            } else if (eh != null && eh.getExistsOnly()) {
                eh.setNoMoreItems(true);
            }
        } else if (eh != null && eh.getExistsOnly()) {
            eh.setNoMoreItems(true);
        }
    }
    return retValue.toString();
}
Also used : ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) StringTokenizer(java.util.StringTokenizer) PObject(pcgen.core.PObject) ArrayList(java.util.ArrayList) HashMapToList(pcgen.base.util.HashMapToList) CDOMList(pcgen.cdom.base.CDOMList) List(java.util.List) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 42 with Spell

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

the class SpelllistToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
    if (!count.isValid()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
    }
    if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
        return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
    }
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
    }
    List<CDOMReference<? extends CDOMListObject<Spell>>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<? extends CDOMListObject<Spell>> ref;
        if (Constants.LST_ALL.equals(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(SPELLLIST_CLASS);
        } else if (token.startsWith("DOMAIN.")) {
            ref = context.getReferenceContext().getCDOMReference(DOMAINSPELLLIST_CLASS, token.substring(7));
        } else {
            ref = context.getReferenceContext().getCDOMReference(SPELLLIST_CLASS, token);
        }
        refs.add(ref);
    }
    PrimitiveChoiceSet<CDOMListObject<Spell>> rcs = new SpellReferenceChoiceSet(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    ChoiceSet<? extends CDOMListObject<Spell>> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Select class whose list of spells this class will use");
    TransitionChoice<CDOMListObject<Spell>> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(pcc, ObjectKey.SPELLLIST_CHOICE, tc);
    tc.setRequired(false);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) SpellReferenceChoiceSet(pcgen.cdom.choiceset.SpellReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) PrimitiveChoiceSet(pcgen.cdom.base.PrimitiveChoiceSet) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CDOMListObject(pcgen.cdom.base.CDOMListObject) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) CDOMReference(pcgen.cdom.base.CDOMReference) SpellReferenceChoiceSet(pcgen.cdom.choiceset.SpellReferenceChoiceSet)

Example 43 with Spell

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

the class CharacterFacadeImpl method refreshAvailableTempBonuses.

void refreshAvailableTempBonuses() {
    List<TempBonusFacadeImpl> tempBonuses = new ArrayList<>();
    // first objects on the PC
    for (CDOMObject cdo : theCharacter.getCDOMObjectList()) {
        scanForTempBonuses(tempBonuses, cdo);
    }
    //
    // next do all abilities to get TEMPBONUS:ANYPC only
    GameMode game = (GameMode) dataSet.getGameMode();
    for (AbilityCategory cat : game.getAllAbilityCategories()) {
        if (cat.getParentCategory() == cat) {
            for (Ability aFeat : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, cat).getAllObjects()) {
                scanForAnyPcTempBonuses(tempBonuses, aFeat);
            }
        }
    }
    // Do all the PC's spells
    for (Spell aSpell : theCharacter.aggregateSpellList("", "", "", 0, 9)) {
        scanForTempBonuses(tempBonuses, aSpell);
    }
    // Do all the pc's innate spells.
    Collection<CharacterSpell> innateSpells = theCharacter.getCharacterSpells(charDisplay.getRace(), Constants.INNATE_SPELL_BOOK_NAME);
    for (CharacterSpell aCharacterSpell : innateSpells) {
        if (aCharacterSpell == null) {
            continue;
        }
        scanForTempBonuses(tempBonuses, aCharacterSpell.getSpell());
    }
    // Next do all spells to get TEMPBONUS:ANYPC or TEMPBONUS:EQUIP
    for (Spell spell : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Spell.class)) {
        scanForNonPcTempBonuses(tempBonuses, spell);
    }
    // do all Templates to get TEMPBONUS:ANYPC or TEMPBONUS:EQUIP
    for (PCTemplate aTemp : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(PCTemplate.class)) {
        scanForNonPcTempBonuses(tempBonuses, aTemp);
    }
    Collections.sort(tempBonuses);
    availTempBonuses.updateContents(tempBonuses);
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) GameMode(pcgen.core.GameMode) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 44 with Spell

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

the class SpellLevelTest method testGetPCBasedBonusKnownSpells.

/**
	 * Test method for {@link pcgen.core.analysis.SpellLevel#getPCBasedBonusKnownSpells(pcgen.core.PlayerCharacter, pcgen.core.PCClass)}.
	 * @throws Exception 
	 */
public void testGetPCBasedBonusKnownSpells() throws Exception {
    LoadContext context = Globals.getContext();
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    final String classLine = "CLASS:Sorcerer	TYPE:Base.PC	SPELLSTAT:CHA	SPELLTYPE:Arcane	MEMORIZE:NO	BONUS:CASTERLEVEL|Sorcerer|CL";
    PCClassLoader classLoader = new PCClassLoader();
    PCClass pcc = classLoader.parseLine(context, null, classLine, source);
    Spell spell = TestHelper.makeSpell("Bless");
    String abilityLine = "Spell bonanza	CATEGORY:FEAT	SPELLKNOWN:CLASS|Sorcerer=3|KEY_Bless";
    AbilityLoader abilityLoader = new AbilityLoader();
    abilityLoader.parseLine(context, null, abilityLine, source);
    Ability ab1 = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, "Spell bonanza");
    // Do the post parsing cleanup
    context.resolveDeferredTokens();
    context.getReferenceContext().buildDeferredObjects();
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().validate(null);
    assertTrue(context.getReferenceContext().resolveReferences(null));
    PlayerCharacter aPC = getCharacter();
    Collection<Integer> levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
    assertEquals("Initial number of spell levels incorrect", 0, levels.size());
    addAbility(AbilityCategory.FEAT, ab1);
    // Now for the tests
    levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
    assertEquals("Incorrect number of spell levels returned", 1, levels.size());
    assertEquals("Incorrect spell level returned", Integer.valueOf(3), levels.iterator().next());
    Collection<Spell> result = listManagerFacet.getSet(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST), 3);
    assertEquals("Incorrect number of spells returned", 1, result.size());
    assertEquals("Incorrect spell returned", spell, result.iterator().next());
}
Also used : Ability(pcgen.core.Ability) AbilityLoader(pcgen.persistence.lst.AbilityLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) PCClass(pcgen.core.PCClass) URI(java.net.URI) Spell(pcgen.core.spell.Spell) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader)

Example 45 with Spell

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

the class PlayerCharacterTest method testAvailableSpellsMemorizedDivine.

/**
	 * Tests available spell slot calculations for a divine caster who 
	 * memorizes spells.
	 */
public void testAvailableSpellsMemorizedDivine() {
    readyToRun();
    final PlayerCharacter character = new PlayerCharacter();
    character.setRace(human);
    character.setStat(wis, 15);
    character.incrementClassLevel(1, classMemDivine, true);
    PCClass pcMdClass = character.getClassKeyed(classMemDivine.getKeyName());
    Spell spellNonSpec0 = new Spell();
    spellNonSpec0.setName("Basic Spell Lvl0");
    CharacterSpell charSpellNonSpec0 = new CharacterSpell(pcMdClass, spellNonSpec0);
    Spell spellNonSpec1 = new Spell();
    spellNonSpec1.setName("Basic Spell Lvl1");
    CharacterSpell charSpellNonSpec1 = new CharacterSpell(pcMdClass, spellNonSpec1);
    Spell spellNonSpec2 = new Spell();
    spellNonSpec2.setName("Basic Spell Lvl2");
    CharacterSpell charSpellNonSpec2 = new CharacterSpell(pcMdClass, spellNonSpec2);
    final List<Ability> none = Collections.emptyList();
    boolean available = character.availableSpells(1, pcMdClass, Globals.getDefaultSpellBook(), true, false);
    assertEquals("availableSpells should not be called when there ar eno limits on known spells", false, available);
    // Test specialty/non with no spells, some spells, all spells, spells from lower level
    String spellBookName = "Town Spells";
    SpellBook townSpells = new SpellBook(spellBookName, SpellBook.TYPE_PREPARED_LIST);
    assertTrue("Adding spellbook " + townSpells, character.addSpellBook(townSpells));
    assertTrue("Adding domain " + luckDomain, character.addDomain(luckDomain));
    DomainApplication.applyDomain(character, luckDomain);
    // Test for spell availability with no spells in list
    for (int i = 0; i < 3; i++) {
        assertEquals("Empty list - Non specialty available for level " + i, true, character.availableSpells(i, pcMdClass, townSpells.getName(), false, false));
        assertEquals("Empty list - Specialty available for level " + i, i > 0, character.availableSpells(i, pcMdClass, townSpells.getName(), false, true));
    }
    // Test for spell availability with some spells in list
    assertEquals("", character.addSpell(charSpellNonSpec0, none, pcMdClass.getKeyName(), spellBookName, 0, 0));
    assertEquals("", character.addSpell(charSpellNonSpec1, none, pcMdClass.getKeyName(), spellBookName, 1, 1));
    assertEquals("", character.addSpell(charSpellNonSpec2, none, pcMdClass.getKeyName(), spellBookName, 2, 2));
    for (int i = 0; i < 3; i++) {
        assertEquals("Partial list - Non specialty available for level " + i, true, character.availableSpells(i, pcMdClass, townSpells.getName(), false, false));
        assertEquals("Partial list - Specialty available for level " + i, i > 0, character.availableSpells(i, pcMdClass, townSpells.getName(), false, true));
    }
    // Test for spell availability with only 1st level with a spare slot
    assertEquals("", character.addSpell(charSpellNonSpec0, none, pcMdClass.getKeyName(), spellBookName, 0, 0));
    assertEquals("", character.addSpell(charSpellNonSpec0, none, pcMdClass.getKeyName(), spellBookName, 0, 0));
    assertEquals("", character.addSpell(charSpellNonSpec2, none, pcMdClass.getKeyName(), spellBookName, 2, 2));
    for (int i = 0; i < 3; i++) {
        assertEquals("Full lvl0, lvl2 list - Non specialty available for level " + i, i == 1, character.availableSpells(i, pcMdClass, townSpells.getName(), false, false));
        //TODO: The current implementation only finds the domain specialty slot if a domain spell is already prepared. 
        // So the domain spell can't be the last added. Once fixed, i==1 should be i>=1
        assertEquals("Full lvl0, lvl2 list - Specialty available for level " + i, i >= 1, character.availableSpells(i, pcMdClass, townSpells.getName(), false, true));
    }
    // Test for spell availability with 1st having one domain spell full and one non domain free
    CharacterSpell charSpellSpec1 = new CharacterSpell(luckDomain, luckDomainLvl1Spell);
    assertEquals("", character.addSpell(charSpellSpec1, none, pcMdClass.getKeyName(), spellBookName, 1, 1));
    for (int i = 0; i < 3; i++) {
        assertEquals("Specialty: No, Level: " + i + ". 1st lvl non domain only free", i == 1, character.availableSpells(i, pcMdClass, townSpells.getName(), false, false));
        assertEquals("Specialty: Yes, Level: " + i + ". 1st lvl non domain only free", i == 2, character.availableSpells(i, pcMdClass, townSpells.getName(), false, true));
    }
    // Test for spell availability with 2nd having both domain and normal full
    CharacterSpell charSpellSpec2 = new CharacterSpell(luckDomain, luckDomainLvl2Spell);
    assertEquals("", character.addSpell(charSpellSpec2, none, pcMdClass.getKeyName(), spellBookName, 2, 2));
    for (int i = 0; i < 3; i++) {
        assertEquals("Specialty: No, Level: " + i + ". 1st lvl non domain only free", i == 1, character.availableSpells(i, pcMdClass, townSpells.getName(), false, false));
        assertEquals("Specialty: Yes, Level: " + i + ". 1st lvl non domain only free", false, character.availableSpells(i, pcMdClass, townSpells.getName(), false, true));
    }
}
Also used : SpellBook(pcgen.core.character.SpellBook) 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