Search in sources :

Example 1 with CantBlockTargetEffect

use of mage.abilities.effects.common.combat.CantBlockTargetEffect in project mage by magefree.

the class BorosBattleshaperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature1 = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (creature1 != null) {
        if (game.getOpponents(creature1.getControllerId()).contains(game.getActivePlayerId())) {
            // Blocks
            ContinuousEffectImpl effect = new BlocksIfAbleTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
            effect = new GainAbilityTargetEffect(BlocksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, "");
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
        } else {
            // Attacks
            ContinuousEffectImpl effect = new AttacksIfAbleTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
            effect = new GainAbilityTargetEffect(AttacksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, "");
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
        }
    }
    Permanent creature2 = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (creature2 != null) {
        if (game.getOpponents(creature2.getControllerId()).contains(game.getActivePlayerId())) {
            // Blocks
            ContinuousEffectImpl effect = new CantBlockTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature2.getId(), game));
            game.addEffect(effect, source);
        } else {
            // Attacks
            ContinuousEffectImpl effect = new CantAttackTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature2.getId(), game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) CantAttackTargetEffect(mage.abilities.effects.common.combat.CantAttackTargetEffect) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BlocksIfAbleTargetEffect(mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect) CantBlockTargetEffect(mage.abilities.effects.common.combat.CantBlockTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) AttacksIfAbleTargetEffect(mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect)

Example 2 with CantBlockTargetEffect

use of mage.abilities.effects.common.combat.CantBlockTargetEffect in project mage by magefree.

the class HuatliWarriorPoetDamageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (source.getTargets().isEmpty()) {
        return true;
    }
    Target multiTarget = source.getTargets().get(0);
    for (UUID target : multiTarget.getTargets()) {
        Permanent permanent = game.getPermanent(target);
        if (permanent != null && permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game, false, true) > 0) {
            ContinuousEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) CantBlockTargetEffect(mage.abilities.effects.common.combat.CantBlockTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Example 3 with CantBlockTargetEffect

use of mage.abilities.effects.common.combat.CantBlockTargetEffect in project mage by magefree.

the class ChandraPyromasterEffect3 method apply.

@Override
public boolean apply(Game game, Ability source) {
    game.damagePlayerOrPlaneswalker(source.getTargets().get(0).getFirstTarget(), 1, source.getSourceId(), source, game, false, true);
    Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (creature != null) {
        creature.damage(1, source.getSourceId(), source, game, false, true);
        ContinuousEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(creature.getId(), game));
        game.addEffect(effect, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) CantBlockTargetEffect(mage.abilities.effects.common.combat.CantBlockTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 4 with CantBlockTargetEffect

use of mage.abilities.effects.common.combat.CantBlockTargetEffect 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)

Aggregations

CantBlockTargetEffect (mage.abilities.effects.common.combat.CantBlockTargetEffect)4 Permanent (mage.game.permanent.Permanent)4 FixedTarget (mage.target.targetpointer.FixedTarget)4 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 UUID (java.util.UUID)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)2 ArrayList (java.util.ArrayList)1 ContinuousEffectImpl (mage.abilities.effects.ContinuousEffectImpl)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 AttacksIfAbleTargetEffect (mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect)1 BlocksIfAbleTargetEffect (mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect)1 CantAttackTargetEffect (mage.abilities.effects.common.combat.CantAttackTargetEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetPermanent (mage.target.TargetPermanent)1 TargetOpponent (mage.target.common.TargetOpponent)1