use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class SpellBuilderFacadeImpl method addSpellInfoToList.
private void addSpellInfoToList(final Spell aSpell, List<PCClass> classes, List<Domain> domains, String spellType) {
Set<String> unfoundItems = new HashSet<>();
final HashMapToList<CDOMList<Spell>, Integer> levelInfo = character.getSpellLevelInfo(aSpell);
if ((levelInfo == null) || (levelInfo.isEmpty())) {
return;
}
for (CDOMList<Spell> spellList : levelInfo.getKeySet()) {
if (spellList instanceof ClassSpellList) {
String key = spellList.getKeyName();
final PCClass aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, key);
if (aClass != null) {
if (!("".equals(spellType)) && (!spellType.contains(aClass.getSpellType()))) {
continue;
}
if (!classes.contains(aClass)) {
classes.add(aClass);
}
} else {
key = 'C' + key;
if (!unfoundItems.contains(key)) {
unfoundItems.add(key);
Logging.errorPrint("Class " + key.substring(1) + " not found. Was used in spell " + aSpell);
}
}
} else if (spellList instanceof DomainSpellList) {
if (!("".equals(spellType)) && (!spellType.contains("Divine"))) {
continue;
}
String key = spellList.getKeyName();
final Domain aDomain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, key);
if (aDomain != null) {
if (!domains.contains(aDomain)) {
domains.add(aDomain);
}
} else {
key = 'D' + key;
if (!unfoundItems.contains(key)) {
unfoundItems.add(key);
Logging.errorPrint("Domain " + key.substring(1) + " not found. Was used in spell " + aSpell);
}
}
} else {
Logging.errorPrint("Unknown spell source: " + spellList);
}
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class SpellBuilderFacadeImpl method processLevelChange.
/**
* Update lists that depend on the selected level of spell
* e.g. the list of spells
*/
private void processLevelChange() {
int baseSpellLevel = spellLevel.get();
// List of available spells
List<Spell> spellsOfLevel = new ArrayList<>();
for (AvailableSpell availSpell : classSpells) {
if (availSpell.getLevel() == baseSpellLevel) {
spellsOfLevel.add(availSpell.getSpell());
}
}
Globals.sortPObjectListByName(spellsOfLevel);
availSpells.setContents(spellsOfLevel);
InfoFacade selSpell = spell.get();
if (selSpell == null || !spellsOfLevel.contains(selSpell)) {
Spell newSpell = null;
if (!spellsOfLevel.isEmpty()) {
newSpell = spellsOfLevel.get(0);
}
selectSpell(newSpell);
}
// Spell type
List<String> spellTypeList = getSpellTypeList();
availSpellTypes.setContents(spellTypeList);
spellType.set(spellTypeList.get(0));
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class Gui2InfoFactory method getDescription.
@Override
public String getDescription(TempBonusFacade tempBonusFacade) {
if (tempBonusFacade == null || !(tempBonusFacade instanceof TempBonusFacadeImpl)) {
return EMPTY_STRING;
}
try {
TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) tempBonusFacade;
CDOMObject originObj = tempBonus.getOriginObj();
String desc = originObj.getSafe(StringKey.TEMP_DESCRIPTION);
if (StringUtils.isEmpty(desc)) {
if (originObj instanceof Spell) {
Spell sp = (Spell) originObj;
desc = DescriptionFormatting.piWrapDesc(sp, pc.getDescription(sp), false);
} else if (originObj instanceof Ability) {
Ability ab = (Ability) originObj;
List<CNAbility> wrappedAbility = Collections.singletonList(CNAbilityFactory.getCNAbility(ab.getCDOMCategory(), Nature.NORMAL, ab));
desc = DescriptionFormatting.piWrapDesc(ab, pc.getDescription(wrappedAbility), false);
}
}
return desc;
} catch (Exception e) {
//$NON-NLS-1$
Logging.errorPrint("Failed to get description for " + tempBonusFacade, e);
return EMPTY_STRING;
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class KitSpells method testApply.
@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
theSpells = null;
PCClass aClass = findDefaultSpellClass(castingClass, aPC);
if (aClass == null) {
warnings.add("SPELLS: Character does not have " + castingClass + " spellcasting class.");
return false;
}
String workingBook = spellBook == null ? Globals.getDefaultSpellBook() : spellBook;
List<KitSpellBookEntry> aSpellList = new ArrayList<>();
if (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS) && !workingBook.equals(Globals.getDefaultSpellBook())) {
warnings.add("SPELLS: " + aClass.getDisplayName() + " can only add to " + Globals.getDefaultSpellBook());
return false;
}
for (KnownSpellIdentifier ksi : spells.getKeySet()) {
Collection<Spell> allSpells = ksi.getContainedSpells(aPC, Collections.singletonList(aClass.get(ObjectKey.CLASS_SPELLLIST)));
Set<List<CDOMSingleRef<Ability>>> feats = spells.getSecondaryKeySet(ksi);
for (Spell sp : allSpells) {
for (List<CDOMSingleRef<Ability>> list : feats) {
Integer count = spells.get(ksi, list);
aSpellList.add(new KitSpellBookEntry(spellBook, sp, list, count));
}
}
}
final Formula choiceFormula = getCount();
int numberOfChoices;
if (choiceFormula == null) {
numberOfChoices = aSpellList.size();
} else {
numberOfChoices = choiceFormula.resolve(aPC, "").intValue();
}
//
if (numberOfChoices > aSpellList.size()) {
numberOfChoices = aSpellList.size();
}
if (numberOfChoices == 0) {
return false;
}
List<KitSpellBookEntry> xs;
if (numberOfChoices == aSpellList.size()) {
xs = aSpellList;
} else {
//
while (true) {
xs = Globals.getChoiceFromList("Choose " + aClass.getKeyName() + " spell(s) for " + workingBook, aSpellList, new ArrayList<>(), numberOfChoices, aPC);
if (!xs.isEmpty()) {
break;
}
}
}
//
for (KitSpellBookEntry obj : xs) {
if (obj != null) {
obj.setPCClass(aClass);
if (theSpells == null) {
theSpells = new ArrayList<>();
}
theSpells.add(obj);
} else {
warnings.add("SPELLS: Non-existant spell chosen");
}
}
if (theSpells != null && !theSpells.isEmpty()) {
return true;
}
return false;
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class KitSpells method updatePCSpells.
/**
* Add spells from this Kit to the PC
*
* @param pc The PC to add the spells to
* @param aSpell A Spell to add to the PC
* @param pcClass The class instance the spells are to be added to.
*/
private void updatePCSpells(final PlayerCharacter pc, final KitSpellBookEntry aSpell, final PCClass pcClass) {
Spell spell = aSpell.getSpell();
int spLevel = 99;
// Check to see if we have any domains that have this spell.
PObject owner = null;
if (pc.hasDomains()) {
for (Domain domain : pc.getDomainSet()) {
List<? extends CDOMList<Spell>> lists = pc.getSpellLists(domain);
int newLevel = SpellLevel.getFirstLevelForKey(spell, lists, pc);
if (newLevel > 0 && newLevel < spLevel) {
spLevel = newLevel;
owner = domain;
}
}
}
if (spLevel == 99) {
spLevel = SpellLevel.getFirstLevelForKey(spell, pc.getSpellLists(pcClass), pc);
owner = pcClass;
}
if (spLevel < 0) {
Logging.errorPrint("SPELLS: " + pcClass.getDisplayName() + " cannot cast spell \"" + spell.getKeyName() + "\"");
return;
}
final CharacterSpell cs = new CharacterSpell(owner, spell);
final List<CDOMSingleRef<Ability>> modifierList = aSpell.getModifiers();
int adjustedLevel = spLevel;
List<Ability> metamagicFeatList = new ArrayList<>();
for (CDOMSingleRef<Ability> feat : modifierList) {
Ability anAbility = feat.get();
adjustedLevel += anAbility.getSafe(IntegerKey.ADD_SPELL_LEVEL);
metamagicFeatList.add(anAbility);
}
if (metamagicFeatList.size() <= 0) {
metamagicFeatList = null;
}
if (!pc.hasSpellBook(aSpell.getBookName())) {
pc.addSpellBook(aSpell.getBookName());
}
for (int numTimes = 0; numTimes < aSpell.getCopies(); numTimes++) {
final String aString = pc.addSpell(cs, metamagicFeatList, pcClass.getKeyName(), aSpell.getBookName(), adjustedLevel, spLevel);
if (!aString.isEmpty()) {
Logging.errorPrint("Add spell failed:" + aString);
return;
}
}
}
Aggregations