use of pcgen.core.Ability in project pcgen by PCGen.
the class AbilityToken method getAspectString.
/**
* Gets the aspect string.
*
* @param pc
* The character being exported.
* @param ability
* The ability
*
* @return the aspect string
*/
private String getAspectString(PlayerCharacter pc, List<CNAbility> abilities) {
if (abilities.isEmpty()) {
return "";
}
Ability sampleAbilityObject = abilities.get(0).getAbility();
Set<AspectName> aspectKeys = sampleAbilityObject.getKeysFor(MapKey.ASPECT);
SortedSet<AspectName> sortedKeys = new TreeSet<>(aspectKeys);
StringBuilder buff = new StringBuilder();
for (AspectName key : sortedKeys) {
if (buff.length() > 0) {
buff.append(", ");
}
buff.append(Aspect.printAspect(pc, key, abilities));
}
return buff.toString();
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class AbilityToken method getAbilityList.
/**
* Returns the correct list of abilities for the character. This method is
* overridden in subclasses if they need to change the list of abilities
* looked at.
*
* @param pc
* The character who's abilities we are retrieving.
* @param aCategory
* The category of ability being reported.
* @return List of abilities.
*/
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
for (AbilityCategory aCat : allCats) {
if (AbilityCategory.ANY.equals(aCategory) || aCat.getParentCategory().equals(aCategory)) {
for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.NORMAL)) {
listOfAbilities.addToListFor(cna.getAbility(), cna);
}
}
}
return listOfAbilities;
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class AbstractGlobalTargetedSaveRestoreTest method testAddAbilityNormalTarget.
@Test
public void testAddAbilityNormalTarget() {
TokenRegistration.register(plugin.bonustokens.SkillRank.class);
T target = create(getObjectClass(), "Target");
Ability abil = context.getReferenceContext().constructCDOMObject(Ability.class, "GrantedAbility");
context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, abil);
new plugin.lsttokens.add.AbilityToken().parseToken(context, target, "FEAT|NORMAL|GrantedAbility");
Skill granted = create(Skill.class, "GrantedSkill");
create(Skill.class, "IgnoredSkill");
new plugin.lsttokens.choose.SkillToken().parseToken(context, abil, "GrantedSkill|IgnoredSkill");
new plugin.lsttokens.BonusLst().parseToken(context, abil, "SKILLRANK|%LIST|1");
abil.put(ObjectKey.MULTIPLE_ALLOWED, true);
Object o = prepare(target);
finishLoad();
assertEquals(0.0f, SkillRankControl.getTotalRank(pc, granted));
applyObject(target);
pc.setDirty(true);
assertEquals(1.0f, SkillRankControl.getTotalRank(pc, granted));
runRoundRobin(getPreEqualityCleanup());
assertEquals(1.0f, SkillRankControl.getTotalRank(pc, granted));
assertEquals(1.0f, SkillRankControl.getTotalRank(reloadedPC, granted));
remove(o);
reloadedPC.setDirty(true);
//This fails (see CODE-2387)
//assertEquals(0.0f, SkillRankControl.getTotalRank(reloadedPC, granted));
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class GeneralSaveRestoreTest method testTemplateFeat.
public void testTemplateFeat() {
//Represents CODE-2547
TokenRegistration.register(new plugin.lsttokens.deprecated.TemplateFeatToken());
TokenRegistration.register(new plugin.lsttokens.ability.StackToken());
TokenRegistration.register(new plugin.exporttokens.deprecated.TemplateToken());
Language lang = context.getReferenceContext().constructCDOMObject(Language.class, "English");
Ability a = context.getReferenceContext().constructCDOMObject(Ability.class, "Ab");
context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, a);
PCTemplate pct = context.getReferenceContext().constructCDOMObject(PCTemplate.class, "Templ");
try {
assertTrue(context.processToken(a, "MULT", "YES"));
assertTrue(context.processToken(a, "STACK", "YES"));
assertTrue(context.processToken(a, "CHOOSE", "LANG|English"));
assertTrue(context.processToken(a, "AUTO", "LANG|%LIST"));
assertTrue(context.processToken(pct, "FEAT", "Ab"));
} catch (PersistenceLayerException e) {
fail(e.getMessage());
}
finishLoad();
pc.addTemplate(pct);
assertTrue(pc.hasLanguage(lang));
runRoundRobin(null);
assertTrue(reloadedPC.hasLanguage(lang));
List<CNAbility> cnaList = pc.getMatchingCNAbilities(a);
assertEquals(1, cnaList.size());
List<String> assocs = pc.getAssociationList(cnaList.get(0));
assertEquals(1, assocs.size());
assertEquals("English", assocs.get(0));
cnaList = reloadedPC.getMatchingCNAbilities(a);
assertEquals(1, cnaList.size());
assocs = reloadedPC.getAssociationList(cnaList.get(0));
assertEquals(1, assocs.size());
assertEquals("English", assocs.get(0));
assertEquals("Ab(English)", ExportHandler.getTokenString(pc, "TEMPLATE.0.FEAT"));
assertEquals("Ab(English)", ExportHandler.getTokenString(reloadedPC, "TEMPLATE.0.FEAT"));
reloadedPC.removeTemplate(pct);
assertFalse(reloadedPC.hasLanguage(lang));
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class AbstractGlobalTargetedSaveRestoreTest method testAddAbilityVirtualTarget.
@Test
public void testAddAbilityVirtualTarget() {
TokenRegistration.register(plugin.bonustokens.SkillRank.class);
T target = create(getObjectClass(), "Target");
Ability abil = context.getReferenceContext().constructCDOMObject(Ability.class, "GrantedAbility");
context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, abil);
new plugin.lsttokens.add.AbilityToken().parseToken(context, target, "FEAT|VIRTUAL|GrantedAbility");
Skill granted = create(Skill.class, "GrantedSkill");
create(Skill.class, "IgnoredSkill");
new plugin.lsttokens.choose.SkillToken().parseToken(context, abil, "GrantedSkill|IgnoredSkill");
new plugin.lsttokens.BonusLst().parseToken(context, abil, "SKILLRANK|%LIST|1");
abil.put(ObjectKey.MULTIPLE_ALLOWED, true);
Object o = prepare(target);
finishLoad();
assertEquals(0.0f, SkillRankControl.getTotalRank(pc, granted));
applyObject(target);
pc.setDirty(true);
pc.calcActiveBonuses();
assertEquals(1.0f, SkillRankControl.getTotalRank(pc, granted));
runRoundRobin(getPreEqualityCleanup());
assertEquals(1.0f, SkillRankControl.getTotalRank(pc, granted));
assertEquals(1.0f, SkillRankControl.getTotalRank(reloadedPC, granted));
remove(o);
reloadedPC.setDirty(true);
//This fails (see CODE-2387)
//assertEquals(0.0f, SkillRankControl.getTotalRank(reloadedPC, granted));
}
Aggregations