예제 #1
0
  @Override
  protected boolean canPlayAI(Player ai, SpellAbility sa) {
    final Card hostCard = sa.getHostCard();
    // if there is no target and host card isn't in play, don't activate
    if ((sa.getTargetRestrictions() == null) && !hostCard.isInPlay()) {
      return false;
    }

    final Cost cost = sa.getPayCosts();

    // temporarily disabled until better AI
    if (!ComputerUtilCost.checkLifeCost(ai, cost, hostCard, 4, null)) {
      return false;
    }

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

    if (!ComputerUtilCost.checkSacrificeCost(ai, cost, hostCard)) {
      return false;
    }

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

    return false;
  } // protectAllCanPlayAI()
예제 #2
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();
    if (!this.payCostFromSource()) {
      boolean needsAnnoucement =
          ability.hasParam("Announce") && this.getType().contains(ability.getParam("Announce"));

      CardCollectionView typeList = activator.getCardsIn(ZoneType.Battlefield);
      typeList = CardLists.getValidCards(typeList, this.getType().split(";"), activator, source);

      final Integer amount = this.convertAmount();
      if (!needsAnnoucement && amount != null && typeList.size() < amount) {
        return false;
      }
    } else if (!source.isInPlay()) {
      return false;
    }

    return true;
  }
예제 #3
0
  @Override
  public void resolve(SpellAbility sa) {
    final Card card = sa.getHostCard();
    final Game game = card.getGame();

    final boolean remDestroyed = sa.hasParam("RememberDestroyed");
    final boolean remAttached = sa.hasParam("RememberAttached");
    if (remDestroyed || remAttached) {
      card.clearRemembered();
    }

    final boolean noRegen = sa.hasParam("NoRegen");
    final boolean sac = sa.hasParam("Sacrifice");

    final List<Card> tgtCards = getTargetCards(sa);
    final List<Card> untargetedCards = new ArrayList<Card>();

    final TargetRestrictions tgt = sa.getTargetRestrictions();

    if (sa.hasParam("Radiance")) {
      for (final Card c :
          CardUtil.getRadiance(card, tgtCards.get(0), sa.getParam("ValidTgts").split(","))) {
        untargetedCards.add(c);
      }
    }

    for (final Card tgtC : tgtCards) {
      if (tgtC.isInPlay() && ((tgt == null) || tgtC.canBeTargetedBy(sa))) {
        boolean destroyed = false;
        final Card lki = CardUtil.getLKICopy(tgtC);
        if (remAttached) {
          card.addRemembered(tgtC.getEnchantedBy(false));
          card.addRemembered(tgtC.getEquippedBy(false));
          card.addRemembered(tgtC.getFortifiedBy(false));
        }
        if (sac) {
          destroyed = game.getAction().sacrifice(tgtC, sa) != null;
        } else if (noRegen) {
          destroyed = game.getAction().destroyNoRegeneration(tgtC, sa);
        } else {
          destroyed = game.getAction().destroy(tgtC, sa);
        }
        if (destroyed && remDestroyed) {
          card.addRemembered(tgtC);
        }
        if (destroyed && sa.hasParam("RememberLKI")) {
          card.addRemembered(lki);
        }
      }
    }

    for (final Card unTgtC : untargetedCards) {
      if (unTgtC.isInPlay()) {
        boolean destroyed = false;
        if (sac) {
          destroyed = game.getAction().sacrifice(unTgtC, sa) != null;
        } else if (noRegen) {
          destroyed = game.getAction().destroyNoRegeneration(unTgtC, sa);
        } else {
          destroyed = game.getAction().destroy(unTgtC, sa);
        }
        if (destroyed && remDestroyed) {
          card.addRemembered(unTgtC);
        }
      }
    }
  }
예제 #4
0
  /* (non-Javadoc)
   * @see forge.card.abilityfactory.SpellEffect#resolve(java.util.Map, forge.card.spellability.SpellAbility)
   */
  @Override
  public void resolve(SpellAbility sa) {
    Card host = sa.getHostCard();
    int numDam = AbilityUtils.calculateAmount(host, sa.getParam("Amount"), sa);

    final List<GameObject> tgts = getTargets(sa);
    final List<Card> untargetedCards = new ArrayList<Card>();

    if (sa.hasParam("Radiance") && (sa.usesTargeting())) {
      Card origin = null;
      for (int i = 0; i < tgts.size(); i++) {
        if (tgts.get(i) instanceof Card) {
          origin = (Card) tgts.get(i);
          break;
        }
      }
      if (origin != null) {
        // Can't radiate from a player
        for (final Card c :
            CardUtil.getRadiance(host, origin, sa.getParam("ValidTgts").split(","))) {
          untargetedCards.add(c);
        }
      }
    }

    final boolean targeted = (sa.usesTargeting());
    final boolean preventionWithEffect = sa.hasParam("PreventionSubAbility");

    for (final Object o : tgts) {
      numDam =
          (sa.usesTargeting() && sa.hasParam("DividedAsYouChoose"))
              ? sa.getTargetRestrictions().getDividedValue(o)
              : numDam;
      if (o instanceof Card) {
        final Card c = (Card) o;
        if (c.isInPlay() && (!targeted || c.canBeTargetedBy(sa))) {
          if (preventionWithEffect) {
            Map<String, String> effectMap = new TreeMap<String, String>();
            effectMap.put("EffectString", sa.getSVar(sa.getParam("PreventionSubAbility")));
            effectMap.put("ShieldAmount", String.valueOf(numDam));
            if (sa.hasParam("ShieldEffectTarget")) {
              String effTgtString = "";
              List<GameObject> effTgts = new ArrayList<GameObject>();
              effTgts = AbilityUtils.getDefinedObjects(host, sa.getParam("ShieldEffectTarget"), sa);
              for (final Object effTgt : effTgts) {
                if (effTgt instanceof Card) {
                  effTgtString = String.valueOf(((Card) effTgt).getId());
                  effectMap.put("ShieldEffectTarget", "CardUID_" + effTgtString);
                } else if (effTgt instanceof Player) {
                  effTgtString = ((Player) effTgt).getName();
                  effectMap.put("ShieldEffectTarget", "PlayerNamed_" + effTgtString);
                }
              }
            }
            c.addPreventNextDamageWithEffect(host, effectMap);
          } else {
            c.addPreventNextDamage(numDam);
          }
        }

      } else if (o instanceof Player) {
        final Player p = (Player) o;
        if (!targeted || p.canBeTargetedBy(sa)) {
          if (preventionWithEffect) {
            Map<String, String> effectMap = new TreeMap<String, String>();
            effectMap.put("EffectString", sa.getSVar(sa.getParam("PreventionSubAbility")));
            effectMap.put("ShieldAmount", String.valueOf(numDam));
            if (sa.hasParam("ShieldEffectTarget")) {
              String effTgtString = "";
              List<GameObject> effTgts = new ArrayList<GameObject>();
              effTgts = AbilityUtils.getDefinedObjects(host, sa.getParam("ShieldEffectTarget"), sa);
              for (final Object effTgt : effTgts) {
                if (effTgt instanceof Card) {
                  effTgtString = String.valueOf(((Card) effTgt).getId());
                  effectMap.put("ShieldEffectTarget", "CardUID_" + effTgtString);
                } else if (effTgt instanceof Player) {
                  effTgtString = ((Player) effTgt).getName();
                  effectMap.put("ShieldEffectTarget", "PlayerNamed_" + effTgtString);
                }
              }
            }
            p.addPreventNextDamageWithEffect(host, effectMap);
          } else {
            p.addPreventNextDamage(numDam);
          }
        }
      }
    }

    for (final Card c : untargetedCards) {
      if (c.isInPlay()) {
        c.addPreventNextDamage(numDam);
      }
    }
  } // preventDamageResolve