Started to rework player.moveCard methods to handle multiple cards.

This commit is contained in:
LevelX2 2015-05-22 15:15:39 +02:00
parent e68bd0e876
commit 467a11b4cd
48 changed files with 241 additions and 359 deletions

View file

@ -86,7 +86,7 @@ public class EnterBattlefieldPayCostOrPutGraveyardEffect extends ReplacementEffe
if (replace) {
Card card = game.getCard(event.getTargetId());
if (card != null) {
player.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, game.getState().getZone(event.getTargetId()));
player.moveCards(card, game.getState().getZone(event.getTargetId()), Zone.GRAVEYARD, source, game);
}
return true;
}

View file

@ -38,11 +38,9 @@ import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetCard;
import mage.util.CardUtil;
/**
@ -156,7 +154,7 @@ public class LookLibraryControllerEffect extends OneShotEffect {
}
/**
* Put the rest of the cards back to library
* Put the rest of the cards back to defined zone
*
* @param source
* @param player
@ -166,27 +164,14 @@ public class LookLibraryControllerEffect extends OneShotEffect {
protected void putCardsBack(Ability source, Player player, Cards cards, Game game) {
switch(targetZoneLookedCards) {
case LIBRARY:
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard(this.getPutBackText()));
while (player.isInGame() && cards.size() > 1) {
player.choose(Outcome.Neutral, cards, target, game);
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
player.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.LIBRARY, putOnTop, false);
}
target.clearChosen();
}
if (cards.size() == 1) {
Card card = cards.get(cards.iterator().next(), game);
player.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.LIBRARY, putOnTop, false);
if (putOnTop) {
player.putCardsOnTopOfLibrary(cards, game, source, true);
} else {
player.putCardsOnBottomOfLibrary(cards, game, source, true);
}
break;
case GRAVEYARD:
for (Card card : cards.getCards(game)) {
player.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, Zone.LIBRARY);
card.moveToZone(Zone.GRAVEYARD, source.getSourceId(), game, true);
}
player.moveCards(cards, Zone.LIBRARY, Zone.GRAVEYARD, source, game);
break;
default:
// not supported yet
@ -205,16 +190,6 @@ public class LookLibraryControllerEffect extends OneShotEffect {
}
}
protected String getPutBackText() {
StringBuilder sb = new StringBuilder("card to put ");
if (putOnTop) {
sb.append("on your library (last chosen will be on top)");
} else {
sb.append("on bottom of your library (last chosen will be mostbottom)");
}
return sb.toString();
}
@Override
public String getText(Mode mode) {
return setText(mode, "");

View file

@ -33,6 +33,7 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.Cards;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
@ -70,14 +71,7 @@ public class PutTopCardOfLibraryIntoGraveTargetEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
int cardsCount = Math.min(numberCards.calculate(game, source, this), player.getLibrary().size());
for (int i = 0; i < cardsCount; i++) {
Card card = player.getLibrary().removeFromTop(game);
if (card != null) {
player.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, Zone.LIBRARY);
}
}
return true;
return player.moveCards(player.getLibrary().getTopCards(game, numberCards.calculate(game, source, this)), Zone.LIBRARY, Zone.GRAVEYARD, source, game);
}
return false;
}

View file

@ -84,36 +84,37 @@ public class ReturnFromExileEffect extends OneShotEffect {
ExileZone exile = game.getExile().getExileZone(exileId);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && exile != null) {
exile = exile.copy();
for (UUID cardId : exile) {
Card card = game.getCard(cardId);
Player owner = game.getPlayer(card.getOwnerId());
if (owner != null) {
switch (zone) {
case BATTLEFIELD:
card.moveToZone(zone, source.getSourceId(), game, tapped);
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " moves " + card.getName() + " to " + zone.toString().toLowerCase());
}
break;
case HAND:
controller.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.EXILED);
break;
case GRAVEYARD:
controller.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, Zone.EXILED);
break;
case LIBRARY:
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.EXILED, true, true);
break;
default:
card.moveToZone(zone, source.getSourceId(), game, tapped);
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " moves " + card.getName() + " to " + zone.toString().toLowerCase());
}
if (zone == Zone.GRAVEYARD) {
controller.moveCards(exile, zone, Zone.EXILED, source, game);
} else {
exile = exile.copy();
for (UUID cardId : exile) {
Card card = game.getCard(cardId);
Player owner = game.getPlayer(card.getOwnerId());
if (owner != null) {
switch (zone) {
case BATTLEFIELD:
card.moveToZone(zone, source.getSourceId(), game, tapped);
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " moves " + card.getName() + " to " + zone.toString().toLowerCase());
}
break;
case HAND:
controller.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.EXILED);
break;
case LIBRARY:
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.EXILED, true, true);
break;
default:
card.moveToZone(zone, source.getSourceId(), game, tapped);
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " moves " + card.getName() + " to " + zone.toString().toLowerCase());
}
}
}
}
game.getExile().getExileZone(exileId).clear();
}
game.getExile().getExileZone(exileId).clear();
return true;
}
return false;

View file

@ -150,7 +150,7 @@ class MadnessTriggeredAbility extends TriggeredAbilityImpl {
Player owner = game.getPlayer(card.getOwnerId());
if (owner != null) {
// if cast was not successfull, the card is moved to graveyard
owner.moveCardToGraveyardWithInfo(card, getSourceId(), game, Zone.EXILED);
owner.moveCards(card, Zone.EXILED, Zone.GRAVEYARD, this, game);
}
}
return false;

View file

@ -64,13 +64,21 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
public CardsImpl() { }
public CardsImpl(Card card) {
this.add(card.getId());
if (card != null) {
this.add(card.getId());
}
}
public CardsImpl(Collection<UUID> cardIds) {
if (cardIds != null) {
this.addAll(cardIds);
}
}
public CardsImpl(Zone zone) {
this.zone = zone;
}
public CardsImpl(Zone zone, Collection<Card> cards) {
this(zone);
for (Card card: cards) {

View file

@ -438,6 +438,20 @@ public interface Player extends MageItem, Copyable<Player> {
*/
UUID getCommanderId();
/**
* Moves cards from one zone to another
*
* @param cards
* @param fromZone
* @param toZone
* @param source
* @param game
* @return
*/
boolean moveCards(Cards cards, Zone fromZone, Zone toZone, Ability source, Game game);
boolean moveCards(List<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game);
boolean moveCards(Card card, Zone fromZone, Zone toZone, Ability source, Game game);
/**
* Uses card.moveToZone and posts a inform message about moving the card
* into the game log

View file

@ -2821,13 +2821,42 @@ public abstract class PlayerImpl implements Player, Serializable {
this.commanderId = commanderId;
}
;
@Override
public UUID getCommanderId() {
return this.commanderId;
}
@Override
public boolean moveCards(Cards cards, Zone fromZone, Zone toZone, Ability source, Game game) {
ArrayList<Card> cardList = new ArrayList<>();
cardList.addAll(cards.getCards(game));
return moveCards(cardList, fromZone, toZone, source, game);
}
@Override
public boolean moveCards(Card card, Zone fromZone, Zone toZone, Ability source, Game game) {
ArrayList<Card> cardList = new ArrayList<>();
if (card != null) {
cardList.add(card);
}
return moveCards(cardList, fromZone, toZone, source, game);
}
@Override
public boolean moveCards(List<Card> cards, Zone fromZone, Zone toZone, Ability source, Game game) {
switch(toZone) {
case GRAVEYARD:
return moveCardsToGraveyardWithInfo(cards, source, game, fromZone);
case HAND:
for(Card card: cards) {
moveCardToHandWithInfo(card, playerId, game, fromZone);
}
return true;
default:
throw new UnsupportedOperationException("to Zone not supported yet");
}
}
@Override
public boolean moveCardToHandWithInfo(Card card, UUID sourceId, Game game, Zone fromZone) {
return this.moveCardToHandWithInfo(card, sourceId, game, fromZone, true);