* Undercity Reaches - fixed rollback error on plane's draw trigger

This commit is contained in:
Oleg Agafonov 2020-08-29 20:40:02 +04:00
parent 30fe344e23
commit 87d8383eb8
2 changed files with 57 additions and 4 deletions

View file

@ -0,0 +1,53 @@
package org.mage.test.cards.planes;
import mage.constants.PhaseStep;
import mage.constants.Planes;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* @author JayDi85
*/
public class UndercityReachesTest extends CardTestPlayerBase {
@Test
public void test_CanTriggerByController() {
removeAllCardsFromHand(playerA);
// Whenever a creature deals combat damage to a player, its controller may a draw a card
addPlane(playerA, Planes.PLANE_UNDERCITY_REACHES);
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1);
attack(1, playerA, "Balduvian Bears");
setChoice(playerA, "Yes"); // draw
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertLife(playerB, 20 - 2);
assertHandCount(playerA, 1);
}
@Test
public void test_CanTriggerByOther() {
removeAllCardsFromHand(playerB);
// Whenever a creature deals combat damage to a player, its controller may a draw a card
addPlane(playerA, Planes.PLANE_UNDERCITY_REACHES);
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1);
attack(2, playerB, "Balduvian Bears");
setChoice(playerB, "Yes"); // draw
setStrictChooseMode(true);
setStopAt(2, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertLife(playerA, 20 - 2);
assertHandCount(playerB, 1 + 1); // +1 from turn draw, +1 from trigger
}
}

View file

@ -43,7 +43,7 @@ public class UndercityReachesPlane extends Plane {
this.setPlaneType(Planes.PLANE_UNDERCITY_REACHES); this.setPlaneType(Planes.PLANE_UNDERCITY_REACHES);
this.setExpansionSetCodeForImage("PCA"); this.setExpansionSetCodeForImage("PCA");
// Whenever a creature deals combat damage to a player, its controller may a draw a card // Whenever a creature deals combat damage to a player, its controller may draw a card.
Ability ability = new UndercityReachesTriggeredAbility(); Ability ability = new UndercityReachesTriggeredAbility();
this.getAbilities().add(ability); this.getAbilities().add(ability);
@ -68,7 +68,7 @@ public class UndercityReachesPlane extends Plane {
class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl { class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl {
public UndercityReachesTriggeredAbility() { public UndercityReachesTriggeredAbility() {
super(Zone.COMMAND, null, true); super(Zone.COMMAND, null, false); // effect must be optional
} }
public UndercityReachesTriggeredAbility(final UndercityReachesTriggeredAbility ability) { public UndercityReachesTriggeredAbility(final UndercityReachesTriggeredAbility ability) {
@ -98,9 +98,9 @@ class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl {
if (((DamagedPlayerEvent) event).isCombatDamage()) { if (((DamagedPlayerEvent) event).isCombatDamage()) {
Permanent creature = game.getPermanent(event.getSourceId()); Permanent creature = game.getPermanent(event.getSourceId());
if (creature != null) { if (creature != null) {
Effect effect = new DrawCardTargetEffect(StaticValue.get(1), false, true); Effect effect = new DrawCardTargetEffect(StaticValue.get(1), true, false);
effect.setTargetPointer(new FixedTarget(creature.getControllerId())); effect.setTargetPointer(new FixedTarget(creature.getControllerId()));
effect.apply(game, null); effect.apply(game, this);
return true; return true;
} }
} }