use of pcgen.core.Domain in project pcgen by PCGen.
the class CharacterFacadeImpl method addDomain.
/**
* @see pcgen.core.facade.CharacterFacade#addDomain(pcgen.core.facade.DomainFacade)
*/
@Override
public void addDomain(DomainFacade domainFacade) {
if (!(domainFacade instanceof DomainFacadeImpl)) {
return;
}
DomainFacadeImpl domainFI = (DomainFacadeImpl) domainFacade;
Domain domain = domainFI.getRawObject();
if (charDisplay.hasDomain(domain)) {
return;
}
if (!isQualifiedFor(domainFacade)) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_qualifyMess", domain.getDisplayName()));
return;
}
// Check selected domains vs Max number allowed
if (charDisplay.getDomainCount() >= theCharacter.getMaxCharacterDomains()) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_errorNoMoreDomains"));
return;
}
if (!theCharacter.hasDefaultDomainSource()) {
// No source for the domain yet? Default to the last added class level
int level = charDisplay.getLevelInfoSize();
PCLevelInfo highestLevelInfo = charDisplay.getLevelInfo(level - 1);
PCClass cls = theCharacter.getClassKeyed(highestLevelInfo.getClassKeyName());
theCharacter.setDefaultDomainSource(new ClassSource(cls, highestLevelInfo.getClassLevel()));
}
if (theCharacter.addDomain(domain)) {
domains.addElement(domainFI);
DomainApplication.applyDomain(theCharacter, domain);
theCharacter.calcActiveBonuses();
remainingDomains.set(theCharacter.getMaxCharacterDomains() - charDisplay.getDomainCount());
updateDomainTodo();
spellSupportFacade.refreshAvailableKnownSpells();
companionSupportFacade.refreshCompanionData();
}
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class ChooseLst method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if (obj instanceof NonInteractive) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
}
String key;
String val;
int pipeLoc = value.indexOf(Constants.PIPE);
if (value.startsWith("FEAT=")) {
key = "FEATEQ";
val = value.substring(5);
} else if (value.startsWith("LANGAUTO:")) {
key = "LANGAUTO";
val = value.substring(9);
} else if (pipeLoc == -1) {
key = value;
val = null;
} else {
key = value.substring(0, pipeLoc);
val = value.substring(pipeLoc + 1);
}
if (!((obj instanceof Ability) || (obj instanceof Domain) || (obj instanceof Race) || (obj instanceof PCTemplate) || (obj instanceof Skill) || (obj instanceof EquipmentModifier))) {
//Allow TEMPBONUS related choose
if (!"NUMBER".equals(key)) {
return new ParseResult.Fail(getTokenName() + " is not supported for " + obj.getClass().getSimpleName(), context);
}
}
if (key.startsWith("NUMCHOICES=")) {
String maxCount = key.substring(11);
if (maxCount == null || maxCount.isEmpty()) {
return new ParseResult.Fail("NUMCHOICES in CHOOSE must be a formula: " + value, context);
}
Formula f = FormulaFactory.getFormulaFor(maxCount);
if (!f.isValid()) {
return new ParseResult.Fail("Number of Choices in " + getTokenName() + " was not valid: " + f.toString(), context);
}
context.getObjectContext().put(obj, FormulaKey.NUMCHOICES, f);
pipeLoc = val.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
key = val;
val = null;
} else {
key = val.substring(0, pipeLoc);
val = val.substring(pipeLoc + 1);
}
}
return context.processSubToken(obj, getTokenName(), key, val);
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class DomainChoiceManagerTest method test001.
/**
* Test the constructor
*/
public void test001() {
Race pObj = new Race();
pObj.setName("My PObject");
LoadContext context = Globals.getContext();
Domain foo = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Foo");
Domain bar = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Bar");
Domain baz = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Baz");
Domain qux = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Qux");
Domain quux = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Quux");
context.unconditionallyProcess(pObj, "CHOOSE", "DOMAIN|KEY_Foo|KEY_Bar|KEY_Baz|KEY_Qux|KEY_Quux");
assertTrue(context.getReferenceContext().resolveReferences(null));
assertNotNull(pObj.get(ObjectKey.CHOOSE_INFO));
pObj.put(FormulaKey.NUMCHOICES, FormulaFactory.getFormulaFor(4));
PlayerCharacter aPC = getCharacter();
ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, aPC);
is(choiceManager, not(eq(null)), "Found the chooser");
List<Domain> aList = new ArrayList<>();
List<Domain> sList = new ArrayList<>();
choiceManager.getChoices(aPC, aList, sList);
assertEquals(5, aList.size());
assertTrue(aList.contains(foo));
assertTrue(aList.contains(bar));
assertTrue(aList.contains(baz));
assertTrue(aList.contains(qux));
assertTrue(aList.contains(quux));
assertEquals(0, sList.size());
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class DomainTokenTest method testUnparseMultiple.
@Test
public void testUnparseMultiple() throws PersistenceLayerException {
Domain wp1 = construct(primaryContext, getLegalValue());
primaryProf.addToListFor(ListKey.DOMAIN, buildQO(wp1));
Domain wp2 = construct(primaryContext, getAlternateLegalValue());
primaryProf.addToListFor(ListKey.DOMAIN, buildQO(wp2));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getLegalValue() + getJoinCharacter() + getAlternateLegalValue());
}
use of pcgen.core.Domain in project pcgen by PCGen.
the class NPCGenerator method selectDomains.
private void selectDomains(final PlayerCharacter aPC, final PCClass aClass) {
final WeightedCollection<Domain> domains = theConfiguration.getDomainWeights(aPC.getDeity().getKeyName(), aClass.getKeyName());
for (Iterator<Domain> iterator = domains.iterator(); iterator.hasNext(); ) {
Domain domain = iterator.next();
if (!domain.qualifies(aPC, domain)) {
iterator.remove();
}
}
if (domains.isEmpty()) {
return;
}
while (aPC.getDomainCount() < aPC.getMaxCharacterDomains()) {
final Domain domain = domains.getRandomValue();
//Can't add twice, so have to select another...
if (aPC.hasDomain(domain)) {
continue;
}
// space remains for another domain, so add it
aPC.addDomain(domain, new ClassSource(aClass));
DomainApplication.applyDomain(aPC, domain);
aPC.calcActiveBonuses();
}
}
Aggregations