Search in sources :

Example 31 with SacrificeTargetCost

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;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 32 with SacrificeTargetCost

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;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Collection(java.util.Collection) FilterArtifactCard(mage.filter.common.FilterArtifactCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 33 with SacrificeTargetCost

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;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 34 with SacrificeTargetCost

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;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 35 with SacrificeTargetCost

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;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect)

Aggregations

SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)51 Cost (mage.abilities.costs.Cost)38 Player (mage.players.Player)37 Permanent (mage.game.permanent.Permanent)30 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)25 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)13 Card (mage.cards.Card)12 UUID (java.util.UUID)11 FilterCard (mage.filter.FilterCard)8 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)8 TapSourceCost (mage.abilities.costs.common.TapSourceCost)7 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)7 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)4 CardsImpl (mage.cards.CardsImpl)4 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)4 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)4 MageObject (mage.MageObject)3 Ability (mage.abilities.Ability)3 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)3 TargetPlayer (mage.target.TargetPlayer)3