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.MagicGame;
|
||||||
import magic.model.MagicMessage;
|
import magic.model.MagicMessage;
|
||||||
import magic.model.MagicPlayer;
|
import magic.model.MagicPlayer;
|
||||||
|
import magic.model.MagicLocationType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -14,15 +15,12 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractMillAction extends MagicAction {
|
public abstract class AbstractMillAction extends MagicAction {
|
||||||
protected final MagicPlayer player;
|
protected final MagicPlayer player;
|
||||||
protected final MagicCardList milledCards = new MagicCardList();
|
|
||||||
|
|
||||||
protected AbstractMillAction(final MagicPlayer player) {
|
protected AbstractMillAction(final MagicPlayer player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MagicCard> getMilledCards() {
|
protected abstract List<MagicCard> getMilledCards();
|
||||||
return milledCards;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undoAction(final MagicGame game) {
|
public void undoAction(final MagicGame game) {
|
||||||
|
@ -32,14 +30,17 @@ public abstract class AbstractMillAction extends MagicAction {
|
||||||
return String.format("top %d cards", finalCount);
|
return String.format("top %d cards", finalCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void setCardsToMill(MagicGame game);
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAction(final MagicGame game) {
|
public void doAction(final MagicGame game) {
|
||||||
getMilledCards().clear();
|
List<MagicCard> toMill = getMilledCards();
|
||||||
setCardsToMill(game);
|
for (final MagicCard card : toMill) {
|
||||||
final int count = getMilledCards().size();
|
game.doAction(new ShiftCardAction(
|
||||||
|
card,
|
||||||
|
MagicLocationType.OwnersLibrary,
|
||||||
|
MagicLocationType.Graveyard
|
||||||
|
));
|
||||||
|
}
|
||||||
|
final int count = toMill.size();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
setScore(player,ArtificialScoringSystem.getMillScore(count));
|
setScore(player,ArtificialScoringSystem.getMillScore(count));
|
||||||
game.logAppendMessage(
|
game.logAppendMessage(
|
||||||
|
|
|
@ -6,6 +6,8 @@ import magic.model.MagicGame;
|
||||||
import magic.model.MagicLocationType;
|
import magic.model.MagicLocationType;
|
||||||
import magic.model.MagicPlayer;
|
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.
|
* 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;
|
amount = aAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setCardsToMill(MagicGame game) {
|
@Override
|
||||||
final MagicCardList topN = player.getLibrary().getCardsFromTop(amount);
|
protected List<MagicCard> getMilledCards() {
|
||||||
for (final MagicCard card : topN) {
|
return player.getLibrary().getCardsFromTop(amount);
|
||||||
milledCards.add(card);
|
|
||||||
game.doAction(new ShiftCardAction(
|
|
||||||
card,
|
|
||||||
MagicLocationType.OwnersLibrary,
|
|
||||||
MagicLocationType.Graveyard
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import magic.model.MagicLocationType;
|
||||||
import magic.model.MagicPlayer;
|
import magic.model.MagicPlayer;
|
||||||
import magic.model.MagicType;
|
import magic.model.MagicType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action that removes cards from players library and moves them to that player's graveyard,
|
* 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).
|
* 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());
|
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 all = player.getLibrary().getCardsFromTop(Integer.MAX_VALUE);
|
||||||
|
final MagicCardList milledCards = new MagicCardList();
|
||||||
int seenTargets = 0;
|
int seenTargets = 0;
|
||||||
for (final MagicCard card : all) {
|
for (final MagicCard card : all) {
|
||||||
milledCards.add(card);
|
milledCards.add(card);
|
||||||
game.doAction(new ShiftCardAction(
|
|
||||||
card,
|
|
||||||
MagicLocationType.OwnersLibrary,
|
|
||||||
MagicLocationType.Graveyard
|
|
||||||
));
|
|
||||||
if (card.hasType(cardType)) {
|
if (card.hasType(cardType)) {
|
||||||
seenTargets++;
|
seenTargets++;
|
||||||
}
|
}
|
||||||
|
@ -51,5 +50,6 @@ public class MillLibraryUntilAction extends AbstractMillAction {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return milledCards;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue