From 81ff37ad17c16f671099f3fae89a33040fabb074 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 15 Dec 2019 00:50:44 +0100 Subject: [PATCH] Fixed a bug that sometimes wrongly power of new source instance was used to determine a number and fixed also a bug that counters were added wrongly to an already new instance of the source object (fixes #6035). --- .../triggers/dies/ElendaTheDuskRoseTest.java | 168 ++++++++++++++++++ .../common/SourcePermanentPowerCount.java | 6 +- .../counter/AddCountersSourceEffect.java | 5 +- 3 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/ElendaTheDuskRoseTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/ElendaTheDuskRoseTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/ElendaTheDuskRoseTest.java new file mode 100644 index 00000000000..db65bc50928 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/ElendaTheDuskRoseTest.java @@ -0,0 +1,168 @@ +package org.mage.test.cards.triggers.dies; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.filter.Filter; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * + * @author LevelX2 + */ +public class ElendaTheDuskRoseTest extends CardTestPlayerBase { + + @Test + public void testAddCounter() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + + addCard(Zone.HAND, playerA, "Lightning Bolt", 1); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + // Lifelink + // Whenever another creature dies, put a +1/+1 counter on Elenda, The Dusk Rose. + // When Elenda dies, create X 1/1 white Vampire creature tokens with lifelink, where X is Elenda's power. + addCard(Zone.HAND, playerA, "Elenda, the Dusk Rose", 1); // {2}{W}{B} 1/1 + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elenda, the Dusk Rose"); + + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", "Silvercoat Lion"); + + setStopAt(3, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Elenda, the Dusk Rose", 1); + + assertGraveyardCount(playerA, "Lightning Bolt", 1); + assertGraveyardCount(playerB, "Silvercoat Lion", 1); + + assertPowerToughness(playerA, "Elenda, the Dusk Rose", 2, 2); + } + + @Test + public void testCreateVampireTokens() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + + addCard(Zone.HAND, playerA, "Lightning Bolt", 2); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + // Lifelink + // Whenever another creature dies, put a +1/+1 counter on Elenda, The Dusk Rose. + // When Elenda dies, create X 1/1 white Vampire creature tokens with lifelink, where X is Elenda's power. + addCard(Zone.HAND, playerA, "Elenda, the Dusk Rose", 1); // {2}{W}{B} 1/1 + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elenda, the Dusk Rose"); + + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", "Silvercoat Lion"); + + castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerA, "Lightning Bolt", "Elenda, the Dusk Rose"); + + setStopAt(3, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Elenda, the Dusk Rose", 0); + + assertGraveyardCount(playerA, "Lightning Bolt", 2); + assertGraveyardCount(playerB, "Silvercoat Lion", 1); + assertGraveyardCount(playerA, "Elenda, the Dusk Rose", 1); + + assertPermanentCount(playerA, "Vampire", 2); + assertPowerToughness(playerA, "Vampire", 1, 1, Filter.ComparisonScope.All); + } + + @Test + public void testKillAndReanimate() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); /// 2/2 + // Whenever a creature is put into your graveyard from the battlefield, you may sacrifice Angelic Renewal. If you do, return that card to the battlefield. + addCard(Zone.BATTLEFIELD, playerA, "Angelic Renewal", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2); + addCard(Zone.HAND, playerB, "Lightning Bolt", 2); + + // Lifelink + // Whenever another creature dies, put a +1/+1 counter on Elenda, The Dusk Rose. + // When Elenda dies, create X 1/1 white Vampire creature tokens with lifelink, where X is Elenda's power. + addCard(Zone.HAND, playerA, "Elenda, the Dusk Rose", 1); // {2}{W}{B} 1/1 + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elenda, the Dusk Rose"); + + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", "Silvercoat Lion"); + + castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerB, "Lightning Bolt", "Elenda, the Dusk Rose"); + setChoice(playerA, "No"); // use Angelic Renewal on Silvercoat Lion + setChoice(playerA, "Yes"); // use Angelic Renewal on Elenda, the Dusk Rose + + setStopAt(3, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Elenda, the Dusk Rose", 1); + assertPowerToughness(playerA, "Elenda, the Dusk Rose", 1, 1); + + assertGraveyardCount(playerB, "Lightning Bolt", 2); + assertGraveyardCount(playerA, "Silvercoat Lion", 1); + assertGraveyardCount(playerA, "Elenda, the Dusk Rose", 0); + + assertPermanentCount(playerA, "Vampire", 2); + assertPowerToughness(playerA, "Vampire", 1, 1, Filter.ComparisonScope.All); + } + + @Test + public void testKillMultipleAndReanimate() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); /// 2/2 + // Whenever a creature is put into your graveyard from the battlefield, you may sacrifice Angelic Renewal. If you do, return that card to the battlefield. + addCard(Zone.BATTLEFIELD, playerA, "Angelic Renewal", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 3); + // Sweltering Suns deals 3 damage to each creature. + // Cycling {3} ({3}, Discard this card: Draw a card.) + addCard(Zone.HAND, playerB, "Sweltering Suns", 1); // Sorcery {1}{R}{R} + + // Lifelink + // Whenever another creature dies, put a +1/+1 counter on Elenda, The Dusk Rose. + // When Elenda dies, create X 1/1 white Vampire creature tokens with lifelink, where X is Elenda's power. + addCard(Zone.HAND, playerA, "Elenda, the Dusk Rose", 1); // {2}{W}{B} 1/1 + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elenda, the Dusk Rose"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Sweltering Suns"); + + setChoice(playerA, "Yes"); // use Angelic Renewal on Elenda, the Dusk Rose + setChoice(playerA, "No"); // use Angelic Renewal on Silvercoat Lion + + setStopAt(2, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertGraveyardCount(playerA, "Angelic Renewal", 1); + + assertPermanentCount(playerA, "Silvercoat Lion", 0); + assertPermanentCount(playerA, "Elenda, the Dusk Rose", 1); + assertPowerToughness(playerA, "Elenda, the Dusk Rose", 1, 1); + + assertGraveyardCount(playerB, "Sweltering Suns", 1); + assertGraveyardCount(playerA, "Silvercoat Lion", 1); + assertGraveyardCount(playerA, "Elenda, the Dusk Rose", 0); + + assertPermanentCount(playerA, "Vampire", 1); + assertPowerToughness(playerA, "Vampire", 1, 1, Filter.ComparisonScope.All); + } + +} diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentPowerCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentPowerCount.java index f55eb7a3f87..af4effc0f04 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentPowerCount.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentPowerCount.java @@ -3,6 +3,7 @@ package mage.abilities.dynamicvalue.common; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; @@ -29,7 +30,10 @@ public class SourcePermanentPowerCount implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(sourceAbility.getSourceId()); + Permanent sourcePermanent = game.getPermanent(sourceAbility.getSourceId()); + if (sourcePermanent == null || sourcePermanent.getZoneChangeCounter(game) > sourceAbility.getSourceObjectZoneChangeCounter()) { + sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD); + } if (sourcePermanent != null && (allowNegativeValues || sourcePermanent.getPower().getValue() >= 0)) { return sourcePermanent.getPower().getValue(); diff --git a/Mage/src/main/java/mage/abilities/effects/common/counter/AddCountersSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/counter/AddCountersSourceEffect.java index 64c7abd88e5..1b5ba2047d6 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/counter/AddCountersSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/counter/AddCountersSourceEffect.java @@ -1,4 +1,3 @@ - package mage.abilities.effects.common.counter; import java.util.ArrayList; @@ -96,7 +95,9 @@ public class AddCountersSourceEffect extends OneShotEffect { if (permanent == null && source.getAbilityType() == AbilityType.STATIC) { permanent = game.getPermanentEntering(source.getSourceId()); } - if (permanent != null) { + if (permanent != null + && (source.getSourceObjectZoneChangeCounter() == 0 // from static ability + || source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game))) { // prevent to add counters to later source objects if (counter != null) { Counter newCounter = counter.copy(); int countersToAdd = amount.calculate(game, source, this);