From 2b617fa6f7e44d9dbac4af53b6585849e220cc3d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 1 Aug 2015 18:27:17 +0200 Subject: [PATCH] * Fixed a bug of ConditionalTriggeredAbility if the ability triggered multiple times at the same time. --- .../mage/sets/magic2012/JacesArchivist.java | 28 ++-- .../multiplayer/BloodchiefAscensionTest.java | 138 ++++++++++++------ ...oGraveFromAnywhereAllTriggeredAbility.java | 11 +- .../ConditionalGainActivatedAbility.java | 11 +- .../ConditionalTriggeredAbility.java | 14 +- .../effects/common/LoseLifeTargetEffect.java | 12 +- Mage/src/mage/players/PlayerImpl.java | 2 +- 7 files changed, 137 insertions(+), 79 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2012/JacesArchivist.java b/Mage.Sets/src/mage/sets/magic2012/JacesArchivist.java index 5836f1f85d2..7c944d51a83 100644 --- a/Mage.Sets/src/mage/sets/magic2012/JacesArchivist.java +++ b/Mage.Sets/src/mage/sets/magic2012/JacesArchivist.java @@ -27,20 +27,22 @@ */ package mage.sets.magic2012; -import mage.constants.*; +import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ColoredManaCost; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.ColoredManaSymbol; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.players.Player; -import java.util.UUID; - /** * @author Loki */ @@ -55,6 +57,7 @@ public class JacesArchivist extends CardImpl { this.power = new MageInt(2); this.toughness = new MageInt(2); + // {U}, {T}: Each player discards his or her hand, then draws cards equal to the greatest number of cards a player discarded this way. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new JacesArchivistEffect(), new ColoredManaCost(ColoredManaSymbol.U)); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -71,6 +74,7 @@ public class JacesArchivist extends CardImpl { } class JacesArchivistEffect extends OneShotEffect { + JacesArchivistEffect() { super(Outcome.Discard); staticText = "Each player discards his or her hand, then draws cards equal to the greatest number of cards a player discarded this way"; @@ -83,20 +87,18 @@ class JacesArchivistEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int maxDiscarded = 0; - Player sourcePlayer = game.getPlayer(source.getControllerId()); - for (UUID playerId : sourcePlayer.getInRange()) { + Player controller = game.getPlayer(source.getControllerId()); + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { - int discarded = 0; - for (Card c : player.getHand().getCards(game)) { - if (player.discard(c, source, game)) - discarded++; - } - if (discarded > maxDiscarded) + int discarded = player.getHand().size(); + player.discard(discarded, false, source, game); + if (discarded > maxDiscarded) { maxDiscarded = discarded; + } } } - for (UUID playerId : sourcePlayer.getInRange()) { + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { player.drawCards(maxDiscarded, game); diff --git a/Mage.Tests/src/test/java/org/mage/test/multiplayer/BloodchiefAscensionTest.java b/Mage.Tests/src/test/java/org/mage/test/multiplayer/BloodchiefAscensionTest.java index abad3873732..54944174eae 100644 --- a/Mage.Tests/src/test/java/org/mage/test/multiplayer/BloodchiefAscensionTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/multiplayer/BloodchiefAscensionTest.java @@ -39,108 +39,156 @@ import org.mage.test.serverside.base.CardTestMultiPlayerBase; * @author LevelX2 */ public class BloodchiefAscensionTest extends CardTestMultiPlayerBase { - - @Test + + @Test public void testBloodchiefAscensionAllPlayers() { // Enchantment // At the beginning of each end step, if an opponent lost 2 or more life this turn, you may put a quest counter on Bloodchief Ascension. (Damage causes loss of life.) - // Whenever a card is put into an opponent's graveyard from anywhere, if Bloodchief Ascension has three or more quest counters on it, you may have that player lose 2 life. If you do, you gain 2 life. + // Whenever a card is put into an opponent's graveyard from anywhere, if Bloodchief Ascension has three or more quest counters on it, you may have that player lose 2 life. If you do, you gain 2 life. addCard(Zone.BATTLEFIELD, playerA, "Bloodchief Ascension"); - - addCard(Zone.BATTLEFIELD, playerA, "Mountain",3); + + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); addCard(Zone.HAND, playerA, "Fireball"); - addCard(Zone.BATTLEFIELD, playerD, "Mountain",3); + addCard(Zone.BATTLEFIELD, playerD, "Mountain", 3); addCard(Zone.HAND, playerD, "Fireball"); - addCard(Zone.BATTLEFIELD, playerC, "Mountain",3); + addCard(Zone.BATTLEFIELD, playerC, "Mountain", 3); addCard(Zone.HAND, playerC, "Fireball"); - addCard(Zone.BATTLEFIELD, playerB, "Mountain",3); + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 3); addCard(Zone.HAND, playerB, "Fireball"); - + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Fireball", playerA); setChoice(playerA, "X=2"); - + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerD, "Fireball", playerD); setChoice(playerD, "X=2"); - + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerC, "Fireball", playerC); setChoice(playerC, "X=2"); - + castSpell(4, PhaseStep.PRECOMBAT_MAIN, playerB, "Fireball", playerB); setChoice(playerB, "X=2"); - - // Player order: A -> D -> C -> B + // Player order: A -> D -> C -> B setStopAt(4, PhaseStep.END_TURN); execute(); - + assertLife(playerA, 18); assertLife(playerB, 18); assertLife(playerC, 18); assertLife(playerD, 18); - + assertGraveyardCount(playerA, "Fireball", 1); assertGraveyardCount(playerB, "Fireball", 1); assertGraveyardCount(playerC, "Fireball", 1); assertGraveyardCount(playerD, "Fireball", 1); - - assertCounterCount("Bloodchief Ascension", CounterType.QUEST, 2); // 1 opponent out of range - } - /** - * One of my opponents in a multiplayer game had a Bloodchief Ascension in play. I took lethal damage on my turn, - * but he didn't get a counter on Bloodchief Ascension at my end step. I think he should, even though I had left - * the game from dying, because of: - * - * 800.4g. If a player leaves the game during his or her turn, that turn continues to its completion without an - * active player. If the active player would receive priority, instead the next player in turn order receives priority, - * or the top object on the stack resolves, or the phase or step ends, whichever is appropriate. - */ + } + + /** + * One of my opponents in a multiplayer game had a Bloodchief Ascension in + * play. I took lethal damage on my turn, but he didn't get a counter on + * Bloodchief Ascension at my end step. I think he should, even though I had + * left the game from dying, because of: + * + * 800.4g. If a player leaves the game during his or her turn, that turn + * continues to its completion without an active player. If the active + * player would receive priority, instead the next player in turn order + * receives priority, or the top object on the stack resolves, or the phase + * or step ends, whichever is appropriate. + */ @Test public void testBloodchiefAscension() { // Enchantment // At the beginning of each end step, if an opponent lost 2 or more life this turn, you may put a quest counter on Bloodchief Ascension. (Damage causes loss of life.) - // Whenever a card is put into an opponent's graveyard from anywhere, if Bloodchief Ascension has three or more quest counters on it, you may have that player lose 2 life. If you do, you gain 2 life. + // Whenever a card is put into an opponent's graveyard from anywhere, if Bloodchief Ascension has three or more quest counters on it, you may have that player lose 2 life. If you do, you gain 2 life. addCard(Zone.BATTLEFIELD, playerA, "Bloodchief Ascension"); - addCard(Zone.BATTLEFIELD, playerA, "Mountain",3); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); addCard(Zone.HAND, playerA, "Fireball"); - addCard(Zone.BATTLEFIELD, playerD, "Mountain",3); + addCard(Zone.BATTLEFIELD, playerD, "Mountain", 3); addCard(Zone.HAND, playerD, "Fireball"); - addCard(Zone.BATTLEFIELD, playerC, "Mountain",3); + addCard(Zone.BATTLEFIELD, playerC, "Mountain", 3); addCard(Zone.HAND, playerC, "Fireball"); - addCard(Zone.BATTLEFIELD, playerB, "Mountain",21); + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 21); addCard(Zone.HAND, playerB, "Fireball"); - + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Fireball", playerA); setChoice(playerA, "X=2"); - + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerD, "Fireball", playerD); setChoice(playerD, "X=2"); - + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerC, "Fireball", playerC); setChoice(playerC, "X=2"); - + castSpell(4, PhaseStep.PRECOMBAT_MAIN, playerB, "Fireball", playerB); setChoice(playerB, "X=20"); - - // Player order: A -> D -> C -> B + // Player order: A -> D -> C -> B setStopAt(4, PhaseStep.END_TURN); execute(); - + assertLife(playerA, 18); assertLife(playerB, 0); assertLife(playerC, 18); assertLife(playerD, 18); - + Assert.assertTrue("playerB has lost", playerB.hasLost()); - + assertGraveyardCount(playerA, "Fireball", 1); assertGraveyardCount(playerC, "Fireball", 1); - assertGraveyardCount(playerD, "Fireball", 1); - - assertCounterCount("Bloodchief Ascension", CounterType.QUEST, 2); // 1 opponent out of range + assertGraveyardCount(playerD, "Fireball", 1); + + assertCounterCount("Bloodchief Ascension", CounterType.QUEST, 2); // 1 opponent out of range + + } + + /** + * Bloodchief Ascension effect is not working corretly on multiplayer. + * Whenever one player activated Jace's Archivist, the damage of the + * discarded cards was going on a single player, not on the players who + * discarded the cards. + */ + @Test + public void testJacesArchivist() { + // Enchantment + // At the beginning of each end step, if an opponent lost 2 or more life this turn, you may put a quest counter on Bloodchief Ascension. (Damage causes loss of life.) + // Whenever a card is put into an opponent's graveyard from anywhere, if Bloodchief Ascension has three or more quest counters on it, you may have that player lose 2 life. If you do, you gain 2 life. + + skipInitShuffling(); + addCard(Zone.LIBRARY, playerA, "Auramancer"); + addCard(Zone.HAND, playerA, "Auramancer", 2); + + addCard(Zone.BATTLEFIELD, playerD, "Bloodchief Ascension"); + addCounters(2, PhaseStep.UPKEEP, playerD, "Bloodchief Ascension", CounterType.QUEST, 3); + addCard(Zone.BATTLEFIELD, playerD, "Island", 1); + // {U}, {T}: Each player discards his or her hand, then draws cards equal to the greatest number of cards a player discarded this way. + addCard(Zone.BATTLEFIELD, playerD, "Jace's Archivist", 1); // {1}{U}{U} + addCard(Zone.LIBRARY, playerD, "Demolish"); + addCard(Zone.HAND, playerD, "Demolish", 1); + + addCard(Zone.HAND, playerC, "Cobblebrute", 4); + addCard(Zone.HAND, playerB, "Bellows Lizard", 5); + + // Player order: A -> D -> C -> B + activateAbility(2, PhaseStep.PRECOMBAT_MAIN, playerD, "{U},{T}: Each player discards"); + setStopAt(2, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Auramancer", 3); + assertGraveyardCount(playerD, "Demolish", 2); + assertGraveyardCount(playerC, "Cobblebrute", 4); + + assertHandCount(playerA, 4); + assertHandCount(playerD, 4); + assertHandCount(playerC, 4); + assertHandCount(playerB, "Bellows Lizard", 5); + + assertLife(playerA, 14); + assertLife(playerD, 34); + assertLife(playerC, 12); + assertLife(playerB, 20); } } diff --git a/Mage/src/mage/abilities/common/PutCardIntoGraveFromAnywhereAllTriggeredAbility.java b/Mage/src/mage/abilities/common/PutCardIntoGraveFromAnywhereAllTriggeredAbility.java index 77fef28b1d6..fb2b469a727 100644 --- a/Mage/src/mage/abilities/common/PutCardIntoGraveFromAnywhereAllTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/PutCardIntoGraveFromAnywhereAllTriggeredAbility.java @@ -44,7 +44,6 @@ import mage.target.targetpointer.FixedTarget; * * @author LevelX2 */ - public class PutCardIntoGraveFromAnywhereAllTriggeredAbility extends TriggeredAbilityImpl { private final FilterCard filter; @@ -58,7 +57,7 @@ public class PutCardIntoGraveFromAnywhereAllTriggeredAbility extends TriggeredAb public PutCardIntoGraveFromAnywhereAllTriggeredAbility(Effect effect, boolean optional, FilterCard filter, TargetController targetController) { this(effect, optional, filter, targetController, SetTargetPointer.NONE); } - + public PutCardIntoGraveFromAnywhereAllTriggeredAbility(Effect effect, boolean optional, FilterCard filter, TargetController targetController, SetTargetPointer setTargetPointer) { this(Zone.BATTLEFIELD, effect, optional, filter, targetController, setTargetPointer); } @@ -110,13 +109,13 @@ public class PutCardIntoGraveFromAnywhereAllTriggeredAbility extends TriggeredAb if (card != null && filter.match(card, getSourceId(), getControllerId(), game)) { switch (setTargetPointer) { case CARD: - for (Effect effect: getEffects()) { - effect.setTargetPointer(new FixedTarget(card.getId())); + for (Effect effect : getEffects()) { + effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game))); } break; case PLAYER: - for (Effect effect: getEffects()) { - effect.setTargetPointer(new FixedTarget(card.getOwnerId())); + for (Effect effect : getEffects()) { + effect.setTargetPointer(new FixedTarget(card.getOwnerId(), 0)); } break; diff --git a/Mage/src/mage/abilities/decorator/ConditionalGainActivatedAbility.java b/Mage/src/mage/abilities/decorator/ConditionalGainActivatedAbility.java index f0456f2e11f..9fe5123f838 100644 --- a/Mage/src/mage/abilities/decorator/ConditionalGainActivatedAbility.java +++ b/Mage/src/mage/abilities/decorator/ConditionalGainActivatedAbility.java @@ -28,8 +28,6 @@ package mage.abilities.decorator; import java.util.UUID; - -import mage.constants.Zone; import mage.abilities.ActivatedAbilityImpl; import mage.abilities.condition.Condition; import mage.abilities.costs.Cost; @@ -38,6 +36,7 @@ import mage.abilities.costs.mana.ManaCosts; import mage.abilities.effects.Effect; import mage.abilities.effects.Effects; import mage.constants.EffectType; +import mage.constants.Zone; import mage.game.Game; /** @@ -47,12 +46,12 @@ import mage.game.Game; */ public class ConditionalGainActivatedAbility extends ActivatedAbilityImpl { - private Condition condition; - private String staticText = ""; + private final Condition condition; + private String staticText = ""; - private static final Effects emptyEffects = new Effects(); + private static final Effects emptyEffects = new Effects(); - public ConditionalGainActivatedAbility(Zone zone, Effect effect, ManaCosts cost, Condition condition, String rule) { + public ConditionalGainActivatedAbility(Zone zone, Effect effect, ManaCosts cost, Condition condition, String rule) { super(zone, effect, cost); this.condition = condition; this.staticText = rule; diff --git a/Mage/src/mage/abilities/decorator/ConditionalTriggeredAbility.java b/Mage/src/mage/abilities/decorator/ConditionalTriggeredAbility.java index 7a05e126a7c..a6888eabba5 100644 --- a/Mage/src/mage/abilities/decorator/ConditionalTriggeredAbility.java +++ b/Mage/src/mage/abilities/decorator/ConditionalTriggeredAbility.java @@ -1,9 +1,11 @@ package mage.abilities.decorator; +import mage.abilities.Modes; import mage.abilities.TriggeredAbility; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.condition.Condition; import mage.abilities.effects.Effects; +import mage.constants.EffectType; import mage.game.Game; import mage.game.events.GameEvent; @@ -34,7 +36,7 @@ public class ConditionalTriggeredAbility extends TriggeredAbilityImpl { public ConditionalTriggeredAbility(final ConditionalTriggeredAbility triggered) { super(triggered); - this.ability = triggered.ability; + this.ability = triggered.ability.copy(); this.condition = triggered.condition; this.text = triggered.text; } @@ -74,4 +76,14 @@ public class ConditionalTriggeredAbility extends TriggeredAbilityImpl { return ability.getEffects(); } + @Override + public Modes getModes() { + return ability.getModes(); + } + + @Override + public Effects getEffects(Game game, EffectType effectType) { + return ability.getEffects(game, effectType); + } + } diff --git a/Mage/src/mage/abilities/effects/common/LoseLifeTargetEffect.java b/Mage/src/mage/abilities/effects/common/LoseLifeTargetEffect.java index b057048f2d9..501f3850958 100644 --- a/Mage/src/mage/abilities/effects/common/LoseLifeTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/LoseLifeTargetEffect.java @@ -1,16 +1,16 @@ /* * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR @@ -20,12 +20,11 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.abilities.effects.common; import mage.abilities.Ability; @@ -103,5 +102,4 @@ public class LoseLifeTargetEffect extends OneShotEffect { return sb.toString(); } - } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 032325c8251..2f92485f6ab 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -693,7 +693,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public Cards discard(int amount, boolean random, Ability source, Game game) { Cards discardedCards = new CardsImpl(); - if (this.getHand().size() == 1) { + if (this.getHand().size() == 1 || this.getHand().size() == amount) { discardedCards.addAll(this.getHand()); while (this.getHand().size() > 0) { discard(this.getHand().get(this.getHand().iterator().next(), game), source, game);