diff --git a/src/magic/model/action/AbstractMillAction.java b/src/magic/model/action/AbstractMillAction.java index dfb59ed0c6..a6e24a4c00 100644 --- a/src/magic/model/action/AbstractMillAction.java +++ b/src/magic/model/action/AbstractMillAction.java @@ -6,6 +6,7 @@ import magic.model.MagicCardList; import magic.model.MagicGame; import magic.model.MagicMessage; import magic.model.MagicPlayer; +import magic.model.MagicLocationType; import java.util.List; @@ -14,15 +15,12 @@ import java.util.List; */ public abstract class AbstractMillAction extends MagicAction { protected final MagicPlayer player; - protected final MagicCardList milledCards = new MagicCardList(); protected AbstractMillAction(final MagicPlayer player) { this.player = player; } - public List getMilledCards() { - return milledCards; - } + protected abstract List getMilledCards(); @Override public void undoAction(final MagicGame game) { @@ -32,14 +30,17 @@ public abstract class AbstractMillAction extends MagicAction { return String.format("top %d cards", finalCount); } - protected abstract void setCardsToMill(MagicGame game); - - @Override public void doAction(final MagicGame game) { - getMilledCards().clear(); - setCardsToMill(game); - final int count = getMilledCards().size(); + List toMill = getMilledCards(); + for (final MagicCard card : toMill) { + game.doAction(new ShiftCardAction( + card, + MagicLocationType.OwnersLibrary, + MagicLocationType.Graveyard + )); + } + final int count = toMill.size(); if (count > 0) { setScore(player,ArtificialScoringSystem.getMillScore(count)); game.logAppendMessage( diff --git a/src/magic/model/action/MillLibraryAction.java b/src/magic/model/action/MillLibraryAction.java index bbd827455a..e88bb4c4ca 100644 --- a/src/magic/model/action/MillLibraryAction.java +++ b/src/magic/model/action/MillLibraryAction.java @@ -6,6 +6,8 @@ import magic.model.MagicGame; import magic.model.MagicLocationType; import magic.model.MagicPlayer; +import java.util.List; + /** * Action that removes fixed amount of cards from players library and moves them to that player's graveyard. */ @@ -24,15 +26,8 @@ public class MillLibraryAction extends AbstractMillAction { amount = aAmount; } - protected void setCardsToMill(MagicGame game) { - final MagicCardList topN = player.getLibrary().getCardsFromTop(amount); - for (final MagicCard card : topN) { - milledCards.add(card); - game.doAction(new ShiftCardAction( - card, - MagicLocationType.OwnersLibrary, - MagicLocationType.Graveyard - )); - } + @Override + protected List getMilledCards() { + return player.getLibrary().getCardsFromTop(amount); } } diff --git a/src/magic/model/action/MillLibraryUntilAction.java b/src/magic/model/action/MillLibraryUntilAction.java index eecde6e9c4..24eaaa019b 100644 --- a/src/magic/model/action/MillLibraryUntilAction.java +++ b/src/magic/model/action/MillLibraryUntilAction.java @@ -7,6 +7,8 @@ import magic.model.MagicLocationType; import magic.model.MagicPlayer; import magic.model.MagicType; +import java.util.List; + /** * Action that removes cards from players library and moves them to that player's graveyard, * until certain card type is seen given number of times (or whole library is milled). @@ -34,16 +36,13 @@ public class MillLibraryUntilAction extends AbstractMillAction { return String.format("top %d cards - until %d %s(s) are seen -", finalCount, cards, cardType.getDisplayName()); } - protected void setCardsToMill(MagicGame game) { + @Override + protected List getMilledCards() { final MagicCardList all = player.getLibrary().getCardsFromTop(Integer.MAX_VALUE); + final MagicCardList milledCards = new MagicCardList(); int seenTargets = 0; for (final MagicCard card : all) { milledCards.add(card); - game.doAction(new ShiftCardAction( - card, - MagicLocationType.OwnersLibrary, - MagicLocationType.Graveyard - )); if (card.hasType(cardType)) { seenTargets++; } @@ -51,5 +50,6 @@ public class MillLibraryUntilAction extends AbstractMillAction { break; } } + return milledCards; } }