Search in sources :

Example 61 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent 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)

Example 62 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class GargantuanGorillaFightEffect 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) {
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
        SacrificeTargetCost cost = new SacrificeTargetCost(target);
        if (!controller.chooseUse(Outcome.Benefit, "Sacrifice a Forest?", source, game) || !cost.canPay(source, source, source.getControllerId(), game) || !cost.pay(source, game, source, source.getControllerId(), true)) {
            sourcePermanent.sacrifice(source, game);
            controller.damage(7, sourcePermanent.getId(), source, game);
        } else if (cost.isPaid()) {
            for (Permanent permanent : cost.getPermanents()) {
                if (filterSnow.match(permanent, game)) {
                    game.addEffect(new GainAbilitySourceEffect(TrampleAbility.getInstance(), Duration.EndOfTurn), source);
                    break;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect)

Example 63 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class GlobalRuinDestroyLandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Set<UUID> lands = new HashSet<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            for (SubType landName : Arrays.stream(SubType.values()).filter(p -> p.getSubTypeSet() == SubTypeSet.BasicLandType).collect(Collectors.toSet())) {
                FilterControlledLandPermanent filter = new FilterControlledLandPermanent(landName + " you control");
                filter.add(landName.getPredicate());
                Target target = new TargetControlledPermanent(1, 1, filter, true);
                if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                    player.chooseTarget(outcome, target, source, game);
                    lands.add(target.getFirstTarget());
                }
            }
        }
    }
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_LAND, game)) {
        if (!lands.contains(permanent.getId())) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Target(mage.target.Target) Arrays(java.util.Arrays) StaticFilters(mage.filter.StaticFilters) SubTypeSet(mage.constants.SubTypeSet) Set(java.util.Set) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) SubType(mage.constants.SubType) Collectors(java.util.stream.Collectors) Player(mage.players.Player) HashSet(java.util.HashSet) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Ability(mage.abilities.Ability) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) SubType(mage.constants.SubType) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) UUID(java.util.UUID) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) HashSet(java.util.HashSet)

Example 64 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class GuardDogsEffect method init.

@Override
public void init(Ability source, Game game) {
    this.controlledTarget = new TargetControlledPermanent();
    this.controlledTarget.setNotTarget(true);
    this.controlledTarget.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
    super.init(source, game);
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent)

Example 65 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class RunEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getTargets().getFirstTarget());
    if (targetPlayer != null) {
        FilterControlledPermanent filter = new FilterControlledPermanent("artifact or creature");
        filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.CREATURE.getPredicate()));
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
        if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
            targetPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                permanent.sacrifice(source, game);
                int damage = permanent.getManaValue();
                if (damage > 0) {
                    targetPlayer.damage(damage, source.getSourceId(), source, game);
                }
            }
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Aggregations

TargetControlledPermanent (mage.target.common.TargetControlledPermanent)100 Player (mage.players.Player)94 Permanent (mage.game.permanent.Permanent)87 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)49 UUID (java.util.UUID)47 Target (mage.target.Target)45 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)23 Card (mage.cards.Card)17 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)16 ArrayList (java.util.ArrayList)13 TargetPermanent (mage.target.TargetPermanent)13 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)10 FilterCard (mage.filter.FilterCard)10 TargetPlayer (mage.target.TargetPlayer)10 FilterPermanent (mage.filter.FilterPermanent)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)8 Cost (mage.abilities.costs.Cost)7 FilterControlledArtifactPermanent (mage.filter.common.FilterControlledArtifactPermanent)7 TargetCardInHand (mage.target.common.TargetCardInHand)6 OneShotEffect (mage.abilities.effects.OneShotEffect)5