Search in sources :

Example 46 with TargetCreaturePermanent

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

the class SparkMageTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
    if (damageEvent.isCombatDamage() && event.getSourceId().equals(this.getSourceId())) {
        Player opponent = game.getPlayer(event.getPlayerId());
        if (opponent != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
            filter.add(new ControllerIdPredicate(opponent.getId()));
            this.getTargets().clear();
            this.getTargets().add(new TargetCreaturePermanent(filter));
            return true;
        }
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 47 with TargetCreaturePermanent

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

the class StandOrFallEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // 802.2. As the combat phase starts, the attacking player doesn’t choose an opponent to become the defending player.
    // Instead, all the attacking player’s opponents are defending players during the combat phase.
    // 
    // 802.2a Any rule, object, or effect that refers to a “defending player” refers to one specific defending player, not to all of the defending players.
    // If an ability of an attacking creature refers to a defending player, or a spell or ability refers to both an attacking creature and a defending player,
    // then unless otherwise specified, the defending player it’s referring to is the player that creature was attacking at the time it became an attacking
    // creature that combat, or the controller of the planeswalker that creature was attacking at the time it became an attacking creature that combat. If a spell or ability
    // could apply to multiple attacking creatures, the appropriate defending player is individually determined for each of those attacking creatures.
    // If there are multiple defending players that could be chosen, the controller of the spell or ability chooses one.
    // 
    // https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/756140-stand-or-fall-mechanics
    Player player = game.getPlayer(source.getControllerId());
    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
        Player targetPlayer = game.getPlayer(opponents.iterator().next());
        if (opponents.size() > 1) {
            TargetOpponent targetOpponent = new TargetOpponent(true);
            if (player != null && player.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
                targetPlayer = game.getPlayer(targetOpponent.getFirstTarget());
                game.informPlayers(player.getLogName() + " chose " + targetPlayer.getLogName() + " as the defending player");
            }
        }
        if (player != null && targetPlayer != null) {
            int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
            TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
            List<Permanent> pile1 = new ArrayList<>();
            creatures.setRequired(false);
            if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
                List<UUID> targets = creatures.getTargets();
                for (UUID targetId : targets) {
                    Permanent p = game.getPermanent(targetId);
                    if (p != null) {
                        pile1.add(p);
                    }
                }
            }
            List<Permanent> pile2 = new ArrayList<>();
            for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
                if (!pile1.contains(p)) {
                    pile2.add(p);
                }
            }
            boolean choice = targetPlayer.choosePile(outcome, "Choose which pile can block this turn.", pile1, pile2, game);
            List<Permanent> chosenPile = choice ? pile2 : pile1;
            List<Permanent> otherPile = choice ? pile1 : pile2;
            for (Permanent permanent : chosenPile) {
                if (permanent != null) {
                    RestrictionEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
                    effect.setText("");
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    game.addEffect(effect, source);
                }
            }
            game.informPlayers("Creatures that can block this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CantBlockTargetEffect(mage.abilities.effects.common.combat.CantBlockTargetEffect) ArrayList(java.util.ArrayList) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) UUID(java.util.UUID) RestrictionEffect(mage.abilities.effects.RestrictionEffect)

Example 48 with TargetCreaturePermanent

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

the class ZndrspltsJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    choice.chooseFriendOrFoe(controller, source, game);
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
        filter.add(new ControllerIdPredicate(player.getId()));
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        if (!player.choose(Outcome.Copy, target, source.getSourceId(), game)) {
            continue;
        }
        Effect effect = new CreateTokenCopyTargetEffect(player.getId());
        effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
        effect.apply(game, source);
    }
    for (Player player : choice.getFoes()) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
        filter.add(new ControllerIdPredicate(player.getId()));
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        if (!player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
            continue;
        }
        Effect effect = new ReturnToHandTargetEffect();
        effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
        effect.apply(game, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect)

Example 49 with TargetCreaturePermanent

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

the class BecomesAuraAttachToManifestSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanent(source.getSourceId());
    if (controller != null && enchantment != null) {
        // manifest top card
        Card card = controller.getLibrary().getFromTop(game);
        if (card != null) {
            new ManifestEffect(1).apply(game, source);
            Permanent enchantedCreature = game.getPermanent(card.getId());
            if (enchantedCreature != null) {
                enchantedCreature.addAttachment(enchantment.getId(), source, game);
                FilterCreaturePermanent filter = new FilterCreaturePermanent();
                Target target = new TargetCreaturePermanent(filter);
                target.addTarget(enchantedCreature.getId(), source, game);
                game.addEffect(new BecomesAuraSourceEffect(target), source);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ManifestEffect(mage.abilities.effects.keyword.ManifestEffect) BecomesAuraSourceEffect(mage.abilities.effects.common.continuous.BecomesAuraSourceEffect) Card(mage.cards.Card)

Example 50 with TargetCreaturePermanent

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

the class SnappingThraggTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player opponent = game.getPlayer(event.getPlayerId());
    if (opponent != null && event.getSourceId().equals(this.sourceId)) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
        filter.add(new ControllerIdPredicate(opponent.getId()));
        this.getTargets().clear();
        this.addTarget(new TargetCreaturePermanent(filter));
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Aggregations

TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)71 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)59 Player (mage.players.Player)49 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)37 Permanent (mage.game.permanent.Permanent)35 UUID (java.util.UUID)25 Target (mage.target.Target)18 FixedTarget (mage.target.targetpointer.FixedTarget)18 Effect (mage.abilities.effects.Effect)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 OneShotEffect (mage.abilities.effects.OneShotEffect)7 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)6 Card (mage.cards.Card)6 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)6 ArrayList (java.util.ArrayList)5 Ability (mage.abilities.Ability)5 MageObject (mage.MageObject)4 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)4 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)4 RestrictionEffect (mage.abilities.effects.RestrictionEffect)3