/**
   * Count the number of times the character has the ability. This can be limited to either hidden
   * or visible Abilities, and can be limited to only counting once per ability rather than once per
   * time taken (e.g. Weapon Specialisation in two weapons would count as 2 unless the onceOnly flag
   * was true).
   *
   * @param pc the Character with the abilities
   * @param cna The feat to be counted.
   * @param visible Should it be counted if it is visible?
   * @param hidden Should it be counted if it is hidden?
   * @param onceOnly Should it be counted as one if was taken multiple times?
   * @return The number of occurrences of the ability.
   */
  protected Float countVisibleAbility(
      PlayerCharacter pc,
      final CNAbility cna,
      final boolean visible,
      final boolean hidden,
      final boolean onceOnly) {
    Visibility v = cna.getAbility().getSafe(ObjectKey.VISIBILITY);

    // TODO This is a bug, it assumes export
    boolean abilityInvisibile = v.isVisibleTo(View.HIDDEN_EXPORT);

    int count = 0;

    if (abilityInvisibile) {
      if (hidden) {
        count += onceOnly ? 1 : Math.max(1, pc.getSelectCorrectedAssociationCount(cna));
      }
    } else {
      if (visible) {
        count += onceOnly ? 1 : Math.max(1, pc.getSelectCorrectedAssociationCount(cna));
      }
    }

    return (float) count;
  }
Esempio n. 2
0
  @Override
  public void applyChoice(
      CDOMObject owner, CategorizedAbilitySelection choice, PlayerCharacter pc) {
    if (!pc.isImporting()) {
      pc.getSpellList();
    }

    // See if our choice is not auto or virtual
    Ability anAbility =
        pc.getMatchingAbility(AbilityCategory.FEAT, choice.getAbility(), Nature.NORMAL);

    if (anAbility != null) {
      // how many sub-choices to make
      double abilityCount =
          (pc.getSelectCorrectedAssociationCount(anAbility)
              * anAbility.getSafe(ObjectKey.SELECTION_COST).doubleValue());

      boolean result = false;
      // adjust the associated List
      if (anAbility.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        pc.removeAssociation(anAbility, choice.getSelection());
        result = pc.hasAssociations(anAbility);
      }

      boolean removed = false;

      // if no sub choices made (i.e. all of them removed in Chooser box),
      // then remove the Feat
      if (!result) {
        removed = pc.removeRealAbility(AbilityCategory.FEAT, anAbility);
        CDOMObjectUtilities.removeAdds(anAbility, pc);
        CDOMObjectUtilities.restoreRemovals(anAbility, pc);
      }

      AbilityUtilities.adjustPool(anAbility, pc, false, abilityCount, removed);
      pc.adjustMoveRates();
    }
    double cost = choice.getAbility().getSafe(ObjectKey.SELECTION_COST).doubleValue();
    pc.adjustAbilities(AbilityCategory.FEAT, BigDecimal.valueOf(-cost));
  }