use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class SpelllistToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
}
List<CDOMReference<? extends CDOMListObject<Spell>>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<? extends CDOMListObject<Spell>> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(SPELLLIST_CLASS);
} else if (token.startsWith("DOMAIN.")) {
ref = context.getReferenceContext().getCDOMReference(DOMAINSPELLLIST_CLASS, token.substring(7));
} else {
ref = context.getReferenceContext().getCDOMReference(SPELLLIST_CLASS, token);
}
refs.add(ref);
}
PrimitiveChoiceSet<CDOMListObject<Spell>> rcs = new SpellReferenceChoiceSet(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
ChoiceSet<? extends CDOMListObject<Spell>> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Select class whose list of spells this class will use");
TransitionChoice<CDOMListObject<Spell>> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(pcc, ObjectKey.SPELLLIST_CHOICE, tc);
tc.setRequired(false);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class FavclassToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
context.getObjectContext().remove(race, ObjectKey.ANY_FAVORED_CLASS);
context.getObjectContext().removeList(race, ListKey.FAVORED_CLASS);
context.getObjectContext().removeFromList(race, ListKey.NEW_CHOOSE_ACTOR, this);
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (Constants.HIGHEST_LEVEL_CLASS.equalsIgnoreCase(token)) {
foundAny = true;
context.getObjectContext().put(race, ObjectKey.ANY_FAVORED_CLASS, true);
} else if (Constants.LST_PERCENT_LIST.equalsIgnoreCase(token)) {
foundOther = true;
context.getObjectContext().addToList(race, ListKey.NEW_CHOOSE_ACTOR, this);
} else {
CDOMReference<? extends PCClass> ref;
foundOther = true;
int dotLoc = token.indexOf('.');
if (dotLoc == -1) {
// Primitive
ref = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, token);
} else {
ParseResult pr = checkForIllegalSeparator('.', value);
if (!pr.passed()) {
return pr;
}
// SubClass
String parent = token.substring(0, dotLoc);
String subclass = token.substring(dotLoc + 1);
SubClassCategory scc = SubClassCategory.getConstant(parent);
ref = context.getReferenceContext().getCDOMReference(SUBCLASS_CLASS, scc, subclass);
}
context.getObjectContext().addToList(race, ListKey.FAVORED_CLASS, ref);
}
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains " + Constants.HIGHEST_LEVEL_CLASS + " and a specific reference: " + value);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class PCClassTest method testAddAbility.
/**
* Test the definition and application of abilities.
* @throws PersistenceLayerException
*/
public void testAddAbility() throws PersistenceLayerException {
LoadContext context = Globals.getContext();
// Create some abilities to be added
AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab1);
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab2);
// Link them to a template
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
String classPCCText = "CLASS:Cleric HD:8 CLASSTYPE:PC TYPE:Base.PC ABB:Clr ABILITY:TestCat|AUTOMATIC|Ability1\n" + "CLASS:Cleric STARTSKILLPTS:2\n" + "2 ABILITY:TestCat|AUTOMATIC|Ability2";
PCClass pcclass = parsePCClassText(classPCCText, source);
ab1.setCDOMCategory(cat);
ab2.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "TestCat");
assertTrue(context.getReferenceContext().resolveReferences(null));
CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
Collection<CDOMReference<Ability>> mods = pcclass.getListMods(autoList);
assertEquals(1, mods.size());
CDOMReference<Ability> ref = mods.iterator().next();
Collection<Ability> abilities = ref.getContainedObjects();
assertEquals(1, abilities.size());
assertEquals(ab1, abilities.iterator().next());
Collection<AssociatedPrereqObject> assocs = pcclass.getListAssociations(autoList, ref);
assertEquals(1, assocs.size());
PCClassLevel level = pcclass.getOriginalClassLevel(2);
mods = level.getListMods(autoList);
assertEquals(1, mods.size());
ref = mods.iterator().next();
abilities = ref.getContainedObjects();
assertEquals(1, abilities.size());
assertEquals(ab2, abilities.iterator().next());
assocs = level.getListAssociations(autoList, ref);
assertEquals(1, assocs.size());
// Add the class to the character
PlayerCharacter pc = getCharacter();
pc.incrementClassLevel(1, pcclass, true);
assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
assertFalse("Character should not have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
pc.incrementClassLevel(1, pcclass, true);
assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class DeityWeaponToken method getCollection.
@Override
public <R> Collection<R> getCollection(PlayerCharacter pc, Converter<WeaponProf, R> c) {
Deity deity = pc.getDisplay().getDeity();
if (deity == null) {
return Collections.emptySet();
}
HashSet<R> set = new HashSet<>();
List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
for (CDOMReference<WeaponProf> ref : dwp) {
set.addAll(c.convert(ref));
}
return set;
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class DeityToken method getCollection.
@Override
public <R> Collection<R> getCollection(PlayerCharacter pc, Converter<Domain, R> c) {
HashSet<R> returnSet = new HashSet<>();
Deity deity = pc.getDisplay().getDeity();
if (deity == null) {
return returnSet;
}
CDOMReference<DomainList> list = Deity.DOMAINLIST;
Collection<CDOMReference<Domain>> mods = deity.getListMods(list);
for (CDOMReference<Domain> ref : mods) {
Collection<AssociatedPrereqObject> assoc = deity.getListAssociations(list, ref);
for (AssociatedPrereqObject apo : assoc) {
if (PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, deity)) {
returnSet.addAll(c.convert(ref));
break;
}
}
}
return returnSet;
}
Aggregations