use of pcgen.core.Domain in project pcgen by PCGen.
the class SpellBuilderFacadeImpl method recalcCasterLevelDetails.
private void recalcCasterLevelDetails() {
// Metamagic
int levelAdjust = 0;
for (AbilityFacade feat : selMetamagicFeats) {
levelAdjust += ((Ability) feat).getSafe(IntegerKey.ADD_SPELL_LEVEL);
}
// Limit Caster level
int minClassLevel = 1;
int maxClassLevel = 20;
PCClass aClass;
InfoFacade castingClass = pcClass.get();
if (castingClass instanceof PCClass) {
aClass = (PCClass) castingClass;
} else if (castingClass instanceof Domain) {
// TODO We should not be hardcoding the link between cleric and domains
aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, "Cleric");
} else {
Logging.errorPrint("Found Casting Class in recalc that was not a Class or Domain: " + castingClass.getClass());
return;
}
if (aClass != null) {
minClassLevel = character.getSpellSupport(aClass).getMinLevelForSpellLevel(spellLevel.get() + levelAdjust, true);
minClassLevel = Math.max(1, minClassLevel);
if (aClass.hasMaxLevel()) {
maxClassLevel = aClass.getSafe(IntegerKey.LEVEL_LIMIT);
}
}
updateAvailCasterLevels(minClassLevel, maxClassLevel);
int currCasterLevel = casterLevel.get() == null ? 0 : casterLevel.get();
if (currCasterLevel < minClassLevel) {
casterLevel.set(minClassLevel);
} else if (currCasterLevel > maxClassLevel) {
casterLevel.set(maxClassLevel);
}
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class SpellBuilderFacadeImpl method setClass.
@Override
public void setClass(InfoFacade classFacade) {
pcClass.set(classFacade);
if (classFacade instanceof Domain) {
spellList = ((Domain) classFacade).get(ObjectKey.DOMAIN_SPELLLIST);
} else {
spellList = ((PCClass) classFacade).get(ObjectKey.CLASS_SPELLLIST);
}
classSpells = new ArrayList<>();
for (AvailableSpell availSpell : masterAvailableSpellFacet.getAllSpellsInList(spellList, datasetID)) {
if (canCreateItem(availSpell.getSpell())) {
classSpells.add(availSpell);
}
}
if (spellLevel.get() == null) {
spellLevel.set(availSpellLevels.getElementAt(0));
}
processLevelChange();
}
use of pcgen.core.Domain 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.core.Domain in project pcgen by PCGen.
the class KitDeity method testApply.
@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
domainsToAdd = null;
theDeity = theDeityRef.get();
if (!aPC.canSelectDeity(theDeity)) {
warnings.add("DEITY: Cannot select deity \"" + theDeity.getDisplayName() + "\"");
return false;
}
aPC.setDeity(theDeity);
if (theDomains == null || theDomains.isEmpty()) {
// nothing else to do.
return true;
}
if (aPC.getMaxCharacterDomains() <= 0) {
warnings.add("DEITY: Not allowed to choose a domain");
return true;
}
int numberOfChoices;
if (choiceCount == null) {
numberOfChoices = theDomains.size();
} else {
numberOfChoices = choiceCount.resolve(aPC, "").intValue();
}
//
if (numberOfChoices > theDomains.size()) {
numberOfChoices = theDomains.size();
}
if (numberOfChoices == 0) {
// No choices allowed, we are done.
return true;
}
List<CDOMSingleRef<Domain>> xs;
if (numberOfChoices == theDomains.size()) {
xs = theDomains;
} else {
//
while (true) {
xs = Globals.getChoiceFromList("Choose Domains", theDomains, new ArrayList<>(), numberOfChoices, aPC);
if (!xs.isEmpty()) {
break;
}
}
}
//
for (CDOMSingleRef<Domain> ref : xs) {
Domain domain = ref.get();
if (!domain.qualifies(aPC, domain)) {
warnings.add("DEITY: Not qualified for domain \"" + domain.getDisplayName() + "\"");
continue;
}
if (aPC.getDomainCount() >= aPC.getMaxCharacterDomains()) {
warnings.add("DEITY: No more allowed domains");
return false;
}
if (!aPC.hasDefaultDomainSource()) {
warnings.add("DEITY: Cannot add domain \"" + domain.getDisplayName() + "\" as the character does not have a domain " + "source yet.");
return false;
}
if (domainsToAdd == null) {
domainsToAdd = new ArrayList<>();
}
domainsToAdd.add(domain);
aPC.addDomain(domain);
DomainApplication.applyDomain(aPC, domain);
}
aPC.calcActiveBonuses();
return true;
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class KitDeity method apply.
@Override
public void apply(PlayerCharacter aPC) {
if (theDeity == null) {
return;
}
aPC.setDeity(theDeity);
if (domainsToAdd != null) {
for (Domain domain : domainsToAdd) {
aPC.addDomain(domain);
DomainApplication.applyDomain(aPC, domain);
}
}
aPC.calcActiveBonuses();
theDeity = null;
domainsToAdd = null;
}
Aggregations