use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class IndulgentTormentorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(source.getFirstTarget());
if (opponent != null) {
Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
if (cost.canPay(source, source, opponent.getId(), game) && opponent.chooseUse(outcome, "Sacrifice a creature to prevent the card draw?", source, game)) {
if (cost.pay(source, game, source, opponent.getId(), false, null)) {
return true;
}
}
cost = new PayLifeCost(3);
if (cost.canPay(source, source, opponent.getId(), game) && opponent.chooseUse(outcome, "Pay 3 life to prevent the card draw?", source, game)) {
if (cost.pay(source, game, source, opponent.getId(), false, null)) {
return true;
}
}
game.getPlayer(source.getControllerId()).drawCards(1, source, game);
return true;
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class LegacyOfTheBelovedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
Permanent p = (Permanent) game.getLastKnownInformation(((SacrificeTargetCost) cost).getPermanents().get(0).getId(), Zone.BATTLEFIELD);
if (p != null) {
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, p.getManaValue()));
TargetCardInLibrary target = new TargetCardInLibrary(0, 2, filter);
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.searchLibrary(target, source, game)) {
player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
player.shuffleLibrary(source, game);
return true;
}
}
}
}
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class PossessedPortalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
Cost discardCost = new DiscardCardCost();
if (player != null && discardCost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Discard, "Discard a card? (Otherwise sacrifice a permanent)", source, game)) {
discardCost.pay(source, game, source, playerId, true, null);
} else {
Cost sacrificeCost = new SacrificeTargetCost(new TargetControlledPermanent());
sacrificeCost.pay(source, game, source, playerId, true, null);
}
}
return true;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class SithEvokerEffect method apply.
@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 mode");
choice.setChoices(choices);
if (!controller.choose(outcome, choice, game)) {
return false;
}
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
for (Object cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
Permanent p = (Permanent) game.getLastKnownInformation(((SacrificeTargetCost) cost).getPermanents().get(0).getId(), Zone.BATTLEFIELD);
if (p != null) {
String chosen = choice.getChoice();
switch(chosen) {
case "Gain life equal to creature's power":
new GainLifeEffect(p.getPower().getValue()).apply(game, source);
break;
default:
// "Gain life equal to creature's toughness"
new GainLifeEffect(p.getToughness().getValue()).apply(game, source);
break;
}
return true;
}
}
}
}
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class SwordOfTheAgesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Set<Card> cardsToExile = new HashSet<>();
if (controller != null) {
int totalPower = 0;
Card card = game.getCard(source.getSourceId());
if (card != null) {
// consulted this on mtgjudges - regardless of what zone they end up in after sac, the creature cards and Sword will be moved to exile (unless there's another replacement effect for exiling them)
cardsToExile.add(card);
}
for (Cost cost : source.getCosts()) {
// Sword of the Ages doesn't count itself for total damage if it's a creature: http://www.mtgsalvation.com/forums/the-game/commander-edh/202963-sword-of-the-ages
if (cost instanceof SacrificeTargetCost) {
for (Permanent permanent : ((SacrificeTargetCost) cost).getPermanents()) {
totalPower += permanent.getPower().getValue();
Card permanentCard = game.getCard(permanent.getId());
if (permanentCard != null) {
cardsToExile.add(permanentCard);
}
}
}
}
if (totalPower > 0) {
Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (player != null) {
player.damage(totalPower, source.getSourceId(), source, game);
} else {
Permanent creature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (creature != null) {
creature.damage(totalPower, source.getSourceId(), source, game, false, true);
}
}
}
return controller.moveCards(cardsToExile, Zone.EXILED, source, game);
}
return false;
}
Aggregations