foul-magics/Mage/src/main/java/mage/abilities/effects/common/PutTopCardOfLibraryIntoGraveControllerEffect.java
Evan Kranzler 785be83484
Refactoring cards that mill (WIP, do not merge) (#6713)
* added mill method

* updated mill effects to use new method

* refactored individual cards

* small updated to Grindstone and Sphinx's Tutelage

* another updated to Grindstone

* fixed a test

* fixed Countermand null check

* more refactoring

* updated dredge ability to use mill
2020-06-24 07:50:00 -04:00

46 lines
1.3 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
/**
* @author LevelX2
*/
public class PutTopCardOfLibraryIntoGraveControllerEffect extends OneShotEffect {
private final int numberCards;
public PutTopCardOfLibraryIntoGraveControllerEffect(int numberCards) {
super(Outcome.Discard);
this.numberCards = numberCards;
this.staticText = setText();
}
public PutTopCardOfLibraryIntoGraveControllerEffect(final PutTopCardOfLibraryIntoGraveControllerEffect effect) {
super(effect);
this.numberCards = effect.numberCards;
}
@Override
public PutTopCardOfLibraryIntoGraveControllerEffect copy() {
return new PutTopCardOfLibraryIntoGraveControllerEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
return !controller.millCards(numberCards, source, game).isEmpty();
}
return false;
}
private String setText() {
return "mill " + (numberCards == 1 ? "a card" : CardUtil.numberToText(numberCards) + " cards");
}
}