use of pcgen.core.spell.Spell 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.spell.Spell in project pcgen by PCGen.
the class SpellMemTokenTest method additionalSetUp.
/*
* @see TestCase#setUp()
*/
@Override
protected void additionalSetUp() throws Exception {
LoadContext context = Globals.getContext();
// Human
human = new Race();
final BonusObj bon = Bonus.newBonus(context, "FEAT|POOL|2");
human.addToListFor(ListKey.BONUS, bon);
testSpell = new Spell();
testSpell.setName("Test Spell");
testSpell.put(StringKey.KEY_NAME, "TEST_SPELL");
context.unconditionallyProcess(testSpell, "CLASSES", "KEY_TEST_ARCANE=1");
context.unconditionallyProcess(testSpell, "DOMAINS", "Fire=0");
context.unconditionallyProcess(testSpell, "CLASSES", "KEY_TEST_DIVINE=1");
arcaneClass = new PCClass();
arcaneClass.setName("TestArcane");
arcaneClass.put(StringKey.KEY_NAME, "KEY_TEST_ARCANE");
BuildUtilities.setFact(arcaneClass, "SpellType", "Arcane");
context.unconditionallyProcess(arcaneClass, "SPELLSTAT", "CHA");
arcaneClass.put(ObjectKey.SPELLBOOK, false);
arcaneClass.put(ObjectKey.MEMORIZE_SPELLS, false);
context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "KNOWN", "4,2,1");
context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "CAST", "3,1,0");
context.getReferenceContext().importObject(arcaneClass);
divineClass = new PCClass();
divineClass.setName("TestDivine");
divineClass.put(StringKey.KEY_NAME, "KEY_TEST_DIVINE");
BuildUtilities.setFact(divineClass, "SpellType", "Divine");
context.unconditionallyProcess(divineClass, "SPELLSTAT", "WIS");
divineClass.put(ObjectKey.SPELLBOOK, false);
divineClass.put(ObjectKey.MEMORIZE_SPELLS, true);
context.unconditionallyProcess(divineClass.getOriginalClassLevel(1), "CAST", "3,1,0");
context.getReferenceContext().constructCDOMObject(Domain.class, "Fire");
context.getReferenceContext().importObject(divineClass);
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class PCGVer2Creator method tempBonusName.
/**
* creates a unique tuple based on the creator and target getName()
* @param creator
* @param target
* @return temp bonus name
**/
private String tempBonusName(final Object creator, Object target) {
final StringBuilder cb = new StringBuilder(100);
cb.append(IOConstants.TAG_TEMPBONUS).append(':');
if (creator instanceof CDOMObject) {
final CDOMObject oCreator = (CDOMObject) creator;
if (oCreator instanceof Ability) {
cb.append(IOConstants.TAG_FEAT).append('=');
} else if (oCreator instanceof Spell) {
cb.append(IOConstants.TAG_SPELL).append('=');
} else if (oCreator instanceof Equipment) {
cb.append(IOConstants.TAG_EQUIPMENT).append('=');
} else if (oCreator instanceof PCClass) {
cb.append(IOConstants.TAG_CLASS).append('=');
} else if (oCreator instanceof PCTemplate) {
cb.append(IOConstants.TAG_TEMPLATE).append('=');
} else if (oCreator instanceof Skill) {
cb.append(IOConstants.TAG_SKILL).append('=');
} else {
cb.append(IOConstants.TAG_ERROR).append('=');
}
cb.append(EntityEncoder.encode(oCreator.getKeyName()));
// Hmm, need to get the Type of oCreater also?
// Might be required so the PCGVer2Parser can search correct type to re-create
} else {
return Constants.EMPTY_STRING;
}
cb.append('|');
cb.append(IOConstants.TAG_TEMPBONUSTARGET).append(':');
if (target instanceof PlayerCharacter) {
cb.append(IOConstants.TAG_PC);
} else if (target instanceof Equipment) {
cb.append(EntityEncoder.encode(((Equipment) target).getName()));
}
return cb.toString();
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class PCGVer2Creator method appendSpellListLines.
/*
* ###############################################################
* Spell List Information methods
* ###############################################################
*/
/*
* #Spell List Information
* SPELLLIST:sourceclassname|spelllistentry|spelllistentry
*/
private void appendSpellListLines(StringBuilder buffer) {
for (PCClass pcClass : charDisplay.getClassSet()) {
TransitionChoice<CDOMListObject<Spell>> csc = pcClass.get(ObjectKey.SPELLLIST_CHOICE);
if (csc != null) {
List<? extends CDOMList<Spell>> assocList = charDisplay.getSpellLists(pcClass);
buffer.append(IOConstants.TAG_SPELLLIST).append(':');
buffer.append(pcClass.getKeyName());
for (CDOMList<Spell> spell : assocList) {
buffer.append('|');
if (ClassSpellList.class.equals(spell.getClass())) {
buffer.append("CLASS");
} else {
buffer.append("DOMAIN");
}
buffer.append('.').append(spell.getLSTformat());
}
buffer.append(IOConstants.LINE_SEP);
}
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class SpellsLst method processAdds.
private Collection<? extends String> processAdds(LoadContext context, MapToList<CDOMReference<Spell>, AssociatedPrereqObject> mtl) {
TripleKeyMap<Set<Prerequisite>, Map<AssociationKey<?>, Object>, CDOMReference<Spell>, String> m = new TripleKeyMap<>();
for (CDOMReference<Spell> lw : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(lw)) {
Map<AssociationKey<?>, Object> am = new HashMap<>();
String dc = null;
for (AssociationKey<?> ak : assoc.getAssociationKeys()) {
// else
if (AssociationKey.DC_FORMULA.equals(ak)) {
dc = assoc.getAssociation(AssociationKey.DC_FORMULA);
} else {
am.put(ak, assoc.getAssociation(ak));
}
}
m.put(new HashSet<>(assoc.getPrerequisiteList()), am, lw, dc);
}
}
Set<String> set = new TreeSet<>();
for (Set<Prerequisite> prereqs : m.getKeySet()) {
for (Map<AssociationKey<?>, Object> am : m.getSecondaryKeySet(prereqs)) {
StringBuilder sb = new StringBuilder();
sb.append(am.get(AssociationKey.SPELLBOOK));
Formula times = AssociationKey.TIMES_PER_UNIT.cast(am.get(AssociationKey.TIMES_PER_UNIT));
sb.append(Constants.PIPE).append("TIMES=").append(times);
String timeunit = AssociationKey.TIME_UNIT.cast(am.get(AssociationKey.TIME_UNIT));
if (timeunit != null) {
sb.append(Constants.PIPE).append("TIMEUNIT=").append(timeunit);
}
String casterLvl = AssociationKey.CASTER_LEVEL.cast(am.get(AssociationKey.CASTER_LEVEL));
if (casterLvl != null) {
sb.append(Constants.PIPE).append("CASTERLEVEL=").append(casterLvl);
}
Set<String> spellSet = new TreeSet<>();
for (CDOMReference<Spell> spell : m.getTertiaryKeySet(prereqs, am)) {
String spellString = spell.getLSTformat(false);
String dc = m.get(prereqs, am, spell);
if (dc != null) {
spellString += Constants.COMMA + dc;
}
spellSet.add(spellString);
}
sb.append(Constants.PIPE);
sb.append(StringUtil.join(spellSet, Constants.PIPE));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
set.add(sb.toString());
}
}
return set;
}
Aggregations