Search in sources :

Example 21 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbilityDepthTest method containsExpected.

protected boolean containsExpected(Ability granted) {
    Collection<CNAbility> abilities = grantedAbilityFacet.getPoolAbilities(id, AbilityCategory.FEAT);
    if (abilities.isEmpty()) {
        System.err.println("No Abilities");
        return false;
    }
    for (CNAbility a : abilities) {
        boolean abilityExpected = a.getAbility().equals(granted);
        if (abilityExpected) {
            boolean c = assocCheck.check(a);
            if (!c) {
                System.err.println("Incorrect Associations");
            }
            return c;
        }
    }
    System.err.println("Did not find Ability: " + granted.getKeyName());
    return false;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility)

Example 22 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class CharacterFacadeImpl method refreshLanguageList.

/**
	 * Regenerate the character's list of languages.
	 */
void refreshLanguageList() {
    long startTime = new Date().getTime();
    List<Language> sortedLanguages = new ArrayList<>(charDisplay.getLanguageSet());
    Collections.sort(sortedLanguages);
    languages.updateContents(sortedLanguages);
    autoLanguagesCache = null;
    boolean allowBonusLangAfterFirst = Globals.checkRule(RuleConstants.INTBONUSLANG);
    boolean atFirstLvl = theCharacter.getTotalLevels() <= 1;
    int bonusLangMax = theCharacter.getBonusLanguageCount();
    currBonusLangs = new ArrayList<>();
    CNAbility a = theCharacter.getBonusLanguageAbility();
    List<String> currBonusLangNameList = theCharacter.getAssociationList(a);
    for (LanguageFacade langFacade : languages) {
        Language lang = (Language) langFacade;
        if (currBonusLangNameList.contains(lang.getKeyName())) {
            currBonusLangs.add(lang);
        }
    }
    int bonusLangRemain = bonusLangMax - currBonusLangs.size();
    if (!allowBonusLangAfterFirst && !atFirstLvl) {
        bonusLangRemain = 0;
    }
    numBonusLang.set(bonusLangRemain);
    if (bonusLangRemain > 0) {
        if (allowBonusLangAfterFirst) {
            todoManager.addTodo(new TodoFacadeImpl(Tab.SUMMARY, "Languages", "in_sumTodoBonusLanguage", 110));
            todoManager.removeTodo("in_sumTodoBonusLanguageFirstOnly");
        } else {
            todoManager.addTodo(new TodoFacadeImpl(Tab.SUMMARY, "Languages", "in_sumTodoBonusLanguageFirstOnly", 110));
            todoManager.removeTodo("in_sumTodoBonusLanguage");
        }
    } else {
        todoManager.removeTodo("in_sumTodoBonusLanguage");
        todoManager.removeTodo("in_sumTodoBonusLanguageFirstOnly");
    }
    int numSkillLangSelected = 0;
    int skillLangMax = 0;
    //TODO: Need to cope with multiple skill languages
    SkillFacade speakLangSkill = dataSet.getSpeakLanguageSkill();
    if (speakLangSkill != null) {
        Skill skill = (Skill) speakLangSkill;
        List<String> langList = theCharacter.getAssociationList(skill);
        numSkillLangSelected = langList.size();
        skillLangMax = SkillRankControl.getTotalRank(theCharacter, skill).intValue();
    }
    int skillLangRemain = skillLangMax - numSkillLangSelected;
    numSkillLang.set(skillLangRemain);
    if (skillLangRemain > 0) {
        todoManager.addTodo(new TodoFacadeImpl(Tab.SUMMARY, "Languages", "in_sumTodoSkillLanguage", 112));
    } else {
        todoManager.removeTodo("in_sumTodoSkillLanguage");
    }
    if (skillLangRemain < 0) {
        todoManager.addTodo(new TodoFacadeImpl(Tab.SUMMARY, "Languages", "in_sumTodoSkillLanguageTooMany", 112));
    } else {
        todoManager.removeTodo("in_sumTodoSkillLanguageTooMany");
    }
    long endTime = new Date().getTime();
    Logging.log(Logging.DEBUG, "refreshLanguageList took " + (endTime - startTime) + " ms.");
}
Also used : ArrayList(java.util.ArrayList) SkillFacade(pcgen.facade.core.SkillFacade) Date(java.util.Date) LanguageFacade(pcgen.facade.core.LanguageFacade) CNAbility(pcgen.cdom.content.CNAbility) Skill(pcgen.core.Skill) Language(pcgen.core.Language)

Example 23 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class CharacterFacadeImpl method getAbilityNature.

/**
	 * @see pcgen.core.facade.CharacterFacade#getAbilityNature(pcgen.core.facade.AbilityFacade)
	 */
@Override
public Nature getAbilityNature(AbilityFacade ability) {
    if (ability == null || !(ability instanceof Ability)) {
        return null;
    }
    /*
		 * TODO This is making a somewhat DRASTIC assumption that ANY Ability
		 * Category is appropriate. Unfortunately, the point at which this
		 * method is called from the UI it is unclear to the untrained eye how
		 * to get the category.
		 */
    List<CNAbility> cnas = theCharacter.getMatchingCNAbilities((Ability) ability);
    Nature nature = null;
    for (CNAbility cna : cnas) {
        nature = Nature.getBestNature(nature, cna.getNature());
    }
    return nature;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) Nature(pcgen.cdom.enumeration.Nature)

Example 24 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class CharacterAbilities method addElement.

private void addElement(Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap, CNAbilitySelection cnas) {
    CNAbility cas = cnas.getCNAbility();
    Ability ability = cas.getAbility();
    if (!ability.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
        // Filter out hidden abilities
        return;
    }
    AbilityCategoryFacade cat = (AbilityCategoryFacade) cas.getAbilityCategory();
    DefaultListFacade<AbilityFacade> listFacade = workingAbilityListMap.get(cat);
    if (listFacade == null) {
        listFacade = new DefaultListFacade<>();
        workingAbilityListMap.put(cat, listFacade);
    }
    if (!listFacade.containsElement(ability)) {
        listFacade.addElement(ability);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) AbilityFacade(pcgen.facade.core.AbilityFacade)

Example 25 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class CharacterAbilities method removeAbility.

/**
	 * Process a request by the user to remove an ability. The user will be  
	 * informed if the request cannot be allowed. Updates to the displayed 
	 * lists are handled by events (see initForCharacter).
	 * 
	 * @param categoryFacade The category from which the ability is being removed.
	 * @param abilityFacade The ability to be removed.
	 */
public void removeAbility(AbilityCategoryFacade categoryFacade, AbilityFacade abilityFacade) {
    if (abilityFacade == null || !(abilityFacade instanceof Ability) || categoryFacade == null || !(categoryFacade instanceof AbilityCategory)) {
        return;
    }
    Ability anAbility = (Ability) abilityFacade;
    AbilityCategory theCategory = (AbilityCategory) categoryFacade;
    try {
        Ability pcAbility = theCharacter.getMatchingAbility(theCategory, anAbility, Nature.NORMAL);
        if (pcAbility != null) {
            CNAbility cna = CNAbilityFactory.getCNAbility(theCategory, Nature.NORMAL, anAbility);
            AbilityUtilities.driveChooseAndAdd(cna, theCharacter, false);
            theCharacter.adjustMoveRates();
        }
    } catch (Exception exc) {
        //$NON-NLS-1$
        Logging.errorPrintLocalised("in_iayFailedToRemoveAbility", exc);
        delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString(//$NON-NLS-1$
        "in_iayRemoveAbility") + ": " + exc.getMessage());
        return;
    }
    theCharacter.calcActiveBonuses();
    // update the ability info
    rebuildAbilityLists();
    return;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) AbilityCategory(pcgen.core.AbilityCategory)

Aggregations

CNAbility (pcgen.cdom.content.CNAbility)131 Ability (pcgen.core.Ability)77 ArrayList (java.util.ArrayList)37 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)28 AbilityCategory (pcgen.core.AbilityCategory)26 Test (org.junit.Test)21 HashMapToList (pcgen.base.util.HashMapToList)16 List (java.util.List)15 PlayerCharacter (pcgen.core.PlayerCharacter)9 Language (pcgen.core.Language)7 HashSet (java.util.HashSet)5 Nature (pcgen.cdom.enumeration.Nature)5 SpecialAbility (pcgen.core.SpecialAbility)5 BonusObj (pcgen.core.bonus.BonusObj)5 BigDecimal (java.math.BigDecimal)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 LoadContext (pcgen.rules.context.LoadContext)4 StringTokenizer (java.util.StringTokenizer)3 GenericMapToList (pcgen.base.util.GenericMapToList)3 PCClass (pcgen.core.PCClass)3