foul-magics/Mage/src/main/java/mage/abilities/effects/common/ExileAllEffect.java
Evan Kranzler 80e11b2052
(WIP) Replacing blocking/blocked by predicates (#8729)
* replaced blocking/blocked by predicates

* added test for knight of dusk (currently fails)

* added source parameter to filters and everything else that needs it

* some changes to various predicates

* test fix

* small changes to filter code

* merge fix

* fixed a test failure

* small change to Karn, Scion of Urza

* removed sourceId from filter methods and other similar places

* added new getobject method to fix some test failures

* a few more fixes

* fixed merge conflicts

* merge fix
2022-03-23 18:45:02 -04:00

66 lines
1.9 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
/**
* @author LevelX2
*/
public class ExileAllEffect extends OneShotEffect {
private final FilterPermanent filter;
private final boolean forSource;
public ExileAllEffect(FilterPermanent filter) {
this(filter, false);
}
public ExileAllEffect(FilterPermanent filter, boolean forSource) {
super(Outcome.Exile);
this.filter = filter;
this.forSource = forSource;
setText();
}
public ExileAllEffect(final ExileAllEffect effect) {
super(effect);
this.filter = effect.filter.copy();
this.forSource = effect.forSource;
}
@Override
public ExileAllEffect copy() {
return new ExileAllEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
game.getBattlefield().getActivePermanents(
filter, source.getControllerId(), source, game
).stream().forEach(cards::add);
if (forSource) {
return controller.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
}
return controller.moveCards(cards, Zone.EXILED, source, game);
}
private void setText() {
StringBuilder sb = new StringBuilder();
sb.append("exile all ").append(filter.getMessage());
staticText = sb.toString();
}
}