fix #11349 (You Cannot Pass!)

This commit is contained in:
xenohedron 2023-10-28 17:16:37 -04:00
parent ad66b91642
commit e335023cd6
3 changed files with 76 additions and 16 deletions

View file

@ -55,7 +55,8 @@ enum YouCannotPassPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return YouCannotPassWatcher.checkCreature(input, game);
YouCannotPassWatcher watcher = game.getState().getWatcher(YouCannotPassWatcher.class);
return watcher != null && watcher.checkCreature(input, game);
}
}
@ -69,16 +70,19 @@ class YouCannotPassWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.CREATURE_BLOCKED) {
if (event.getType() != GameEvent.EventType.BLOCKER_DECLARED) {
return;
}
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.isLegendary(game)) {
set.add(new MageObjectReference(event.getSourceId(), game));
Permanent attacker = game.getPermanent(event.getTargetId());
Permanent blocker = game.getPermanent(event.getSourceId());
if (attacker == null || blocker == null) {
return;
}
permanent = game.getPermanent(event.getSourceId());
if (permanent != null && permanent.isLegendary(game)) {
set.add(new MageObjectReference(event.getTargetId(), game));
if (attacker.isLegendary(game)) {
set.add(new MageObjectReference(blocker, game));
}
if (blocker.isLegendary(game)) {
set.add(new MageObjectReference(attacker, game));
}
}
@ -88,11 +92,7 @@ class YouCannotPassWatcher extends Watcher {
set.clear();
}
static boolean checkCreature(Permanent permanent, Game game) {
return game
.getState()
.getWatcher(YouCannotPassWatcher.class)
.set
.contains(new MageObjectReference(permanent, game));
boolean checkCreature(Permanent permanent, Game game) {
return set.contains(new MageObjectReference(permanent, game));
}
}

View file

@ -1,6 +1,5 @@
package org.mage.test.cards.single.ltr;
import mage.cards.f.FeldonOfTheThirdPath;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
@ -84,4 +83,4 @@ public class RadagastTheBrownTest extends CardTestPlayerBase {
assertPermanentCount(playerA, 12);
}
}
}

View file

@ -0,0 +1,61 @@
package org.mage.test.cards.single.ltr;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* @author xenohedron
*/
public class YouCannotPassTest extends CardTestPlayerBase {
private static final String ycp = "You Cannot Pass!"; // {W} Instant
// Destroy target creature that blocked or was blocked by a legendary creature this turn.
private static final String yargle = "Yargle, Glutton of Urborg"; // legendary 9/3
private static final String treefolk = "Indomitable Ancients"; // 2/10
@Test
public void testBlocked() {
addCard(Zone.BATTLEFIELD, playerA, yargle);
addCard(Zone.BATTLEFIELD, playerB, treefolk);
addCard(Zone.BATTLEFIELD, playerA, "Plains");
addCard(Zone.HAND, playerA, ycp);
attack(1, playerA, yargle);
block(1, playerB, treefolk, yargle);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, ycp, treefolk);
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertGraveyardCount(playerA, ycp, 1);
assertGraveyardCount(playerB, treefolk, 1);
assertDamageReceived(playerA, yargle, 2);
}
@Test
public void testBlockedBy() {
addCard(Zone.BATTLEFIELD, playerA, treefolk);
addCard(Zone.BATTLEFIELD, playerB, yargle);
addCard(Zone.BATTLEFIELD, playerA, "Plains");
addCard(Zone.HAND, playerA, ycp);
attack(1, playerA, treefolk);
block(1, playerB, yargle, treefolk);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, ycp, treefolk);
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertGraveyardCount(playerA, ycp, 1);
assertGraveyardCount(playerA, treefolk, 1);
assertDamageReceived(playerB, yargle, 2);
}
}