Search in sources :

Example 51 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class BlimComedicGeniusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    game.addEffect(new GainControlTargetEffect(Duration.Custom, true, targetPointer.getFirst(game, source)).setTargetPointer(new FixedTarget(source.getFirstTarget(), game)), source);
    game.getState().processAction(game);
    Map<UUID, Cards> cardsMap = new HashMap<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        int count = game.getBattlefield().count(filter, source.getSourceId(), playerId, game);
        if (count < 1) {
            continue;
        }
        player.loseLife(count, game, source, true);
        TargetDiscard target = new TargetDiscard(StaticFilters.FILTER_CARD, playerId);
        player.choose(outcome, target, source.getSourceId(), game);
        cardsMap.put(playerId, new CardsImpl(target.getTargets()));
    }
    for (Map.Entry<UUID, Cards> entry : cardsMap.entrySet()) {
        Player player = game.getPlayer(entry.getKey());
        if (player == null) {
            continue;
        }
        player.discard(entry.getValue(), false, source, game);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) HashMap(java.util.HashMap) Map(java.util.Map) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 52 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class AminatouUltimateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceLeftOrRight();
        if (!controller.choose(Outcome.Neutral, choice, game)) {
            return false;
        }
        boolean left = choice.getChoice().equals("Left");
        PlayerList playerList = game.getState().getPlayerList().copy();
        // set playerlist to controller
        while (!playerList.get().equals(source.getControllerId())) {
            playerList.getNext();
        }
        UUID currentPlayer = playerList.get();
        UUID nextPlayer;
        UUID firstNextPlayer = null;
        while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer)) {
            nextPlayer = playerList.get();
            if (nextPlayer == null) {
                return false;
            }
            // skip players out of range
            if (!game.getState().getPlayersInRange(controller.getId(), game).contains(nextPlayer)) {
                continue;
            }
            // save first next player to check for iteration stop
            if (firstNextPlayer == null) {
                firstNextPlayer = nextPlayer;
            }
            FilterNonlandPermanent nextPlayerNonlandPermanentsFilter = new FilterNonlandPermanent();
            nextPlayerNonlandPermanentsFilter.add(new ControllerIdPredicate(nextPlayer));
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(nextPlayerNonlandPermanentsFilter, game)) {
                if (permanent.getId().equals(source.getSourceId())) {
                    continue;
                }
                ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, currentPlayer);
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
            currentPlayer = nextPlayer;
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PlayerList(mage.players.PlayerList) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ChoiceLeftOrRight(mage.choices.ChoiceLeftOrRight) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 53 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class AuraThiefDiesTriggeredEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean ret = false;
    for (Permanent enchantment : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_ENCHANTMENT, source.getControllerId(), source.getControllerId(), game)) {
        ContinuousEffect gainControl = new GainControlTargetEffect(Duration.EndOfGame);
        gainControl.setTargetPointer(new FixedTarget(enchantment.getId(), game));
        game.addEffect(gainControl, source);
        ret = true;
    }
    return ret;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 54 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class CaptivatingGlanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    final boolean clashResult;
    Player controller = game.getPlayer(source.getControllerId());
    Permanent captivatingGlance = game.getPermanent(source.getSourceId());
    if (controller != null && captivatingGlance != null) {
        Permanent enchantedCreature = game.getPermanent(captivatingGlance.getAttachedTo());
        clashResult = ClashEffect.getInstance().apply(game, source);
        if (enchantedCreature != null) {
            if (clashResult) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, false, controller.getId());
                effect.setTargetPointer(new FixedTarget(enchantedCreature.getId(), game));
                game.addEffect(effect, source);
            } else {
                Player opponentWhomControllerClashedWith = game.getPlayer(targetPointer.getFirst(game, source));
                if (opponentWhomControllerClashedWith != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, false, opponentWhomControllerClashedWith.getId());
                    effect.setTargetPointer(new FixedTarget(enchantedCreature.getId(), game));
                    game.addEffect(effect, source);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 55 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class ClambassadorsEffect 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, filter, true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
                controller.chooseTarget(outcome, target, source, game);
            }
        }
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
        if (permanent != null && opponent != null) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
            game.informPlayers(opponent.getLogName() + " has gained control of " + permanent.getLogName());
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Aggregations

GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)57 FixedTarget (mage.target.targetpointer.FixedTarget)52 Permanent (mage.game.permanent.Permanent)48 ContinuousEffect (mage.abilities.effects.ContinuousEffect)42 Player (mage.players.Player)40 UUID (java.util.UUID)22 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)15 TargetPermanent (mage.target.TargetPermanent)13 FilterPermanent (mage.filter.FilterPermanent)12 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)12 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)9 Target (mage.target.Target)8 TargetPlayer (mage.target.TargetPlayer)7 MageObject (mage.MageObject)5 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 OneShotEffect (mage.abilities.effects.OneShotEffect)4 TargetOpponent (mage.target.common.TargetOpponent)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3