コード例 #1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * forge.card.cost.CostPart#canPay(forge.card.spellability.SpellAbility,
   * forge.Card, forge.Player, forge.card.cost.Cost)
   */
  @Override
  public final boolean canPay(final SpellAbility ability) {
    final Player activator = ability.getActivatingPlayer();
    final Card source = ability.getHostCard();
    CardCollectionView validCards = activator.getCardsIn(ZoneType.Battlefield);
    validCards = CardLists.getValidCards(validCards, this.getType().split(";"), activator, source);
    validCards =
        CardLists.filter(
            validCards,
            new Predicate<Card>() {
              @Override
              public boolean apply(final Card c) {
                return c.hasCounters();
              }
            });
    if (validCards.isEmpty()) {
      return false;
    }
    Integer i = this.convertAmount();

    if (i == null) {
      i = AbilityUtils.calculateAmount(source, this.getAmount(), ability);
    }
    int allCounters = 0;
    for (Card c : validCards) {
      final Map<CounterType, Integer> tgtCounters = c.getCounters();
      for (Integer value : tgtCounters.values()) {
        allCounters += value;
      }
    }

    return i <= allCounters;
  }
コード例 #2
0
ファイル: AiCostDecision.java プロジェクト: DeretsunGit/forge
  @Override
  public PaymentDecision visit(CostRemoveCounter cost) {
    final String amount = cost.getAmount();
    Integer c = cost.convertAmount();
    final String type = cost.getType();

    if (c == null) {
      final String sVar = ability.getSVar(amount);
      if (sVar.equals("XChoice")) {
        c = AbilityUtils.calculateAmount(source, "ChosenX", ability);
      } else if (amount.equals("All")) {
        c = source.getCounters(cost.counter);
      } else {
        c = AbilityUtils.calculateAmount(source, amount, ability);
      }
    }

    if (!cost.payCostFromSource()) {
      List<Card> typeList;
      if (type.equals("OriginalHost")) {
        typeList = Lists.newArrayList(ability.getOriginalHost());
      } else {
        typeList =
            CardLists.getValidCards(player.getCardsIn(cost.zone), type.split(";"), player, source);
      }
      for (Card card : typeList) {
        if (card.getCounters(cost.counter) >= c) {
          return PaymentDecision.card(card, c);
        }
      }
      return null;
    }

    if (c > source.getCounters(cost.counter)) {
      System.out.println("Not enough " + cost.counter + " on " + source.getName());
      return null;
    }

    return PaymentDecision.card(source, c);
  }
コード例 #3
0
ファイル: AiCostDecision.java プロジェクト: DeretsunGit/forge
  @Override
  public PaymentDecision visit(CostRemoveAnyCounter cost) {
    final String amount = cost.getAmount();
    final int c = AbilityUtils.calculateAmount(source, amount, ability);
    final String type = cost.getType();

    List<Card> typeList =
        CardLists.getValidCards(
            player.getCardsIn(ZoneType.Battlefield), type.split(";"), player, source);
    List<Card> hperms =
        CardLists.filter(
            typeList,
            new Predicate<Card>() {
              @Override
              public boolean apply(final Card crd) {
                for (final CounterType c1 : CounterType.values()) {
                  if (crd.getCounters(c1) >= c && ComputerUtil.isNegativeCounter(c1, crd)) {
                    return true;
                  }
                }
                return false;
              }
            });

    if (hperms.isEmpty()) return null;

    PaymentDecision result = PaymentDecision.card(hperms);
    Card valid = hperms.get(0);
    for (CounterType c1 : valid.getCounters().keySet()) {
      if (valid.getCounters(c1) >= c && ComputerUtil.isNegativeCounter(c1, valid)) {
        result.ct = c1;
        break;
      }
    }
    // Only find cards with enough negative counters
    // TODO: add ai for Chisei, Heart of Oceans
    return result;
  }