use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class DawnbreakReclaimerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
/**
* 04.11.2015 If any opponent has a creature card in their graveyard as
* Dawnbreak Reclaimer's ability resolves, then you must choose one of
* those cards. You can't choose a different opponent with no creature
* cards in their graveyard to avoid returning one of those cards.
*
* 04.11.2015 If there are no creature cards in any opponent's graveyard
* as Dawnbreak Reclaimer's ability resolves, you'll still have the
* option to return a creature card from your graveyard to the
* battlefield. You choose which opponent will choose a creature card in
* your graveyard.
*/
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
FilterCreatureCard filter = new FilterCreatureCard("a creature card in an opponent's graveyard");
filter.add(TargetController.OPPONENT.getOwnerPredicate());
TargetCard chosenCreatureOpponentGraveyard = new TargetCard(Zone.GRAVEYARD, filter);
Player opponent = null;
Card cardOpponentGraveyard = null;
chosenCreatureOpponentGraveyard.setNotTarget(true);
if (chosenCreatureOpponentGraveyard.canChoose(source.getSourceId(), source.getControllerId(), game)) {
controller.choose(Outcome.Detriment, chosenCreatureOpponentGraveyard, source.getSourceId(), game);
cardOpponentGraveyard = game.getCard(chosenCreatureOpponentGraveyard.getFirstTarget());
if (cardOpponentGraveyard != null) {
opponent = game.getPlayer(cardOpponentGraveyard.getOwnerId());
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + cardOpponentGraveyard.getIdName() + " of " + opponent.getLogName());
}
}
if (opponent == null) {
// if no card from opponent was available controller has to chose an opponent to select a creature card in controllers graveyard
TargetOpponent targetOpponent = new TargetOpponent(true);
controller.choose(outcome, targetOpponent, source.getSourceId(), game);
opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName() + " to select a creature card from their graveyard");
}
}
if (opponent != null) {
FilterCreatureCard filterCreatureCard = new FilterCreatureCard("a creature card in " + controller.getName() + "'s the graveyard");
filterCreatureCard.add(new OwnerIdPredicate(controller.getId()));
TargetCardInGraveyard targetControllerGaveyard = new TargetCardInGraveyard(filterCreatureCard);
targetControllerGaveyard.setNotTarget(true);
Card controllerCreatureCard = null;
if (targetControllerGaveyard.canChoose(source.getSourceId(), opponent.getId(), game) && opponent.choose(outcome, targetControllerGaveyard, source.getSourceId(), game)) {
controllerCreatureCard = game.getCard(targetControllerGaveyard.getFirstTarget());
if (controllerCreatureCard != null) {
game.informPlayers(sourceObject.getLogName() + ": " + opponent.getLogName() + " has chosen " + controllerCreatureCard.getIdName() + " of " + controller.getLogName());
}
}
Set<Card> cards = new HashSet<>();
if (cardOpponentGraveyard != null) {
cards.add(cardOpponentGraveyard);
}
if (controllerCreatureCard != null) {
cards.add(controllerCreatureCard);
}
if (!cards.isEmpty()) {
if (controller.chooseUse(outcome, "Return those cards to the battlefield under their owners' control?", "Opponent's creature card: " + (cardOpponentGraveyard == null ? "none" : cardOpponentGraveyard.getLogName()) + ", your creature card: " + (controllerCreatureCard == null ? "none" : controllerCreatureCard.getLogName()), null, null, source, game)) {
controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class DeadReckoningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
TargetCardInYourGraveyard target1 = new TargetCardInYourGraveyard(new FilterCreatureCard("creature card in your graveyard"));
TargetCreaturePermanent target2 = new TargetCreaturePermanent();
if (controller != null) {
if (target1.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.Benefit, target1, source.getSourceId(), game) && target2.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.Damage, target2, source.getSourceId(), game)) {
Card creatureInGraveyard = game.getCard(target1.getFirstTarget());
if (creatureInGraveyard != null) {
if (controller.putCardsOnTopOfLibrary(creatureInGraveyard, game, source, true)) {
int power = creatureInGraveyard.getPower().getValue();
Permanent creature = game.getPermanent(target2.getFirstTarget());
if (creature != null) {
creature.damage(power, source.getSourceId(), source, game, false, true);
return true;
}
}
}
}
}
return false;
}
use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class GhoulsNightOutTypeChangingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID controllerId = source.getControllerId();
Player controller = game.getPlayer(controllerId);
if (controller != null) {
Set<Card> cardsToBattlefield = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
boolean creatureInGraveyard = false;
for (UUID cardId : player.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
creatureInGraveyard = true;
break;
}
}
if (creatureInGraveyard) {
FilterCreatureCard filter = new FilterCreatureCard("creature card in " + player.getName() + "'s graveyard");
TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
target.setNotTarget(true);
controller.chooseTarget(controllerId.equals(playerId) ? Outcome.Benefit : Outcome.Detriment, player.getGraveyard(), target, source, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cardsToBattlefield.add(card);
}
}
}
}
if (!cardsToBattlefield.isEmpty()) {
controller.moveCards(cardsToBattlefield, Zone.BATTLEFIELD, source, game);
cardsToBattlefield.removeIf(card -> game.getState().getZone(card.getId()) != Zone.BATTLEFIELD);
if (!cardsToBattlefield.isEmpty()) {
game.addEffect(new GhoulsNightOutTypeChangingEffect().setTargetPointer(new FixedTargets(cardsToBattlefield, game)), source);
game.addEffect(new GainAbilityTargetEffect(new DecayedAbility(), Duration.Custom).setTargetPointer(new FixedTargets(cardsToBattlefield, game)), source);
return true;
}
}
}
return false;
}
use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class HeraldsHornEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
// Look at the top card of your library.
if (controller != null && controller.getLibrary().hasCards() && sourceObject != null) {
Card card = controller.getLibrary().getFromTop(game);
Cards cards = new CardsImpl(card);
controller.lookAtCards(sourceObject.getIdName(), cards, game);
// If it's a creature card of the chosen type, you may reveal it and put it into your hand.
FilterCreatureCard filter = new FilterCreatureCard("creature card of the chosen type");
SubType subtype = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
filter.add(subtype.getPredicate());
String message = "Reveal the top card of your library and put that card into your hand?";
if (card != null) {
if (filter.match(card, game) && controller.chooseUse(Outcome.Benefit, message, source, game)) {
controller.moveCards(card, Zone.HAND, source, game);
controller.revealCards(sourceObject.getIdName() + " put into hand", cards, game);
return true;
}
}
}
return false;
}
use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class StitcherGeralfEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
cards.addAll(player.millCards(3, source, game));
}
}
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.GRAVEYARD);
TargetCard target = new TargetCard(0, 2, Zone.GRAVEYARD, new FilterCreatureCard("creature cards to exile"));
controller.chooseTarget(outcome, cards, target, source, game);
int power = 0;
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
power += card.getPower().getValue();
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
}
}
return new CreateTokenEffect(new StitcherGeralfZombieToken(power)).apply(game, source);
}
return false;
}
Aggregations