Search in sources :

Example 11 with GenericManaCost

use of mage.abilities.costs.mana.GenericManaCost 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)

Example 12 with GenericManaCost

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

the class HeroOfLeinaTowerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    ManaCosts cost = new ManaCostsImpl("{X}");
    if (you != null && you.chooseUse(Outcome.BoostCreature, "Do you want to to pay {X}?", source, game)) {
        int costX = you.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
        cost.add(new GenericManaCost(costX));
        if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
            Permanent sourcePermanent = game.getPermanent(source.getSourceId());
            if (sourcePermanent != null) {
                return new AddCountersSourceEffect(CounterType.P1P1.createInstance(costX), true).apply(game, source);
            }
        }
    }
    return false;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) Permanent(mage.game.permanent.Permanent) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 13 with GenericManaCost

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

the class ThespiansStageCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Permanent copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (sourcePermanent != null && copyFromPermanent != null) {
        Permanent newPermanent = game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new EmptyCopyApplier());
        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ThespiansStageCopyEffect(), new GenericManaCost(2));
        ability.addCost(new TapSourceCost());
        ability.addTarget(new TargetLandPermanent());
        newPermanent.addAbility(ability, source.getSourceId(), game);
        return true;
    }
    return false;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ColorlessManaAbility(mage.abilities.mana.ColorlessManaAbility) Ability(mage.abilities.Ability) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetLandPermanent(mage.target.common.TargetLandPermanent) TapSourceCost(mage.abilities.costs.common.TapSourceCost)

Example 14 with GenericManaCost

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

the class WildbornPreserverCreateReflexiveTriggerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    ManaCosts cost = new ManaCostsImpl("{X}");
    if (player == null) {
        return false;
    }
    if (!player.chooseUse(outcome, "Pay " + cost.getText() + "?", source, game)) {
        return false;
    }
    int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
    cost.add(new GenericManaCost(costX));
    if (!cost.pay(source, game, source, source.getControllerId(), false, null)) {
        return false;
    }
    game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(costX)), false, "put X +1/+1 counters on {this}"), source);
    return true;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 15 with GenericManaCost

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

the class RandomPlayer method getAction.

private Ability getAction(Game game) {
    List<ActivatedAbility> playables = getPlayableAbilities(game);
    Ability ability;
    while (true) {
        if (playables.size() == 1) {
            ability = playables.get(0);
        } else {
            ability = playables.get(RandomUtil.nextInt(playables.size()));
        }
        List<Ability> options = getPlayableOptions(ability, game);
        if (!options.isEmpty()) {
            if (options.size() == 1) {
                ability = options.get(0);
            } else {
                ability = options.get(RandomUtil.nextInt(options.size()));
            }
        }
        if (!ability.getManaCosts().getVariableCosts().isEmpty()) {
            int amount = getAvailableManaProducers(game).size() - ability.getManaCosts().manaValue();
            if (amount > 0) {
                ability = ability.copy();
                ability.getManaCostsToPay().add(new GenericManaCost(RandomUtil.nextInt(amount)));
            }
        }
        // else {
        break;
    // }
    }
    return ability;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) GenericManaCost(mage.abilities.costs.mana.GenericManaCost)

Aggregations

GenericManaCost (mage.abilities.costs.mana.GenericManaCost)31 Player (mage.players.Player)15 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)12 Permanent (mage.game.permanent.Permanent)10 ManaCosts (mage.abilities.costs.mana.ManaCosts)7 Ability (mage.abilities.Ability)6 CounterUnlessPaysEffect (mage.abilities.effects.common.CounterUnlessPaysEffect)6 FixedTarget (mage.target.targetpointer.FixedTarget)5 SpellAbility (mage.abilities.SpellAbility)4 PassAbility (mage.abilities.common.PassAbility)4 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)4 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)4 ManaCost (mage.abilities.costs.mana.ManaCost)4 Effect (mage.abilities.effects.Effect)3 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)3 StackAbility (mage.game.stack.StackAbility)3 ActivatedAbility (mage.abilities.ActivatedAbility)2 RevealTargetFromHandCost (mage.abilities.costs.common.RevealTargetFromHandCost)2 TapSourceCost (mage.abilities.costs.common.TapSourceCost)2 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)2