Esempio n. 1
0
  /**
   * Filters out cost modification effects that are not active.
   *
   * @param game
   * @return
   */
  private List<CostModificationEffect> getApplicableCostModificationEffects(Game game) {
    List<CostModificationEffect> costEffects = new ArrayList<>();

    for (CostModificationEffect effect : costModificationEffects) {
      HashSet<Ability> abilities = costModificationEffects.getAbility(effect.getId());
      for (Ability ability : abilities) {
        if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, null)) {
          if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
            costEffects.add(effect);
            break;
          }
        }
      }
    }

    return costEffects;
  }
Esempio n. 2
0
  /**
   * Inspects all {@link Permanent permanent's} {@link Ability abilities} on the battlefield for
   * {@link CostModificationEffect cost modification effects} and applies them if necessary.
   *
   * @param abilityToModify
   * @param game
   */
  public void costModification(Ability abilityToModify, Game game) {
    List<CostModificationEffect> costEffects = getApplicableCostModificationEffects(game);

    for (CostModificationEffect effect : costEffects) {
      if (effect.getModificationType() == CostModificationType.INCREASE_COST) {
        HashSet<Ability> abilities = costModificationEffects.getAbility(effect.getId());
        for (Ability ability : abilities) {
          if (effect.applies(abilityToModify, ability, game)) {
            effect.apply(game, ability, abilityToModify);
          }
        }
      }
    }

    for (CostModificationEffect effect : costEffects) {
      if (effect.getModificationType() == CostModificationType.REDUCE_COST) {
        HashSet<Ability> abilities = costModificationEffects.getAbility(effect.getId());
        for (Ability ability : abilities) {
          if (effect.applies(abilityToModify, ability, game)) {
            effect.apply(game, ability, abilityToModify);
          }
        }
      }
    }

    for (CostModificationEffect effect : costEffects) {
      if (effect.getModificationType() == CostModificationType.SET_COST) {
        HashSet<Ability> abilities = costModificationEffects.getAbility(effect.getId());
        for (Ability ability : abilities) {
          if (effect.applies(abilityToModify, ability, game)) {
            effect.apply(game, ability, abilityToModify);
          }
        }
      }
    }
  }