示例#1
0
  /**
   * Checks all available splice effects to be applied.
   *
   * @param abilityToModify
   * @param game
   */
  public void applySpliceEffects(Ability abilityToModify, Game game) {
    if (((SpellAbility) abilityToModify).getSpellAbilityType().equals(SpellAbilityType.SPLICE)) {
      // on a spliced ability of a spell can't be spliced again
      return;
    }
    List<SpliceCardEffect> spliceEffects =
        getApplicableSpliceCardEffects(game, abilityToModify.getControllerId());
    // get the applyable splice abilities
    List<SpliceOntoArcaneAbility> spliceAbilities = new ArrayList<>();
    for (SpliceCardEffect effect : spliceEffects) {
      HashSet<Ability> abilities = spliceCardEffects.getAbility(effect.getId());
      for (Ability ability : abilities) {
        if (effect.applies(abilityToModify, ability, game)) {
          spliceAbilities.add((SpliceOntoArcaneAbility) ability);
        }
      }
    }
    // check if player wants to use splice

    if (spliceAbilities.size() > 0) {
      Player controller = game.getPlayer(abilityToModify.getControllerId());
      if (controller.chooseUse(Outcome.Benefit, "Splice a card?", game)) {
        Cards cardsToReveal = new CardsImpl();
        do {
          FilterCard filter = new FilterCard("a card to splice");
          ArrayList<Predicate<MageObject>> idPredicates = new ArrayList<>();
          for (SpliceOntoArcaneAbility ability : spliceAbilities) {
            idPredicates.add(new CardIdPredicate((ability.getSourceId())));
          }
          filter.add(Predicates.or(idPredicates));
          TargetCardInHand target = new TargetCardInHand(filter);
          controller.chooseTarget(Outcome.Benefit, target, abilityToModify, game);
          UUID cardId = target.getFirstTarget();
          if (cardId != null) {
            SpliceOntoArcaneAbility selectedAbility = null;
            for (SpliceOntoArcaneAbility ability : spliceAbilities) {
              if (ability.getSourceId().equals(cardId)) {
                selectedAbility = ability;
                break;
              }
            }
            if (selectedAbility != null) {
              SpliceCardEffect spliceEffect =
                  (SpliceCardEffect) selectedAbility.getEffects().get(0);
              spliceEffect.apply(game, selectedAbility, abilityToModify);
              cardsToReveal.add(game.getCard(cardId));
              spliceAbilities.remove(selectedAbility);
            }
          }
        } while (!spliceAbilities.isEmpty()
            && controller.chooseUse(Outcome.Benefit, "Splice another card?", game));
        controller.revealCards("Spliced cards", cardsToReveal, game);
      }
    }
  }
示例#2
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player you = game.getPlayer(source.getControllerId());
   if (you == null) {
     return false;
   }
   Permanent arsenalThresher = game.getPermanent(source.getSourceId());
   FilterArtifactCard filter = new FilterArtifactCard();
   filter.add(new AnotherPredicate());
   if (you.chooseUse(
       Outcome.Benefit, "Do you want to reveal other artifacts in your hand?", game)) {
     Cards cards = new CardsImpl();
     if (you.getHand().count(filter, game) > 0) {
       TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
       if (you.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
         for (UUID uuid : target.getTargets()) {
           cards.add(you.getHand().get(uuid, game));
         }
         you.revealCards("Revealed cards", cards, game);
         if (arsenalThresher != null) {
           arsenalThresher.addCounters(CounterType.P1P1.createInstance(cards.size()), game);
           return true;
         }
       }
     }
   }
   return false;
 }
示例#3
0
 public void assignDamageToBlockers(boolean first, Game game) {
   if (attackers.size() > 0 && (!first || hasFirstOrDoubleStrike(game))) {
     if (blockers.isEmpty()) {
       unblockedDamage(first, game);
     } else {
       Permanent attacker = game.getPermanent(attackers.get(0));
       if (attacker
           .getAbilities()
           .containsKey(DamageAsThoughNotBlockedAbility.getInstance().getId())) {
         Player player = game.getPlayer(attacker.getControllerId());
         if (player.chooseUse(
             Outcome.Damage,
             "Do you wish to assign damage for "
                 + attacker.getLogName()
                 + " as though it weren't blocked?",
             game)) {
           blocked = false;
           unblockedDamage(first, game);
         }
       }
       if (blockers.size() == 1) {
         singleBlockerDamage(first, game);
       } else {
         multiBlockerDamage(first, game);
       }
     }
   }
 }
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(targetPointer.getFirst(game, source));
   MageObject mageObject = game.getObject(source.getSourceId());
   if (player != null && mageObject != null) {
     String message = userMessage;
     if (message == null) {
       message =
           getCostText()
               + " to prevent "
               + executingEffect.getText(source.getModes().getMode())
               + "?";
     }
     message = CardUtil.replaceSourceName(message, mageObject.getLogName());
     cost.clearPaid();
     if (cost.canPay(source, source.getSourceId(), player.getId(), game)
         && player.chooseUse(executingEffect.getOutcome(), message, source, game)) {
       cost.pay(source, game, source.getSourceId(), player.getId(), false, null);
     }
     if (!cost.isPaid()) {
       executingEffect.setTargetPointer(this.targetPointer);
       return executingEffect.apply(game, source);
     }
     return true;
   }
   return false;
 }
示例#5
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = getPayingPlayer(game, source);
   MageObject mageObject = game.getObject(source.getSourceId());
   if (player != null && mageObject != null) {
     String message;
     if (chooseUseText == null) {
       message =
           new StringBuilder(getCostText())
               .append(" and ")
               .append(executingEffect.getText(source.getModes().getMode()))
               .append("?")
               .toString();
     } else {
       message = chooseUseText;
     }
     message = CardUtil.replaceSourceName(message, mageObject.getName());
     if (cost.canPay(source, source.getSourceId(), player.getId(), game)
         && player.chooseUse(executingEffect.getOutcome(), message, game)) {
       cost.clearPaid();
       if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) {
         executingEffect.setTargetPointer(this.targetPointer);
         if (executingEffect instanceof OneShotEffect) {
           if (!(executingEffect instanceof PostResolveEffect)) {
             return executingEffect.apply(game, source);
           }
         } else {
           game.addEffect((ContinuousEffect) executingEffect, source);
         }
       }
     }
     return true;
   }
   return false;
 }
示例#6
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(targetPointer.getFirst(game, source));
   if (player == null) {
     return false;
   }
   if (player.getLife() > 2
       && player.chooseUse(
           Outcome.Neutral,
           "Pay 2 life? If you don't, return a permanent you control to its owner's hand.",
           game)) {
     player.loseLife(2, game);
     game.informPlayers(
         player.getName() + " pays 2 life. He will not return a permanent he or she controls.");
     return true;
   } else {
     Target target = new TargetControlledPermanent();
     if (target.canChoose(source.getSourceId(), player.getId(), game)
         && player.chooseTarget(outcome, target, source, game)) {
       Permanent permanent = game.getPermanent(target.getFirstTarget());
       if (permanent != null) {
         game.informPlayers(player.getName() + " returns " + permanent.getName() + " to hand.");
         return permanent.moveToZone(Zone.HAND, source.getSourceId(), game, false);
       }
     }
   }
   return false;
 }
示例#7
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
      FilterCard filter = new FilterCard("red instant or sorcery card from your graveyard to play");
      filter.add(new ColorPredicate(ObjectColor.RED));
      filter.add(
          Predicates.or(
              new CardTypePredicate(CardType.INSTANT), new CardTypePredicate(CardType.SORCERY)));

      String message =
          "Play red instant or sorcery card from your graveyard without paying its mana cost?";
      Set<Card> cards = player.getGraveyard().getCards(filter, game);
      TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
      while (!cards.isEmpty() && player.chooseUse(outcome, message, source, game)) {
        target.clearChosen();
        if (player.choose(outcome, target, source.getSourceId(), game)) {
          Card card = game.getCard(target.getFirstTarget());
          if (card != null) {
            player.cast(card.getSpellAbility(), game, true);
            player.getGraveyard().remove(card);
            cards.remove(card);
          }
        }
      }

      return true;
    }
    return false;
  }
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (event.getType() == EventType.DAMAGE_PLAYER) {
     DamageEvent damageEvent = (DamageEvent) event;
     UUID playerId = getSourceControllerId(event.getSourceId(), game);
     if (!damageEvent.isCombatDamage()
         && game.getOpponents(event.getTargetId()).contains(playerId)) {
       Player target = game.getPlayer(event.getTargetId());
       Player player = game.getPlayer(playerId);
       if (target != null && player != null) {
         int numPlaneswalkers = game.getBattlefield().countAll(filter, target.getId(), game);
         if (numPlaneswalkers > 0
             && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) {
           redirectTarget = new TargetPermanent(filter);
           if (numPlaneswalkers == 1) {
             redirectTarget.add(
                 game.getBattlefield()
                     .getAllActivePermanents(filter, target.getId(), game)
                     .get(0)
                     .getId(),
                 game);
           } else {
             player.choose(Outcome.Damage, redirectTarget, null, game);
           }
           return true;
         }
       }
     }
   }
   return false;
 }
示例#9
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Card card = player.getLibrary().getFromTop(game);
    if (card != null) {
      Cards cards = new CardsImpl();
      cards.add(card);
      player.lookAtCards("Explorer's Scope", cards, game);
      if (card.getCardType().contains(CardType.LAND)) {
        String message = "Put " + card.getName() + " onto the battlefield tapped?";
        if (player.chooseUse(Outcome.PutLandInPlay, message, game)) {
          if (card.putOntoBattlefield(
              game, Zone.LIBRARY, source.getId(), source.getControllerId())) {
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
              permanent.setTapped(true);
            }
          }
        }
      }
    }
    return true;
  }
示例#10
0
  @Override
  public boolean apply(Game game, Ability source) {

    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Cards cards = new CardsImpl(Zone.PICK);
    int count = source.getManaCostsToPay().getX();
    count = Math.min(player.getLibrary().size(), count);
    boolean legendaryIncluded = false;
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
        if (filter.match(card, game)) {
          legendaryIncluded = true;
        }
        game.setZone(card.getId(), Zone.PICK);
      }
    }
    player.lookAtCards("Heroes' Podium", cards, game);

    // You may reveal a legendary creature card from among them and put it into your hand.
    if (!cards.isEmpty()
        && legendaryIncluded
        && player.chooseUse(
            outcome, "Put a legendary creature card into your hand?", source, game)) {
      if (cards.size() == 1) {
        Card card = cards.getRandom(game);
        cards.remove(card);
        card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
        return true;
      } else {
        TargetCard target = new TargetCard(Zone.PICK, filter);
        if (player.choose(outcome, cards, target, game)) {
          Card card = cards.get(target.getFirstTarget(), game);
          if (card != null) {
            cards.remove(card);
            card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
          }
        }
      }
    }

    // Put the rest on the bottom of your library in a random order
    while (cards.size() > 0) {
      Card card = cards.getRandom(game);
      if (card != null) {
        cards.remove(card);
        card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
      }
    }
    return true;
  }
示例#11
0
  @Override
  public boolean apply(Game game, Ability source) {
    Cards cardsToCast = new CardsImpl();
    Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (targetOpponent != null && sourceObject != null) {
      List<Card> allCards = targetOpponent.getLibrary().getTopCards(game, 7);
      Cards cards = new CardsImpl(Zone.LIBRARY, allCards);
      targetOpponent.revealCards(
          sourceObject.getIdName() + " - " + targetOpponent.getName() + "'s top library cards",
          cards,
          game);
      for (Card card : allCards) {
        if (filter.match(card, game)) {
          cardsToCast.add(card);
        }
      }
      // cast an instant or sorcery for free
      if (cardsToCast.size() > 0) {
        int numberOfSpells = 1;
        if (SpellMasteryCondition.getInstance().apply(game, source)) {
          numberOfSpells++;
        }
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {

          TargetCard target = new TargetCard(Zone.LIBRARY, filter); // zone should be ignored here
          target.setNotTarget(true);
          while (numberOfSpells > 0
              && cardsToCast.size() > 0
              && controller.chooseUse(
                  outcome,
                  "Cast an instant or sorcery card from among them for free?",
                  source,
                  game)
              && controller.choose(outcome, cardsToCast, target, game)) {
            Card card = cardsToCast.get(target.getFirstTarget(), game);
            if (card != null) {
              controller.cast(card.getSpellAbility(), game, true);
              numberOfSpells--;
              cardsToCast.remove(card);
              allCards.remove(card);
            }
            if (!controller.isInGame()) {
              return false;
            }
            target.clearChosen();
          }
        }

        targetOpponent.moveCards(allCards, Zone.LIBRARY, Zone.GRAVEYARD, source, game);
      }
      return true;
    }
    return false;
  }
示例#12
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   Permanent archmage = game.getPermanent(source.getSourceId());
   Player you = game.getPlayer(source.getControllerId());
   if (event.getPlayerId().equals(source.getControllerId())
       && archmage != null
       && you != null
       && you.chooseUse(Outcome.Benefit, "Would you like to skip drawing a card?", game)) {
     return true;
   }
   return false;
 }
示例#13
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) {
      if (controller.getLibrary().size() > 0) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card == null) {
          return false;
        }
        controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
        if (card.getCardType().contains(CardType.CREATURE)) {
          FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
          boolean found = false;
          for (Permanent permanent :
              game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) {
            if (CardUtil.shareSubtypes(card, permanent, game)) {
              found = true;
              break;
            }
          }
          if (found) {
            game.informPlayers(
                sourceObject.getLogName()
                    + ": Found a creature that shares a creature type with the revealed card.");
            if (controller.chooseUse(Outcome.Benefit, "Cast the card?", source, game)) {
              controller.cast(card.getSpellAbility(), game, true);
            } else {
              game.informPlayers(
                  sourceObject.getLogName()
                      + ": "
                      + controller.getLogName()
                      + " canceled casting the card.");
              controller.getLibrary().putOnBottom(card, game);
            }
          } else {
            game.informPlayers(
                sourceObject.getLogName()
                    + ": No creature that shares a creature type with the revealed card.");
            controller.getLibrary().putOnBottom(card, game);
          }
        } else {
          game.informPlayers(
              sourceObject.getLogName() + ": Put " + card.getLogName() + " on the bottom.");
          controller.getLibrary().putOnBottom(card, game);
        }

        return true;
      }
    }
    return false;
  }
示例#14
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null
       && player.chooseUse(
           Outcome.DrawCard, "Do you wish to draw a card? If you do, discard a card.", game)) {
     if (player.drawCards(1, game) > 0) {
       player.discard(1, source, game);
     }
     return true;
   }
   return false;
 }
示例#15
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(targetPointer.getFirst(game, source));
   if (player != null) {
     int cardsToDraw = amount.calculate(game, source);
     if (upTo) {
       cardsToDraw = player.getAmount(0, cardsToDraw, "Draw how many cards?", game);
     }
     if (!optional || player.chooseUse(outcome, "Use draw effect?", game)) {
       player.drawCards(cardsToDraw, game);
     }
     return true;
   }
   return false;
 }
示例#16
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Card sourceCard = game.getCard(source.getSourceId());
   if (controller == null || sourceCard == null) {
     return false;
   }
   if (controller.getLibrary().size() > 0) {
     controller.shuffleLibrary(game);
     Card card = controller.getLibrary().getFromTop(game);
     if (card == null) {
       return false;
     }
     controller.revealCards(sourceCard.getName(), new CardsImpl(card), game);
     if (card.getCardType().contains(CardType.LAND)) {
       String message = "Put " + card.getName() + " onto the battlefield?";
       if (controller.chooseUse(Outcome.PutLandInPlay, message, game)) {
         card.putOntoBattlefield(
             game, Zone.LIBRARY, source.getSourceId(), source.getControllerId());
         return sourceCard.moveToZone(Zone.HAND, source.getSourceId(), game, false);
       }
     } else {
       if (controller.chooseUse(
           outcome,
           new StringBuilder("Cast ")
               .append(card.getName())
               .append(" without paying its mana cost?")
               .toString(),
           game)) {
         return controller.cast(card.getSpellAbility(), game, true);
       }
     }
     return true;
   }
   return false;
 }
示例#17
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player you = game.getPlayer(source.getControllerId());
   ManaCosts cost = new ManaCostsImpl("{X}");
   if (you != null && you.chooseUse(Outcome.Neutral, "Do you want to to pay {X}?", game)) {
     int costX =
         you.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
     cost.add(new GenericManaCost(costX));
     if (cost.pay(source, game, source.getId(), source.getControllerId(), false)) {
       Token token = new GoblinSoldierToken();
       return token.putOntoBattlefield(
           costX, game, source.getSourceId(), source.getControllerId());
     }
   }
   return false;
 }
示例#18
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) {
      if (controller.chooseUse(Outcome.Benefit, choiceText, source, game)) {
        Set<Card> sideboard = controller.getSideboard().getCards(filter, game);
        List<Card> exile = game.getExile().getAllCards(game);
        Cards filteredCards = new CardsImpl();
        Card card = null;

        for (Card sideboardCard : sideboard) {
          filteredCards.add(sideboardCard.getId());
        }
        for (Card exileCard : exile) {
          if (exileCard.getOwnerId().equals(source.getControllerId())
              && exileCard.hasSubtype("Eldrazi")) {
            filteredCards.add(exileCard);
          }
        }

        if (filteredCards.isEmpty()) {
          game.informPlayer(
              controller,
              "You have no "
                  + filter.getMessage()
                  + " outside the game (your sideboard) or in exile.");
        } else {
          TargetCard target = new TargetCard(Zone.OUTSIDE, filter);
          target.setNotTarget(true);
          if (controller.choose(outcome, filteredCards, target, game)) {
            card = controller.getSideboard().get(target.getFirstTarget(), game);
            if (card == null) {
              card = game.getCard(target.getFirstTarget());
            }
          }
        }

        if (card != null) {
          card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
          controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
        }
      }
      return true;
    }
    return false;
  }
示例#19
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || !player.chooseUse(Outcome.PutCreatureInPlay, choiceText, game)) {
      return false;
    }

    TargetCardInHand target = new TargetCardInHand(filter);
    if (player.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
      Card card = game.getCard(target.getFirstTarget());
      if (card != null) {
        card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), source.getControllerId());
        return true;
      }
    }
    return false;
  }
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   Permanent permanent = game.getPermanent(source.getSourceId());
   if (player != null && permanent != null) {
     if (player.chooseUse(
         Outcome.Benefit,
         "Pay " + cost.getText() /* + " or sacrifice " + permanent.getName() */ + "?",
         game)) {
       cost.clearPaid();
       if (cost.pay(source, game, source.getId(), source.getControllerId(), false)) return true;
     }
     permanent.sacrifice(source.getSourceId(), game);
     return true;
   }
   return false;
 }
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent target = game.getPermanent(source.getFirstTarget());
    StringBuilder sb = new StringBuilder();

    if (controller != null && target != null) {
      for (int i = 0; i < 5; i++) {
        if (!controller.chooseUse(
            Outcome.Neutral, "Do you wish to choose another color?", source, game)) {
          break;
        }
        ChoiceColor choiceColor = new ChoiceColor();
        controller.choose(Outcome.Benefit, choiceColor, game);
        if (!controller.isInGame()) {
          return false;
        }
        if (!game.isSimulation())
          game.informPlayers(
              target.getName()
                  + ": "
                  + controller.getLogName()
                  + " has chosen "
                  + choiceColor.getChoice());
        if (choiceColor.getColor().isBlack()) {
          sb.append("B");
        } else if (choiceColor.getColor().isBlue()) {
          sb.append("U");
        } else if (choiceColor.getColor().isRed()) {
          sb.append("R");
        } else if (choiceColor.getColor().isGreen()) {
          sb.append("G");
        } else if (choiceColor.getColor().isWhite()) {
          sb.append("W");
        }
      }
      String colors = new String(sb);
      ObjectColor chosenColors = new ObjectColor(colors);
      ContinuousEffect effect = new BecomesColorTargetEffect(chosenColors, duration);
      effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
      game.addEffect(effect, source);

      return true;
    }
    return false;
  }
示例#22
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     ManaCosts cost = new ManaCostsImpl("{5}{R}{R}");
     if (player.chooseUse(Outcome.Damage, "Pay " + cost.getText() + "?", game)) {
       cost.clearPaid();
       if (cost.pay(source, game, source.getId(), source.getControllerId(), false)) {
         new UntapAllControllerEffect(new FilterAttackingCreature(), "").apply(game, source);
         game.getState()
             .getTurnMods()
             .add(new TurnMod(source.getControllerId(), Constants.TurnPhase.COMBAT, null, false));
         return true;
       }
     }
   }
   return false;
 }
示例#23
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
     if (card != null) {
       if (controller.chooseUse(outcome, "Cast " + card.getLogName() + "?", source, game)) {
         if (controller.cast(card.getSpellAbility(), game, true)) {
           ContinuousEffect effect = new TorrentialGearhulkReplacementEffect(card.getId());
           effect.setTargetPointer(
               new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
           game.addEffect(effect, source);
         }
       }
     }
     return true;
   }
   return false;
 }
示例#24
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) {
     int flipsWon = 0;
     boolean controllerStopped = false;
     while (controller.flipCoin(game)) {
       ++flipsWon;
       if (!controller.chooseUse(
           outcome,
           new StringBuilder("You won ")
               .append(flipsWon)
               .append(flipsWon == 1 ? " flip." : " flips.")
               .append(" Flip another coin?")
               .toString(),
           source,
           game)) {
         controllerStopped = true;
         break;
       }
     }
     if (controllerStopped) {
       Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
       if (creature != null) {
         creature.damage(3, source.getSourceId(), game, false, true);
       }
       if (flipsWon > 1) {
         new DamagePlayersEffect(6, TargetController.OPPONENT).apply(game, source);
       }
       if (flipsWon > 2) {
         controller.drawCards(9, game);
         new UntapAllLandsControllerEffect().apply(game, source);
       }
     } else {
       game.informPlayers(sourceObject.getIdName() + " had no effect");
     }
     return true;
   }
   return false;
 }
示例#25
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    TargetCardInLibrary target = new TargetCardInLibrary();
    if (player.searchLibrary(target, game)) {
      Card card = player.getLibrary().remove(target.getFirstTarget(), game);
      if (card != null) {
        card.moveToZone(Zone.EXILED, source.getSourceId(), game, false);
        player.shuffleLibrary(game);

        StringBuilder sb = new StringBuilder();
        sb.append("Have ").append(player.getLogName()).append(" put ").append(card.getName());
        sb.append(" in his hand? If none of his opponents says yes, he'll draw three cards.");

        boolean putInHand = false;
        Set<UUID> opponents = game.getOpponents(source.getControllerId());
        for (UUID opponentUuid : opponents) {
          Player opponent = game.getPlayer(opponentUuid);
          if (opponent != null
              && !putInHand
              && opponent.chooseUse(Outcome.Neutral, sb.toString(), source, game)) {
            putInHand = true;
          }
        }

        if (putInHand) {
          game.getExile().getPermanentExile().remove(card);
          card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
        } else {
          player.drawCards(3, game);
        }
        return true;
      }
    }
    player.shuffleLibrary(game);
    return false;
  }
示例#26
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Card sourceCard = game.getCard(source.getSourceId());
   if (controller != null && sourceCard != null) {
     if (game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
       boolean onTop =
           controller.chooseUse(
               outcome,
               "Put "
                   + sourceCard.getName()
                   + " on top of it's owners library (otherwise on bottom)?",
               source,
               game);
       controller.moveCardToLibraryWithInfo(
           sourceCard, source.getSourceId(), game, Zone.GRAVEYARD, onTop, true);
     }
     return true;
   }
   return false;
 }
示例#27
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Card card = player.getLibrary().getFromTop(game);
    if (card != null) {
      Cards cards = new CardsImpl();
      cards.add(card);
      player.lookAtCards("Into the Wilds", cards, game);
      if (filter.match(card, game)) {
        String message = "Put " + card.getName() + " onto the battlefield?";
        if (player.chooseUse(outcome, message, game)) {
          return card.putOntoBattlefield(
              game, Zone.LIBRARY, source.getId(), source.getControllerId(), false);
        }
      }
    }
    return true;
  }
示例#28
0
 @Override
 public boolean resolve(Game game) {
   if (optional) {
     Player player = game.getPlayer(this.getControllerId());
     MageObject object = game.getObject(sourceId);
     StringBuilder sb = new StringBuilder();
     if (object != null) {
       sb.append("Use the following ability from ").append(object.getName()).append("? ");
       sb.append(this.getRule(object.getName()));
     } else {
       sb.append("Use the following ability? ").append(this.getRule());
     }
     if (!player.chooseUse(getEffects().get(0).getOutcome(), sb.toString(), game)) {
       return false;
     }
   }
   // 20091005 - 603.4
   if (checkInterveningIfClause(game)) {
     return super.resolve(game);
   }
   return false;
 }
示例#29
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
      boolean targetChosen = false;
      TargetPermanent target = new TargetPermanent(1, 1, filter, true);
      if (target.canChoose(controller.getId(), game)
          && controller.chooseUse(
              outcome, "Return another creature you control to its owner's hand?", source, game)) {
        controller.chooseTarget(Outcome.ReturnToHand, target, source, game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
          targetChosen = true;
          permanent.moveToZone(Zone.HAND, this.getId(), game, false);
        }
      }

      if (!targetChosen) {
        new SacrificeSourceEffect().apply(game, source);
      }
      return true;
    }
    return false;
  }
示例#30
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     boolean costPaid = false;
     for (UUID playerId : controller.getInRange()) {
       Cost cost =
           new SacrificeTargetCost(
               new TargetControlledPermanent(new FilterControlledLandPermanent()));
       Player player = game.getPlayer(playerId);
       if (player != null
           && cost.canPay(source, source.getSourceId(), playerId, game)
           && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", game)
           && cost.pay(source, game, source.getSourceId(), playerId, true)) {
         costPaid = true;
       }
     }
     if (costPaid) {
       super.apply(game, source);
     }
     return true;
   }
   return false;
 }