Search in sources :

Example 31 with GainControlTargetEffect

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

the class WellspringEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn);
    effect.setTargetPointer(new FixedTarget(permanent.getAttachedTo(), game));
    game.addEffect(effect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 32 with GainControlTargetEffect

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

the class OrderOfSuccessionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<UUID, UUID> playerCreature = new HashMap<>(2);
        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()) && controller.canRespond()) {
            playerList.getNext();
        }
        Player currentPlayer = game.getPlayer(playerList.get());
        Player nextPlayer;
        UUID firstNextPlayer = null;
        while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer) && controller.canRespond()) {
            nextPlayer = game.getPlayer(playerList.get());
            if (nextPlayer == null) {
                return false;
            }
            // save first next player to check for iteration stop
            if (firstNextPlayer == null) {
                firstNextPlayer = nextPlayer.getId();
            }
            if (!nextPlayer.canRespond()) {
                continue;
            }
            // if player is in range they choose a creature to control
            if (currentPlayer != null && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent("creature controlled by " + nextPlayer.getLogName());
                filter.add(new ControllerIdPredicate(nextPlayer.getId()));
                Target target = new TargetCreaturePermanent(filter);
                target.setNotTarget(true);
                if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game)) {
                    if (currentPlayer.chooseTarget(outcome, target, source, game)) {
                        playerCreature.put(currentPlayer.getId(), target.getFirstTarget());
                    }
                }
            }
            currentPlayer = nextPlayer;
        }
        // change control of targets
        for (Map.Entry<UUID, UUID> entry : playerCreature.entrySet()) {
            Player player = game.getPlayer(entry.getKey());
            if (player != null) {
                Permanent creature = game.getPermanent(entry.getValue());
                if (creature != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, player.getId());
                    effect.setTargetPointer(new FixedTarget(creature.getId(), game));
                    game.addEffect(effect, source);
                    game.informPlayers(new StringBuilder(player.getLogName()).append(" gains control of ").append(creature.getName()).toString());
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) HashMap(java.util.HashMap) PlayerList(mage.players.PlayerList) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ChoiceLeftOrRight(mage.choices.ChoiceLeftOrRight) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with GainControlTargetEffect

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

the class WildMammothEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent sourcePermanent = game.getPermanent(source.getSourceId());
        if (sourcePermanent != null) {
            Player newController = null;
            int maxCreatures = 0;
            boolean tie = false;
            FilterPermanent filter = new FilterPermanent();
            filter.add(CardType.CREATURE.getPredicate());
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    int value = game.getBattlefield().countAll(filter, playerId, game);
                    if (value > maxCreatures) {
                        maxCreatures = value;
                    }
                }
            }
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    int value = game.getBattlefield().countAll(filter, playerId, game);
                    if (value == maxCreatures) {
                        if (newController == null) {
                            newController = player;
                        } else {
                            tie = true;
                            break;
                        }
                    }
                }
            }
            if (!controller.equals(newController) && !tie && newController != null) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newController.getId());
                effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 34 with GainControlTargetEffect

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

the class RichesEffect 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) {
        Cards creaturesToSteal = new CardsImpl();
        // For each opponent, get the creature to steal
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (controller.hasOpponent(playerId, game)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null) {
                    TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
                    target.setNotTarget(true);
                    if (opponent.choose(Outcome.Detriment, target, source.getSourceId(), game)) {
                        creaturesToSteal.add(target.getTargets().get(0));
                    }
                }
            }
        }
        // controller depends on another creatures controller.
        for (UUID target : creaturesToSteal) {
            GainControlTargetEffect eff = new GainControlTargetEffect(Duration.EndOfGame, true);
            eff.setTargetPointer(new FixedTarget(target, game));
            game.addEffect(eff, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 35 with GainControlTargetEffect

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

the class TahngarthFirstMateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(game.getActivePlayerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (controller == null || player == null || permanent == null) {
        return false;
    }
    TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
    target.setNotTarget(true);
    if (!controller.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfCombat, player.getId());
    effect.setTargetPointer(new FixedTarget(permanent, game));
    game.addEffect(effect, source);
    game.getState().processAction(game);
    return game.getCombat().addAttackerToCombat(permanent.getId(), target.getFirstTarget(), game);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetPlayerOrPlaneswalker(mage.target.common.TargetPlayerOrPlaneswalker)

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