예제 #1
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;
  }
예제 #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) {
     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;
 }
예제 #3
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;
 }
예제 #4
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;
  }
예제 #5
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;
 }
예제 #6
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;
 }
  @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;
  }
예제 #8
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;
 }
예제 #9
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;
 }
예제 #10
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;
 }
예제 #11
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;
 }
예제 #12
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;
 }
예제 #13
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;
  }