Search in sources :

Example 66 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class UnnaturalHungerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent aura = game.getPermanent(source.getSourceId());
    if (aura != null) {
        Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
        if (attachedTo != null) {
            FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
            // not attached permanent
            filter.add(Predicates.not(new PermanentIdPredicate(aura.getAttachedTo())));
            Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(filter));
            Player enchantedCreatureController = game.getPlayer(attachedTo.getControllerId());
            if (enchantedCreatureController != null && cost.canPay(source, source, enchantedCreatureController.getId(), game) && enchantedCreatureController.chooseUse(outcome, "Sacrifice another creature to prevent " + attachedTo.getPower().getValue() + " damage?", source, game) && cost.pay(source, game, source, enchantedCreatureController.getId(), true)) {
            }
            if (enchantedCreatureController != null && !cost.isPaid()) {
                enchantedCreatureController.damage(attachedTo.getPower().getValue(), source.getSourceId(), source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 67 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class BirthingPodEffect 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);
        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) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 68 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class ChainOfPlasmaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID targetId = source.getFirstTarget();
        Player affectedPlayer = null;
        Player player = game.getPlayer(targetId);
        if (player != null) {
            player.damage(3, source.getSourceId(), source, game);
            affectedPlayer = player;
        } else {
            Permanent permanent = game.getPermanent(targetId);
            if (permanent != null) {
                permanent.damage(3, source.getSourceId(), source, game, false, true);
                affectedPlayer = game.getPlayer(permanent.getControllerId());
            }
        }
        if (affectedPlayer != null) {
            if (affectedPlayer.chooseUse(Outcome.Copy, "Discard a card to copy the spell?", source, game)) {
                Cost cost = new DiscardCardCost();
                if (cost.pay(source, game, source, affectedPlayer.getId(), false, null)) {
                    Spell spell = game.getStack().getSpell(source.getSourceId());
                    if (spell != null) {
                        spell.createCopyOnStack(game, source, affectedPlayer.getId(), true);
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost) Spell(mage.game.stack.Spell)

Example 69 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class CorpseweftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int amount = 0;
        for (Cost cost : source.getCosts()) {
            if (cost instanceof ExileFromGraveCost) {
                amount = ((ExileFromGraveCost) cost).getExiledCards().size() * 2;
                new CreateTokenEffect(new CorpseweftZombieToken(amount, amount), 1, true, false).apply(game, source);
            }
        }
        if (amount > 0) {
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) Cost(mage.abilities.costs.Cost) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) CorpseweftZombieToken(mage.game.permanent.token.CorpseweftZombieToken)

Example 70 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class EsperSentinelEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && opponent != null && permanent != null) {
        Cost cost = ManaUtil.createManaCost(permanent.getPower().getValue(), false);
        if (!opponent.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + "?", source, game) || !cost.pay(source, game, source, opponent.getId(), false)) {
            controller.drawCards(1, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Cost(mage.abilities.costs.Cost)

Aggregations

Cost (mage.abilities.costs.Cost)174 Player (mage.players.Player)142 Permanent (mage.game.permanent.Permanent)86 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)41 Card (mage.cards.Card)32 UUID (java.util.UUID)30 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)29 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)26 TapSourceCost (mage.abilities.costs.common.TapSourceCost)23 FilterCard (mage.filter.FilterCard)22 MageObject (mage.MageObject)19 PayLifeCost (mage.abilities.costs.common.PayLifeCost)17 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)16 FixedTarget (mage.target.targetpointer.FixedTarget)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)14 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)13 ContinuousEffect (mage.abilities.effects.ContinuousEffect)12 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)11 OneShotEffect (mage.abilities.effects.OneShotEffect)9