Exemplo n.º 1
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (player != null && permanent != null) {
      String colors;
      ChoiceColor colorChoice = new ChoiceColor();
      colorChoice.setMessage("Choose the first color");
      while (!player.choose(Outcome.GainLife, colorChoice, game)) {
        if (!player.canRespond()) {
          return false;
        }
      }
      game.getState().setValue(permanent.getId() + "_color1", colorChoice.getColor().toString());
      colors = colorChoice.getChoice().toLowerCase() + " and ";

      colorChoice.getChoices().remove(colorChoice.getChoice());
      colorChoice.setMessage("Choose the second color");
      while (!player.choose(Outcome.GainLife, colorChoice, game) && player.canRespond()) {
        game.debugMessage("player canceled choosing type. retrying.");
      }
      game.getState().setValue(permanent.getId() + "_color2", colorChoice.getColor().toString());
      colors = colors + colorChoice.getChoice().toLowerCase();
      game.informPlayers(
          permanent.getName() + ": " + player.getLogName() + " has chosen " + colors);
    }
    return false;
  }
Exemplo n.º 2
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = source.getSourceObject(game);
   if (controller != null && sourceObject != null) {
     Choice choice = new ChoiceImpl(true);
     choice.setMessage("Choose a creature type:");
     choice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!controller.choose(Outcome.BoostCreature, choice, game)) {
       if (!controller.canRespond()) {
         return false;
       }
     }
     Cards revealedCards = new CardsImpl();
     while (controller.getLibrary().size() > 0) {
       Card card = controller.getLibrary().removeFromTop(game);
       if (card.getCardType().contains(CardType.CREATURE)
           && card.getSubtype().contains(choice.getChoice())) {
         controller.moveCards(card, Zone.BATTLEFIELD, source, game);
         break;
       }
       revealedCards.add(card);
     }
     controller.revealCards(sourceObject.getIdName(), revealedCards, game);
     controller.moveCards(revealedCards, Zone.LIBRARY, source, game);
     controller.shuffleLibrary(source, game);
     return true;
   }
   return false;
 }
Exemplo n.º 3
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller == null) {
     return false;
   }
   int totalPowerSacrificed = 0;
   List<UUID> perms = new ArrayList<>();
   for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
     Player player = game.getPlayer(playerId);
     if (player != null) {
       TargetControlledCreaturePermanent target =
           new TargetControlledCreaturePermanent(
               1, 1, new FilterControlledCreaturePermanent(), true);
       if (target.canChoose(player.getId(), game)) {
         while (!target.isChosen() && player.canRespond()) {
           player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
         }
         perms.addAll(target.getTargets());
       }
     }
   }
   for (UUID permID : perms) {
     Permanent permanent = game.getPermanent(permID);
     if (permanent != null) {
       int power = permanent.getPower().getValue();
       if (permanent.sacrifice(source.getSourceId(), game)) {
         totalPowerSacrificed += power;
       }
     }
   }
   new CreateTokenEffect(new ReignOfThePitToken(totalPowerSacrificed)).apply(game, source);
   return true;
 }
Exemplo n.º 4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject mageObject = game.getObject(source.getSourceId());
   if (controller != null && mageObject != null) {
     Choice typeChoice = new ChoiceImpl(true);
     typeChoice.setMessage("Choose creature type");
     typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!controller.choose(outcome, typeChoice, game)) {
       if (!controller.canRespond()) {
         return false;
       }
     }
     if (!game.isSimulation()) {
       game.informPlayers(
           mageObject.getName()
               + ": "
               + controller.getLogName()
               + " has chosen "
               + typeChoice.getChoice());
     }
     Cards cardsToLibrary = new CardsImpl();
     FilterCreatureCard filter = new FilterCreatureCard();
     filter.add(new SubtypePredicate(typeChoice.getChoice()));
     cardsToLibrary.addAll(
         controller
             .getGraveyard()
             .getCards(filter, source.getSourceId(), source.getControllerId(), game));
     controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false);
     controller.shuffleLibrary(game);
     return true;
   }
   return false;
 }
Exemplo n.º 5
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (player != null) {
     Choice typeChoice = new ChoiceImpl(true);
     typeChoice.setMessage("Choose a creature type:");
     typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!player.choose(outcome, typeChoice, game)) {
       if (!player.canRespond()) {
         return false;
       }
     }
     if (typeChoice.getChoice() != null) {
       game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
     }
     FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
     filterCreaturePermanent.add(new SubtypePredicate(typeChoice.getChoice()));
     for (Permanent creature :
         game.getBattlefield()
             .getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) {
       creature.untap(game);
     }
     return true;
   }
   return false;
 }
Exemplo n.º 6
0
    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
      Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget();
      if (permanent != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose what " + permanent.getIdName() + " becomes to");
        choice.getChoices().add(choice33);
        choice.getChoices().add(choice22);
        choice.getChoices().add(choice16);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
          while (!choice.isChosen()) {
            controller.choose(Outcome.Neutral, choice, game);
            if (!controller.canRespond()) {
              return false;
            }
          }
        }
        int power = 0;
        int toughness = 0;
        switch (choice.getChoice()) {
          case choice33:
            power = 3;
            toughness = 3;
            break;
          case choice22:
            power = 2;
            toughness = 2;
            game.addEffect(
                new GainAbilitySourceEffect(FlyingAbility.getInstance(), Duration.Custom), source);
            break;
          case choice16:
            power = 1;
            toughness = 6;
            game.addEffect(
                new GainAbilitySourceEffect(DefenderAbility.getInstance(), Duration.Custom),
                source);
            break;
        }
        permanent.getPower().modifyBaseValue(power);
        permanent.getToughness().modifyBaseValue(toughness);
        // game.addEffect(new SetPowerToughnessSourceEffect(power, toughness, Duration.Custom,
        // SubLayer.SetPT_7b), source);

      }
      return false;
    }
Exemplo n.º 7
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Cards cards = new CardsImpl(Zone.PICK);
    int count = Math.min(player.getLibrary().size(), 4);
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      cards.add(card);
      game.setZone(card.getId(), Zone.PICK);
    }

    if (cards.size() == 0) {
      return false;
    }
    TargetCard target1 = new TargetCard(Zone.PICK, filter1);
    if (player.choose(Outcome.Detriment, cards, target1, game)) {
      Card card = cards.get(target1.getFirstTarget(), game);
      if (card != null) {
        cards.remove(card);
        card.moveToExile(getId(), "Clone Shell (Imprint)", source.getSourceId(), game);
        card.setFaceDown(true, game);
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
          permanent.imprint(card.getId(), game);
        }
      }
      target1.clearChosen();
    }

    if (cards.size() > 0) {
      TargetCard target2 = new TargetCard(Zone.PICK, filter2);
      while (player.canRespond() && cards.size() > 1) {
        player.choose(Outcome.Benefit, cards, target2, game);
        Card card = cards.get(target2.getFirstTarget(), game);
        if (card != null) {
          cards.remove(card);
          card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
        }
        target2.clearChosen();
      }
      Card card = cards.get(cards.iterator().next(), game);
      card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
    }

    return true;
  }
Exemplo n.º 8
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     Choice typeChoice = new ChoiceImpl(true);
     typeChoice.setMessage("Choose a creature type:");
     typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
       if (!player.canRespond()) {
         return false;
       }
     }
     FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
     filter.add(new SubtypePredicate(typeChoice.getChoice()));
     return new DrawCardSourceControllerEffect(new PermanentsOnBattlefieldCount(filter))
         .apply(game, source);
   }
   return false;
 }
Exemplo n.º 9
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     int tappedAmount = 0;
     TargetPermanent target = new TargetPermanent(0, 1, filter, false);
     while (true && controller.canRespond()) {
       target.clearChosen();
       if (target.canChoose(source.getControllerId(), game)) {
         Map<String, Serializable> options = new HashMap<>();
         options.put("UI.right.btn.text", "Tapping complete");
         controller.choose(outcome, target, source.getControllerId(), game, options);
         if (target.getTargets().size() > 0) {
           UUID creature = target.getFirstTarget();
           if (creature != null) {
             game.getPermanent(creature).tap(game);
             tappedAmount++;
           }
         } else {
           break;
         }
       } else {
         break;
       }
     }
     if (tappedAmount > 0) {
       AngelToken angelToken = new AngelToken();
       angelToken.putOntoBattlefield(
           tappedAmount, game, source.getSourceId(), source.getControllerId());
       game.informPlayers(
           new StringBuilder(controller.getLogName())
               .append(" puts ")
               .append(tappedAmount)
               .append(" token")
               .append(tappedAmount != 1 ? "s" : "")
               .append(" onto the battlefield")
               .toString());
     }
     return true;
   }
   return false;
 }
Exemplo n.º 10
0
 protected static int playerPaysXGenericMana(Player player, Ability source, Game game) {
   int xValue = 0;
   boolean payed = false;
   while (player.canRespond() && !payed) {
     xValue =
         player.announceXMana(0, Integer.MAX_VALUE, "How much mana will you pay?", game, source);
     if (xValue > 0) {
       Cost cost = new GenericManaCost(xValue);
       payed = cost.pay(source, game, source.getSourceId(), player.getId(), false, null);
     } else {
       payed = true;
     }
   }
   game.informPlayers(
       new StringBuilder(player.getLogName())
           .append(" pays {")
           .append(xValue)
           .append("}.")
           .toString());
   return xValue;
 }
Exemplo n.º 11
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    int amount = new GetXValue().calculate(game, source, this);

    if (controller != null && sourceObject != null) {
      TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard());
      if (controller.searchLibrary(target, game)) {
        Cards chosen = new CardsImpl();
        for (UUID cardId : (List<UUID>) target.getTargets()) {
          Card card = controller.getLibrary().remove(cardId, game);
          chosen.add(card);
        }
        controller.shuffleLibrary(source, game);

        TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));

        while (chosen.size() > 1 && controller.canRespond()) {
          controller.choose(Outcome.Neutral, chosen, targetToLib, game);
          Card card = chosen.get(targetToLib.getFirstTarget(), game);
          if (card != null) {
            chosen.remove(card);
            controller.moveCardToLibraryWithInfo(
                card, source.getSourceId(), game, Zone.LIBRARY, true, false);
          }
          targetToLib.clearChosen();
        }

        if (chosen.size() == 1) {
          Card card = chosen.get(chosen.iterator().next(), game);
          controller.moveCardToLibraryWithInfo(
              card, source.getSourceId(), game, Zone.LIBRARY, true, false);
        }
      }
      return true;
    }
    return false;
  }
 @Override
 public void init(Ability source, Game game) {
   super.init(source, game);
   MageObject sourceObject = game.getObject(source.getSourceId());
   Player controller = game.getPlayer(source.getControllerId());
   if (sourceObject != null && controller != null) {
     choice.clearChoice();
     while (!choice.isChosen()) {
       controller.choose(Outcome.Protect, choice, game);
       if (!controller.canRespond()) {
         return;
       }
     }
     if (choice.isChosen() && !game.isSimulation()) {
       game.informPlayers(
           sourceObject.getLogName()
               + ": "
               + controller.getLogName()
               + " has chosen protection from "
               + choice.getChoice());
     }
   }
 }
Exemplo n.º 13
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;
  }