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();
}
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();
}
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;
}
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);
}
}
}
}
}
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;
}
Aggregations