use of pcgen.core.Domain in project pcgen by PCGen.
the class PCMaxCastableDomainTermEvaluator method resolve.
@Override
public Float resolve(PlayerCharacter pc) {
Domain domain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, domainKey);
if (domain == null) {
return 0.0f;
}
ClassSource source = pc.getDomainSource(domain);
if (source == null) {
return 0.0f;
}
String classKey = source.getPcclass().getKeyName();
PCClass spClass = pc.getClassKeyed(classKey);
int cutoff = pc.getSpellSupport(spClass).getHighestLevelSpell();
Float max = 0.0f;
if (pc.getSpellSupport(spClass).hasCastList()) {
for (int i = 0; i < cutoff; i++) {
if (pc.getSpellSupport(spClass).getCastForLevel(i, pc) != 0) {
max = Math.max(max, i);
}
}
} else {
for (int i = 0; i < cutoff; i++) {
if (pc.getSpellSupport(spClass).getKnownForLevel(i, pc) != 0) {
max = Math.max(max, i);
}
}
}
return max;
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class PCClassLevelDomainTest method testSimple.
@Test
public void testSimple() throws PersistenceLayerException {
PCClass source = create(PCClass.class, "Source");
PCClassLevel pcl = source.getOriginalClassLevel(2);
Domain granted = create(Domain.class, "Granted");
ParseResult result = token.parseToken(context, pcl, "Granted");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
finishLoad();
assertEquals(0, domainFacet.getCount(id));
classFacet.addClass(id, source);
PCClass pcc = pc.getClassKeyed(source.getKeyName());
classFacet.setLevel(id, pcc, 1);
//TODO get rid of this using facets :)
DomainApplication.addDomainsUpToLevel(source, 1, pc);
assertEquals(0, domainFacet.getCount(id));
classFacet.setLevel(id, pcc, 2);
DomainApplication.addDomainsUpToLevel(source, 2, pc);
assertTrue(domainFacet.contains(id, granted));
assertEquals(1, domainFacet.getCount(id));
DomainApplication.removeDomainsForLevel(source, 2, pc);
DomainApplication.removeDomainsForLevel(source, 1, pc);
pc.validateCharacterDomains();
classFacet.removeClass(id, source);
assertEquals(0, domainFacet.getCount(id));
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class PCGVer2Parser method parseSpellLine.
/*
* ###############################################################
* Character Spells Information methods
* ###############################################################
*/
private void parseSpellLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String message = "Illegal Spell line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
warnings.add(message);
return;
}
Spell aSpell = null;
PCClass aPCClass = null;
PObject source = null;
String spellBook = null;
int times = 1;
int spellLevel = 0;
int numPages = 0;
final List<Ability> metaFeats = new ArrayList<>();
int ppCost = -1;
for (final PCGElement element : tokens.getElements()) {
final String tag = element.getName();
if (IOConstants.TAG_SPELLNAME.equals(tag)) {
String spellName = EntityEncoder.decode(element.getText());
spellName = SpellMigration.getNewSpellKey(spellName, pcgenVersion, SettingsHandler.getGame().getName());
// either NULL (no spell) a Spell instance,
aSpell = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, spellName);
if (aSpell == null) {
final String message = "Could not find spell named: " + spellName;
warnings.add(message);
return;
}
} else if (IOConstants.TAG_TIMES.equals(tag)) {
try {
times = Integer.parseInt(element.getText());
} catch (NumberFormatException nfe) {
// nothing we can do about it
}
} else if (IOConstants.TAG_CLASS.equals(tag)) {
final String classKey = EntityEncoder.decode(element.getText());
aPCClass = thePC.getClassKeyed(classKey);
if (aPCClass == null) {
final String message = "Invalid class specification: " + classKey;
warnings.add(message);
return;
}
} else if (IOConstants.TAG_SPELL_BOOK.equals(tag)) {
spellBook = EntityEncoder.decode(element.getText());
} else if (IOConstants.TAG_SPELLLEVEL.equals(tag)) {
try {
spellLevel = Integer.parseInt(element.getText());
} catch (NumberFormatException nfe) {
// nothing we can do about it
}
} else if (IOConstants.TAG_SPELLPPCOST.equals(tag)) {
try {
ppCost = Integer.parseInt(element.getText());
} catch (NumberFormatException nfe) {
// nothing we can do about it
}
} else if (IOConstants.TAG_SPELLNUMPAGES.equals(tag)) {
try {
numPages = Integer.parseInt(element.getText());
} catch (NumberFormatException nfe) {
// nothing we can do about it
}
} else if (IOConstants.TAG_SOURCE.equals(tag)) {
String typeName = Constants.EMPTY_STRING;
String objectKey = Constants.EMPTY_STRING;
for (final PCGElement child : element.getChildren()) {
final String childTag = child.getName();
if (IOConstants.TAG_TYPE.equals(childTag)) {
typeName = child.getText().toUpperCase();
} else if (IOConstants.TAG_NAME.equals(childTag)) {
objectKey = child.getText();
}
}
if (IOConstants.TAG_DOMAIN.equals(typeName)) {
Domain domain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(DOMAIN_CLASS, objectKey);
ClassSource cs = thePC.getDomainSource(domain);
if (cs == null) {
final String message = "Could not find domain: " + objectKey;
warnings.add(message);
return;
}
source = domain;
} else {
// it's either the class, sub-class or a cast-as class
// first see if it's the class
ClassSpellList csl = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(ClassSpellList.class, objectKey);
if (((aPCClass != null) && objectKey.equals(aPCClass.getKeyName())) || (aPCClass != null && thePC.getSpellLists(aPCClass).contains(csl))) {
source = aPCClass;
} else {
// see if PC has the class
source = thePC.getClassKeyed(objectKey);
}
}
} else if (IOConstants.TAG_FEATLIST.equals(tag)) {
for (PCGElement child : element.getChildren()) {
final String featKey = EntityEncoder.decode(child.getText());
final Ability anAbility = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, featKey);
if (anAbility != null) {
metaFeats.add(anAbility);
}
}
}
}
if ((aPCClass == null) || (spellBook == null)) {
final String message = "Illegal Spell line ignored: " + line;
warnings.add(message);
return;
}
/*
* this can only happen if the source type was NOT DOMAIN!
*/
if (source == null) {
source = aPCClass;
}
// if (obj instanceof List)
// {
// // find the instance of Spell in this class
// // best suited to this spell
// for (final Spell spell : (ArrayList<Spell>) obj)
// {
// // valid spell has a non-negative spell level
// if ((spell != null)
// && (SpellLevel.getFirstLevelForKey(spell,
// thePC.getSpellLists(source), thePC) >= 0))
// {
// aSpell = spell;
// break;
// }
// }
// if (aSpell == null)
// {
// Logging.errorPrint("Could not resolve spell " + obj.toString());
// }
// }
// if (aSpell == null)
// {
// final String message =
// "Could not find spell named: " + String.valueOf(obj);
// warnings.add(message);
//
// return;
// }
// just to make sure the spellbook is present
thePC.addSpellBook(spellBook);
final SpellBook book = thePC.getSpellBookByName(spellBook);
thePC.calculateKnownSpellsForClassLevel(aPCClass);
final Integer[] spellLevels = SpellLevel.levelForKey(aSpell, thePC.getSpellLists(source), thePC);
boolean found = false;
for (int sindex = 0; sindex < spellLevels.length; ++sindex) {
final int level = spellLevels[sindex];
final int metmagicLevels = totalAddedLevelsFromMetamagic(metaFeats);
if (spellLevel > 0 && spellLevel != (level + metmagicLevels)) {
// Skip spell in class lists that does not match level the character knows it.
continue;
}
if (level < 0) {
Collection<CDOMReference<Spell>> mods = source.getListMods(Spell.SPELLS);
if (mods == null) {
continue;
}
for (CDOMReference<Spell> ref : mods) {
Collection<Spell> refSpells = ref.getContainedObjects();
Collection<AssociatedPrereqObject> assocs = source.getListAssociations(Spell.SPELLS, ref);
for (Spell sp : refSpells) {
if (aSpell.getKeyName().equals(sp.getKeyName())) {
for (AssociatedPrereqObject apo : assocs) {
String sb = apo.getAssociation(AssociationKey.SPELLBOOK);
if (spellBook.equals(sb)) {
found = true;
break;
}
}
}
}
}
continue;
}
found = true;
// do not load auto knownspells into default spellbook
if (spellBook.equals(Globals.getDefaultSpellBook()) && thePC.getSpellSupport(aPCClass).isAutoKnownSpell(aSpell, level, false, thePC) && thePC.getAutoSpells()) {
continue;
}
CharacterSpell aCharacterSpell = thePC.getCharacterSpellForSpell(aPCClass, aSpell, source);
// so we'll need to add it to the list
if (aCharacterSpell == null) {
aCharacterSpell = new CharacterSpell(source, aSpell);
aCharacterSpell.addInfo(level, times, spellBook);
thePC.addCharacterSpell(aPCClass, aCharacterSpell);
}
SpellInfo aSpellInfo = null;
if (source.getKeyName().equals(aPCClass.getKeyName()) || !spellBook.equals(Globals.getDefaultSpellBook())) {
aSpellInfo = aCharacterSpell.getSpellInfoFor(spellBook, spellLevel);
// metaFeats list have to do with this?
if ((aSpellInfo == null) || !metaFeats.isEmpty()) {
aSpellInfo = aCharacterSpell.addInfo(spellLevel, times, spellBook);
}
}
if (aSpellInfo != null) {
if (!metaFeats.isEmpty()) {
aSpellInfo.addFeatsToList(metaFeats);
}
aSpellInfo.setActualPPCost(ppCost);
aSpellInfo.setNumPages(numPages);
book.setNumPagesUsed(book.getNumPagesUsed() + numPages);
book.setNumSpells(book.getNumSpells() + 1);
}
}
if (!found) {
final String message = "Could not find spell " + aSpell.getDisplayName() + " in " + shortClassName(source) + " " + source.getDisplayName();
warnings.add(message);
}
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class PCGVer2Parser method parseDomainLine.
private void parseDomainLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalDomain", line, pcgpex.getMessage());
warnings.add(msg);
return;
}
final Iterator<PCGElement> it = tokens.getElements().iterator();
if (it.hasNext()) {
PCGElement element = it.next();
// the first element defines the domain name
final String domainKey = EntityEncoder.decode(element.getText());
final Domain aDomain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, domainKey);
if ((aDomain == null) && (!Constants.NONE.equals(domainKey))) {
// TODO
// create Domain object from
// information contained in pcg
// But for now just issue a warning
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.DomainNotFound", domainKey);
warnings.add(msg);
} else if (!thePC.hasDomain(aDomain) && (!Constants.NONE.equals(domainKey))) {
// PC doesn't have the domain, so create a new
// one and add it to the PC domain list
ClassSource source = null;
String fullassoc = null;
while (it.hasNext()) {
element = it.next();
String tag = element.getName();
if (IOConstants.TAG_SOURCE.equals(tag)) {
source = getDomainSource(sourceElementToString(element));
} else if (IOConstants.TAG_ASSOCIATEDDATA.equals(tag)) {
if (fullassoc != null) {
warnings.add("Found multiple selections for Domain: " + aDomain.getKeyName());
}
fullassoc = EntityEncoder.decode(element.getText());
} else if (tag.equals(IOConstants.TAG_DOMAINGRANTS)) {
//Can safely ignore
} else if (!tag.equals(IOConstants.TAG_ADDTOKEN)) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.UnknownDomainInfo", tag + ":" + element.getText());
warnings.add(msg);
}
}
if (source == null) {
warnings.add("Domain not added due to no source: " + domainKey);
} else {
domainInputFacet.importSelection(thePC.getCharID(), aDomain, fullassoc, source);
DomainApplication.applyDomain(thePC, aDomain);
}
try {
//Must process ADD after DOMAIN is added to the PC
for (PCGElement e : new PCGTokenizer(line).getElements()) {
String tag = e.getName();
if (tag.equals(IOConstants.TAG_ADDTOKEN)) {
parseAddTokenInfo(e, aDomain);
}
}
} catch (PCGParseException pcgpex) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalDomain", line, pcgpex.getMessage());
warnings.add(msg);
return;
}
} else {
// PC already has this domain
Logging.errorPrintLocalised(//$NON-NLS-1$
"Errors.PCGenParser.DuplicateDomain", domainKey);
}
}
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class DomainTargetSaveRestoreTest method testDomainCSkill.
@Test
public void testDomainCSkill() {
Skill granted = create(Skill.class, "Granted");
new ExclusiveToken().parseToken(context, granted, "Yes");
Domain target = create(getObjectClass(), "Target");
create(Skill.class, "MySkill");
new CskillToken().parseToken(context, target, "LIST");
new SkillToken().parseToken(context, target, "Granted|MySkill");
Object o = prepare(target);
finishLoad();
applyObject(target);
PCClass myclass = pc.getClassKeyed("MyClass");
assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(granted, myclass));
runRoundRobin(getPreEqualityCleanup());
assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(granted, myclass));
myclass = reloadedPC.getClassKeyed("MyClass");
assertEquals(SkillCost.CLASS, reloadedPC.getSkillCostForClass(granted, myclass));
remove(o);
reloadedPC.setDirty(true);
assertEquals(SkillCost.EXCLUSIVE, reloadedPC.getSkillCostForClass(granted, myclass));
}
Aggregations