* Aetherspouts - Fixed that the order the cards go to top or bottom (if more than one) could not be selected.

This commit is contained in:
LevelX2 2014-10-10 23:50:26 +02:00
parent d35b168cd5
commit 1e225cdf78
5 changed files with 116 additions and 23 deletions

View file

@ -27,18 +27,26 @@
*/
package mage.sets.magic2015;
import java.util.ArrayList;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.common.FilterAttackingCreature;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import mage.players.Player;
import mage.players.PlayerList;
import mage.target.TargetCard;
/**
*
@ -92,30 +100,103 @@ class AEtherspoutsEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
boolean result = true;
game.getPlayerList();
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (Permanent permanent:game.getState().getBattlefield().getActivePermanents(new FilterAttackingCreature(), source.getControllerId(), source.getSourceId(), game)) {
Player owner = game.getPlayer(permanent.getOwnerId());
if (owner != null) {
owner.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, Zone.BATTLEFIELD,
owner.chooseUse(Outcome.ReturnToHand, "Put " + permanent.getLogName() + " to the top? (else it goes to bottom)", game), true);
} else {
result = false;
PlayerList playerList = game.getPlayerList();
playerList.setCurrent(game.getActivePlayerId());
Player player = game.getPlayer(game.getActivePlayerId());
do {
ArrayList<Permanent> permanentsToTop = new ArrayList<>();
ArrayList<Permanent> permanentsToBottom = new ArrayList<>();
for (Permanent permanent:game.getState().getBattlefield().getActivePermanents(new FilterAttackingCreature(), player.getId(), source.getSourceId(), game)) {
if (permanent.getOwnerId().equals(player.getId())) {
if (player.chooseUse(outcome, "Put " + permanent.getLogName() + " to the top? (else it goes to bottom)", game)) {
permanentsToTop.add(permanent);
game.informPlayers(permanent.getLogName() + " goes to the top of " + player.getName() + "'s library");
} else {
permanentsToBottom.add(permanent);
game.informPlayers(permanent.getLogName() + " goes to the bottom of " + player.getName() + "'s library");
}
}
}
}
return result;
// PlayerList playerList = game.getPlayerList();
// playerList.setCurrent(game.getActivePlayerId());
// Player player = game.getPlayer(game.getActivePlayerId());
// do {
// player = playerList.getNext(game);
// } while (!player.getId().equals(game.getActivePlayerId()));
// cards to top
Cards cards = new CardsImpl();
ArrayList<Permanent> toLibrary = new ArrayList<>();
for (Permanent permanent: permanentsToTop) {
if (permanent instanceof PermanentToken) {
toLibrary.add(permanent);
} else {
Card card = game.getCard(permanent.getId());
if (card != null) {
cards.add(card);
}
}
}
TargetCard target = new TargetCard(Zone.BATTLEFIELD, new FilterCard("order to put on the top of library (last choosen will be the top most)"));
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);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
toLibrary.add(permanent);
}
}
target.clearChosen();
}
if (cards.size() == 1) {
Card card = cards.get(cards.iterator().next(), game);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
toLibrary.add(permanent);
}
}
// move all permanents to lib at the same time
for(Permanent permanent: toLibrary) {
player.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, Zone.BATTLEFIELD, true, false);
}
// cards to bottom
cards.clear();
toLibrary.clear();
for (Permanent permanent: permanentsToBottom) {
if (permanent instanceof PermanentToken) {
toLibrary.add(permanent);
} else {
Card card = game.getCard(permanent.getId());
if (card != null) {
cards.add(card);
}
}
}
target = new TargetCard(Zone.BATTLEFIELD, new FilterCard("order to put on bottom of library (last choosen will be bottommost card)"));
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);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
toLibrary.add(permanent);
}
}
target.clearChosen();
}
if (cards.size() == 1) {
Card card = cards.get(cards.iterator().next(), game);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
toLibrary.add(permanent);
}
}
// move all permanents to lib at the same time
for(Permanent permanent: toLibrary) {
player.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, Zone.BATTLEFIELD, false, false);
}
player = playerList.getNext(game);
} while (!player.getId().equals(game.getActivePlayerId()));
return true;
}
return false;
}

View file

@ -332,7 +332,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
}
break;
case PICK:
case BATTLEFIELD: // for sacrificing permanents
case BATTLEFIELD: // for sacrificing permanents or putting to library
break;
default:
Card sourceCard = game.getCard(sourceId);

View file

@ -170,6 +170,7 @@ public interface Permanent extends Card, Controllable {
boolean canUseActivatedAbilities(Game game);
boolean removeFromCombat(Game game);
boolean removeFromCombat(Game game, boolean withInfo);
boolean isDeathtouched();
/**

View file

@ -1024,8 +1024,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean removeFromCombat(Game game) {
return removeFromCombat(game, true);
}
@Override
public boolean removeFromCombat(Game game, boolean withInfo) {
if (this.isAttacking() || this.blocking > 0) {
if (game.getCombat().removeFromCombat(objectId, game)) {
if (game.getCombat().removeFromCombat(objectId, game) && withInfo) {
game.informPlayers(new StringBuilder(this.getLogName()).append(" removed from combat").toString());
}
}

View file

@ -734,7 +734,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public boolean removeFromBattlefield(Permanent permanent, Game game) {
permanent.removeFromCombat(game);
permanent.removeFromCombat(game, false);
game.getBattlefield().removePermanent(permanent.getId());
if (permanent.getAttachedTo() != null) {
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
@ -742,6 +742,12 @@ public abstract class PlayerImpl implements Player, Serializable {
attachedTo.removeAttachment(permanent.getId(), game);
}
}
if (permanent.getPairedCard() != null) {
Permanent pairedCard = game.getPermanent(permanent.getPairedCard());
if (pairedCard != null) {
pairedCard.clearPairedCard();
}
}
return true;
}