use of pcgen.core.character.CharacterSpell 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.character.CharacterSpell in project pcgen by PCGen.
the class PlayerCharacter method getCharacterSpells.
public Collection<CharacterSpell> getCharacterSpells(PObject spellSource, int level) {
List<CharacterSpell> csList = new ArrayList<>(getCharacterSpells(spellSource));
// Add in the spells granted by objects
addBonusKnownSpellsToList(spellSource, csList);
List<CharacterSpell> aList = new ArrayList<>();
for (CharacterSpell cs : csList) {
if (cs.hasSpellInfoFor(level)) {
aList.add(cs);
}
}
return aList;
}
use of pcgen.core.character.CharacterSpell 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();
}
use of pcgen.core.character.CharacterSpell 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);
}
use of pcgen.core.character.CharacterSpell 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));
}
}
Aggregations