Ejemplo n.º 1
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Permanent permanent = (Permanent) game.getLastKnownInformation(target, Zone.BATTLEFIELD);
   if (permanent != null && controller != null) {
     Player player = game.getPlayer(permanent.getOwnerId());
     if (player != null) {
       FilterCreatureCard filter =
           new FilterCreatureCard(
               new StringBuilder("a creature card from ")
                   .append(player.getLogName())
                   .append("'s graveyard")
                   .toString());
       filter.add(new OwnerIdPredicate(player.getId()));
       Target targetCreature = new TargetCardInGraveyard(filter);
       if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game)
           && controller.chooseTarget(outcome, targetCreature, source, game)) {
         Card card = game.getCard(targetCreature.getFirstTarget());
         if (card != null && game.getState().getZone(card.getId()).equals(Zone.GRAVEYARD)) {
           return card.putOntoBattlefield(
               game, Zone.GRAVEYARD, source.getSourceId(), player.getId());
         }
       }
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 2
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null && source.getTargets().size() > 0) {
     Target multiTarget = source.getTargets().get(0);
     for (UUID target : multiTarget.getTargets()) {
       Permanent permanent = game.getPermanent(target);
       if (permanent != null) {
         permanent.addCounters(
             CounterType.P1P1.createInstance(multiTarget.getTargetAmount(target)), game);
         game.informPlayers(
             new StringBuilder(controller.getLogName())
                 .append(" puts ")
                 .append(multiTarget.getTargetAmount(target))
                 .append(" ")
                 .append(CounterType.P1P1.getName().toLowerCase())
                 .append(" counter on ")
                 .append(permanent.getName())
                 .toString());
       }
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
  private void exileCards(Player player, int count, Ability source, Game game) {
    int amount =
        Math.min(
            count,
            player.getHand().size()
                + game.getBattlefield().getAllActivePermanents(player.getId()).size());

    while (amount > 0) {
      Target target = new TargetControlledPermanent(0, 1, filter, true);
      if (target.canChoose(player.getId(), game)
          && player.choose(Outcome.Exile, target, source.getSourceId(), game)) {

        for (UUID targetId : target.getTargets()) {
          Permanent chosen = game.getPermanent(targetId);
          if (chosen != null) {
            chosen.moveToExile(source.getId(), "Descent into Madness", source.getSourceId(), game);
            amount--;
          }
        }
      }

      if (amount > 0) {
        TargetCard targetInHand = new TargetCard(Zone.HAND, filterInHand);
        if (targetInHand.canChoose(player.getId(), game)
            && player.choose(Outcome.Exile, player.getHand(), targetInHand, game)) {

          Card card = player.getHand().get(targetInHand.getFirstTarget(), game);
          if (card != null) {
            card.moveToExile(source.getId(), "Descent into Madness", source.getSourceId(), game);
            amount--;
          }
        }
      }
    }
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 6
0
 @Override
 public boolean apply(Card input, Game game) {
   for (Target target : input.getSpellAbility().getTargets()) {
     if (target.canTarget(toBeCheckedPermanentId, input.getSpellAbility(), game)) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 7
0
  public Deglamer(UUID ownerId) {
    super(ownerId, 118, "Deglamer", Rarity.COMMON, new CardType[] {CardType.INSTANT}, "{1}{G}");
    this.expansionSetCode = "MOR";

    this.color.setGreen(true);

    // Choose target artifact or enchantment. Its owner shuffles it into his or her library.
    this.getSpellAbility().addEffect(new DeglamerShuffleIntoLibraryEffect());
    Target target = new TargetPermanent(1, 1, filter, true);
    target.setRequired(true);
    this.getSpellAbility().addTarget(target);
  }
Ejemplo n.º 8
0
  public EchoingTruth(UUID ownerId) {
    super(ownerId, 66, "Echoing Truth", Rarity.COMMON, new CardType[] {CardType.INSTANT}, "{1}{U}");
    this.expansionSetCode = "DDF";

    this.color.setBlue(true);

    // Return target nonland permanent and all other permanents with the same name as that permanent
    // to their owners' hands.
    Target target = new TargetNonlandPermanent();
    target.setRequired(true);
    this.getSpellAbility().addTarget(target);
    this.getSpellAbility().addEffect(new ReturnToHandAllNamedPermanentsEffect());
  }
Ejemplo n.º 9
0
 public GruulTurf(UUID ownerId) {
   super(ownerId, 134, "Gruul Turf", Rarity.COMMON, new CardType[] {CardType.LAND}, "");
   this.expansionSetCode = "HOP";
   this.addAbility(new EntersBattlefieldTappedAbility());
   Ability ability = new EntersBattlefieldTriggeredAbility(new ReturnToHandTargetEffect(), false);
   Target target = new TargetControlledPermanent(filter);
   target.setRequired(true);
   ability.addTarget(target);
   this.addAbility(ability);
   this.addAbility(
       new SimpleManaAbility(
           Constants.Zone.BATTLEFIELD, new Mana(1, 1, 0, 0, 0, 0, 0), new TapSourceCost()));
 }
Ejemplo n.º 10
0
 @Override
 public boolean apply(Game game, Ability source, Ability abilityToModify) {
   // Target target = abilityToModify.getTargets().get(0);
   for (Target target : abilityToModify.getTargets()) {
     if (target.getMaxNumberOfTargets() == Integer.MAX_VALUE) {
       int additionalTargets = target.getTargets().size() - 1;
       for (int i = 0; i < additionalTargets; i++) {
         abilityToModify.getManaCostsToPay().add(striveCosts.copy());
       }
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 11
0
 @Override
 public boolean apply(MageObject input, Game game) {
   Spell spell = game.getStack().getSpell(input.getId());
   if (spell != null) {
     Targets spellTargets = spell.getSpellAbility().getTargets();
     int numberOfTargets = 0;
     for (Target target : spellTargets) {
       numberOfTargets += target.getTargets().size();
     }
     if (numberOfTargets == targets) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 12
0
 @Override
 public boolean applies(Ability abilityToModify, Ability source, Game game) {
   if (abilityToModify instanceof SpellAbility) {
     if (game.getOpponents(source.getControllerId()).contains(abilityToModify.getControllerId())) {
       for (Target target : abilityToModify.getTargets()) {
         for (UUID targetUUID : target.getTargets()) {
           if (targetUUID.equals(source.getSourceId())) {
             return true;
           }
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 13
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;
 }
Ejemplo n.º 14
0
  @Override
  public boolean apply(ObjectPlayer<StackObject> input, Game game) {
    UUID controllerId = input.getPlayerId();
    if (controllerId == null) {
      return false;
    }

    for (Target target : input.getObject().getStackAbility().getTargets()) {
      for (UUID targetId : target.getTargets()) {
        if (controllerId.equals(targetId)) {
          return true;
        }
      }
    }
    return false;
  }
Ejemplo n.º 15
0
 @Override
 public boolean resolve(Game game) {
   int manaX = this.getManaCostsToPay().getX();
   FilterPermanent filter =
       new FilterCreaturePermanent("creature with power " + manaX + " or less");
   filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan, manaX + 1));
   Target target = new TargetPermanent(filter);
   Player player = game.getPlayer(controllerId);
   if (player != null) {
     if (player.chooseTarget(Outcome.Benefit, target, this, game)) {
       this.getEffects().get(0).setTargetPointer(new FixedTarget(target.getFirstTarget()));
       return super.resolve(game);
     }
   }
   return false;
 }
Ejemplo n.º 16
0
  public GoForTheThroat(UUID ownerId) {
    super(
        ownerId,
        43,
        "Go for the Throat",
        Rarity.UNCOMMON,
        new CardType[] {CardType.INSTANT},
        "{1}{B}");
    this.expansionSetCode = "MBS";
    this.color.setBlack(true);

    Target target = new TargetCreaturePermanent(filter);
    target.setTargetName("nonartifact creature");
    this.getSpellAbility().addTarget(target);
    this.getSpellAbility().addEffect(new DestroyTargetEffect());
  }
Ejemplo n.º 17
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getTargets().get(1).getFirstTarget());
    if (player == null) {
      return false;
    }

    Target target = new TargetControlledPermanent(new FilterControlledCreaturePermanent());
    if (target.canChoose(player.getId(), game)
        && player.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
      Permanent permanent = game.getPermanent(target.getFirstTarget());
      if (permanent != null) {
        return permanent.sacrifice(source.getSourceId(), game);
      }
    }
    return false;
  }
Ejemplo n.º 18
0
 protected boolean chooseRandom(Target target, Game game) {
   Set<UUID> possibleTargets = target.possibleTargets(playerId, game);
   if (possibleTargets.isEmpty()) {
     return false;
   }
   if (possibleTargets.size() == 1) {
     target.add(possibleTargets.iterator().next(), game);
     return true;
   }
   Iterator<UUID> it = possibleTargets.iterator();
   int targetNum = rnd.nextInt(possibleTargets.size());
   UUID targetId = it.next();
   for (int i = 0; i < targetNum; i++) {
     targetId = it.next();
   }
   target.add(targetId, game);
   return true;
 }
Ejemplo n.º 19
0
 @Override
 public boolean applies(Ability abilityToModify, Ability source, Game game) {
   if (abilityToModify instanceof SpellAbility) {
     if (source.getControllerId().equals(abilityToModify.getControllerId())) {
       for (UUID modeId : abilityToModify.getModes().getSelectedModes()) {
         Mode mode = abilityToModify.getModes().get(modeId);
         for (Target target : mode.getTargets()) {
           for (UUID targetUUID : target.getTargets()) {
             Permanent enchantment = game.getPermanent(source.getSourceId());
             UUID attachedTo = enchantment.getAttachedTo();
             if (targetUUID.equals(attachedTo)) {
               return true;
             }
           }
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 20
0
 @Override
 public boolean apply(Game game, Ability source) {
   if (source.getTargets().size() > 0) {
     Target multiTarget = source.getTargets().get(0);
     for (UUID target : multiTarget.getTargets()) {
       Permanent permanent = game.getPermanent(target);
       if (permanent != null) {
         permanent.damage(
             multiTarget.getTargetAmount(target), source.getSourceId(), game, true, false);
       } else {
         Player player = game.getPlayer(target);
         if (player != null) {
           player.damage(
               multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true);
         }
       }
     }
   }
   return true;
 }
Ejemplo n.º 21
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;
  }
Ejemplo n.º 22
0
 protected void addAbilityNode(SimulationNode parent, Ability ability, Game game) {
   Game sim = game.copy();
   sim.getStack().push(new StackAbility(ability, playerId));
   ability.activate(sim, false);
   sim.applyEffects();
   SimulationNode newNode = new SimulationNode(parent, sim, playerId);
   logger.debug(
       indent(newNode.getDepth())
           + "simulating -- node #:"
           + SimulationNode.getCount()
           + " triggered ability option");
   for (Target target : ability.getTargets()) {
     for (UUID targetId : target.getTargets()) {
       newNode.getTargets().add(targetId);
     }
   }
   for (Choice choice : ability.getChoices()) {
     newNode.getChoices().add(choice.getChoice());
   }
   parent.children.add(newNode);
 }
Ejemplo n.º 23
0
 @Override
 public boolean apply(Game game, Ability source) {
   boolean result = false;
   int destroyedCreatures = 0;
   for (Target target : source.getTargets()) {
     if (target instanceof TargetPermanent) {
       Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
       if (targetPermanent != null) {
         if (targetPermanent.destroy(source.getSourceId(), game, false)) {
           destroyedCreatures++;
         }
       }
     }
   }
   if (destroyedCreatures > 0) {
     new SearchLibraryPutInPlayEffect(
             new TargetCardInLibrary(destroyedCreatures, filterForest), true, true)
         .apply(game, source);
   }
   return result;
 }
Ejemplo n.º 24
0
  @Override
  public boolean apply(Game game, Ability source) {
    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    for (UUID opponentId : opponents) {
      Player player = game.getPlayer(opponentId);
      Target target = new TargetControlledPermanent(filter);

      if (target.canChoose(player.getId(), game)) {
        while (!target.isChosen() && target.canChoose(player.getId(), game)) {
          player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        }

        Permanent permanent = game.getPermanent(target.getFirstTarget());

        if (permanent != null) {
          permanent.sacrifice(source.getSourceId(), game);
        }
      }
    }
    return true;
  }
Ejemplo n.º 25
0
 protected boolean chooseRandomTarget(Target target, Ability source, Game game) {
   Set<UUID> possibleTargets =
       target.possibleTargets(source == null ? null : source.getSourceId(), playerId, game);
   if (possibleTargets.isEmpty()) return false;
   if (!target.isRequired()) {
     if (rnd.nextInt(possibleTargets.size() + 1) == 0) {
       return false;
     }
   }
   if (possibleTargets.size() == 1) {
     target.addTarget(possibleTargets.iterator().next(), source, game);
     return true;
   }
   Iterator<UUID> it = possibleTargets.iterator();
   int targetNum = rnd.nextInt(possibleTargets.size());
   UUID targetId = it.next();
   for (int i = 0; i < targetNum; i++) {
     targetId = it.next();
   }
   target.addTarget(targetId, source, game);
   return true;
 }
Ejemplo n.º 26
0
    @Override
    public boolean checkTrigger(GameEvent event, Game game) {
      if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
        Permanent permanent = game.getPermanent(event.getTargetId());
        if (permanent.getCardType().contains(CardType.CREATURE)
            && (permanent.getControllerId().equals(this.controllerId))) {

          if (!this.getTargets().isEmpty()) {
            // remove previous target
            if (this.getTargets().get(0).getTargets().size() > 0) {
              this.getTargets().clear();
              this.addTarget(new TargetCreaturePermanent());
            }
            Target target = this.getTargets().get(0);
            if (target instanceof TargetCreaturePermanent) {
              target.add(event.getTargetId(), game);
            }
          }
          return true;
        }
      }
      return false;
    }
Ejemplo n.º 27
0
 protected String getTargetDescriptionForLog(Targets targets, Game game) {
   StringBuilder sb =
       new StringBuilder(); // threadLocal StringBuilder can't be used because calling method
   // already uses it
   if (targets.size() > 0) {
     String usedVerb = null;
     for (Target target : targets) {
       if (!target.getTargets().isEmpty()) {
         if (!target.isNotTarget()) {
           if (usedVerb == null || usedVerb.equals(" choosing ")) {
             usedVerb = " targeting ";
             sb.append(usedVerb);
           }
         } else if (target.isNotTarget() && (usedVerb == null || usedVerb.equals(" targeting "))) {
           usedVerb = " choosing ";
           sb.append(usedVerb);
         }
         sb.append(target.getTargetedName(game));
       }
     }
   }
   return sb.toString();
 }
Ejemplo n.º 28
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;
  }
Ejemplo n.º 29
0
  public TriumphOfCruelty(UUID ownerId) {
    super(
        ownerId,
        122,
        "Triumph of Cruelty",
        Rarity.UNCOMMON,
        new CardType[] {CardType.ENCHANTMENT},
        "{2}{B}");
    this.expansionSetCode = "AVR";

    this.color.setBlack(true);

    // At the beginning of your upkeep, target opponent discards a card if you control the creature
    // with the greatest power or tied for the greatest power.
    TriggeredAbility ability =
        new BeginningOfUpkeepTriggeredAbility(
            new DiscardTargetEffect(1), Constants.TargetController.YOU, false);
    Target target = new TargetOpponent();
    target.setRequired(true);
    ability.addTarget(target);
    this.addAbility(
        new ConditionalTriggeredAbility(
            ability, ControlsBiggestOrTiedCreatureCondition.getInstance(), ruleText));
  }
Ejemplo n.º 30
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (sourceObject != null && controller != null) {
     Cards cards = new CardsImpl();
     cards.addAll(controller.getLibrary().getTopCards(game, 3));
     if (!cards.isEmpty()) {
       controller.revealCards(staticText, cards, game);
       Card cardToGraveyard;
       if (cards.size() == 1) {
         cardToGraveyard = cards.getRandom(game);
       } else {
         Player opponent;
         Set<UUID> opponents = game.getOpponents(controller.getId());
         if (opponents.size() == 1) {
           opponent = game.getPlayer(opponents.iterator().next());
         } else {
           Target target = new TargetOpponent(true);
           controller.chooseTarget(Outcome.Detriment, target, source, game);
           opponent = game.getPlayer(target.getFirstTarget());
         }
         TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
         opponent.chooseTarget(outcome, cards, target, source, game);
         cardToGraveyard = game.getCard(target.getFirstTarget());
       }
       if (cardToGraveyard != null) {
         controller.moveCards(cardToGraveyard, Zone.LIBRARY, Zone.GRAVEYARD, source, game);
         cards.remove(cardToGraveyard);
       }
       controller.moveCards(cards, Zone.LIBRARY, Zone.HAND, source, game);
     }
     return true;
   }
   return false;
 }