Search in sources :

Example 11 with SacrificeTargetCost

use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.

the class EldritchEvolutionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent != null && controller != null) {
        int newConvertedCost = sacrificedPermanent.getManaValue() + 2;
        FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost + " or less");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, newConvertedCost + 1));
        filter.add(CardType.CREATURE.getPredicate());
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 12 with SacrificeTargetCost

use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.

the class NeoformReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent == null || controller == null) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            ContinuousEffectImpl effect = new NeoformReplacementEffect();
            effect.setTargetPointer(new FixedTarget(card, game));
            game.addEffect(effect, source);
            if (!controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                effect.discard();
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) FixedTarget(mage.target.targetpointer.FixedTarget) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 13 with SacrificeTargetCost

use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.

the class PyreOfHeroesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent == null || controller == null) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(new SharesCreatureTypePredicate(sacrificedPermanent));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 14 with SacrificeTargetCost

use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.

the class WormsOfTheEarthDestroyEffect 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) {
        Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent("two lands"), false));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (player.chooseUse(outcome, "Do you want to destroy " + sourcePermanent.getLogName() + "? (sacrifice two lands or have it deal 5 damage to you)", source, game)) {
                    cost.clearPaid();
                    if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Sacrifice, "Will you sacrifice two lands? (otherwise you'll be dealt 5 damage)", source, game)) {
                        if (!cost.pay(source, game, source, player.getId(), false, null)) {
                            player.damage(5, source.getSourceId(), source, game);
                        }
                    } else {
                        player.damage(5, source.getSourceId(), source, game);
                    }
                    sourcePermanent = game.getPermanent(source.getSourceId());
                    if (sourcePermanent != null) {
                        sourcePermanent.destroy(source, game, false);
                    }
                    break;
                }
            }
        }
        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) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 15 with SacrificeTargetCost

use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.

the class LifesLegacyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int power = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
            power = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
            break;
        }
    }
    if (power > 0) {
        controller.drawCards(power, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

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