From 7fc072f467ff7bfb79a489080b0758fb572a050d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 24 May 2014 19:19:08 +0200 Subject: [PATCH] * Fixed a bug that effects where applied to early and often (e.g. dying creature during combat damage step raised Nighthowlers tougness, so he survived lethal damage). --- ...hnessCalculationAfterCombatDamageTest.java | 44 +++++++++++++++++++ .../abilities/effects/common/CopyEffect.java | 27 ++++++++---- Mage/src/mage/cards/CardImpl.java | 4 +- .../mage/game/permanent/PermanentCard.java | 14 ++---- 4 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/combat/PowerToughnessCalculationAfterCombatDamageTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/combat/PowerToughnessCalculationAfterCombatDamageTest.java b/Mage.Tests/src/test/java/org/mage/test/combat/PowerToughnessCalculationAfterCombatDamageTest.java new file mode 100644 index 00000000000..2161857f9bc --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/combat/PowerToughnessCalculationAfterCombatDamageTest.java @@ -0,0 +1,44 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package org.mage.test.combat; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.game.permanent.Permanent; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * Test that calculated p/t is applied after combat damage resolution, so a 2/2 Nighthowler + * dies if blocked from a 2/2 creature. + * + * @author LevelX2 + */ +public class PowerToughnessCalculationAfterCombatDamageTest extends CardTestPlayerBase { + + @Test + public void powerToughnessCalculation() { + addCard(Zone.BATTLEFIELD, playerA, "Pain Seer"); + addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion"); + // Nighthowler and enchanted creature each get +X/+X, where X is the number of creature cards in all graveyards. + addCard(Zone.BATTLEFIELD, playerB, "Nighthowler"); + addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion"); + + attack(2, playerB, "Nighthowler"); + block(2, playerA, "Pain Seer", "Nighthowler"); + + setStopAt(2, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertGraveyardCount(playerB, "Nighthowler", 1); + assertGraveyardCount(playerA, "Pain Seer", 1); + } +} diff --git a/Mage/src/mage/abilities/effects/common/CopyEffect.java b/Mage/src/mage/abilities/effects/common/CopyEffect.java index 0326ea8e4d5..67fa2424320 100644 --- a/Mage/src/mage/abilities/effects/common/CopyEffect.java +++ b/Mage/src/mage/abilities/effects/common/CopyEffect.java @@ -28,14 +28,17 @@ package mage.abilities.effects.common; +import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Layer; +import mage.constants.Outcome; +import mage.constants.SubLayer; import mage.game.Game; import mage.game.permanent.Permanent; - -import java.util.UUID; import mage.game.permanent.PermanentCard; import mage.game.permanent.PermanentToken; @@ -50,6 +53,7 @@ public class CopyEffect extends ContinuousEffectImpl { */ private MageObject target; private UUID sourceId; + private int zoneChangeCounter; public CopyEffect(Permanent target, UUID sourceId) { this(Duration.Custom, target, sourceId); @@ -65,6 +69,16 @@ public class CopyEffect extends ContinuousEffectImpl { super(effect); this.target = effect.target.copy(); this.sourceId = effect.sourceId; + this.zoneChangeCounter = effect.zoneChangeCounter; + } + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + Permanent permanent = game.getPermanent(sourceId); + if (permanent != null) { + this.zoneChangeCounter = permanent.getZoneChangeCounter(); + } } @Override @@ -119,12 +133,9 @@ public class CopyEffect extends ContinuousEffectImpl { @Override public boolean isInactive(Ability source, Game game) { - // The copy effect is added, if the copy takes place. If source leaves battlefield, the copy effect must cease to exist + // The copy effect is added, if the copy takes place. If source left battlefield, the copy effect must cease to exist Permanent permanent = game.getPermanent(this.sourceId); - if (permanent == null) { - return true; - } - return false; + return permanent == null || permanent.getZoneChangeCounter() != this.zoneChangeCounter; } @Override diff --git a/Mage/src/mage/cards/CardImpl.java b/Mage/src/mage/cards/CardImpl.java index a9812f60fa0..b57517c7d22 100644 --- a/Mage/src/mage/cards/CardImpl.java +++ b/Mage/src/mage/cards/CardImpl.java @@ -461,7 +461,7 @@ public abstract class CardImpl> extends MageObjectImpl } updateZoneChangeCounter(); game.setZone(objectId, event.getToZone()); - game.fireEvent(event); + game.addSimultaneousEvent(event); return true; } return false; @@ -604,7 +604,7 @@ public abstract class CardImpl> extends MageObjectImpl @Override public void addInfo(String key, String value) { if (info == null) { - info = new HashMap(); + info = new HashMap<>(); } info.put(key, value); } diff --git a/Mage/src/mage/game/permanent/PermanentCard.java b/Mage/src/mage/game/permanent/PermanentCard.java index 09c53cb4ff4..1950f2f4684 100644 --- a/Mage/src/mage/game/permanent/PermanentCard.java +++ b/Mage/src/mage/game/permanent/PermanentCard.java @@ -107,7 +107,8 @@ public class PermanentCard extends PermanentImpl { this.rarity = card.getRarity(); this.cardNumber = card.getCardNumber(); this.usesVariousArt = card.getUsesVariousArt(); - + this.zoneChangeCounter = card.getZoneChangeCounter(); + canTransform = card.canTransform(); if (canTransform) { secondSideCard = card.getSecondCardFace(); @@ -162,11 +163,6 @@ public class PermanentCard extends PermanentImpl { } game.setZone(objectId, event.getToZone()); game.addSimultaneousEvent(event); - if (event.getFromZone().equals(Zone.BATTLEFIELD)) { - game.getState().handleSimultaneousEvent(game); - game.resetForSourceId(getId()); - game.applyEffects(); // LevelX2: needed to execute isInactive for of custom duration copy effect if source returns directly (e.g. cloudshifted clone) - } return game.getState().getZone(objectId) == toZone; } } @@ -193,11 +189,7 @@ public class PermanentCard extends PermanentImpl { game.getExile().createZone(exileId, name).add(card); } game.setZone(objectId, event.getToZone()); - game.fireEvent(event); - if (event.getFromZone().equals(Zone.BATTLEFIELD)) { - game.resetForSourceId(getId()); - game.applyEffects(); - } + game.addSimultaneousEvent(event); return true; } }