use of pcgen.cdom.reference.CDOMSingleRef 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.cdom.reference.CDOMSingleRef 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;
}
}
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class KitSpells method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (castingClass != null) {
sb.append(castingClass.getLSTformat(false));
}
sb.append(' ').append(spellBook).append(": ");
boolean needComma = false;
for (KnownSpellIdentifier ksi : spells.getKeySet()) {
if (needComma) {
sb.append(',');
}
needComma = true;
sb.append(ksi.getLSTformat());
Set<List<CDOMSingleRef<Ability>>> abilities = spells.getSecondaryKeySet(ksi);
for (List<CDOMSingleRef<Ability>> list : abilities) {
if (list != null) {
sb.append(" [");
sb.append(ReferenceUtilities.joinLstFormat(list, ","));
sb.append(']');
}
Integer count = spells.get(ksi, list);
if (count > 1) {
sb.append(" (").append(count).append(")");
}
}
}
return sb.toString();
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class KitStat method testApply.
@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
for (Map.Entry<CDOMSingleRef<PCStat>, Formula> me : statMap.entrySet()) {
PCStat mapStat = me.getKey().get();
int sVal = me.getValue().resolve(aPC, "").intValue();
for (PCStat currentStat : aPC.getStatSet()) {
if (!aPC.isNonAbility(currentStat) && currentStat.equals(mapStat)) {
aPC.setStat(currentStat, sVal);
if ("INT".equals(currentStat.getKeyName())) {
recalculateSkillPoints(aPC);
}
break;
}
}
}
return true;
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class KitTemplate method buildSelectedTemplateMap.
/**
* Extract the templates to be applied and their choices
* @param aPC The PC the kit is being applied to.
* @param apply Is this a real application, false if a test run.
* @return The map of templates and child templates to be added
*/
private HashMapToList<PCTemplate, PCTemplate> buildSelectedTemplateMap(PlayerCharacter aPC, boolean apply) {
boolean tempShowHP = SettingsHandler.getShowHPDialogAtLevelUp();
SettingsHandler.setShowHPDialogAtLevelUp(false);
if (!apply) {
ChooserFactory.pushChooserClassname(//$NON-NLS-1$
"pcgen.util.chooser.RandomChooser");
}
HashMapToList<PCTemplate, PCTemplate> selectedMap = new HashMapToList<>();
for (CDOMSingleRef<PCTemplate> ref : templateList.getKeySet()) {
PCTemplate templateToAdd = ref.get();
List<CDOMSingleRef<PCTemplate>> subList = templateList.getListFor(ref);
List<PCTemplate> subAdded = new ArrayList<>();
if (subList != null) {
for (CDOMSingleRef<PCTemplate> subRef : subList) {
PCTemplate ownedTemplate = subRef.get();
subAdded.add(ownedTemplate);
aPC.setTemplatesAdded(templateToAdd, ownedTemplate);
}
}
aPC.addTemplate(templateToAdd);
selectedMap.initializeListFor(templateToAdd);
selectedMap.addAllToListFor(templateToAdd, subAdded);
}
if (!apply) {
ChooserFactory.popChooserClassname();
}
SettingsHandler.setShowHPDialogAtLevelUp(tempShowHP);
return selectedMap;
}
Aggregations