Refactor PutCards to address issue #9643 (#9644)

This commit is contained in:
Alex W. Jackson 2022-10-14 01:07:14 -04:00 committed by GitHub
parent 332db3aecb
commit 5e891f50c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 69 additions and 48 deletions

View file

@ -1,5 +1,12 @@
package mage.constants;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author awjackson
@ -46,4 +53,55 @@ public enum PutCards {
String message = owner ? messageOwner : messageYour;
return withOrder ? message + order : message;
}
public boolean moveCard(Player player, Card card, Ability source, Game game, String description) {
switch (this) {
case TOP_OR_BOTTOM:
if (player.chooseUse(Outcome.Neutral,
"Put the " + description + " on the top or bottom of its owner's library?",
null, "Top", "Bottom", source, game
)) {
return player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, true);
} else {
return player.putCardsOnBottomOfLibrary(new CardsImpl(card), game, source, true);
}
case TOP_ANY:
return player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, true);
case BOTTOM_ANY:
return player.putCardsOnBottomOfLibrary(new CardsImpl(card), game, source, true);
case BOTTOM_RANDOM:
return player.putCardsOnBottomOfLibrary(new CardsImpl(card), game, source, false);
case BATTLEFIELD_TAPPED:
return player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
case BATTLEFIELD:
case EXILED:
case HAND:
case GRAVEYARD:
return player.moveCards(card, this.zone, source, game);
default:
throw new UnsupportedOperationException("Missing case for " + this.name() + "in PutCards.moveCard");
}
}
public boolean moveCards(Player player, Cards cards, Ability source, Game game) {
switch (this) {
case TOP_OR_BOTTOM:
throw new UnsupportedOperationException("PutCards.TOP_OR_BOTTOM does not support moving multiple cards");
case TOP_ANY:
return player.putCardsOnTopOfLibrary(cards, game, source, true);
case BOTTOM_ANY:
return player.putCardsOnBottomOfLibrary(cards, game, source, true);
case BOTTOM_RANDOM:
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
case BATTLEFIELD_TAPPED:
return player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
case BATTLEFIELD:
case EXILED:
case HAND:
case GRAVEYARD:
return player.moveCards(cards, this.zone, source, game);
default:
throw new UnsupportedOperationException("Missing case for " + this.name() + "in PutCards.moveCards");
}
}
}