Esempio n. 1
0
  /* (non-Javadoc)
   * @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
   */
  @Override
  protected boolean canPlayAI(Player ai, SpellAbility sa) {
    final Cost cost = sa.getPayCosts();
    final Game game = ai.getGame();
    final PhaseHandler ph = game.getPhaseHandler();
    final List<String> keywords =
        sa.hasParam("KW") ? Arrays.asList(sa.getParam("KW").split(" & ")) : new ArrayList<String>();
    final String numDefense = sa.hasParam("NumDef") ? sa.getParam("NumDef") : "";
    final String numAttack = sa.hasParam("NumAtt") ? sa.getParam("NumAtt") : "";

    if (!ComputerUtilCost.checkLifeCost(ai, cost, sa.getHostCard(), 4, null)) {
      return false;
    }

    if (!ComputerUtilCost.checkDiscardCost(ai, cost, sa.getHostCard())) {
      return false;
    }

    if (!ComputerUtilCost.checkCreatureSacrificeCost(ai, cost, sa.getHostCard())) {
      return false;
    }

    if (!ComputerUtilCost.checkRemoveCounterCost(cost, sa.getHostCard())) {
      return false;
    }

    if (!ComputerUtilCost.checkTapTypeCost(ai, cost, sa.getHostCard())) {
      return false;
    }

    if (game.getStack().isEmpty() && hasTapCost(cost, sa.getHostCard())) {
      if (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) && ph.isPlayerTurn(ai)) {
        return false;
      }
      if (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)
          && ph.isPlayerTurn(ai.getOpponent())) {
        return false;
      }
    }
    if (ComputerUtil.preventRunAwayActivations(sa)) {
      return false;
    }

    // Phase Restrictions
    if (game.getStack().isEmpty() && ph.getPhase().isBefore(PhaseType.COMBAT_BEGIN)) {
      // Instant-speed pumps should not be cast outside of combat when the
      // stack is empty
      if (!sa.isCurse() && !SpellAbilityAi.isSorcerySpeed(sa)) {
        return false;
      }
    } else if (!game.getStack().isEmpty() && !sa.isCurse()) {
      return pumpAgainstRemoval(ai, sa);
    }

    if (sa.hasParam("ActivationNumberSacrifice")) {
      final SpellAbilityRestriction restrict = sa.getRestrictions();
      final int sacActivations =
          Integer.parseInt(sa.getParam("ActivationNumberSacrifice").substring(2));
      final int activations = restrict.getNumberTurnActivations();
      // don't risk sacrificing a creature just to pump it
      if (activations >= sacActivations - 1) {
        return false;
      }
    }

    final Card source = sa.getHostCard();
    if (source.getSVar("X").equals("Count$xPaid")) {
      source.setSVar("PayX", "");
    }

    int defense;
    if (numDefense.contains("X") && source.getSVar("X").equals("Count$xPaid")) {
      // Set PayX here to maximum value.
      final int xPay = ComputerUtilMana.determineLeftoverMana(sa, ai);
      source.setSVar("PayX", Integer.toString(xPay));
      defense = xPay;
      if (numDefense.equals("-X")) {
        defense = -xPay;
      }
    } else {
      defense = AbilityUtils.calculateAmount(sa.getHostCard(), numDefense, sa);
    }

    int attack;
    if (numAttack.contains("X") && source.getSVar("X").equals("Count$xPaid")) {
      // Set PayX here to maximum value.
      final String toPay = source.getSVar("PayX");

      if (toPay.equals("")) {
        final int xPay = ComputerUtilMana.determineLeftoverMana(sa, ai);
        source.setSVar("PayX", Integer.toString(xPay));
        attack = xPay;
      } else {
        attack = Integer.parseInt(toPay);
      }
    } else {
      attack = AbilityUtils.calculateAmount(sa.getHostCard(), numAttack, sa);
    }

    if ((numDefense.contains("X") && defense == 0) || (numAttack.contains("X") && attack == 0)) {
      return false;
    }

    // Untargeted
    if ((sa.getTargetRestrictions() == null) || !sa.getTargetRestrictions().doesTarget()) {
      final List<Card> cards =
          AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa);

      if (cards.size() == 0) {
        return false;
      }

      // when this happens we need to expand AI to consider if its ok for
      // everything?
      for (final Card card : cards) {
        if (sa.isCurse()) {
          if (!card.getController().isOpponentOf(ai)) {
            return false;
          }

          if (!containsUsefulKeyword(ai, keywords, card, sa, attack)) {
            continue;
          }

          return true;
        }
        if (!card.getController().isOpponentOf(ai)
            && shouldPumpCard(ai, sa, card, defense, attack, keywords)) {
          return true;
        }
      }
      return false;
    }
    // Targeted
    if (!this.pumpTgtAI(ai, sa, defense, attack, false)) {
      return false;
    }

    return true;
  } // pumpPlayAI()
Esempio n. 2
0
  @Override
  protected boolean canPlayAI(Player ai, SpellAbility sa) {
    final TargetRestrictions tgt = sa.getTargetRestrictions();
    final Card source = sa.getHostCard();
    final Game game = source.getGame();

    boolean useAbility = true;

    //        if (card.getController().isComputer()) {
    //            final List<Card> creatures = AllZoneUtil.getCreaturesInPlay();
    //            if (!creatures.isEmpty()) {
    //                cardToCopy = CardFactoryUtil.getBestCreatureAI(creatures);
    //            }
    //        }

    // TODO - add some kind of check to answer
    // "Am I going to attack with this?"
    // TODO - add some kind of check for during human turn to answer
    // "Can I use this to block something?"

    PhaseHandler phase = game.getPhaseHandler();
    // don't use instant speed clone abilities outside computers
    // Combat_Begin step
    if (!phase.is(PhaseType.COMBAT_BEGIN)
        && phase.isPlayerTurn(ai)
        && !SpellAbilityAi.isSorcerySpeed(sa)
        && !sa.hasParam("ActivationPhases")
        && !sa.hasParam("Permanent")) {
      return false;
    }

    // don't use instant speed clone abilities outside humans
    // Combat_Declare_Attackers_InstantAbility step
    if (!phase.is(PhaseType.COMBAT_DECLARE_ATTACKERS)
        || phase.isPlayerTurn(ai)
        || game.getCombat().getAttackers().isEmpty()) {
      return false;
    }

    // don't activate during main2 unless this effect is permanent
    if (phase.is(PhaseType.MAIN2) && !sa.hasParam("Permanent")) {
      return false;
    }

    if (null == tgt) {
      final List<Card> defined = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);

      boolean bFlag = false;
      for (final Card c : defined) {
        bFlag |= (!c.isCreature() && !c.isTapped() && !(c.getTurnInZone() == phase.getTurn()));

        // for creatures that could be improved (like Figure of Destiny)
        if (c.isCreature() && (sa.hasParam("Permanent") || (!c.isTapped() && !c.isSick()))) {
          int power = -5;
          if (sa.hasParam("Power")) {
            power = AbilityUtils.calculateAmount(source, sa.getParam("Power"), sa);
          }
          int toughness = -5;
          if (sa.hasParam("Toughness")) {
            toughness = AbilityUtils.calculateAmount(source, sa.getParam("Toughness"), sa);
          }
          if ((power + toughness) > (c.getCurrentPower() + c.getCurrentToughness())) {
            bFlag = true;
          }
        }
      }

      if (!bFlag) { // All of the defined stuff is cloned, not very
        // useful
        return false;
      }
    } else {
      sa.resetTargets();
      useAbility &= cloneTgtAI(sa);
    }

    return useAbility;
  } // end cloneCanPlayAI()