Search in sources :

Example 6 with AttackedThisTurnWatcher

use of mage.watchers.common.AttackedThisTurnWatcher in project mage by magefree.

the class OracleEnVecDestroyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    if (watcher != null) {
        for (UUID targetId : chosenCreatures) {
            Permanent permanent = game.getPermanent(targetId);
            if (permanent != null && !watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
                Effect effect = new DestroyTargetEffect();
                effect.setTargetPointer(new FixedTarget(targetId, game));
                effect.apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) RestrictionEffect(mage.abilities.effects.RestrictionEffect) RequirementEffect(mage.abilities.effects.RequirementEffect) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 7 with AttackedThisTurnWatcher

use of mage.watchers.common.AttackedThisTurnWatcher in project mage by magefree.

the class SirensCallDestroyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    if (player != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(player.getId())) {
            // Non Creature Cards are safe.
            if (!permanent.isCreature(game)) {
                continue;
            }
            // Walls are safe.
            if (permanent.hasSubtype(SubType.WALL, game)) {
                continue;
            }
            // Creatures that attacked are safe.
            AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
            if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
                continue;
            }
            // Creatures that weren't controlled since the beginning of turn are safe.
            if (!permanent.wasControlledFromStartOfControllerTurn()) {
                continue;
            }
            // Destroy the rest.
            permanent.destroy(source, game, false);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Example 8 with AttackedThisTurnWatcher

use of mage.watchers.common.AttackedThisTurnWatcher in project mage by magefree.

the class MaddeningImpDelayedDestroyEffect method apply.

public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    if (player != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(player.getId())) {
            MageObjectReference mor = new MageObjectReference(permanent, game);
            // Only affect permanents present when the ability resolved
            if (!activeCreatures.contains(mor)) {
                continue;
            }
            // Creatures that attacked are safe.
            AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
            if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(mor)) {
                continue;
            }
            // Destroy the rest.
            permanent.destroy(source, game, false);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Example 9 with AttackedThisTurnWatcher

use of mage.watchers.common.AttackedThisTurnWatcher in project mage by magefree.

the class CouldAttackThisTurnWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player activePlayer = game.getPlayer(game.getActivePlayerId());
    if (activePlayer != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, game)) {
            // Noncreature cards are safe.
            if (!permanent.isCreature(game)) {
                continue;
            }
            // Tapped cards are safe.
            if (permanent.isTapped()) {
                continue;
            }
            // Creatures that attacked are safe.
            AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
            if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
                continue;
            }
            // Creatures that couldn't attack are safe.
            CouldAttackThisTurnWatcher watcher2 = game.getState().getWatcher(CouldAttackThisTurnWatcher.class);
            if (watcher2 != null && !watcher2.getCouldAttackThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
                continue;
            }
            // Destroy the rest.
            permanent.destroy(source, game, false);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Example 10 with AttackedThisTurnWatcher

use of mage.watchers.common.AttackedThisTurnWatcher in project mage by magefree.

the class WallOfDustNextTurnTest method test_SingleOpponentMustAttack.

@Test
public void test_SingleOpponentMustAttack() {
    // Whenever Wall of Dust blocks a creature, that creature can't attack during its controller's next turn.
    addCard(Zone.BATTLEFIELD, playerA, "Wall of Dust");
    // 2/2
    addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1);
    // 2/2
    addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 1);
    // 
    Ability ability = new SimpleStaticAbility(new AttacksIfAbleAllEffect(StaticFilters.FILTER_OPPONENTS_PERMANENT_CREATURE, Duration.EndOfGame));
    ability.addWatcher(new AttackedThisTurnWatcher());
    addCustomCardWithAbility("all attacks", playerA, ability);
    // 1 - nothing
    checkPermanentCount("turn 1", 1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Balduvian Bears", 1);
    checkPermanentCount("turn 1", 1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Ashcoat Bear", 1);
    checkLife("turn 1", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, 20);
    // 2 - auto-attack B -> A, 1 attacked, 1 blocked (by wall)
    block(2, playerA, "Wall of Dust", "Balduvian Bears");
    checkPermanentCount("turn 2", 2, PhaseStep.POSTCOMBAT_MAIN, playerB, "Balduvian Bears", 1);
    checkPermanentCount("turn 2", 2, PhaseStep.POSTCOMBAT_MAIN, playerB, "Ashcoat Bear", 1);
    checkLife("turn 2", 2, PhaseStep.POSTCOMBAT_MAIN, playerA, 20 - 2);
    // 3 - nothing
    checkPermanentCount("turn 3", 3, PhaseStep.POSTCOMBAT_MAIN, playerB, "Balduvian Bears", 1);
    checkPermanentCount("turn 3", 3, PhaseStep.POSTCOMBAT_MAIN, playerB, "Ashcoat Bear", 1);
    checkLife("turn 3", 3, PhaseStep.POSTCOMBAT_MAIN, playerA, 20 - 2);
    // 4 - auto-attack, B -> A, 1 attacked, 1 can't attacked (by wall's abilitiy during next turn)
    checkPermanentCount("turn 4", 4, PhaseStep.POSTCOMBAT_MAIN, playerB, "Balduvian Bears", 1);
    checkPermanentCount("turn 4", 4, PhaseStep.POSTCOMBAT_MAIN, playerB, "Ashcoat Bear", 1);
    checkLife("turn 4", 4, PhaseStep.POSTCOMBAT_MAIN, playerA, 20 - 2 * 2);
    // 5 - nothing
    checkPermanentCount("turn 5", 5, PhaseStep.POSTCOMBAT_MAIN, playerB, "Balduvian Bears", 1);
    checkPermanentCount("turn 5", 5, PhaseStep.POSTCOMBAT_MAIN, playerB, "Ashcoat Bear", 1);
    checkLife("turn 5", 5, PhaseStep.POSTCOMBAT_MAIN, playerA, 20 - 2 * 2);
    // 6 - auto-attack, B -> A, 2 attacked
    checkPermanentCount("turn 6", 6, PhaseStep.POSTCOMBAT_MAIN, playerB, "Balduvian Bears", 1);
    checkPermanentCount("turn 6", 6, PhaseStep.POSTCOMBAT_MAIN, playerB, "Ashcoat Bear", 1);
    checkLife("turn 6", 6, PhaseStep.POSTCOMBAT_MAIN, playerA, 20 - 2 * 2 - 2 * 2);
    setStopAt(6, PhaseStep.END_TURN);
    setStrictChooseMode(true);
    execute();
    assertAllCommandsUsed();
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) AttacksIfAbleAllEffect(mage.abilities.effects.common.combat.AttacksIfAbleAllEffect) Test(org.junit.Test)

Aggregations

AttackedThisTurnWatcher (mage.watchers.common.AttackedThisTurnWatcher)11 MageObjectReference (mage.MageObjectReference)9 Permanent (mage.game.permanent.Permanent)9 Player (mage.players.Player)5 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Ability (mage.abilities.Ability)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 RequirementEffect (mage.abilities.effects.RequirementEffect)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 DestroyTargetEffect (mage.abilities.effects.common.DestroyTargetEffect)1 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)1 AttacksIfAbleAllEffect (mage.abilities.effects.common.combat.AttacksIfAbleAllEffect)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1