Search in sources :

Example 76 with CNAbility

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

the class CharacterAbilities method addCategorisedAbility.

/**
	 * Add the ability to the categorised list held by CharacterAbilities. 
	 * One copy will be added for each choice.
	 * 
	 * @param cat The AbilityCategory that the ability is being added to.
	 * @param ability The ability being added.
	 * @param nature The nature via which the ability is being added.
	 * @param workingAbilityListMap The map to be adjusted.
	 */
private void addCategorisedAbility(CNAbility cna, Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap) {
    Ability ability = cna.getAbility();
    List<CNAbilitySelection> cas = new ArrayList<>();
    Category<Ability> cat = cna.getAbilityCategory();
    Nature nature = cna.getNature();
    if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        List<String> choices = theCharacter.getAssociationList(cna);
        if (choices == null || choices.isEmpty()) {
            Logging.errorPrint("Ignoring Ability: " + ability + " (" + cat + " / " + nature + ") that UI has as added to the PC, but it has no associations");
        } else {
            for (String choice : choices) {
                cas.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ability), choice));
            }
        }
    } else {
        cas.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ability)));
    }
    for (CNAbilitySelection sel : cas) {
        addElement(workingAbilityListMap, sel);
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) Nature(pcgen.cdom.enumeration.Nature) ArrayList(java.util.ArrayList) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 77 with CNAbility

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

the class CharacterAbilities method rebuildAbilityLists.

/**
	 * Rebuild the ability lists for the character to include the character's 
	 * current abilities.
	 */
synchronized void rebuildAbilityLists() {
    Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap = new LinkedHashMap<>();
    DefaultListFacade<AbilityCategoryFacade> workingActiveCategories = new DefaultListFacade<>();
    for (AbilityCategoryFacade category : dataSetFacade.getAbilities().getKeys()) {
        AbilityCategory cat = (AbilityCategory) category;
        for (CNAbility cna : theCharacter.getPoolAbilities(cat)) {
            addCategorisedAbility(cna, workingAbilityListMap);
        }
        // deal with visibility
        boolean visible = cat.isVisibleTo(theCharacter, View.VISIBLE_DISPLAY);
        if (visible && !workingActiveCategories.containsElement(cat)) {
            int index = getCatIndex(cat, workingActiveCategories);
            workingActiveCategories.addElement(index, cat);
        }
        if (!visible && workingActiveCategories.containsElement(cat)) {
            workingActiveCategories.removeElement(cat);
        //				updateAbilityCategoryTodo(cat);
        }
        if (visible) {
            adviseSelectionChangeLater(cat);
        }
    }
    // Update map contents
    for (AbilityCategoryFacade category : workingAbilityListMap.keySet()) {
        DefaultListFacade<AbilityFacade> workingListFacade = workingAbilityListMap.get(category);
        DefaultListFacade<AbilityFacade> masterListFacade = abilityListMap.get(category);
        if (masterListFacade == null) {
            abilityListMap.put(category, workingListFacade);
        } else {
            masterListFacade.updateContentsNoOrder(workingListFacade.getContents());
        }
        updateAbilityCategoryTodo((AbilityCategory) category);
    }
    Set<AbilityCategoryFacade> origCats = new HashSet<>(abilityListMap.keySet());
    for (AbilityCategoryFacade category : origCats) {
        if (!workingAbilityListMap.containsKey(category)) {
            if (workingActiveCategories.containsElement(category)) {
                abilityListMap.get(category).clearContents();
            } else {
                abilityListMap.remove(category);
            }
            updateAbilityCategoryTodo((AbilityCategory) category);
        }
    }
    activeCategories.updateContents(workingActiveCategories.getContents());
}
Also used : AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) LinkedHashMap(java.util.LinkedHashMap) CNAbility(pcgen.cdom.content.CNAbility) AbilityFacade(pcgen.facade.core.AbilityFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade) AbilityCategory(pcgen.core.AbilityCategory) HashSet(java.util.HashSet)

Example 78 with CNAbility

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

the class CharacterAbilities method removeElement.

private void removeElement(CNAbilitySelection cnas) {
    CNAbility cas = cnas.getCNAbility();
    Ability ability = cas.getAbility();
    AbilityCategoryFacade cat = (AbilityCategoryFacade) cas.getAbilityCategory();
    DefaultListFacade<AbilityFacade> listFacade = abilityListMap.get(cat);
    if (listFacade != null) {
        listFacade.removeElement(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 79 with CNAbility

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

the class CharacterAbilities method addAbility.

/**
	 * Process a request by the user to add 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 in which the ability s bing added.
	 * @param abilityFacade The ability to be added.
	 */
public void addAbility(AbilityCategoryFacade categoryFacade, AbilityFacade abilityFacade) {
    if (abilityFacade == null || !(abilityFacade instanceof Ability) || categoryFacade == null || !(categoryFacade instanceof AbilityCategory)) {
        return;
    }
    Ability ability = (Ability) abilityFacade;
    AbilityCategory category = (AbilityCategory) categoryFacade;
    if (!checkAbilityQualify(ability, category)) {
        return;
    }
    // we can only be here if the PC can add the ability
    try {
        theCharacter.setDirty(true);
        theCharacter.getSpellList();
        CNAbility cna = CNAbilityFactory.getCNAbility(category, Nature.NORMAL, ability);
        AbilityUtilities.driveChooseAndAdd(cna, theCharacter, true);
    } catch (Exception exc) {
        Logging.errorPrint("Failed to add ability due to ", exc);
        ShowMessageDelegate.showMessageDialog(LanguageBundle.getFormattedString("in_iayAddAbility", //$NON-NLS-1$
        exc.getMessage()), Constants.APPLICATION_NAME, MessageType.ERROR);
    }
    // Recalc the innate spell list
    theCharacter.getSpellList();
    theCharacter.calcActiveBonuses();
    // update the ability info
    rebuildAbilityLists();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) AbilityCategory(pcgen.core.AbilityCategory)

Example 80 with CNAbility

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

the class CharacterFacadeImpl method getLanguageChoosers.

@Override
public ListFacade<LanguageChooserFacade> getLanguageChoosers() {
    CNAbility cna = theCharacter.getBonusLanguageAbility();
    DefaultListFacade<LanguageChooserFacade> chooserList = new DefaultListFacade<>();
    chooserList.addElement(new LanguageChooserFacadeImpl(this, LanguageBundle.getString("in_sumLangBonus"), //$NON-NLS-1$
    cna));
    SkillFacade speakLangSkill = dataSet.getSpeakLanguageSkill();
    if (speakLangSkill != null) {
        chooserList.addElement(new LanguageChooserFacadeImpl(this, //$NON-NLS-1$
        LanguageBundle.getString("in_sumLangSkill"), (Skill) speakLangSkill));
    }
    return chooserList;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) LanguageChooserFacade(pcgen.facade.core.LanguageChooserFacade) Skill(pcgen.core.Skill) SkillFacade(pcgen.facade.core.SkillFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

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