use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class MinionLeshracEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent minionLeshrac = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && minionLeshrac != null) {
FilterControlledPermanent filterCreature = new FilterControlledPermanent();
filterCreature.add(CardType.CREATURE.getPredicate());
filterCreature.add(AnotherPredicate.instance);
TargetControlledPermanent target = new TargetControlledPermanent(filterCreature);
SacrificeTargetCost cost = new SacrificeTargetCost(target);
if (controller.chooseUse(Outcome.AIDontUseIt, "Sacrifice another creature to prevent the damage?", source, game) && cost.canPay(source, source, source.getControllerId(), game) && cost.pay(source, game, source, source.getControllerId(), true)) {
return true;
}
if (controller.damage(5, minionLeshrac.getId(), source, game) > 0) {
minionLeshrac.tap(source, game);
return true;
}
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class ShivanWumpusEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
boolean costPaid = false;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent()));
Player player = game.getPlayer(playerId);
if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
costPaid = true;
}
}
if (costPaid) {
super.apply(game, source);
}
return true;
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class SpiritSistersCallPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId = source.getFirstTarget();
Card card = game.getCard(targetId);
if (card == null || game.getState().getZone(targetId) != Zone.GRAVEYARD) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("a permanent that shares a card type with the chosen card");
filter.add(new SpiritSistersCallPredicate(new HashSet<CardType>(card.getCardType(game))));
return new DoIfCostPaid(new SpiritSistersCallReturnToBattlefieldEffect(), new SacrificeTargetCost(filter)).apply(game, source);
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class ThallidOmnivoreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
List<Permanent> permanents = sacrificeCost.getPermanents();
if (!permanents.isEmpty() && permanents.get(0).hasSubtype(SubType.SAPROLING, game)) {
controller.gainLife(2, game, source);
}
}
}
return true;
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class MindExtractionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(source.getFirstTarget());
if (controller == null || player == null) {
return false;
}
Permanent sacrificedCreature = null;
for (Cost cost : source.getCosts()) {
if (!(cost instanceof SacrificeTargetCost)) {
continue;
}
SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
for (Permanent permanent : sacCost.getPermanents()) {
sacrificedCreature = permanent;
break;
}
}
if (sacrificedCreature == null) {
return false;
}
ObjectColor color = sacrificedCreature.getColor(game);
Cards cards = new CardsImpl(player.getHand());
if (cards.isEmpty()) {
return true;
}
player.revealCards(source, cards, game);
if (color.isColorless()) {
return true;
}
Cards toDiscard = new CardsImpl();
cards.getCards(game).stream().filter(card -> card.getColor(game).shares(color)).forEach(toDiscard::add);
player.discard(toDiscard, false, source, game);
return true;
}
Aggregations