Search in sources :

Example 46 with Cost

use of mage.abilities.costs.Cost 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 47 with Cost

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

the class SageOfHoursEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        int countersRemoved = 0;
        for (Cost cost : source.getCosts()) {
            if (cost instanceof RemoveAllCountersSourceCost) {
                countersRemoved = ((RemoveAllCountersSourceCost) cost).getRemovedCounters();
            }
        }
        int turns = countersRemoved / 5;
        for (int i = 0; i < turns; i++) {
            game.getState().getTurnMods().add(new TurnMod(player.getId(), false));
        }
        game.informPlayers("Removed " + countersRemoved + " +1/+1 counters: " + player.getLogName() + " takes " + CardUtil.numberToText(turns, "an") + (turns > 1 ? " extra turns " : " extra turn ") + "after this one");
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) RemoveAllCountersSourceCost(mage.abilities.costs.common.RemoveAllCountersSourceCost) TurnMod(mage.game.turn.TurnMod) RemoveAllCountersSourceCost(mage.abilities.costs.common.RemoveAllCountersSourceCost) Cost(mage.abilities.costs.Cost)

Example 48 with Cost

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

the class StringOfDisappearancesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    Player affectedPlayer = game.getPlayer(permanent.getControllerId());
    new ReturnToHandTargetEffect().apply(game, source);
    if (affectedPlayer == null) {
        return false;
    }
    if (!affectedPlayer.chooseUse(Outcome.Copy, "Pay {U}{U} to copy the spell?", source, game)) {
        return true;
    }
    Cost cost = new ManaCostsImpl("{U}{U}");
    if (!cost.pay(source, game, source, affectedPlayer.getId(), false, null)) {
        return true;
    }
    Spell spell = game.getStack().getSpell(source.getSourceId());
    if (spell == null) {
        return true;
    }
    spell.createCopyOnStack(game, source, affectedPlayer.getId(), true);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Spell(mage.game.stack.Spell)

Example 49 with Cost

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

the class TivashGloomSummonerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    PlayerGainedLifeWatcher watcher = game.getState().getWatcher(PlayerGainedLifeWatcher.class);
    if (player == null || watcher == null) {
        return false;
    }
    int lifeGained = watcher.getLifeGained(source.getControllerId());
    Cost cost = new PayLifeCost(lifeGained);
    if (!cost.canPay(source, source, source.getControllerId(), game) || !player.chooseUse(Outcome.PutCreatureInPlay, "Pay " + lifeGained + " life?", source, game) || !cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    new DemonFlyingToken(lifeGained).putOntoBattlefield(1, game, source, source.getControllerId());
    return true;
}
Also used : Player(mage.players.Player) PlayerGainedLifeWatcher(mage.watchers.common.PlayerGainedLifeWatcher) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) DemonFlyingToken(mage.game.permanent.token.DemonFlyingToken)

Example 50 with Cost

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

the class TymnaTheWeaverWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TymnaTheWeaverWatcher watcher = game.getState().getWatcher(TymnaTheWeaverWatcher.class);
        if (watcher != null) {
            int cardsToDraw = watcher.opponentsThatGotCombatDamage(source.getControllerId(), game);
            Cost cost = new PayLifeCost(cardsToDraw);
            if (cost.canPay(source, source, source.getControllerId(), game) && cost.pay(source, game, source, source.getControllerId(), false)) {
                controller.drawCards(cardsToDraw, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) 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