use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.
the class DomainApplication method addSpellsToClassForLevels.
public static void addSpellsToClassForLevels(PlayerCharacter pc, Domain d, PCClass aClass, int minLevel, int maxLevel) {
if (aClass == null) {
return;
}
for (int aLevel = minLevel; aLevel <= maxLevel; aLevel++) {
Collection<Spell> domainSpells = pc.getSpellsIn(d.get(ObjectKey.DOMAIN_SPELLLIST), aLevel);
for (Spell spell : domainSpells) {
List<CharacterSpell> slist = pc.getCharacterSpells(aClass, spell, Globals.getDefaultSpellBook(), aLevel);
boolean flag = true;
for (CharacterSpell cs1 : slist) {
flag = !(cs1.getOwner().equals(d));
if (!flag) {
break;
}
}
if (flag) {
CharacterSpell cs = new CharacterSpell(d, spell);
cs.addInfo(aLevel, 1, Globals.getDefaultSpellBook());
pc.addCharacterSpell(aClass, cs);
}
}
}
}
use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.
the class DomainApplication method applyDomain.
/**
* Sets the locked flag on a PC
*
* @param pc
*/
public static void applyDomain(PlayerCharacter pc, Domain d) {
ClassSource source = pc.getDomainSource(d);
PCClass aClass = pc.getClassKeyed(source.getPcclass().getKeyName());
if (aClass != null) {
int maxLevel;
for (maxLevel = 0; maxLevel < 10; maxLevel++) {
if (pc.getSpellSupport(aClass).getCastForLevel(maxLevel, pc) == 0) {
break;
}
}
if (maxLevel > 0) {
addSpellsToClassForLevels(pc, d, aClass, 0, maxLevel - 1);
}
if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
DomainSpellList domainSpellList = d.get(ObjectKey.DOMAIN_SPELLLIST);
final List<Spell> aList = pc.getAllSpellsInLists(Collections.singletonList(domainSpellList));
for (Spell gcs : aList) {
if (SpellLevel.getFirstLvlForKey(gcs, domainSpellList, pc) < maxLevel) {
pc.setDomainSpellCount(aClass, 1);
break;
}
}
}
}
Collection<CDOMReference<Spell>> mods = d.getSafeListMods(Spell.SPELLS);
for (CDOMReference<Spell> ref : mods) {
Collection<Spell> spells = ref.getContainedObjects();
Collection<AssociatedPrereqObject> assoc = d.getListAssociations(Spell.SPELLS, ref);
for (AssociatedPrereqObject apo : assoc) {
if (!PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, d)) {
continue;
}
for (Spell s : spells) {
String book = apo.getAssociation(AssociationKey.SPELLBOOK);
List<CharacterSpell> aList = pc.getCharacterSpells(aClass, s, book, -1);
if (aList.isEmpty()) {
Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
CharacterSpell cs = new CharacterSpell(d, s);
int resolvedTimes = times.resolve(pc, d.getQualifiedKey()).intValue();
cs.addInfo(1, resolvedTimes, book);
pc.addCharacterSpell(aClass, cs);
}
}
}
}
}
use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.
the class SpellMemTokenTest method testPreparedCaster.
/**
* Test the SPELLMEM tag for a spontaneous caster. Checks that the
* list of known spells is auto populated and that a spell can be added to
* a prepared list, and that the spell can be retrieved correctly from both
* books.
*/
public void testPreparedCaster() {
PlayerCharacter character = getCharacter();
String spellBook = "Travel";
character.setRace(human);
character.incrementClassLevel(1, divineClass, true);
PCClass dc = character.getClassKeyed(divineClass.getKeyName());
CharacterSpell aCharacterSpell = new CharacterSpell(dc, testSpell);
aCharacterSpell.addInfo(1, 1, null);
character.addCharacterSpell(dc, aCharacterSpell);
character.addSpellBook(spellBook);
List<CharacterSpell> spellList = character.getCharacterSpells(dc, testSpell, "", 1);
CharacterSpell charSpell = spellList.get(0);
String result = character.addSpell(charSpell, null, divineClass.getKeyName(), Globals.getDefaultSpellBook(), 1, 1);
assertEquals("Known spells already has all spells, should reject.", "The Known Spells spellbook contains all spells of this level that you " + "know. You cannot place spells in multiple times.", result);
result = character.addSpell(charSpell, null, divineClass.getKeyName(), spellBook, 1, 1);
assertEquals("No WIS, so should reject attempt to add spell", "You can only prepare 0 spells for level 1 " + "\nand there are no higher-level slots available.", result);
setPCStat(character, wis, 12);
character.calcActiveBonuses();
result = character.addSpell(charSpell, null, divineClass.getKeyName(), spellBook, 1, 1);
assertEquals("Should be no error messages from adding spell", "", result);
SpellMemToken token = new SpellMemToken();
assertEquals("Retrieve spell from known list of divine caster.", "Test Spell", token.getToken("SPELLMEM.0.0.1.0.NAME", character, null));
assertEquals("Retrieve spell from prepared list of divine caster.", "Test Spell", token.getToken("SPELLMEM.0.2.1.0.NAME", character, null));
}
use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.
the class Gui2InfoFactory method produceSpellListInfo.
/**
* Produce the HTML info label for a prepared spell list.
* @param book The spell list being output.
* @return The HTML info for the list.
*/
private String produceSpellListInfo(SpellBook spelllist) {
final HtmlInfoBuilder b = new HtmlInfoBuilder(spelllist.getName());
//$NON-NLS-1$
b.append(" (");
b.append(spelllist.getTypeName());
//$NON-NLS-1$
b.append(")");
b.appendLineBreak();
if (spelllist.getDescription() != null) {
//$NON-NLS-1$
b.appendI18nElement("in_descrip", spelllist.getDescription());
b.appendLineBreak();
}
// Look at each spell on each spellcasting class
for (PCClass pcClass : charDisplay.getClassSet()) {
Map<Integer, Integer> spellCountMap = new TreeMap<>();
int highestSpellLevel = -1;
Collection<? extends CharacterSpell> sp = charDisplay.getCharacterSpells(pcClass);
List<CharacterSpell> classSpells = new ArrayList<>(sp);
// Add in the spells granted by objects
pc.addBonusKnownSpellsToList(pcClass, classSpells);
for (CharacterSpell charSpell : classSpells) {
for (SpellInfo spellInfo : charSpell.getInfoList()) {
if (!spelllist.getName().equals(spellInfo.getBook())) {
continue;
}
int level = spellInfo.getActualLevel();
int count = spellCountMap.containsKey(level) ? spellCountMap.get(level) : 0;
count += spellInfo.getTimes();
spellCountMap.put(level, count);
if (level > highestSpellLevel) {
highestSpellLevel = level;
}
}
}
if (!spellCountMap.isEmpty()) {
//$NON-NLS-1$
b.append("<table border=1><tr><td><font size=-1><b>");
b.append(OutputNameFormatting.piString(pcClass, false));
//$NON-NLS-1$
b.append("</b></font></td>");
for (int i = 0; i <= highestSpellLevel; ++i) {
//$NON-NLS-1$
b.append("<td><font size=-2><b><center> ");
b.append(String.valueOf(i));
//$NON-NLS-1$
b.append(" </b></center></font></td>");
}
//$NON-NLS-1$
b.append("</tr>");
//$NON-NLS-1$
b.append("<tr><td><font size=-1><b>Prepared</b></font></td>");
for (int i = 0; i <= highestSpellLevel; ++i) {
//$NON-NLS-1$
b.append("<td><font size=-1><center>");
b.append(String.valueOf(spellCountMap.get(i) == null ? 0 : spellCountMap.get(i)));
//$NON-NLS-1$
b.append("</center></font></td>");
}
//$NON-NLS-1$
b.append("</tr></table>");
b.appendLineBreak();
}
}
return b.toString();
}
use of pcgen.core.character.CharacterSpell in project pcgen by PCGen.
the class SpellSupportFacadeImpl method addSpellToCharacter.
/**
* Add a spell to the named book for the character. The request will be
* validated and any errors shown to the user by the UIDelegate.
*
* @param spell The spell to be added.
* @param bookName The book to add the spell to.
* @param metamagicFeats List of the metamagic feats that should be applied to this spell.
* @return The new SpellNode, or null if the selection was invalid.
*/
private SpellNode addSpellToCharacter(SpellNode spell, String bookName, List<Ability> metamagicFeats) {
if (!(spell.getSpell() instanceof SpellFacadeImplem)) {
return null;
}
if (spell.getSpellcastingClass() == null) {
return null;
}
CharacterSpell charSpell = ((SpellFacadeImplem) spell.getSpell()).getCharSpell();
if (charSpell == null) {
return null;
}
int level = Integer.parseInt(spell.getSpellLevel());
for (Ability ability : metamagicFeats) {
level += ability.getSafe(IntegerKey.ADD_SPELL_LEVEL);
}
String errorMsg = pc.addSpell(charSpell, metamagicFeats, spell.getSpellcastingClass().getKeyName(), bookName, level, level);
if (!StringUtils.isEmpty(errorMsg)) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, errorMsg);
return null;
}
SpellInfo spellInfo = charSpell.getSpellInfoFor(bookName, level, metamagicFeats);
boolean isKnown = Globals.getDefaultSpellBook().equals(bookName);
SpellFacadeImplem spellImplem = new SpellFacadeImplem(pc, charSpell.getSpell(), charSpell, spellInfo);
SpellNodeImpl node = new SpellNodeImpl(spellImplem, spell.getSpellcastingClass(), String.valueOf(spellInfo.getActualLevel()), getRootNode(bookName));
return node;
}
Aggregations