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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations