Search in sources :

Example 1 with DemonFlyingToken

use of mage.game.permanent.token.DemonFlyingToken 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 2 with DemonFlyingToken

use of mage.game.permanent.token.DemonFlyingToken in project mage by magefree.

the class ReignOfThePitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int totalPowerSacrificed = 0;
    List<UUID> perms = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent(1, 1, new FilterControlledCreaturePermanent(), true);
            if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                while (!target.isChosen() && player.canRespond()) {
                    player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
                }
                perms.addAll(target.getTargets());
            }
        }
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            int power = permanent.getPower().getValue();
            if (permanent.sacrifice(source, game)) {
                totalPowerSacrificed += power;
            }
        }
    }
    new CreateTokenEffect(new DemonFlyingToken(totalPowerSacrificed)).apply(game, source);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) DemonFlyingToken(mage.game.permanent.token.DemonFlyingToken)

Aggregations

DemonFlyingToken (mage.game.permanent.token.DemonFlyingToken)2 Player (mage.players.Player)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Cost (mage.abilities.costs.Cost)1 PayLifeCost (mage.abilities.costs.common.PayLifeCost)1 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 Permanent (mage.game.permanent.Permanent)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1 PlayerGainedLifeWatcher (mage.watchers.common.PlayerGainedLifeWatcher)1