mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
* Plow Under - Fixed that the card owner could not define the order the card go to the library.
This commit is contained in:
parent
97412e3e9e
commit
1c2233b1f8
2 changed files with 59 additions and 8 deletions
|
@ -27,6 +27,9 @@
|
||||||
*/
|
*/
|
||||||
package mage.abilities.effects.common;
|
package mage.abilities.effects.common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
@ -38,6 +41,8 @@ import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.cards.Cards;
|
||||||
|
import mage.cards.CardsImpl;
|
||||||
import mage.target.Target;
|
import mage.target.Target;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
|
@ -71,27 +76,61 @@ public class PutOnLibraryTargetEffect extends OneShotEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
boolean result = false;
|
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
|
List<Card> cards = new ArrayList<>();
|
||||||
|
List<Permanent> permanents = new ArrayList<>();
|
||||||
for (UUID targetId : targetPointer.getTargets(game, source)) {
|
for (UUID targetId : targetPointer.getTargets(game, source)) {
|
||||||
switch (game.getState().getZone(targetId)) {
|
switch (game.getState().getZone(targetId)) {
|
||||||
case BATTLEFIELD:
|
case BATTLEFIELD:
|
||||||
Permanent permanent = game.getPermanent(targetId);
|
Permanent permanent = game.getPermanent(targetId);
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
result |= controller.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, Zone.BATTLEFIELD, onTop, true);
|
permanents.add(permanent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GRAVEYARD:
|
case GRAVEYARD:
|
||||||
Card card = game.getCard(targetId);
|
Card card = game.getCard(targetId);
|
||||||
if (card != null && game.getState().getZone(targetId).equals(Zone.GRAVEYARD)) {
|
if (card != null && game.getState().getZone(targetId).equals(Zone.GRAVEYARD)) {
|
||||||
result |= controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.GRAVEYARD, onTop, true);
|
cards.add(card);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Plow Under
|
||||||
|
// 10/4/2004 The owner decides the order the two lands are stacked there.
|
||||||
|
while (!cards.isEmpty()) {
|
||||||
|
Card card = cards.iterator().next();
|
||||||
|
if (card != null) {
|
||||||
|
Player owner = game.getPlayer(card.getOwnerId());
|
||||||
|
Cards cardsPlayer = new CardsImpl();
|
||||||
|
for (Iterator<Card> iterator = cards.iterator(); iterator.hasNext();) {
|
||||||
|
Card next = iterator.next();
|
||||||
|
if (next.getOwnerId().equals(owner.getId())) {
|
||||||
|
cardsPlayer.add(next);
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!permanents.isEmpty()) {
|
||||||
|
Permanent permanent = permanents.iterator().next();
|
||||||
|
if (permanent != null) {
|
||||||
|
Player owner = game.getPlayer(permanent.getOwnerId());
|
||||||
|
Cards cardsPlayer = new CardsImpl();
|
||||||
|
for (Iterator<Permanent> iterator = permanents.iterator(); iterator.hasNext();) {
|
||||||
|
Permanent next = iterator.next();
|
||||||
|
if (next.getOwnerId().equals(owner.getId())) {
|
||||||
|
cardsPlayer.add(next);
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return result;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -854,14 +854,26 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
if (chosenCard != null) {
|
if (chosenCard != null) {
|
||||||
cards.remove(chosenCard);
|
cards.remove(chosenCard);
|
||||||
Zone fromZone = game.getState().getZone(chosenCard.getId());
|
Zone fromZone = game.getState().getZone(chosenCard.getId());
|
||||||
this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, true, false);
|
if (fromZone.equals(Zone.BATTLEFIELD)) {
|
||||||
|
Permanent permanent = game.getPermanent(chosenCard.getId());
|
||||||
|
this.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, fromZone, true, false);
|
||||||
|
} else {
|
||||||
|
this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
target.clearChosen();
|
target.clearChosen();
|
||||||
}
|
}
|
||||||
if (cards.size() == 1) {
|
if (cards.size() == 1) {
|
||||||
Card chosenCard = cards.get(cards.iterator().next(), game);
|
// Card chosenCard = cards.get(cards.iterator().next(), game);
|
||||||
Zone fromZone = game.getState().getZone(chosenCard.getId());
|
UUID cardId = cards.iterator().next();
|
||||||
this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, true, false);
|
Zone fromZone = game.getState().getZone(cardId);
|
||||||
|
if (fromZone.equals(Zone.BATTLEFIELD)) {
|
||||||
|
Permanent permanent = game.getPermanent(cardId);
|
||||||
|
this.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, fromZone, true, false);
|
||||||
|
} else {
|
||||||
|
Card chosenCard = cards.get(cardId, game);
|
||||||
|
this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue