Fixed a problem that DiesTriggeredAbilities from Tokens that were removed by an effect did nevertheless trigger (fixes #5825).

This commit is contained in:
LevelX2 2019-12-15 13:10:11 +01:00
parent d458e73795
commit 8d46f46cf8
2 changed files with 36 additions and 41 deletions

View file

@ -8,71 +8,69 @@ package org.mage.test.cards.continuous;
import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability;
import mage.abilities.keyword.FlashAbility;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.mage.test.serverside.base.CardTestPlayerBase;
import org.junit.Test;
import mage.abilities.keyword.FlashAbility;
import mage.counters.CounterType;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author drmDev
*/
public class MerfolkTricksterTest extends CardTestPlayerBase {
/*
Merfolk Trickster (UU)
Creature Merfolk Wizard
Flash
When Merfolk Trickster enters the battlefield, tap target creature an opponent controls. It loses all abilities until end of turn.
*/
*/
public final String mTrickster = "Merfolk Trickster";
@Test
public void test_TricksterAndFlyer_FlyingRemoved()
{
public void test_TricksterAndFlyer_FlyingRemoved() {
addCard(Zone.BATTLEFIELD, playerA, "Flying Men"); // (U) 1/1 flyer
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Zone.HAND, playerB, mTrickster);
attack(1, playerA, "Flying Men");
castSpell(1, PhaseStep.DECLARE_BLOCKERS, playerB, mTrickster);
addTarget(playerB, "Flying Men");
setStopAt(1, PhaseStep.END_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 19);
assertTappedCount("Island", true, 2);
assertTapped("Flying Men", true);
Abilities<Ability> noAbilities = new AbilitiesImpl<>();
assertAbilities(playerA, "Flying Men", noAbilities); // no abilities, empty list
Abilities<Ability> flashAbility = new AbilitiesImpl<>();
flashAbility.add(FlashAbility.getInstance());
assertAbilities(playerB, mTrickster, flashAbility); // has flash
assertAbilities(playerB, mTrickster, flashAbility); // has flash
assertAllCommandsUsed();
}
@Test
public void test_TricksterAndFlyerBlocked_FlyingRemovedAndBlocked()
{
public void test_TricksterAndFlyerBlocked_FlyingRemovedAndBlocked() {
addCard(Zone.BATTLEFIELD, playerA, "Flying Men"); // (U) 1/1 flyer
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Zone.HAND, playerB, mTrickster);
attack(1, playerA, "Flying Men");
castSpell(1, PhaseStep.DECLARE_ATTACKERS, playerB, mTrickster);
addTarget(playerB, "Flying Men");
block(1, playerB, mTrickster, "Flying Men");
setStopAt(1, PhaseStep.END_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertTappedCount("Island", true, 2);
@ -81,23 +79,22 @@ public class MerfolkTricksterTest extends CardTestPlayerBase {
assertDamageReceived(playerB, mTrickster, 1);
assertAllCommandsUsed();
}
@Test
public void test_TricksterBlocksFootlightFiend_Survives()
{
public void test_TricksterBlocksFootlightFiend_Survives() {
addCard(Zone.BATTLEFIELD, playerA, "Footlight Fiend"); // (R/B) 1/1 on death pings any target for 1
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Zone.HAND, playerB, mTrickster);
attack(1, playerA, "Footlight Fiend");
castSpell(1, PhaseStep.DECLARE_ATTACKERS, playerB, mTrickster);
addTarget(playerB, "Footlight Fiend");
block(1, playerB, mTrickster, "Footlight Fiend");
addTarget(playerA, mTrickster);
setStopAt(1, PhaseStep.END_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertTappedCount("Island", true, 2);
@ -105,37 +102,36 @@ public class MerfolkTricksterTest extends CardTestPlayerBase {
assertDamageReceived(playerB, mTrickster, 1);
//assertAllCommandsUsed(); // uncommenting this will force a failure since PlayerA cannot do a command to target Trickster, as expected
}
@Test
public void test_TricksterBlocksTibaltToken_Survives()
{
/*
public void test_TricksterBlocksTibaltToken_Survives() {
/*
Tibalt, Rakish Instigator (2R)
Legendary Planeswalker Tibalt
Your opponents can't gain life.
-2: Create a 1/1 red Devil creature token with "When this creature dies, it deals 1 damage to any target."
*/
*/
addCard(Zone.BATTLEFIELD, playerA, "Tibalt, Rakish Instigator");
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Zone.HAND, playerB, mTrickster);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "-2:");
attack(3, playerA, "Devil");
castSpell(3, PhaseStep.DECLARE_ATTACKERS, playerB, mTrickster);
addTarget(playerB, "Devil");
block(3, playerB, mTrickster, "Devil");
addTarget(playerA, mTrickster);
setStopAt(3, PhaseStep.END_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertCounterCount("Tibalt, Rakish Instigator", CounterType.LOYALTY, 3);
assertTappedCount("Island", true, 2);
assertPermanentCount(playerB, mTrickster, 1);
assertDamageReceived(playerB, mTrickster, 1);
assertAllCommandsUsed(); // uncommenting this should force a failure since PlayerA cannot do a command to target Trickster, as expected
// assertAllCommandsUsed(); // uncommenting this should force a failure since PlayerA cannot do a command to target Trickster, as expected
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.common;
import mage.MageObject;
@ -34,11 +33,11 @@ public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility {
if (before == null) {
return false;
}
if (!(before instanceof PermanentToken) && !this.hasSourceObjectAbility(game, before, event)) {
if (!this.hasSourceObjectAbility(game, before, event)) { // the permanent does not have the ability so no trigger
return false;
}
// check now it is in graveyard
if (before.getZoneChangeCounter(game) + 1 == game.getState().getZoneChangeCounter(sourceId)) {
// check now it is in graveyard if it is no token
if (!(before instanceof PermanentToken) && before.getZoneChangeCounter(game) + 1 == game.getState().getZoneChangeCounter(sourceId)) {
Zone after = game.getState().getZone(sourceId);
return after != null && Zone.GRAVEYARD.match(after);
} else {