use of pcgen.core.spell.Spell 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;
}
use of pcgen.core.spell.Spell 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);
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class PlayerCharacter method addBonusKnownSpellsToList.
/**
* Adds to the provided list any spells that have been granted to the character's class by abilities
* through the use of SPELLKNOWN:CLASS tags.
*
* @param aClass The character class owning the spell list.
* @param cSpells The list of spells to be updated.
*/
public void addBonusKnownSpellsToList(CDOMObject aClass, List<CharacterSpell> cSpells) {
if (!(aClass instanceof PCClass)) {
return;
}
ClassSpellList classSpellList = aClass.get(ObjectKey.CLASS_SPELLLIST);
for (Integer spellLevel : knownSpellFacet.getScopes2(id, classSpellList)) {
for (Spell spell : knownSpellFacet.getSet(id, classSpellList, spellLevel)) {
CharacterSpell acs = null;
Collection<? extends CharacterSpell> characterSpells = getCharacterSpells(grantedSpellCache);
for (CharacterSpell cs : characterSpells) {
Spell sp = cs.getSpell();
if (spell.equals(sp) && (cs.getOwner().equals(aClass))) {
acs = cs;
break;
}
}
if (acs == null) {
acs = new CharacterSpell(aClass, spell);
acs.addInfo(spellLevel, 1, Globals.getDefaultSpellBook());
addCharacterSpell(grantedSpellCache, acs);
}
if (!cSpells.contains(acs)) {
cSpells.add(acs);
}
}
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class EquipmentBuilderFacadeImpl method getSpellChoiceForEqMod.
private boolean getSpellChoiceForEqMod(EquipmentModifier eqMod) {
String choiceValue = eqMod.getSafe(StringKey.CHOICE_STRING).substring(15);
SpellBuilderFacadeImpl spellBuilderFI = new SpellBuilderFacadeImpl(choiceValue, character, equip);
if (!delegate.showCustomSpellDialog(spellBuilderFI)) {
return false;
}
InfoFacade castingClass = spellBuilderFI.getClassRef().get();
Spell theSpell = (Spell) spellBuilderFI.getSpellRef().get();
String variant = spellBuilderFI.getVariantRef().get();
if (variant == null) {
variant = "";
}
String spellType = spellBuilderFI.getSpellTypeRef().get();
int baseSpellLevel = spellBuilderFI.getSpellLevelRef().get();
int casterLevel = spellBuilderFI.getCasterLevelRef().get();
ListFacade<AbilityFacade> metamagicFeatsList = spellBuilderFI.getSelectedMetamagicFeats();
Object[] metamagicFeats = new Object[metamagicFeatsList.getSize()];
for (int i = 0; i < metamagicFeats.length; i++) {
metamagicFeats[i] = metamagicFeatsList.getElementAt(i);
}
int charges = getNumCharges(eqMod);
EquipmentModifier existingEqMod = equip.getEqModifierKeyed(eqMod.getKeyName(), true);
if (existingEqMod == null) {
equip.addEqModifier(eqMod, true, character);
}
existingEqMod = equip.getEqModifierKeyed(eqMod.getKeyName(), true);
EqModSpellInfo.setSpellInfo(equip, existingEqMod, (PObject) castingClass, theSpell, variant, spellType, baseSpellLevel, casterLevel, metamagicFeats, charges);
return true;
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class AbstractSpellListToken method getMap.
/**
* Gets the map.
*
* @param context the context
* @param obj the obj
* @param changedLists the changed lists
* @param knownSpells Should this scan be for known spells
* @return the map
*/
protected TripleKeyMapToList<String, Integer, CDOMReference<? extends CDOMList<?>>, CDOMReference<Spell>> getMap(LoadContext context, CDOMObject obj, Collection<CDOMReference<? extends CDOMList<?>>> changedLists, boolean knownSpells) {
TripleKeyMapToList<String, Integer, CDOMReference<? extends CDOMList<?>>, CDOMReference<Spell>> map = new TripleKeyMapToList<>();
for (CDOMReference listRef : changedLists) {
AssociatedChanges<CDOMReference<Spell>> changes = context.getListContext().getChangesInList(getTokenName(), obj, listRef);
Collection<?> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
context.addWriteMessage(getTokenName() + " does not support .CLEAR");
return null;
}
MapToList<CDOMReference<Spell>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl == null || mtl.isEmpty()) {
// TODO Error message - unexpected?
continue;
}
for (CDOMReference<Spell> added : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(added)) {
Integer lvl = assoc.getAssociation(AssociationKey.SPELL_LEVEL);
String prereqString = getPrerequisiteString(context, assoc.getPrerequisiteList());
Boolean known = assoc.getAssociation(AssociationKey.KNOWN);
boolean isKnown = known != null && known.booleanValue();
if (knownSpells == isKnown) {
map.addToListFor(prereqString, lvl, listRef, added);
}
}
}
}
return map;
}
Aggregations