Search in sources :

Example 16 with CharacterSpell

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

the class SpellMemToken method getBonusSpellValue.

/**
	 * Display an * is the spell is a domain/specialty spell,
	 * display ** if it is ONLY a domain/specialty spell. A value
	 * may also be supplied that will be displayed for non-specialty spells.
	 *
	 * @param aPC The character being processed.
	 * @param spellLevel The level of the spell.
	 * @param sString The indicator to use for domain/specialty spells.
	 * @param altLabel The indicator to use for non domain/specialty spells.
	 * @param aObject The class containing the spell.
	 * @param bookName The name of the spell book.
	 * @param cs The spell as it applies to the character
	 * @param aSpell The generic spell.
	 * @return The annotation string indicating domain/specialty status
	 */
private String getBonusSpellValue(PlayerCharacter aPC, final int spellLevel, String sString, String altLabel, final PObject aObject, String bookName, CharacterSpell cs, Spell aSpell) {
    StringBuilder retValue = new StringBuilder();
    if ((aObject != null) && (cs != null) && cs.isSpecialtySpell(aPC) && (aObject instanceof PCClass)) {
        final List<CharacterSpell> charSpells = aPC.getCharacterSpells(aObject, aSpell, bookName, spellLevel);
        boolean isDomainOnly = true;
        for (CharacterSpell cSpell : charSpells) {
            if (!cSpell.isSpecialtySpell(aPC)) {
                isDomainOnly = false;
                break;
            }
        }
        if (isDomainOnly) {
            retValue.append(sString);
        } else {
            retValue.append(sString + sString);
        }
    } else {
        retValue.append(altLabel);
    }
    return retValue.toString();
}
Also used : CharacterSpell(pcgen.core.character.CharacterSpell) PCClass(pcgen.core.PCClass)

Example 17 with CharacterSpell

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

the class PlayerCharacter method aggregateSpellList.

public List<Spell> aggregateSpellList(final String school, final String subschool, final String descriptor, final int minLevel, final int maxLevel) {
    final List<Spell> retList = new ArrayList<>();
    for (PObject pObj : getSpellClassList()) {
        for (int a = minLevel; a <= maxLevel; a++) {
            for (CharacterSpell cs : getCharacterSpells(pObj, a)) {
                final Spell aSpell = cs.getSpell();
                SpellSchool ss = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(SpellSchool.class, school);
                if ((school.isEmpty()) || (ss != null) && aSpell.containsInList(ListKey.SPELL_SCHOOL, ss) || (subschool.isEmpty()) || aSpell.containsInList(ListKey.SPELL_SUBSCHOOL, subschool) || (descriptor.isEmpty()) || aSpell.containsInList(ListKey.SPELL_DESCRIPTOR, descriptor)) {
                    retList.add(aSpell);
                }
            }
        }
    }
    return retList;
}
Also used : SpellSchool(pcgen.cdom.identifier.SpellSchool) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 18 with CharacterSpell

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

the class PlayerCharacter method countSpellsInBook.

/**
	 * Counts the number of spells inside a spellbook Yes, divine casters can
	 * have a "spellbook"
	 *
	 * @param aString
	 * @return spells in a book
	 */
public int countSpellsInBook(final String aString) {
    final StringTokenizer aTok = new StringTokenizer(aString, ".");
    final int classNum = Integer.parseInt(aTok.nextToken());
    final int sbookNum = Integer.parseInt(aTok.nextToken());
    final int levelNum;
    if (sbookNum >= getSpellBookCount()) {
        return 0;
    }
    if (aTok.hasMoreTokens()) {
        levelNum = Integer.parseInt(aTok.nextToken());
    } else {
        levelNum = -1;
    }
    String bookName = Globals.getDefaultSpellBook();
    if (sbookNum > 0) {
        bookName = getSpellBookNames().get(sbookNum);
    }
    final PObject aObject = getSpellClassAtIndex(classNum);
    if (aObject != null) {
        final List<CharacterSpell> aList = getCharacterSpells(aObject, null, bookName, levelNum);
        return aList.size();
    }
    return 0;
}
Also used : StringTokenizer(java.util.StringTokenizer) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 19 with CharacterSpell

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

the class PlayerCharacter method getCharacterSpellForSpell.

/**
	 * Retrieve the character's existing version of this spell, if any.
	 * @param po The source of the spell list for this spell (normally a PCClass)
	 * @param spell The spell to be retrieved
	 * @param owner The source of the spell (either the PCClass or the Domian)
	 * @return The character's existing instance of the spell, or null if none.
	 */
public CharacterSpell getCharacterSpellForSpell(PObject po, Spell spell, PObject owner) {
    List<CharacterSpell> cspells = new ArrayList<>(getCharacterSpells(po));
    // Add in the spells granted by objects
    addBonusKnownSpellsToList(po, cspells);
    for (CharacterSpell cs : cspells) {
        Spell sp = cs.getSpell();
        if (spell.equals(sp) && (cs.getOwner().equals(owner))) {
            return cs;
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 20 with CharacterSpell

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

the class PlayerCharacter method getTotalCasterLevelWithSpellBonus.

public int getTotalCasterLevelWithSpellBonus(CharacterSpell acs, final Spell aSpell, final String spellType, final String classOrRace, final int casterLev) {
    if (aSpell != null && acs.getFixedCasterLevel() != null) {
        return getVariableValue(acs.getFixedCasterLevel(), Constants.EMPTY_STRING).intValue();
    }
    int tBonus = casterLev;
    boolean replaceCasterLevel = false;
    String tType;
    String tStr;
    // final List<TypedBonus> bonuses = new ArrayList<TypedBonus>();
    final List<CasterLevelSpellBonus> bonuses = new ArrayList<>();
    if (classOrRace != null) {
        // bonuses.addAll(getBonusesTo("CASTERLEVEL", classOrRace));
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", classOrRace);
        if (tBonus > 0) {
            tType = getSpellBonusType("CASTERLEVEL", classOrRace);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        // BONUS:CASTERLEVEL|CLASS.Sorcerer|1
        if (!classOrRace.startsWith("RACE.")) {
            tStr = "CLASS." + classOrRace;
            // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
            tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
            if (tBonus > 0) {
                tType = getSpellBonusType("CASTERLEVEL", tStr);
                bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
            }
        }
    }
    if (aSpell == null) {
        return tallyCasterlevelBonuses(casterLev, replaceCasterLevel, bonuses);
    }
    if (!spellType.equals(Constants.NONE)) {
        tStr = "TYPE." + spellType;
        // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        tStr += ".RESET";
        // final List<TypedBonus> reset = getBonusesTo("CASTERLEVEL", tStr);
        // if ( reset.size() > 0 )
        // {
        // bonuses.addAll(reset);
        // replaceCasterLevel = true;
        // }
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            replaceCasterLevel = true;
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
    }
    tStr = "SPELL." + aSpell.getKeyName();
    // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
    tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
    if (tBonus > 0) {
        tType = getSpellBonusType("CASTERLEVEL", tStr);
        bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
    }
    tStr += ".RESET";
    // final List<TypedBonus> reset = getBonusesTo("CASTERLEVEL", tStr);
    // if ( reset.size() > 0 )
    // {
    // bonuses.addAll(reset);
    // replaceCasterLevel = true;
    // }
    tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
    if (tBonus > 0) {
        replaceCasterLevel = true;
        tType = getSpellBonusType("CASTERLEVEL", tStr);
        bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
    }
    /*
		 * This wraps in TreeSet because it looks to me like this is ordered
		 * (given .RESET)
		 */
    for (SpellSchool school : new TreeSet<>(aSpell.getSafeListFor(ListKey.SPELL_SCHOOL))) {
        tStr = "SCHOOL." + school.toString();
        // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (// Allow negative bonus to casterlevel
        tBonus != 0) {
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        tStr += ".RESET";
        // final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
        // tStr);
        // if ( reset.size() > 0 )
        // {
        // bonuses.addAll(reset1);
        // replaceCasterLevel = true;
        // }
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            replaceCasterLevel = true;
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
    }
    for (String subschool : new TreeSet<>(aSpell.getSafeListFor(ListKey.SPELL_SUBSCHOOL))) {
        tStr = "SUBSCHOOL." + subschool;
        // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        tStr += ".RESET";
        // final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
        // tStr);
        // if ( reset.size() > 0 )
        // {
        // bonuses.addAll(reset1);
        // replaceCasterLevel = true;
        // }
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            replaceCasterLevel = true;
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
    }
    //Not wrapped because it wasn't in 5.14
    for (String desc : aSpell.getSafeListFor(ListKey.SPELL_DESCRIPTOR)) {
        tStr = "DESCRIPTOR." + desc;
        // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        tStr += ".RESET";
        // final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
        // tStr);
        // if ( reset.size() > 0 )
        // {
        // bonuses.addAll(reset1);
        // replaceCasterLevel = true;
        // }
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            replaceCasterLevel = true;
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
    }
    final HashMapToList<CDOMList<Spell>, Integer> domainMap = getSpellLevelInfo(aSpell);
    if (domainMap != null) {
        for (CDOMList<Spell> spellList : domainMap.getKeySet()) {
            if (spellList instanceof DomainSpellList) {
                tStr = "DOMAIN." + spellList.getKeyName();
                // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
                tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
                if (tBonus > 0) {
                    tType = getSpellBonusType("CASTERLEVEL", tStr);
                    bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
                }
                tStr += ".RESET";
                // final List<TypedBonus> reset1 =
                // getBonusesTo("CASTERLEVEL", tStr);
                // if ( reset.size() > 0 )
                // {
                // bonuses.addAll(reset1);
                // replaceCasterLevel = true;
                // }
                tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
                if (tBonus > 0) {
                    replaceCasterLevel = true;
                    tType = getSpellBonusType("CASTERLEVEL", tStr);
                    bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
                }
            }
        }
    }
    int result = tallyCasterlevelBonuses(casterLev, replaceCasterLevel, bonuses);
    return (result);
}
Also used : ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) DomainSpellList(pcgen.cdom.list.DomainSpellList) SpellSchool(pcgen.cdom.identifier.SpellSchool) TreeSet(java.util.TreeSet) CDOMList(pcgen.cdom.base.CDOMList)

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