Search in sources :

Example 6 with FilterControlledLandPermanent

use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.

the class WormsOfTheEarthDestroyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent("two lands"), false));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (player.chooseUse(outcome, "Do you want to destroy " + sourcePermanent.getLogName() + "? (sacrifice two lands or have it deal 5 damage to you)", source, game)) {
                    cost.clearPaid();
                    if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Sacrifice, "Will you sacrifice two lands? (otherwise you'll be dealt 5 damage)", source, game)) {
                        if (!cost.pay(source, game, source, player.getId(), false, null)) {
                            player.damage(5, source.getSourceId(), source, game);
                        }
                    } else {
                        player.damage(5, source.getSourceId(), source, game);
                    }
                    sourcePermanent = game.getPermanent(source.getSourceId());
                    if (sourcePermanent != null) {
                        sourcePermanent.destroy(source, game, false);
                    }
                    break;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 7 with FilterControlledLandPermanent

use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.

the class ChainOfVaporEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
        controller.moveCards(permanent, Zone.HAND, source, game);
        Player player = game.getPlayer(permanent.getControllerId());
        TargetControlledPermanent target = new TargetControlledPermanent(0, 1, new FilterControlledLandPermanent("a land to sacrifice (to be able to copy " + sourceObject.getName() + ')'), true);
        if (player != null && player.chooseTarget(Outcome.Sacrifice, target, source, game)) {
            Permanent land = game.getPermanent(target.getFirstTarget());
            if (land != null && land.sacrifice(source, game)) {
                if (player.chooseUse(outcome, "Copy the spell?", source, game)) {
                    Spell spell = game.getStack().getSpell(source.getSourceId());
                    if (spell != null) {
                        spell.createCopyOnStack(game, source, player.getId(), true);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) MageObject(mage.MageObject) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Spell(mage.game.stack.Spell)

Example 8 with FilterControlledLandPermanent

use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.

the class ManaSeismEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int amount = 0;
    TargetControlledPermanent sacrificeLand = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledLandPermanent(), true);
    if (player.chooseTarget(Outcome.Sacrifice, sacrificeLand, source, game)) {
        for (UUID uuid : sacrificeLand.getTargets()) {
            Permanent land = game.getPermanent(uuid);
            if (land != null) {
                land.sacrifice(source, game);
                amount++;
            }
        }
    }
    player.getManaPool().addMana(Mana.ColorlessMana(amount), game, source);
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) UUID(java.util.UUID) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 9 with FilterControlledLandPermanent

use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.

the class PoxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Each player loses a third of their life,
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int lifeToLose = (int) Math.ceil(player.getLife() / 3.0);
                player.loseLife(lifeToLose, game, source, false);
            }
        }
        // then discards a third of the cards in their hand,
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int cardsToDiscard = (int) Math.ceil(player.getHand().size() / 3.0);
                if (cardsToDiscard > 0) {
                    player.discard(cardsToDiscard, false, false, source, game);
                }
            }
        }
        // then sacrifices a third of the creatures they control,
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
                int creaturesToSacrifice = (int) Math.ceil(game.getBattlefield().count(filter, source.getSourceId(), player.getId(), game) / 3.0);
                if (creaturesToSacrifice > 0) {
                    Target target = new TargetControlledCreaturePermanent(creaturesToSacrifice, creaturesToSacrifice, filter, true);
                    target.chooseTarget(Outcome.Sacrifice, playerId, source, game);
                    for (UUID permanentId : target.getTargets()) {
                        Permanent permanent = game.getPermanent(permanentId);
                        if (permanent != null) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            }
        }
        // then sacrifices a third of the lands they control.
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterControlledLandPermanent filter = new FilterControlledLandPermanent();
                int landsToSacrifice = (int) Math.ceil(game.getBattlefield().count(filter, source.getSourceId(), player.getId(), game) / 3.0);
                if (landsToSacrifice > 0) {
                    Target target = new TargetControlledPermanent(landsToSacrifice, landsToSacrifice, filter, true);
                    target.chooseTarget(Outcome.Sacrifice, playerId, source, game);
                    for (UUID permanentId : target.getTargets()) {
                        Permanent permanent = game.getPermanent(permanentId);
                        if (permanent != null) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 10 with FilterControlledLandPermanent

use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.

the class FeastOfWormsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(id);
    Player targetPlayer = null;
    if (permanent != null) {
        targetPlayer = game.getPlayer(permanent.getControllerId());
    }
    if (targetPlayer != null && permanent != null && (permanent.isLegendary())) {
        FilterControlledPermanent filter = new FilterControlledLandPermanent("land to sacrifice");
        filter.add(new ControllerIdPredicate(targetPlayer.getId()));
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, false);
        if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
            targetPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
            Permanent land = game.getPermanent(target.getFirstTarget());
            if (land != null) {
                land.sacrifice(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Aggregations

FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)19 Player (mage.players.Player)19 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)14 Permanent (mage.game.permanent.Permanent)13 UUID (java.util.UUID)11 Target (mage.target.Target)7 OneShotEffect (mage.abilities.effects.OneShotEffect)4 Cost (mage.abilities.costs.Cost)3 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)3 CardsImpl (mage.cards.CardsImpl)3 TargetPermanent (mage.target.TargetPermanent)3 ArrayList (java.util.ArrayList)2 MageObject (mage.MageObject)2 Ability (mage.abilities.Ability)2 Effect (mage.abilities.effects.Effect)2 Card (mage.cards.Card)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 CardType (mage.constants.CardType)2 Outcome (mage.constants.Outcome)2