Search in sources :

Example 46 with Ability

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

Example 47 with Ability

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;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) BigDecimal(java.math.BigDecimal)

Example 48 with Ability

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

Example 50 with Ability

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;
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) List(java.util.List) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

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