1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-09 01:01:06 -09:00

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 ).

This commit is contained in:
LevelX2 2019-12-15 00:50:44 +01:00
parent 515b55f088
commit 81ff37ad17
3 changed files with 176 additions and 3 deletions
Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies
Mage/src/main/java/mage/abilities
dynamicvalue/common
effects/common/counter

View file

@ -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);
}
}

View file

@ -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();

View file

@ -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);