simplified and consolidated effects which check cards put into graveyards from the battlefield

This commit is contained in:
Evan Kranzler 2021-02-25 10:45:26 -05:00
parent c01e1cd133
commit 35be23537f
15 changed files with 311 additions and 594 deletions

View file

@ -1,53 +1,89 @@
package mage.abilities.effects.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public class ReturnToHandFromGraveyardAllEffect extends OneShotEffect {
private final FilterCard filter;
private final TargetController targetController;
public ReturnToHandFromGraveyardAllEffect(FilterCard filter) {
super(Outcome.ReturnToHand);
this.filter = filter;
staticText = "Each player returns all " + filter.getMessage() + " from their graveyard to their hand";
this(filter, TargetController.EACH_PLAYER);
}
public ReturnToHandFromGraveyardAllEffect(final ReturnToHandFromGraveyardAllEffect effect) {
public ReturnToHandFromGraveyardAllEffect(FilterCard filter, TargetController targetController) {
super(Outcome.ReturnToHand);
this.filter = filter;
this.targetController = targetController;
}
private ReturnToHandFromGraveyardAllEffect(final ReturnToHandFromGraveyardAllEffect effect) {
super(effect);
this.filter = effect.filter;
this.targetController = effect.targetController;
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.moveCards(player.getGraveyard()
.getCards(filter, source.getSourceId(), player.getId(), game),
Zone.HAND, source, game);
}
}
return true;
if (controller == null) {
return false;
}
return false;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
switch (targetController) {
case ANY:
case EACH_PLAYER:
break;
case OPPONENT:
if (!controller.hasOpponent(playerId, game)) {
continue;
}
case YOU:
if (!controller.getId().equals(playerId)) {
continue;
}
}
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
player.moveCards(player.getGraveyard().getCards(
filter, source.getSourceId(), player.getId(), game
), Zone.HAND, source, game);
}
return true;
}
@Override
public ReturnToHandFromGraveyardAllEffect copy() {
return new ReturnToHandFromGraveyardAllEffect(this);
}
@Override
public String getText(Mode mode) {
if(staticText!=null&&!staticText.isEmpty()){
return staticText;
}
String rule="";
switch (targetController){
case EACH_PLAYER:
rule+="each player";break;
case OPPONENT:rule+="opponent";break;
case YOU:
}
}
}