simplify AbstractMillAction, remove setCardsToMill have subclass override getMilledCards
parent
d7e856da68
commit
09680d733e
|
@ -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<MagicCard> getMilledCards() {
|
||||
return milledCards;
|
||||
}
|
||||
protected abstract List<MagicCard> 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<MagicCard> 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(
|
||||
|
|
|
@ -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<MagicCard> getMilledCards() {
|
||||
return player.getLibrary().getCardsFromTop(amount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MagicCard> 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue