package mw.server.card.colorless;
import java.util.ArrayList;
import mw.mtgforge.Command;
import mw.server.ChoiceCommand;
import mw.server.GameManager;
import mw.server.MWPlayer;
import mw.server.list.CardList;
import mw.server.model.Ability;
import mw.server.model.Ability_Tap;
import mw.server.model.Card;
import mw.server.model.Spell;
import mw.server.model.SpellAbility;
import mw.server.model.spell.Permanent;
@SuppressWarnings("serial")
public class SpinerockKnoll {
public static Card getCard(final Card card, final GameManager game) {
final SpellAbility removeAbility = new Ability(card, "0") {
public void resolve() {
if (getTargetCard() != null) {
/**
* Remove the card
*/
int pid = card.getControllerID();
game.removeCardFromLibrary(pid, getTargetCard());
card.attachCard(getTargetCard());
/**
* Put top 3 on bottom
*/
game.putCardFromTopOnBottom(pid);
game.putCardFromTopOnBottom(pid);
game.putCardFromTopOnBottom(pid);
}
}
};
/**
* Forms the list of 4 top cards where from one card can be chosen to discard.
*/
final ChoiceCommand runtime = new ChoiceCommand() {
public void execute() {
int aid = card.getControllerID();
CardList library = game.getPlayerById(aid).getLibrary().getCardList();
CardList fourCards = new CardList();
for (int i = 0; i < library.size(); i++) {
if (i < 4) {
fourCards.add(library.get(i));
} else {
break;
}
}
if (fourCards.size() == 0) {
return;
}
setInputChoice(fourCards);
}
/**
* Default UID.
*/
private static final long serialVersionUID = 1L;
};
final Command comesIntoPlay = new Command() {
public void execute() {
card.tap();
removeAbility.setChoiceCommand(runtime);
removeAbility.setNeedsToChooseCard(true);
game.getStack().add(removeAbility);
}
/**
* Default UID.
*/
private static final long serialVersionUID = 1L;
};
card.setEntersTheBattlefieldCommand(comesIntoPlay);
final SpellAbility playTheRemovedCardAbility = new Ability_Tap(card, "R") {
@Override
public void resolve() {
Card removedCard = removeAbility.getTargetCard();
if (removedCard != null) {
ArrayList<SpellAbility> spells = removedCard.getSpellAbilities();
for (int i = 0; i < spells.size(); i++) {
SpellAbility sa = spells.get(i);
if ((sa instanceof Permanent) || (sa instanceof Spell)) {
spells.get(i).setManaToPlay("0");
}
}
game.addLocalEffect(removedCard);
/**
* Don't forget to remove card not to give the possibility to play it once again
*/
card.getAttachedCards().remove(removedCard);
removeAbility.setTargetCard(null);
}
}
@Override
public boolean canPlay() {
Card c = removeAbility.getTargetCard();
if (c == null) {
return false;
}
if (!super.canPlay()) {
return false;
}
MWPlayer player = game.getPlayerById(card.getControllerID());
if (c.isLand()) { // can't play land if player already played it
if (player.canPlayLands()) {
return false;
}
}
return player.getGameStatistics().getLifeLostThisTurn() > 6;
}
};
playTheRemovedCardAbility.setDescription("Hideaway");
playTheRemovedCardAbility.setStackDescription("[Hideaway] " + card + ": play the removed card without paying its mana cost if an opponent was dealt 7 or more damage this turn.");
card.addSpellAbility(playTheRemovedCardAbility);
final SpellAbility cantPlayHideaway = new Ability(card, "0") {
@Override
public void resolve() {
}
@Override
public boolean canPlay() {
return !playTheRemovedCardAbility.canPlay();
}
};
cantPlayHideaway.setInvisible(true);
cantPlayHideaway.setDescription("Hideaway - can't play.");
card.addSpellAbility(cantPlayHideaway);
return card;
}
}
|