Search in sources :

Example 21 with Ability

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();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AspectName(pcgen.cdom.enumeration.AspectName) TreeSet(java.util.TreeSet)

Example 22 with Ability

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;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Example 23 with Ability

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));
}
Also used : Ability(pcgen.core.Ability) Skill(pcgen.core.Skill) SkillToken(plugin.lsttokens.choose.SkillToken) CDOMObject(pcgen.cdom.base.CDOMObject) Test(org.junit.Test)

Example 24 with Ability

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));
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CNAbility(pcgen.cdom.content.CNAbility) Language(pcgen.core.Language) PCTemplate(pcgen.core.PCTemplate)

Example 25 with Ability

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));
}
Also used : Ability(pcgen.core.Ability) Skill(pcgen.core.Skill) SkillToken(plugin.lsttokens.choose.SkillToken) CDOMObject(pcgen.cdom.base.CDOMObject) Test(org.junit.Test)

Aggregations

Ability (pcgen.core.Ability)279 CNAbility (pcgen.cdom.content.CNAbility)128 AbilityCategory (pcgen.core.AbilityCategory)60 PlayerCharacter (pcgen.core.PlayerCharacter)54 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)43 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)25 ParseResult (pcgen.rules.persistence.token.ParseResult)21 HashMapToList (pcgen.base.util.HashMapToList)15 PCClass (pcgen.core.PCClass)15 Spell (pcgen.core.spell.Spell)15 StringTokenizer (java.util.StringTokenizer)14 TestContext (plugin.lsttokens.editcontext.testsupport.TestContext)13 LoadContext (pcgen.rules.context.LoadContext)12 SpecialAbility (pcgen.core.SpecialAbility)11 CharacterSpell (pcgen.core.character.CharacterSpell)11 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)11 List (java.util.List)10 CDOMObject (pcgen.cdom.base.CDOMObject)10 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10