use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class MomentousFallEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int power = 0;
int toughness = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
power = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
toughness = ((SacrificeTargetCost) cost).getPermanents().get(0).getToughness().getValue();
break;
}
}
if (power > 0) {
controller.drawCards(power, source, game);
}
if (toughness > 0) {
controller.gainLife(toughness, game, source);
}
return true;
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class OswaldFiddlebenderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sacrificed = source.getCosts().stream().filter(SacrificeTargetCost.class::isInstance).map(SacrificeTargetCost.class::cast).map(SacrificeTargetCost::getPermanents).flatMap(Collection::stream).findFirst().orElse(null);
if (player == null || sacrificed == null) {
return false;
}
FilterCard filterCard = new FilterArtifactCard("artifact card with mana value " + (sacrificed.getManaValue() + 1));
filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, sacrificed.getManaValue() + 1));
TargetCardInLibrary target = new TargetCardInLibrary(filterCard);
player.searchLibrary(target, source, game);
Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
player.moveCards(card, Zone.BATTLEFIELD, source, game);
player.shuffleLibrary(source, game);
return true;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class ProwlingPangolinEffect 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(2, 2, new FilterControlledCreaturePermanent("two creatures"), true));
Player player = game.getPlayer(playerId);
if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice two creatures?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
costPaid = true;
}
}
if (costPaid) {
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (sourceObject != null) {
sourceObject.sacrifice(source, game);
}
}
return true;
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class TormentedThoughtsDiscardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && targetPlayer != null) {
int power = 0;
COSTS: for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
for (Permanent permanent : sacCost.getPermanents()) {
power = permanent.getPower().getValue();
break COSTS;
}
}
}
if (power > 0) {
targetPlayer.discard(power, false, false, source, game);
}
return true;
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class GargantuanGorillaFightEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
SacrificeTargetCost cost = new SacrificeTargetCost(target);
if (!controller.chooseUse(Outcome.Benefit, "Sacrifice a Forest?", source, game) || !cost.canPay(source, source, source.getControllerId(), game) || !cost.pay(source, game, source, source.getControllerId(), true)) {
sourcePermanent.sacrifice(source, game);
controller.damage(7, sourcePermanent.getId(), source, game);
} else if (cost.isPaid()) {
for (Permanent permanent : cost.getPermanents()) {
if (filterSnow.match(permanent, game)) {
game.addEffect(new GainAbilitySourceEffect(TrampleAbility.getInstance(), Duration.EndOfTurn), source);
break;
}
}
}
return true;
}
return false;
}
Aggregations