use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class PCGVer2Parser method parseTempBonusLine.
/**
* ###############################################################
* Temporary Bonuses
* ###############################################################
* @param line
**/
private void parseTempBonusLine(final String line) {
PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String message = "Illegal TempBonus line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
warnings.add(message);
return;
}
String cTag = null;
String tName = null;
boolean active = true;
for (PCGElement element : tokens.getElements()) {
final String tag = element.getName();
if (IOConstants.TAG_TEMPBONUS.equals(tag)) {
cTag = EntityEncoder.decode(element.getText());
} else if (IOConstants.TAG_TEMPBONUSTARGET.equals(tag)) {
tName = EntityEncoder.decode(element.getText());
} else if (IOConstants.TAG_TEMPBONUSACTIVE.equals(tag)) {
active = element.getText().endsWith(IOConstants.VALUE_Y);
}
}
if ((cTag == null) || (tName == null)) {
warnings.add("Illegal TempBonus line ignored: " + line);
return;
}
//$NON-NLS-1$
final StringTokenizer aTok = new StringTokenizer(cTag, "=", false);
if (aTok.countTokens() < 2) {
return;
}
final String cType = aTok.nextToken();
final String cKey = aTok.nextToken();
Equipment aEq = null;
if (!tName.equals(IOConstants.TAG_PC)) {
// bonus is applied to an equipment item
// so create a new one and add to PC
final Equipment eq = thePC.getEquipmentNamed(tName);
if (eq == null) {
return;
}
aEq = eq.clone();
//aEq.setWeight("0");
aEq.resetTempBonusList();
}
for (PCGElement element : tokens.getElements()) {
final String tag = element.getName();
final String bonus;
if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
bonus = EntityEncoder.decode(element.getText());
} else {
continue;
}
if ((bonus == null) || (bonus.length() <= 0)) {
continue;
}
BonusObj newB = null;
Object creator = null;
LoadContext context = Globals.getContext();
// type of object to set as the creator
if (cType.equals(IOConstants.TAG_FEAT)) {
for (AbilityCategory aCat : SettingsHandler.getGame().getAllAbilityCategories()) {
Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, aCat, cKey);
if (a != null) {
newB = Bonus.newBonus(context, bonus);
creator = a;
break;
}
}
} else if (cType.equals(IOConstants.TAG_EQUIPMENT)) {
Equipment aEquip = thePC.getEquipmentNamed(cKey);
if (aEquip == null) {
aEquip = context.getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, cKey);
}
if (aEquip != null) {
newB = Bonus.newBonus(context, bonus);
creator = aEquip;
}
} else if (cType.equals(IOConstants.TAG_CLASS)) {
final PCClass aClass = thePC.getClassKeyed(cKey);
if (aClass == null) {
continue;
}
int idx = bonus.indexOf('|');
newB = Bonus.newBonus(context, bonus.substring(idx + 1));
creator = aClass;
} else if (cType.equals(IOConstants.TAG_TEMPLATE)) {
PCTemplate aTemplate = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, cKey);
if (aTemplate != null) {
newB = Bonus.newBonus(context, bonus);
creator = aTemplate;
}
} else if (cType.equals(IOConstants.TAG_SKILL)) {
Skill aSkill = context.getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, cKey);
if (aSkill != null) {
newB = Bonus.newBonus(context, bonus);
creator = aSkill;
}
} else if (cType.equals(IOConstants.TAG_SPELL)) {
final Spell aSpell = context.getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, cKey);
if (aSpell != null) {
newB = Bonus.newBonus(context, bonus);
creator = aSpell;
}
} else if (cType.equals(IOConstants.TAG_NAME)) {
newB = Bonus.newBonus(context, bonus);
//newB.setCreatorObject(thePC);
}
if (newB == null) {
return;
}
TempBonusInfo tempBonusInfo;
// Check to see if the target was the PC or an Item
if (tName.equals(IOConstants.TAG_PC)) {
thePC.setApplied(newB, true);
tempBonusInfo = thePC.addTempBonus(newB, creator, thePC);
} else {
thePC.setApplied(newB, true);
aEq.addTempBonus(newB);
tempBonusInfo = thePC.addTempBonus(newB, creator, aEq);
}
if (!active) {
String bonusName = BonusDisplay.getBonusDisplayName(tempBonusInfo);
thePC.setTempBonusFilter(bonusName);
}
}
if (aEq != null) {
aEq.setAppliedName(cKey);
thePC.addTempBonusItemList(aEq);
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class PCGVer2Creator method appendSpellLines.
/*
* ###############################################################
* Character Spells Information methods
* ###############################################################
*/
/*
* #Character Spells Information
* CLASS:Wizard|CANCASTPERDAY:2,4(Totals the levels all up + includes attribute bonuses)
* SPELLNAME:Blah|SCHOOL:blah|SUBSCHOOL:blah|Etc
*
* completely changed due to new Spell API
*/
private void appendSpellLines(StringBuilder buffer) {
for (PCClass pcClass : charDisplay.getClassSet()) {
Collection<? extends CharacterSpell> sp = charDisplay.getCharacterSpells(pcClass);
List<CharacterSpell> classSpells = new ArrayList<>(sp);
// Add in the spells granted by objects
thePC.addBonusKnownSpellsToList(pcClass, classSpells);
Collections.sort(classSpells);
for (CharacterSpell cSpell : classSpells) {
for (SpellInfo spellInfo : cSpell.getInfoList()) {
CDOMObject owner = cSpell.getOwner();
List<? extends CDOMList<Spell>> lists = charDisplay.getSpellLists(owner);
if (SpellLevel.getFirstLevelForKey(cSpell.getSpell(), lists, thePC) < 0) {
Logging.errorPrint("Ignoring unqualified spell " + cSpell.getSpell() + " in list for class " + pcClass + ".");
continue;
}
if (spellInfo.getBook().equals(Globals.getDefaultSpellBook()) && thePC.getSpellSupport(pcClass).isAutoKnownSpell(cSpell.getSpell(), SpellLevel.getFirstLevelForKey(cSpell.getSpell(), lists, thePC), false, thePC) && thePC.getAutoSpells()) {
continue;
}
buffer.append(IOConstants.TAG_SPELLNAME).append(':');
buffer.append(EntityEncoder.encode(cSpell.getSpell().getKeyName()));
buffer.append('|');
buffer.append(IOConstants.TAG_TIMES).append(':');
buffer.append(spellInfo.getTimes());
buffer.append('|');
buffer.append(IOConstants.TAG_CLASS).append(':');
buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
buffer.append('|');
buffer.append(IOConstants.TAG_SPELL_BOOK).append(':');
buffer.append(EntityEncoder.encode(spellInfo.getBook()));
buffer.append('|');
buffer.append(IOConstants.TAG_SPELLLEVEL).append(':');
buffer.append(spellInfo.getActualLevel());
if (spellInfo.getNumPages() > 0) {
buffer.append('|');
buffer.append(IOConstants.TAG_SPELLNUMPAGES).append(':');
buffer.append(spellInfo.getNumPages());
}
final List<Ability> metaFeats = spellInfo.getFeatList();
if ((metaFeats != null) && (!metaFeats.isEmpty())) {
buffer.append('|');
buffer.append(IOConstants.TAG_FEATLIST).append(':');
buffer.append('[');
String del = Constants.EMPTY_STRING;
for (Ability feat : metaFeats) {
buffer.append(del);
buffer.append(IOConstants.TAG_FEAT).append(':');
buffer.append(EntityEncoder.encode(feat.getKeyName()));
//$NON-NLS-1$
del = "|";
}
buffer.append(']');
}
buffer.append('|');
appendSourceInTaggedFormat(buffer, StringPClassUtil.getStringFor(owner.getClass()) + "|" + owner.getKeyName());
buffer.append(IOConstants.LINE_SEP);
}
}
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class PlayerCharacter method calculateKnownSpellsForClassLevel.
public void calculateKnownSpellsForClassLevel(PCClass pcc) {
if (!pcc.containsListFor(ListKey.KNOWN_SPELLS) || importing || !autoKnownSpells) {
return;
}
// If this class has at least one entry in the "Known spells" tag
// And we are set up to automatically assign known spells...
List<? extends CDOMList<Spell>> spellLists = getSpellLists(pcc);
SpellSupportForPCClass spellSupport = getSpellSupport(pcc);
// Recalculate the number of spells per day of each level
// that this chracter can cast in this class.
spellSupport.calcCastPerDayMapForLevel(this);
// Get the maximum spell level that this character can cast.
final int maxCastableLevel = spellSupport.getMaxCastLevel();
for (CDOMList<Spell> list : spellLists) {
for (int spellLevel : availSpellFacet.getScopes2(id, list)) {
if (spellLevel <= maxCastableLevel) {
for (Spell spell : availSpellFacet.getSet(id, list, spellLevel)) {
if (spellSupport.isAutoKnownSpell(spell, spellLevel, true, this)) {
CharacterSpell cs = getCharacterSpellForSpell(pcc, spell, pcc);
if (cs == null) {
// Create a new character spell for this level.
cs = new CharacterSpell(pcc, spell);
cs.addInfo(spellLevel, 1, Globals.getDefaultSpellBook());
addCharacterSpell(pcc, cs);
} else {
if (cs.getSpellInfoFor(Globals.getDefaultSpellBook(), spellLevel) == null) {
cs.addInfo(spellLevel, 1, Globals.getDefaultSpellBook());
} else {
// already know this one
}
}
}
}
}
}
}
for (Domain d : getDomainSet()) {
if (pcc.getKeyName().equals(getDomainSource(d).getPcclass().getKeyName())) {
DomainApplication.addSpellsToClassForLevels(this, d, pcc, 0, maxCastableLevel);
}
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class DomainApplication method removeDomain.
/**
* Remove a domain from the character.
* @param pc The character
* @param domain The domain.
*/
public static void removeDomain(PlayerCharacter pc, Domain domain) {
ClassSource source = pc.getDomainSource(domain);
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) {
removeSpellsFromClassForLevels(pc, domain, aClass);
}
if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
DomainSpellList domainSpellList = domain.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.removeDomainSpellCount(aClass);
break;
}
}
}
}
if (!pc.isImporting()) {
BonusActivation.deactivateBonuses(domain, pc);
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class EqModCost method replaceCostSpellXPCost.
private static String replaceCostSpellXPCost(String costFormula, final String listEntry) {
String modChoice = "";
while (costFormula.contains("%SPELLXPCOST")) {
final int idx = costFormula.indexOf("%SPELLXPCOST");
if (modChoice.isEmpty()) {
final String spellName = EqModSpellInfo.getSpellInfoString(listEntry, "SPELLNAME");
final Spell aSpell = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, spellName);
if (aSpell != null) {
modChoice = Integer.toString(aSpell.getSafe(IntegerKey.XP_COST));
}
}
costFormula = costFormula.substring(0, idx) + modChoice + costFormula.substring(idx + 12);
}
return costFormula;
}
Aggregations