use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class TheThreeSeasonsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Map<Player, Cards> playerCardsMap = new LinkedHashMap<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
int cardCount = Math.min(player.getGraveyard().size(), 3);
if (cardCount < 1) {
continue;
}
TargetCard target = new TargetCardInGraveyard(cardCount, StaticFilters.FILTER_CARD);
target.setNotTarget(true);
controller.chooseTarget(outcome, player.getGraveyard(), target, source, game);
playerCardsMap.put(player, new CardsImpl(target.getTargets()));
}
for (Map.Entry<Player, Cards> entry : playerCardsMap.entrySet()) {
entry.getKey().shuffleCardsToLibrary(entry.getValue(), game, source);
}
return true;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class CustomTestCard method addCustomEffect_ReturnFromAnyToHand.
/**
* Return target card to hand that can be called by text "return from ..."
*
* @param controller
*/
protected void addCustomEffect_ReturnFromAnyToHand(TestPlayer controller) {
// graveyard
Ability ability = new SimpleActivatedAbility(new ReturnFromGraveyardToHandTargetEffect().setText("return from graveyard"), new ManaCostsImpl(""));
ability.addTarget(new TargetCardInGraveyard(StaticFilters.FILTER_CARD));
addCustomCardWithAbility("return from graveyard for " + controller.getName(), controller, ability);
// exile
ability = new SimpleActivatedAbility(new ReturnFromExileEffect(Zone.HAND).setText("return from exile"), new ManaCostsImpl(""));
ability.addTarget(new TargetCardInExile(StaticFilters.FILTER_CARD));
addCustomCardWithAbility("return from exile for " + controller.getName(), controller, ability);
// library
ability = new SimpleActivatedAbility(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD)).setText("return from library"), new ManaCostsImpl(""));
addCustomCardWithAbility("return from library for " + controller.getName(), controller, ability);
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ChandraAblazeEffect5 method apply.
@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(CardType.INSTANT.getPredicate(), CardType.SORCERY.getPredicate()));
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) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
cards.remove(card);
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ReincarnationDelayedEffect method apply.
@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("a creature card from " + player.getName() + "'s graveyard");
filter.add(new OwnerIdPredicate(player.getId()));
Target targetCreature = new TargetCardInGraveyard(filter);
targetCreature.setNotTarget(true);
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()) == Zone.GRAVEYARD) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
return true;
}
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class EnslavedHorrorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Set<Card> toBattlefield = new HashSet<>();
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (playerId.equals(controller.getId())) {
continue;
}
Player player = game.getPlayer(playerId);
if (player != null) {
FilterCreatureCard filterCreatureCard = new FilterCreatureCard("creature card from your graveyard");
filterCreatureCard.add(new OwnerIdPredicate(playerId));
TargetCardInGraveyard target = new TargetCardInGraveyard(0, 1, filterCreatureCard);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), playerId, game) && player.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
toBattlefield.add(card);
}
}
}
}
// must happen simultaneously Rule 101.4
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
return true;
}
return false;
}
Aggregations