Search in sources :

Example 26 with TargetControlledPermanent

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

the class HarmonyOfNatureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledPermanent(0, Integer.MAX_VALUE, HarmonyOfNature.filter, true);
    controller.choose(outcome, target, source.getSourceId(), game);
    if (target.getTargets().isEmpty()) {
        return false;
    }
    int tappedAmount = 0;
    for (UUID permanentId : target.getTargets()) {
        Permanent permanent = game.getPermanent(permanentId);
        if (permanent != null && permanent.tap(source, game)) {
            tappedAmount++;
        }
    }
    if (tappedAmount > 0) {
        controller.gainLife(tappedAmount * 4, game, source);
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) ValueHint(mage.abilities.hint.ValueHint)

Example 27 with TargetControlledPermanent

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

the class HungryHungryHeiferEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
    if (sourceObject != null && controller != null) {
        if (controller.chooseUse(outcome, "Remove a counter from a permanent you control?", source, game)) {
            TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
            RemoveCounterCost cost = new RemoveCounterCost(target);
            if (cost.pay(null, game, source, controller.getId(), true)) {
                return true;
            }
        }
        sourceObject.sacrifice(source, game);
        return true;
    }
    return false;
}
Also used : RemoveCounterCost(mage.abilities.costs.common.RemoveCounterCost) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent)

Example 28 with TargetControlledPermanent

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

the class LinessaZephyrMageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player targetPlayer = game.getPlayer(source.getFirstTarget());
        if (targetPlayer != null) {
            // Target player returns a creature they control to its owner's hand,
            Target target = new TargetControlledCreaturePermanent();
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // then repeats this process for an artifact,
            FilterControlledPermanent filter = new FilterControlledPermanent("artifact you control");
            filter.add(CardType.ARTIFACT.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // an enchantment,
            filter = new FilterControlledPermanent("enchantment you control");
            filter.add(CardType.ENCHANTMENT.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // and a land.
            filter = new FilterControlledPermanent("land you control");
            filter.add(CardType.LAND.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 29 with TargetControlledPermanent

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

the class MarshalingTheTroopsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledPermanent(0, Integer.MAX_VALUE, MarshalingTheTroops.filter, true);
    controller.choose(outcome, target, source.getSourceId(), game);
    if (target.getTargets().isEmpty()) {
        return false;
    }
    int tappedAmount = 0;
    for (UUID permanentId : target.getTargets()) {
        Permanent permanent = game.getPermanent(permanentId);
        if (permanent != null && permanent.tap(source, game)) {
            tappedAmount++;
        }
    }
    if (tappedAmount > 0) {
        controller.gainLife(tappedAmount * 4, game, source);
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) ValueHint(mage.abilities.hint.ValueHint)

Example 30 with TargetControlledPermanent

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

the class SerendibDjinnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetControlledPermanent(1, 1, new FilterControlledLandPermanent(), true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                permanent.sacrifice(source, game);
                if (permanent.hasSubtype(SubType.ISLAND, game)) {
                    controller.damage(3, source.getSourceId(), 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) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

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