Exemple #1
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;
 }
Exemple #2
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     int xSum = 0;
     xSum += playerPaysXGenericMana(controller, source, game);
     for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
       if (playerId != controller.getId()) {
         Player player = game.getPlayer(playerId);
         if (player != null) {
           xSum += playerPaysXGenericMana(player, source, game);
         }
       }
     }
     if (xSum > 0) {
       for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
         Effect effect = new PutTopCardOfLibraryIntoGraveTargetEffect(xSum);
         effect.setTargetPointer(new FixedTarget(playerId));
         effect.apply(game, source);
       }
     }
     // prevent undo
     controller.resetStoredBookmark(game);
     return true;
   }
   return false;
 }
Exemple #3
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());

    // If no controller, exit out here and do not vote.
    if (controller == null) return false;

    this.vote("feather", "quill", controller, game, source);

    Permanent permanent = game.getPermanent(source.getSourceId());

    // Feathers Votes
    // If feathers received zero votes or the permanent is no longer on the battlefield, do not
    // attempt to put P1P1 counter on it.
    if (voteOneCount > 0 && permanent != null)
      permanent.addCounters(CounterType.P1P1.createInstance(voteOneCount), game);

    // Quill Votes
    // Only let the controller loot the appropriate amount of cards if it was voted for.
    if (voteTwoCount > 0) {
      Effect lootCardsEffect = new DrawDiscardControllerEffect(voteTwoCount, voteTwoCount);
      lootCardsEffect.apply(game, source);
    }

    return true;
  }
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     boolean lessCreatures = false;
     boolean lessLife = false;
     FilterPermanent filter = new FilterCreaturePermanent();
     int count = game.getBattlefield().countAll(filter, controller.getId(), game);
     for (UUID uuid : game.getOpponents(controller.getId())) {
       Player opponent = game.getPlayer(uuid);
       if (opponent != null) {
         if (opponent.getLife() > controller.getLife()) {
           lessLife = true;
         }
         if (game.getBattlefield().countAll(filter, uuid, game) > count) {
           lessCreatures = true;
         }
       }
       if (lessLife && lessCreatures) { // no need to search further
         break;
       }
     }
     if (lessLife) {
       controller.gainLife(6, game);
     }
     if (lessCreatures) {
       Effect effect = new CreateTokenEffect(new SoldierToken(), 3);
       effect.apply(game, source);
     }
     return true;
   }
   return false;
 }
Exemple #5
0
  @Override
  public boolean resolve(Game game) {
    boolean result = true;
    // 20100716 - 117.12
    if (checkIfClause(game)) {

      for (Effect effect : getEffects()) {
        if (effect instanceof OneShotEffect) {
          boolean effectResult = effect.apply(game, this);
          result &= effectResult;
          if (logger.isDebugEnabled()) {
            if (!this.getAbilityType().equals(AbilityType.MANA)) {
              if (!effectResult) {
                if (this.getSourceId() != null) {
                  MageObject mageObject = game.getObject(this.getSourceId());
                  if (mageObject != null) {
                    logger.debug("AbilityImpl.resolve: object: " + mageObject.getName());
                  }
                }
                logger.debug(
                    "AbilityImpl.resolve: effect returned false -"
                        + effect.getText(this.getModes().getMode()));
              }
            }
          }
        } else {
          game.addEffect((ContinuousEffect) effect, this);
        }
        /**
         * All restrained trigger events are fired now. To restrain the events is mainly neccessary
         * because of the movement of multiple object at once. If the event is fired directly as one
         * object moved, other objects are not already in the correct zone to check for their
         * effects. (e.g. Valakut, the Molten Pinnacle)
         */
        game.getState().handleSimultaneousEvent(game);
        game.resetShortLivingLKI();
        /**
         * game.applyEffects() has to be done at least for every effect that moves cards/permanent
         * between zones, or changes control of objects so Static effects work as intened if
         * dependant from the moved objects zone it is in Otherwise for example were static
         * abilities with replacement effects deactivated too late Example: {@link
         * org.mage.test.cards.replacement.DryadMilitantTest#testDiesByDestroy testDiesByDestroy}
         */
        if (effect.applyEffectsAfter()) {
          game.applyEffects();
          game.getState().getTriggers().checkStateTriggers(game);
        }
      }
    }
    return result;
  }