From 768ef9a4fc6403e9a7492422a9490f072d7602c3 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 21 Apr 2013 22:34:44 +0200 Subject: [PATCH] Improved handling of applied efffects for replacement effects. --- .../abilities/effects/ContinuousEffects.java | 6 ++++++ Mage/src/mage/actions/MageDrawAction.java | 18 +++++++++++++----- Mage/src/mage/players/Player.java | 1 + Mage/src/mage/players/PlayerImpl.java | 7 ++++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index 00ae523cff..870cf75fec 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -253,6 +253,11 @@ public class ContinuousEffects implements Serializable { } //get all applicable transient Replacement effects for (ReplacementEffect effect: replacementEffects) { + if (event.getAppliedEffects() != null && event.getAppliedEffects().contains(effect.getId())) { + // Effect already applied to this event, ignore it + // TODO: Handle also gained effect that are connected to different abilities. + continue; + } HashSet abilities = replacementEffects.getAbility(effect.getId()); HashSet applicableAbilities = new HashSet(); for (Ability ability : abilities) { @@ -450,6 +455,7 @@ public class ContinuousEffects implements Serializable { } if (rEffect != null) { + event.getAppliedEffects().add(rEffect.getId()); caught = rEffect.replaceEvent(event, rAbility, game); } if (caught) { // Event was completely replaced -> stop applying effects to it diff --git a/Mage/src/mage/actions/MageDrawAction.java b/Mage/src/mage/actions/MageDrawAction.java index 2f9ed00a65..31b49d7df9 100644 --- a/Mage/src/mage/actions/MageDrawAction.java +++ b/Mage/src/mage/actions/MageDrawAction.java @@ -1,5 +1,6 @@ package mage.actions; +import java.util.ArrayList; import mage.Constants; import mage.actions.impl.MageAction; import mage.actions.score.ArtificialScoringSystem; @@ -9,6 +10,7 @@ import mage.game.events.GameEvent; import mage.players.Player; import java.util.List; +import java.util.UUID; /** * Action for drawing cards. @@ -19,13 +21,15 @@ public class MageDrawAction extends MageAction { private final Player player; private final int amount; + private ArrayList appliedEffects; private List drawnCards; private static final int NEGATIVE_VALUE = -1000000; - public MageDrawAction(Player player, int amount) { + public MageDrawAction(Player player, int amount, ArrayList appliedEffects) { this.player = player; this.amount = amount; + this.appliedEffects = appliedEffects; } /** @@ -39,13 +43,15 @@ public class MageDrawAction extends MageAction { int score = 0; for (int i = 0; i < amount; i++) { int value = drawCard(game); - if (value == -1) { - break; + if (value == NEGATIVE_VALUE) { + continue; } numDrawn++; score += value; } - game.fireInformEvent(player.getName() + " draws " + Integer.toString(numDrawn) + " card" + (numDrawn > 1 ? "s" : "")); + if (numDrawn > 0) { + game.fireInformEvent(player.getName() + " draws " + Integer.toString(numDrawn) + " card" + (numDrawn > 1 ? "s" : "")); + } if (player.isEmptyDraw()) { game.doAction(new MageLoseGameAction(player, MageLoseGameAction.DRAW_REASON)); } @@ -64,7 +70,9 @@ public class MageDrawAction extends MageAction { * @return */ protected int drawCard(Game game) { - if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DRAW_CARD, player.getId(), player.getId()))) { + GameEvent event = GameEvent.getEvent(GameEvent.EventType.DRAW_CARD, player.getId(), player.getId()); + event.setAppliedEffects(appliedEffects); + if (!game.replaceEvent(event)) { Card card = player.getLibrary().removeFromTop(game); if (card != null) { card.moveToZone(Constants.Zone.HAND, null, game, false); diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 6d714ff619..644cca18b0 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -165,6 +165,7 @@ public interface Player extends MageItem, Copyable { void reset(); void shuffleLibrary(Game game); int drawCards(int num, Game game); + int drawCards(int num, Game game, ArrayList appliedEffects); boolean cast(SpellAbility ability, Game game, boolean noMana); boolean putInHand(Card card, Game game); boolean removeFromHand(Card card, Game game); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 3206c8e38f..957d6c52ac 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -380,7 +380,12 @@ public abstract class PlayerImpl> implements Player, Ser @Override public int drawCards(int num, Game game) { - return game.doAction(new MageDrawAction(this, num)); + return game.doAction(new MageDrawAction(this, num, null)); + } + + @Override + public int drawCards(int num, Game game, ArrayList appliedEffects) { + return game.doAction(new MageDrawAction(this, num, appliedEffects)); } @Override