use of pcgen.core.Domain in project pcgen by PCGen.
the class PCCasterLevelClassTermEvaluator method resolve.
@Override
public Float resolve(PlayerCharacter pc, final CharacterSpell aSpell) {
// check if this is a domain spell
Domain domain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, source);
final ClassSource cs = pc.getDomainSource(domain);
// If source is a domain, get the Domain source (e.g, "Cleric"),
// otherwise just go with the original varSource
final String varSource = (cs != null) ? cs.getPcclass().getKeyName() : source;
final PCClass spClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, varSource);
String spellType = Constants.NONE;
if ((spClass != null) && (!spClass.getSpellType().equals(Constants.NONE))) {
spellType = spClass.getSpellType();
}
final Double d1 = pc.getTotalBonusTo("PCLEVEL", varSource);
final int pcBonus = (d1 == null) ? 0 : d1.intValue();
// does the class have a Casterlevel?
final Double d2 = pc.getTotalBonusTo("CASTERLEVEL", varSource);
final int castBonus = (d2 == null) ? 0 : d2.intValue();
// If no CASTERLEVEL has been defined for this class then
// use total class level instead
final int iClass = (spClass != null && castBonus == 0) ? pc.getDisplay().getLevel(spClass) : 0;
return (float) pc.getTotalCasterLevelWithSpellBonus(aSpell, aSpell.getSpell(), spellType, varSource, iClass + pcBonus);
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class ClassDomainBracketToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
Logging.deprecationPrint(getMessage(pcc, value));
StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
boolean first = true;
while (pipeTok.hasMoreTokens()) {
String tok = pipeTok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tok)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
}
context.getObjectContext().removeList(pcc, ListKey.DOMAIN);
continue;
}
// Note: May contain PRExxx
String domainKey;
Prerequisite prereq = null;
int openBracketLoc = tok.indexOf('[');
if (openBracketLoc == -1) {
if (tok.indexOf(']') != -1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must have '[' if it contains a PREREQ tag", context);
}
domainKey = tok;
} else {
if (tok.lastIndexOf(']') != tok.length() - 1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must end with ']' if it contains a PREREQ tag", context);
}
domainKey = tok.substring(0, openBracketLoc);
String prereqString = tok.substring(openBracketLoc + 1, tok.length() - 1);
if (prereqString.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " cannot have empty prerequisite : " + value, context);
}
prereq = getPrerequisite(prereqString);
if (prereq == null) {
return new ParseResult.Fail(getTokenName() + " had invalid prerequisite : " + prereqString, context);
}
}
CDOMSingleRef<Domain> domain = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, domainKey);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(domain);
if (prereq != null) {
qo.addPrerequisite(prereq);
}
context.getObjectContext().addToList(pcc, ListKey.DOMAIN, qo);
first = false;
}
return ParseResult.SUCCESS;
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class PreDomainTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Domain goodDomain = new Domain();
goodDomain.setName("Good");
Globals.getContext().getReferenceContext().importObject(goodDomain);
Domain animalDomain = new Domain();
animalDomain.setName("Animal");
Globals.getContext().getReferenceContext().importObject(animalDomain);
deity = new Deity();
deity.setName("Test Deity");
deity.put(ObjectKey.ALIGNMENT, CDOMDirectSingleRef.getRef(ng));
deity.putToList(Deity.DOMAINLIST, CDOMDirectSingleRef.getRef(goodDomain), new SimpleAssociatedObject());
deity.putToList(Deity.DOMAINLIST, CDOMDirectSingleRef.getRef(animalDomain), new SimpleAssociatedObject());
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class PreDomainTest method testAny.
/**
* Test for any domain.
*
* @throws Exception
*/
public void testAny() throws Exception {
final PlayerCharacter character = getCharacter();
PCClass cl = new PCClass();
character.setDefaultDomainSource(new ClassSource(cl, 1));
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREDOMAIN:1,ANY");
assertFalse("Character has no domains", PrereqHandler.passes(prereq, character, null));
character.addDomain(Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, "Good"));
assertTrue("Character has one domain", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREDOMAIN:2,ANY");
assertFalse("Character has only one domain", PrereqHandler.passes(prereq, character, null));
character.addDomain(Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, "Animal"));
assertTrue("Character has two domains", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class PreDeityDomainTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Domain goodDomain = new Domain();
goodDomain.setName("Good");
Globals.getContext().getReferenceContext().importObject(goodDomain);
Domain animalDomain = new Domain();
animalDomain.setName("Animal");
Globals.getContext().getReferenceContext().importObject(animalDomain);
deity = new Deity();
deity.setName("Test Deity");
deity.put(ObjectKey.ALIGNMENT, CDOMDirectSingleRef.getRef(ng));
deity.putToList(Deity.DOMAINLIST, CDOMDirectSingleRef.getRef(goodDomain), new SimpleAssociatedObject());
deity.putToList(Deity.DOMAINLIST, CDOMDirectSingleRef.getRef(animalDomain), new SimpleAssociatedObject());
}
Aggregations