Search in sources :

Example 56 with Spell

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

the class SpellListClassToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    int i;
    StringBuilder retValue = new StringBuilder();
    // Determine the tag type
    final StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    aTok.nextToken();
    i = Integer.parseInt(aTok.nextToken());
    //
    final CDOMObject aObject = pc.getSpellClassAtIndex(i);
    if (aObject != null) {
        PCClass aClass = null;
        if (aObject instanceof PCClass) {
            aClass = (PCClass) aObject;
        }
        if ((aClass != null)) {
            if (tokenSource.endsWith(".CASTERLEVEL")) {
                retValue.append(pc.getCasterLevelForClass(aClass));
            } else if (tokenSource.endsWith(".CONCENTRATION")) {
                if (SettingsHandler.getGame().getSpellBaseConcentration() != "") {
                    Spell sp = new Spell();
                    CharacterSpell cs = new CharacterSpell(aClass, sp);
                    int concentration = pc.getConcentration(sp, cs, aClass, 0, 0, aClass);
                    retValue.append(Delta.toString(concentration));
                }
            } else if (tokenSource.endsWith(".LEVEL")) {
                retValue.append(String.valueOf(pc.getDisplay().getLevel(aClass) + (int) pc.getTotalBonusTo("PCLEVEL", aClass.getKeyName())));
            } else {
                retValue.append(OutputNameFormatting.getOutputName(aObject));
            }
        }
    }
    return retValue.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer) CDOMObject(pcgen.cdom.base.CDOMObject) CharacterSpell(pcgen.core.character.CharacterSpell) PCClass(pcgen.core.PCClass) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell)

Example 57 with Spell

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

the class SpellListDcToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    StringBuilder retValue = new StringBuilder();
    SpellListTokenParams params = new SpellListTokenParams(tokenSource, SpellListToken.SPELLTAG_DC);
    final CDOMObject aObject = pc.getSpellClassAtIndex(params.getClassNum());
    if (aObject != null) {
        PCClass aClass = null;
        if (aObject instanceof PCClass) {
            aClass = (PCClass) aObject;
        }
        int DC = pc.getDC(new Spell(), aClass, params.getLevel(), 0, aClass);
        retValue.append(Integer.toString(DC));
    }
    return retValue.toString();
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell)

Example 58 with Spell

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

the class AvailableSpellFacet method getSpellLevelInfo.

/**
	 * Returns a non-null HashMapToList indicating the spell levels and sources
	 * of those spell levels available to a Player Character for a given Spell.
	 * 
	 * This may return multiple spell levels because it is possible for a spell
	 * to be accessible to a Player Character at multiple levels since it may be
	 * available from multiple sources. This also returns the spell lists
	 * associated with the given level, since it is possible for a multi-class
	 * character to have access to the same spell at different levels. By
	 * returning the source as well as the spell levels, such scenarios can be
	 * appropriately distinguished.
	 * 
	 * This method is value-semantic in that ownership of the returned
	 * HashMapToList is transferred to the class calling this method.
	 * Modification of the returned HashMapToList will not modify this
	 * AvailableSpellFacet and modification of this AvailableSpellFacet will not
	 * modify the returned HashMapToList. Modifications to the returned
	 * HashMapToList will also not modify any future or previous objects
	 * returned by this (or other) methods on AvailableSpellFacet. If you wish
	 * to modify the information stored in this AvailableSpellFacet, you must
	 * use the add*() and remove*() methods of AvailableSpellFacet.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            spell levels should be returned
	 * @param sp
	 *            The Spell for which the spell levels should be returned
	 * @return A non-null HashMapToList indicating the spell levels and sources
	 *         of those spell levels available to a Player Character for a given
	 *         Spell.
	 */
public HashMapToList<CDOMList<Spell>, Integer> getSpellLevelInfo(CharID id, Spell sp) {
    HashMapToList<CDOMList<Spell>, Integer> levelInfo = new HashMapToList<>();
    Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> listMap = (Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>>) getCache(id);
    if (listMap == null) {
        return levelInfo;
    }
    for (Entry<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> me : listMap.entrySet()) {
        CDOMList<Spell> list = me.getKey();
        //Check to ensure we don't use SPELLS:
        if (!(list instanceof ClassSpellList) && !(list instanceof DomainSpellList)) {
            continue;
        }
        Map<Integer, Map<Spell, Set<Object>>> levelMap = me.getValue();
        for (Map.Entry<Integer, Map<Spell, Set<Object>>> lme : levelMap.entrySet()) {
            Integer level = lme.getKey();
            Map<Spell, Set<Object>> spellMap = lme.getValue();
            if (spellMap.containsKey(sp)) {
                levelInfo.addToListFor(list, level);
            } else {
                for (Spell spell : spellMap.keySet()) {
                    if (spell.getKeyName().equals(sp.getKeyName())) {
                        if (Logging.isLoggable(Logging.INFO)) {
                            Logging.log(Logging.INFO, "Found alternate spell of same key: " + spell + " from " + spell.getSource() + " rather than " + sp.getSource());
                        }
                        levelInfo.addToListFor(list, level);
                    }
                }
            }
        }
    }
    return levelInfo;
}
Also used : Set(java.util.Set) ClassSpellList(pcgen.cdom.list.ClassSpellList) Spell(pcgen.core.spell.Spell) DomainSpellList(pcgen.cdom.list.DomainSpellList) HashMapToList(pcgen.base.util.HashMapToList) CDOMList(pcgen.cdom.base.CDOMList) Map(java.util.Map)

Example 59 with Spell

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

the class AvailableSpellInputFacet method processList.

private void processList(CharID id, CDOMList<Spell> spelllist, CDOMReference<? extends CDOMList<?>> listref, CDOMObject cdo) {
    for (CDOMReference<Spell> objref : cdo.getListMods((CDOMReference<? extends CDOMList<Spell>>) listref)) {
        for (AssociatedPrereqObject apo : cdo.getListAssociations(listref, objref)) {
            Collection<Spell> spells = objref.getContainedObjects();
            Integer lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
            if (apo.hasPrerequisites()) {
                List<Prerequisite> prereqs = apo.getPrerequisiteList();
                for (Spell spell : spells) {
                    AvailableSpell as = new AvailableSpell(spelllist, spell, lvl);
                    as.addAllPrerequisites(prereqs);
                    conditionallyAvailableSpellFacet.add(id, as, cdo);
                }
            } else {
                for (Spell spell : spells) {
                    availableSpellFacet.add(id, spelllist, lvl, spell, cdo);
                }
            }
        }
    }
}
Also used : AvailableSpell(pcgen.cdom.helper.AvailableSpell) AvailableSpell(pcgen.cdom.helper.AvailableSpell) Spell(pcgen.core.spell.Spell) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 60 with Spell

use of pcgen.core.spell.Spell 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)

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