Search in sources :

Example 71 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class MageRingResponderAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
        UUID defenderId = game.getCombat().getDefenderId(sourceId);
        filter.add(new ControllerIdPredicate(defenderId));
        this.getTargets().clear();
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 72 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class MagusOfTheAbyssTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player player = game.getPlayer(event.getPlayerId());
    if (player != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("nonartifact creature you control");
        filter.add(Predicates.not(CardType.ARTIFACT.getPredicate()));
        filter.add(new ControllerIdPredicate(player.getId()));
        Target target = new TargetCreaturePermanent(filter);
        target.setAbilityController(getControllerId());
        target.setTargetController(player.getId());
        this.getTargets().clear();
        this.getTargets().add(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Example 73 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate 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 74 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class OrissSamiteGuardianCantCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        game.addEffect(new OrissSamiteGuardianCantCastEffect(), source);
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creatures that player controls");
        filter.add(new ControllerIdPredicate(getTargetPointer().getFirst(game, source)));
        ContinuousEffect effect = new CantAttackAnyPlayerAllEffect(Duration.EndOfTurn, filter);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) CantAttackAnyPlayerAllEffect(mage.abilities.effects.common.combat.CantAttackAnyPlayerAllEffect)

Example 75 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class PublicExecutionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent target = (Permanent) game.getLastKnownInformation(source.getFirstTarget(), Zone.BATTLEFIELD);
    if (target != null) {
        UUID opponent = target.getControllerId();
        if (opponent != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("each other creature that player controls");
            filter.add(new ControllerIdPredicate(opponent));
            filter.add(Predicates.not(new PermanentIdPredicate(target.getId())));
            ContinuousEffect effect = new BoostAllEffect(-2, 0, Duration.EndOfTurn, filter, false);
            game.addEffect(effect, source);
            return true;
        }
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Aggregations

ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)153 Player (mage.players.Player)105 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)87 Permanent (mage.game.permanent.Permanent)70 UUID (java.util.UUID)53 TargetPermanent (mage.target.TargetPermanent)53 FilterPermanent (mage.filter.FilterPermanent)51 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)41 Target (mage.target.Target)29 FixedTarget (mage.target.targetpointer.FixedTarget)21 TargetPlayer (mage.target.TargetPlayer)16 ContinuousEffect (mage.abilities.effects.ContinuousEffect)15 Effect (mage.abilities.effects.Effect)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 FilterLandPermanent (mage.filter.common.FilterLandPermanent)13 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)11 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)9 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)9 MageObject (mage.MageObject)8 HashSet (java.util.HashSet)7