use of pcgen.core.Ability 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;
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class CharacterAbilities method checkAbilityQualify.
private boolean checkAbilityQualify(final Ability anAbility, AbilityCategory theCategory) {
final String aKey = anAbility.getKeyName();
boolean pcHasIt = theCharacter.hasAbilityKeyed(theCategory, aKey);
if (pcHasIt && !anAbility.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString(//$NON-NLS-1$
"InfoAbility.Messages.Duplicate"));
return false;
}
//TODO Why do we regrab the context-based Ability when an Ability was passed in?
Ability ability = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, theCategory, aKey);
if (ability != null && !ability.qualifies(theCharacter, ability) && (!Globals.checkRule(RuleConstants.FEATPRE) || !AbilityUtilities.isFeat(ability))) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString(//$NON-NLS-1$
"InfoAbility.Messages.NotQualified"));
return false;
}
if ((ability != null)) {
final BigDecimal cost = ability.getSafe(ObjectKey.SELECTION_COST);
if (cost.compareTo(theCharacter.getAvailableAbilityPool(theCategory)) > 0) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString(//$NON-NLS-1$
"InfoAbility.Messages.NoPoints"));
return false;
}
}
return true;
}
use of pcgen.core.Ability 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);
}
}
use of pcgen.core.Ability 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;
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class Gui2InfoFactory method getDescription.
@Override
public String getDescription(TempBonusFacade tempBonusFacade) {
if (tempBonusFacade == null || !(tempBonusFacade instanceof TempBonusFacadeImpl)) {
return EMPTY_STRING;
}
try {
TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) tempBonusFacade;
CDOMObject originObj = tempBonus.getOriginObj();
String desc = originObj.getSafe(StringKey.TEMP_DESCRIPTION);
if (StringUtils.isEmpty(desc)) {
if (originObj instanceof Spell) {
Spell sp = (Spell) originObj;
desc = DescriptionFormatting.piWrapDesc(sp, pc.getDescription(sp), false);
} else if (originObj instanceof Ability) {
Ability ab = (Ability) originObj;
List<CNAbility> wrappedAbility = Collections.singletonList(CNAbilityFactory.getCNAbility(ab.getCDOMCategory(), Nature.NORMAL, ab));
desc = DescriptionFormatting.piWrapDesc(ab, pc.getDescription(wrappedAbility), false);
}
}
return desc;
} catch (Exception e) {
//$NON-NLS-1$
Logging.errorPrint("Failed to get description for " + tempBonusFacade, e);
return EMPTY_STRING;
}
}
Aggregations