Search in sources :

Example 6 with Controllable

use of mage.game.Controllable in project mage by magefree.

the class MartyrsCryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    Map<UUID, Integer> playerMap = permanents.stream().filter(Objects::nonNull).map(Controllable::getControllerId).collect(Collectors.toMap(Function.identity(), uuid -> 1, Integer::sum));
    controller.moveCards(new CardsImpl(permanents), Zone.EXILED, source, game);
    for (Map.Entry<UUID, Integer> entry : playerMap.entrySet()) {
        Player player = game.getPlayer(entry.getKey());
        if (player == null) {
            continue;
        }
        player.drawCards(entry.getValue(), source, game);
    }
    return true;
}
Also used : Zone(mage.constants.Zone) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) FilterPermanent(mage.filter.FilterPermanent) Controllable(mage.game.Controllable) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) Map(java.util.Map) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ObjectColor(mage.ObjectColor) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Objects(java.util.Objects) UUID(java.util.UUID) Map(java.util.Map) CardsImpl(mage.cards.CardsImpl)

Aggregations

UUID (java.util.UUID)6 Controllable (mage.game.Controllable)6 Ability (mage.abilities.Ability)5 OneShotEffect (mage.abilities.effects.OneShotEffect)5 CardImpl (mage.cards.CardImpl)5 CardSetInfo (mage.cards.CardSetInfo)5 CardType (mage.constants.CardType)5 Outcome (mage.constants.Outcome)5 Game (mage.game.Game)5 Player (mage.players.Player)5 Map (java.util.Map)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 CardsImpl (mage.cards.CardsImpl)4 Zone (mage.constants.Zone)4 Function (java.util.function.Function)3 StaticFilters (mage.filter.StaticFilters)3 List (java.util.List)2 Cards (mage.cards.Cards)2 Permanent (mage.game.permanent.Permanent)2