use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class PCTemplateTest method testAddAbility.
/**
* Test the definition and application of abilities.
* @throws PersistenceLayerException
* @throws MalformedURLException
*/
public void testAddAbility() throws PersistenceLayerException, MalformedURLException {
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);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
loader.parseLine(context, null, "Template1 ABILITY:TestCat|AUTOMATIC|Ability1 ABILITY:TestCat|AUTOMATIC|Ability2", source);
PCTemplate template = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, "Template1");
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>> listMods = template.getListMods(autoList);
assertEquals(2, listMods.size());
Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
CDOMReference<Ability> ref1 = iterator.next();
CDOMReference<Ability> ref2 = iterator.next();
Collection<Ability> contained1 = ref1.getContainedObjects();
Collection<Ability> contained2 = ref2.getContainedObjects();
assertEquals(1, contained1.size());
assertEquals(1, contained2.size());
assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
// Add the template to the character
PlayerCharacter pc = getCharacter();
pc.addTemplate(template);
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 PCTemplateTest method testAddFeatAbility.
/**
* Test the definition and application of abilities of category FEAT.
* @throws PersistenceLayerException
* @throws MalformedURLException
*/
public void testAddFeatAbility() throws PersistenceLayerException, MalformedURLException {
LoadContext context = Globals.getContext();
// Create some abilities to be added
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(AbilityCategory.FEAT);
context.getReferenceContext().importObject(ab1);
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(AbilityCategory.FEAT);
context.getReferenceContext().importObject(ab2);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
loader.parseLine(context, null, "Template1 ABILITY:FEAT|AUTOMATIC|Ability1 ABILITY:FEAT|AUTOMATIC|Ability2", source);
PCTemplate template = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, "Template1");
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "Feat");
assertTrue(context.getReferenceContext().resolveReferences(null));
CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
Collection<CDOMReference<Ability>> listMods = template.getListMods(autoList);
assertEquals(2, listMods.size());
Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
CDOMReference<Ability> ref1 = iterator.next();
CDOMReference<Ability> ref2 = iterator.next();
Collection<Ability> contained1 = ref1.getContainedObjects();
Collection<Ability> contained2 = ref2.getContainedObjects();
assertEquals(1, contained1.size());
assertEquals(1, contained2.size());
assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
// Add the template to the character
PlayerCharacter pc = getCharacter();
pc.addTemplate(template);
// Need to do this to populate the ability list
//pc.getAutomaticAbilityList(AbilityCategory.FEAT);
assertTrue("Character should have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab2));
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class PObjectTest method testAddAbility.
/**
* Test the definition and application of abilities.
* @throws PersistenceLayerException
*/
public void testAddAbility() throws PersistenceLayerException {
// Create some abilities to be added
LoadContext context = Globals.getContext();
AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
new AbilityCategoryLoader().parseLine(context, "TestCat\tCATEGORY:TestCat", null);
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(SettingsHandler.getGame().getAbilityCategory("TestCat"));
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(SettingsHandler.getGame().getAbilityCategory("TestCat"));
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
// Link them to a template
Race race = new Race();
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
GenericLoader<Race> loader = new GenericLoader<>(Race.class);
loader.parseLine(context, race, "Race1 ABILITY:TestCat|AUTOMATIC|Ability1 ABILITY:TestCat|AUTOMATIC|Ability2", source);
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>> listMods = race.getListMods(autoList);
assertEquals(2, listMods.size());
Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
CDOMReference<Ability> ref1 = iterator.next();
CDOMReference<Ability> ref2 = iterator.next();
Collection<Ability> contained1 = ref1.getContainedObjects();
Collection<Ability> contained2 = ref2.getContainedObjects();
assertEquals(1, contained1.size());
assertEquals(1, contained2.size());
assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
// Add the template to the character
PlayerCharacter pc = getCharacter();
pc.setRace(race);
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 LangbonusToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.COMMA);
boolean foundAny = false;
boolean foundOther = false;
boolean firstToken = true;
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tokText)) {
if (!firstToken) {
return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
}
context.getListContext().removeAllFromList(getTokenName(), race, Language.STARTING_LIST);
} else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
String clearText = tokText.substring(7);
CDOMReference<Language> lang = TokenUtilities.getReference(context, LANGUAGE_CLASS, clearText);
if (lang == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid .CLEAR. reference: " + clearText, context);
}
context.getListContext().removeFromList(getTokenName(), race, Language.STARTING_LIST, lang);
} else {
/*
* Note this is done one-by-one, because .CLEAR. token type
* needs to be able to perform the unlink. That could be
* changed, but the increase in complexity isn't worth it.
* (Changing it to a grouping object that didn't place links in
* the graph would also make it harder to trace the source of
* class skills, etc.)
*/
CDOMReference<Language> lang;
if (Constants.LST_ALL.equals(tokText)) {
foundAny = true;
lang = context.getReferenceContext().getCDOMAllReference(LANGUAGE_CLASS);
} else {
foundOther = true;
lang = TokenUtilities.getTypeOrPrimitive(context, LANGUAGE_CLASS, tokText);
}
if (lang == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid reference: " + tokText, context);
}
context.getListContext().addToList(getTokenName(), race, Language.STARTING_LIST, lang);
}
firstToken = false;
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class MonccskillToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
boolean firstToken = true;
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tokText)) {
if (!firstToken) {
return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
}
context.getListContext().removeAllFromList(getTokenName(), race, monsterList);
} else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
CDOMReference<Skill> skill;
String clearText = tokText.substring(7);
if (Constants.LST_ALL.equals(clearText)) {
skill = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
} else {
skill = getSkillReference(context, clearText);
}
if (skill == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName(), context);
}
context.getListContext().removeFromList(getTokenName(), race, monsterList, skill);
} else {
/*
* Note this is done one-by-one, because .CLEAR. token type
* needs to be able to perform the unlink. That could be
* changed, but the increase in complexity isn't worth it.
* (Changing it to a grouping object that didn't place links in
* the graph would also make it harder to trace the source of
* class skills, etc.)
*/
CDOMReference<Skill> skill;
if (Constants.LST_ALL.equals(tokText)) {
foundAny = true;
skill = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
} else {
foundOther = true;
skill = getSkillReference(context, tokText);
}
if (skill == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName(), context);
}
AssociatedPrereqObject apo = context.getListContext().addToList(getTokenName(), race, monsterList, skill);
apo.setAssociation(AssociationKey.SKILL_COST, SkillCost.CROSS_CLASS);
}
firstToken = false;
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
Aggregations