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);
}
}
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());
}
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);
}
}
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();
}
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;
}
Aggregations