Пример #1
0
  /**
   * @param game
   * @param playerId
   * @param forceChange - does only work for targets with maximal one targetId
   * @param onlyOneTarget - 114.6b one target must be changed to another target
   * @return
   */
  public boolean chooseNewTargets(
      Game game, UUID playerId, boolean forceChange, boolean onlyOneTarget) {
    Player player = game.getPlayer(playerId);
    if (player != null) {
      for (SpellAbility spellAbility : spellAbilities) {
        for (Target target : spellAbility.getTargets()) {
          Target newTarget = target.copy();
          newTarget.clearChosen();
          for (UUID targetId : target.getTargets()) {
            MageObject object = game.getObject(targetId);
            String name = null;
            if (object == null) {
              Player targetPlayer = game.getPlayer(targetId);
              if (targetPlayer != null) {
                name = targetPlayer.getName();
              }
            } else {
              name = object.getName();
            }
            if (name != null
                && (forceChange
                    || player.chooseUse(
                        spellAbility.getEffects().get(0).getOutcome(),
                        "Change target from " + name + "?",
                        game))) {
              if (forceChange
                  && target.possibleTargets(this.getSourceId(), playerId, game).size() > 1) {
                int iteration = 0;
                do {
                  if (iteration > 0) {
                    game.informPlayer(
                        player,
                        "You may only select exactly one target that must be different from the origin target!");
                  }
                  iteration++;
                  newTarget.clearChosen();
                  player.chooseTarget(
                      spellAbility.getEffects().get(0).getOutcome(), newTarget, spellAbility, game);
                } while (targetId.equals(newTarget.getFirstTarget())
                    || newTarget.getTargets().size() != 1);

              } else {
                if (!player.chooseTarget(
                    spellAbility.getEffects().get(0).getOutcome(), newTarget, spellAbility, game)) {
                  newTarget.addTarget(targetId, spellAbility, game, false);
                }
              }
            } else {
              newTarget.addTarget(targetId, spellAbility, game, false);
            }
          }
          target.clearChosen();
          for (UUID newTargetId : newTarget.getTargets()) {
            target.addTarget(newTargetId, spellAbility, game, false);
          }
        }
      }
      return true;
    }
    return false;
  }
Пример #2
0
  @Override
  public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();

    for (UUID playerId : game.getPlayerList()) {
      Player player = game.getPlayer(playerId);

      Target target1 =
          new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent(), true);
      Target target2 =
          new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
      Target target3 =
          new TargetControlledPermanent(1, 1, new FilterControlledEnchantmentPermanent(), true);
      Target target4 =
          new TargetControlledPermanent(1, 1, new FilterControlledLandPermanent(), true);

      if (target1.canChoose(player.getId(), game)) {
        while (player.canRespond()
            && !target1.isChosen()
            && target1.canChoose(player.getId(), game)) {
          player.chooseTarget(Outcome.Benefit, target1, source, game);
        }
        Permanent artifact = game.getPermanent(target1.getFirstTarget());
        if (artifact != null) {
          chosen.add(artifact);
        }
        target1.clearChosen();
      }

      if (target2.canChoose(player.getId(), game)) {
        while (player.canRespond()
            && !target2.isChosen()
            && target2.canChoose(player.getId(), game)) {
          player.chooseTarget(Outcome.Benefit, target2, source, game);
        }
        Permanent creature = game.getPermanent(target2.getFirstTarget());
        if (creature != null) {
          chosen.add(creature);
        }
        target2.clearChosen();
      }

      if (target3.canChoose(player.getId(), game)) {
        while (player.canRespond()
            && !target3.isChosen()
            && target3.canChoose(player.getId(), game)) {
          player.chooseTarget(Outcome.Benefit, target3, source, game);
        }
        Permanent enchantment = game.getPermanent(target3.getFirstTarget());
        if (enchantment != null) {
          chosen.add(enchantment);
        }
        target3.clearChosen();
      }

      if (target4.canChoose(player.getId(), game)) {
        while (player.canRespond()
            && !target4.isChosen()
            && target4.canChoose(player.getId(), game)) {
          player.chooseTarget(Outcome.Benefit, target4, source, game);
        }
        Permanent land = game.getPermanent(target4.getFirstTarget());
        if (land != null) {
          chosen.add(land);
        }
        target4.clearChosen();
      }
    }

    for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
      if (!chosen.contains(permanent)) {
        permanent.sacrifice(source.getSourceId(), game);
      }
    }
    return true;
  }