示例#1
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) {
     controller.shuffleLibrary(source, game);
     if (controller.getLibrary().size() > 0) {
       Card card = controller.getLibrary().removeFromTop(game);
       if (card != null) {
         controller.moveCardToExileWithInfo(
             card,
             source.getSourceId(),
             sourceObject.getIdName(),
             source.getSourceId(),
             game,
             Zone.LIBRARY,
             true);
         ContinuousEffect effect = new MindsDesireCastFromExileEffect();
         effect.setTargetPointer(new FixedTarget(card.getId()));
         game.addEffect(effect, source);
       }
     }
     return true;
   }
   return false;
 }
示例#2
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;
 }
示例#3
0
  @Override
  public boolean apply(Game game, Ability source) {
    Permanent permanent =
        game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    if (permanent != null && sourceObject != null) {

      PutTokenOntoBattlefieldCopyTargetEffect effect =
          new PutTokenOntoBattlefieldCopyTargetEffect();
      effect.setTargetPointer(new FixedTarget(permanent, game));
      effect.apply(game, source);
      game.getState().setValue(source.getSourceId() + "_token", effect.getAddedPermanent());
      for (Permanent addedToken : effect.getAddedPermanent()) {
        Effect sacrificeEffect = new SacrificeTargetEffect("sacrifice Dance of Many");
        sacrificeEffect.setTargetPointer(new FixedTarget(sourceObject, game));
        LeavesBattlefieldTriggeredAbility triggerAbility =
            new LeavesBattlefieldTriggeredAbility(sacrificeEffect, false);
        ContinuousEffect continuousEffect =
            new GainAbilityTargetEffect(triggerAbility, Duration.WhileOnBattlefield);
        continuousEffect.setTargetPointer(new FixedTarget(addedToken, game));
        game.addEffect(continuousEffect, source);
      }
      return true;
    }
    return false;
  }
示例#4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent permanent = game.getPermanent(source.getFirstTarget());
   Player controller = game.getPlayer(source.getControllerId());
   Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
   if (controller != null && permanent != null && sourcePermanent != null) {
     CopyEffect copyEffect = new CopyEffect(Duration.EndOfTurn, permanent, source.getSourceId());
     if (controller.moveCardToExileWithInfo(
         permanent,
         source.getSourceId(),
         sourcePermanent.getIdName(),
         source.getSourceId(),
         game,
         Zone.BATTLEFIELD,
         true)) {
       // Copy exiled permanent
       game.addEffect(copyEffect, source);
       // Create delayed triggered ability
       AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility =
           new AtTheBeginOfNextEndStepDelayedTriggeredAbility(
               new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD, false));
       delayedAbility.setSourceId(source.getSourceId());
       delayedAbility.setControllerId(source.getControllerId());
       delayedAbility.setSourceObject(source.getSourceObject(game), game);
       game.addDelayedTriggeredAbility(delayedAbility);
       return true;
     }
   }
   return false;
 }
示例#5
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
      Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
      if (damagedPlayer == null) {
        return false;
      }
      FilterCard filter =
          new FilterCard(
              "target instant or sorcery card from " + damagedPlayer.getName() + "'s graveyard");
      filter.add(new OwnerIdPredicate(damagedPlayer.getId()));
      filter.add(
          Predicates.or(
              new CardTypePredicate(CardType.INSTANT), new CardTypePredicate(CardType.SORCERY)));

      Target target = new TargetCardInGraveyard(filter);
      if (controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
          controller.cast(card.getSpellAbility(), game, true);
          game.addEffect(new WrexialReplacementEffect(card.getId()), source);
        }
      }
      return true;
    }
    return false;
  }
示例#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;
    }
示例#7
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Player newController = game.getPlayer(this.getTargetPointer().getFirst(game, source));
   if (newController != null && controller != null && !controller.equals(newController)) {
     ContinuousEffect effect =
         new GainControlTargetEffect(Duration.Custom, newController.getId());
     effect.setTargetPointer(new FixedTarget(source.getSourceId()));
     game.addEffect(effect, source);
     return true;
   }
   return false;
 }
示例#8
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;
  }
示例#9
0
  @Override
  public boolean apply(Game game, Ability source) {
    boolean result = false;
    for (Target target : source.getTargets()) {
      if (target instanceof TargetCreaturePermanent) {
        Permanent targetCreature = game.getPermanent(target.getFirstTarget());
        if (targetCreature != null) {
          ContinuousEffect effect1 = new GainControlTargetEffect(Duration.EndOfTurn);
          effect1.setTargetPointer(new FixedTarget(targetCreature.getId()));
          game.addEffect(effect1, source);

          ContinuousEffect effect2 =
              new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
          effect2.setTargetPointer(new FixedTarget(targetCreature.getId()));
          game.addEffect(effect2, source);

          targetCreature.untap(game);
          result = true;
        }
      }
    }
    return result;
  }
示例#10
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     for (Permanent permanent :
         game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), game)) {
       ContinuousEffect effect = new MustBeBlockedByAtLeastOneTargetEffect();
       effect.setTargetPointer(new FixedTarget(permanent.getId()));
       game.addEffect(effect, source);
     }
     return true;
   }
   return false;
 }
示例#11
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Target target = new TargetSource();
     target.setRequired(true);
     target.setNotTarget(true);
     if (controller.chooseTarget(outcome, target, source, game)) {
       ContinuousEffect continuousEffect = new InterventionPactPreventDamageEffect();
       continuousEffect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
       game.addEffect(continuousEffect, source);
     }
     return true;
   }
   return false;
 }
示例#12
0
 public boolean apply(Game game, Ability source) {
   Permanent target = game.getPermanent(source.getFirstTarget());
   if (target != null) {
     for (ObjectColor color : target.getColor(game).getColors()) {
       FilterCard filter = new FilterCard(color.getDescription());
       filter.add(new ColorPredicate(color));
       game.addEffect(
           new GainAbilityControlledEffect(
               new ProtectionAbility(filter),
               Duration.EndOfTurn,
               new FilterControlledCreaturePermanent()),
           source);
     }
     return true;
   }
   return false;
 }
示例#13
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Choice choice = new ChoiceImpl(true);
     choice.setMessage("Choose creature type");
     choice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!controller.choose(Outcome.GainControl, choice, game)) {
       if (!controller.isInGame()) {
         return false;
       }
     }
     String chosenType = choice.getChoice();
     if (!game.isSimulation()) {
       game.informPlayers(controller.getLogName() + " has chosen " + chosenType);
     }
     UUID playerWithMost = null;
     int maxControlled = 0;
     for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
       FilterPermanent filter = new FilterCreaturePermanent(chosenType, chosenType);
       filter.add(new ControllerIdPredicate(playerId));
       int controlled = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
       if (controlled > maxControlled) {
         maxControlled = controlled;
         playerWithMost = playerId;
       } else if (controlled == maxControlled) {
         playerWithMost = null; // Do nothing in case of tie
       }
     }
     if (playerWithMost != null && playerWithMost.equals(controller.getId())) {
       for (Permanent permanent :
           game.getBattlefield()
               .getActivePermanents(
                   new FilterCreaturePermanent(chosenType, chosenType),
                   controller.getId(),
                   source.getSourceId(),
                   game)) {
         ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
         effect.setTargetPointer(new FixedTarget(permanent.getId()));
         game.addEffect(effect, source);
       }
     }
     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;
  }
示例#15
0
 @Override
 public boolean apply(Game game, Ability source) {
   List<Permanent> doNotUntapNextUntapStep = new ArrayList<>();
   for (Permanent creature :
       game.getBattlefield()
           .getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
     creature.tap(game);
     doNotUntapNextUntapStep.add(creature);
   }
   if (!doNotUntapNextUntapStep.isEmpty()) {
     ContinuousEffect effect =
         new DontUntapInControllersNextUntapStepTargetEffect("This creature");
     effect.setTargetPointer(new FixedTargets(doNotUntapNextUntapStep, game));
     game.addEffect(effect, source);
   }
   return true;
 }
示例#16
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;
 }
示例#17
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    int cmc = 0;
    for (Cost cost : source.getCosts()) {
      if (cost instanceof PayVariableLoyaltyCost) {
        cmc = ((PayVariableLoyaltyCost) cost).getAmount();
      }
    }

    FilterCard filter =
        new FilterCreatureCard(
            new StringBuilder("creature card with converted mana cost {")
                .append(cmc)
                .append("} exiled with Ashiok, Nightmare Weaver")
                .toString());
    filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.Equal, cmc));
    Target target = new TargetCardInExile(filter, CardUtil.getCardExileZoneId(game, source));

    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
      if (player.chooseTarget(Outcome.PutCreatureInPlay, target, source, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null
            && player.putOntoBattlefieldWithInfo(card, game, Zone.EXILED, source.getSourceId())) {
          Permanent permanent = game.getPermanent(card.getId());
          if (permanent != null) {
            permanent.changeControllerId(source.getControllerId(), game);
          }
          ContinuousEffectImpl effect = new AshiokNightmareWeaverAddTypeEffect();
          effect.setTargetPointer(new FixedTarget(card.getId()));
          game.addEffect(effect, source);
          return true;
        }
      }
    }
    return false;
  }
示例#18
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     UUID targetId = targetPointer.getFirst(game, source);
     StackObject stackObject = game.getStack().getStackObject(targetId);
     if (stackObject != null
         && game.getStack()
             .counter(targetId, source.getSourceId(), game, Zone.EXILED, false, false)) {
       Card card = ((Spell) stackObject).getCard();
       if (card != null) {
         ContinuousEffect effect = new SpelljackCastFromExileEffect();
         effect.setTargetPointer(
             new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
         game.addEffect(effect, source);
       }
     }
     return true;
   }
   return false;
 }
示例#19
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     CreateTokenEffect effect = new CreateTokenEffect(new ElfToken(), 2);
     effect.apply(game, source);
     if (ClashEffect.getInstance().apply(game, source)) {
       for (UUID tokenId : effect.getLastAddedTokenIds()) {
         Permanent token = game.getPermanent(tokenId);
         if (token != null) {
           ContinuousEffect continuousEffect =
               new GainAbilityTargetEffect(DeathtouchAbility.getInstance(), Duration.EndOfTurn);
           continuousEffect.setTargetPointer(new FixedTarget(tokenId));
           game.addEffect(continuousEffect, source);
         }
       }
     }
     return true;
   }
   return false;
 }
示例#20
0
  @Override
  public boolean apply(Game game, Ability source) {
    Map<Integer, Set<String>> attackerMap = null;
    Object object = game.getState().getValue("blockedAttackers" + source.getSourceId());
    if (object != null && object instanceof Map) {
      attackerMap = (Map<Integer, Set<String>>) object;
      for (Set<String> attackerSet : attackerMap.values()) {
        List<Permanent> doNotUntapNextUntapStep = new ArrayList<>();
        for (Permanent creature :
            game.getBattlefield()
                .getActivePermanents(
                    new FilterCreaturePermanent(), source.getControllerId(), game)) {
          if (attackerSet.contains(CardUtil.getCardZoneString(null, creature.getId(), game))) {
            // tap creature and add the not untap effect
            creature.tap(game);
            doNotUntapNextUntapStep.add(creature);
            game.informPlayers(
                new StringBuilder("Triton Tactics: ")
                    .append(creature.getName())
                    .append(" doesn't untap during its controller's next untap step")
                    .toString());
          }
        }
        if (!doNotUntapNextUntapStep.isEmpty()) {
          ContinuousEffect effect =
              new DontUntapInControllersNextUntapStepTargetEffect("This creature");
          effect.setTargetPointer(new FixedTargets(doNotUntapNextUntapStep, game));
          game.addEffect(effect, source);
        }
      }
    }
    if (attackerMap != null) {
      attackerMap.clear();
    }

    return true;
  }
 @Override
 public boolean apply(Game game, Ability source) {
   ContinuousEffect effectToAdd = (ContinuousEffect) effect.copy();
   game.addEffect(effectToAdd, source);
   return true;
 }