Search in sources :

Example 16 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class EvilTwinPredicate method apply.

@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
    Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DestroyTargetEffect(), new ManaCostsImpl("{U}{B}"));
    ability.addCost(new TapSourceCost());
    ability.addTarget(new TargetCreaturePermanent(filter));
    blueprint.getAbilities().add(ability);
    return true;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) EntersBattlefieldAbility(mage.abilities.common.EntersBattlefieldAbility) Ability(mage.abilities.Ability) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TapSourceCost(mage.abilities.costs.common.TapSourceCost)

Example 17 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class LeylineTyrantDamageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
    String manaString;
    if (costX == 0) {
        manaString = "{0}";
    } else {
        manaString = "";
        for (int i = 0; i < costX; i++) {
            manaString += "{R}";
        }
    }
    Cost cost = new ManaCostsImpl<>(manaString);
    cost.clearPaid();
    if (!cost.pay(source, game, source, source.getControllerId(), false)) {
        return false;
    }
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(costX), false, "{this} deals " + costX + " damage to any target");
    ability.addTarget(new TargetAnyTarget());
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : Player(mage.players.Player) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 18 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class RohgahhOfKherKeepEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player == null) {
        return false;
    }
    Cost cost = new ManaCostsImpl("{R}{R}{R}");
    if (!cost.canPay(source, source, player.getId(), game) || !player.chooseUse(Outcome.Benefit, "Pay {R}{R}{R}?", source, game) || !cost.pay(source, game, source, player.getId(), false)) {
        TargetOpponent target = new TargetOpponent();
        Player opponent = null;
        if (target.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
            opponent = game.getPlayer(target.getFirstTarget());
        }
        new TapAllEffect(filter).apply(game, source);
        if (permanent != null) {
            permanent.tap(source, game);
        }
        if (opponent != null) {
            new GainControlAllEffect(Duration.Custom, filter, opponent.getId()).apply(game, source);
            if (permanent != null) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : TapAllEffect(mage.abilities.effects.common.TapAllEffect) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) GainControlAllEffect(mage.abilities.effects.common.continuous.GainControlAllEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 19 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class ManifestTargetPlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        Set<Card> cards = targetPlayer.getLibrary().getTopCards(game, amount);
        for (Card card : cards) {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        }
        targetPlayer.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
        for (Card card : cards) {
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
                permanent.setManifested(true);
            }
        }
        return true;
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 20 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class FadeAwayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            int creaturesNumber = game.getBattlefield().getAllActivePermanents(FILTER_CREATURE, playerId, game).size();
            if (creaturesNumber > 0) {
                String message = "For how many creatures will you pay (up to " + creaturesNumber + ")?";
                int payAmount = 0;
                boolean paid = false;
                while (player.canRespond() && !paid) {
                    payAmount = player.getAmount(0, creaturesNumber, message, game);
                    ManaCostsImpl cost = new ManaCostsImpl();
                    cost.add(new GenericManaCost(payAmount));
                    cost.clearPaid();
                    if (cost.payOrRollback(source, game, source, playerId)) {
                        paid = true;
                    }
                }
                int sacrificeNumber = creaturesNumber - payAmount;
                game.informPlayers(player.getLogName() + " pays {" + payAmount + "} and sacrifices " + sacrificeNumber + " permanent" + (sacrificeNumber == 1 ? "" : "s"));
                if (sacrificeNumber > 0) {
                    int permanentsNumber = game.getBattlefield().getAllActivePermanents(playerId).size();
                    int targetsNumber = Math.min(sacrificeNumber, permanentsNumber);
                    TargetControlledPermanent target = new TargetControlledPermanent(targetsNumber);
                    player.chooseTarget(Outcome.Sacrifice, target, source, game);
                    for (UUID permanentId : target.getTargets()) {
                        Permanent permanent = game.getPermanent(permanentId);
                        if (permanent != null) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            } else {
                game.informPlayers(player.getLogName() + " has no creatures");
            }
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Aggregations

ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)98 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)33 Ability (mage.abilities.Ability)26 Cost (mage.abilities.costs.Cost)26 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)23 UUID (java.util.UUID)16 Card (mage.cards.Card)16 ManaCosts (mage.abilities.costs.mana.ManaCosts)15 SpellAbility (mage.abilities.SpellAbility)14 FixedTarget (mage.target.targetpointer.FixedTarget)13 Test (org.junit.Test)13 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)12 ManaCost (mage.abilities.costs.mana.ManaCost)11 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)7 TargetPermanent (mage.target.TargetPermanent)7 MageObjectReference (mage.MageObjectReference)6 Effect (mage.abilities.effects.Effect)6 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)6