Search in sources :

Example 1 with ChooseFriendsAndFoes

use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.

the class KhorvathsFuryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    choice.chooseFriendOrFoe(controller, source, game);
    Map<UUID, Integer> cardsToDraw = new HashMap<>();
    for (Player player : choice.getFriends()) {
        if (player != null) {
            int cardsInHand = player.getHand().size();
            player.discard(cardsInHand, false, false, source, game);
            if (cardsInHand > 0) {
                cardsToDraw.put(player.getId(), cardsInHand);
            }
        }
    }
    for (Player player : choice.getFriends()) {
        if (player != null) {
            player.drawCards(cardsToDraw.get(player.getId()) + 1, source, game);
        }
    }
    for (Player player : choice.getFoes()) {
        if (player != null) {
            player.damage(player.getHand().size(), source.getSourceId(), source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) UUID(java.util.UUID)

Example 2 with ChooseFriendsAndFoes

use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.

the class ZndrspltsJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    choice.chooseFriendOrFoe(controller, source, game);
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
        filter.add(new ControllerIdPredicate(player.getId()));
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        if (!player.choose(Outcome.Copy, target, source.getSourceId(), game)) {
            continue;
        }
        Effect effect = new CreateTokenCopyTargetEffect(player.getId());
        effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
        effect.apply(game, source);
    }
    for (Player player : choice.getFoes()) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
        filter.add(new ControllerIdPredicate(player.getId()));
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        if (!player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
            continue;
        }
        Effect effect = new ReturnToHandTargetEffect();
        effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
        effect.apply(game, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect)

Example 3 with ChooseFriendsAndFoes

use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.

the class PirsWhimEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    if (controller != null && !choice.chooseFriendOrFoe(controller, source, game)) {
        return false;
    }
    for (Player player : choice.getFriends()) {
        if (player != null) {
            TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_LAND);
            if (player.searchLibrary(target, source, game)) {
                player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
                player.shuffleLibrary(source, game);
            }
        }
    }
    for (Player player : choice.getFoes()) {
        if (player != null) {
            Effect effect = new SacrificeEffect(StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT, 1, "");
            effect.setTargetPointer(new FixedTarget(player.getId(), game));
            effect.apply(game, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) SacrificeEffect(mage.abilities.effects.common.SacrificeEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) SacrificeEffect(mage.abilities.effects.common.SacrificeEffect) Effect(mage.abilities.effects.Effect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl)

Example 4 with ChooseFriendsAndFoes

use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.

the class RegnasSanctionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    if (!choice.chooseFriendOrFoe(controller, source, game)) {
        return false;
    }
    FilterPermanent filterToTap = new FilterCreaturePermanent();
    for (Player player : choice.getFoes()) {
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (game.getBattlefield().contains(filter, source, game, 1) && player.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
            filterToTap.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
        }
    }
    choice.getFriends().stream().map(MageItem::getId).map(ControllerIdPredicate::new).map(Predicates::not).forEach(filterToTap::add);
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
        if (choice.getFriends().stream().map(MageItem::getId).anyMatch(permanent::isControlledBy)) {
            permanent.addCounters(CounterType.P1P1.createInstance(), source, game);
        }
    }
    return new TapAllEffect(filterToTap).apply(game, source);
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) TapAllEffect(mage.abilities.effects.common.TapAllEffect) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent)

Example 5 with ChooseFriendsAndFoes

use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.

the class VirtussManeuverEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    if (controller != null && !choice.chooseFriendOrFoe(controller, source, game)) {
        return false;
    }
    Map<UUID, Card> getBackMap = new HashMap<>();
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        FilterCard filter = new FilterCreatureCard("creature card in your graveyard");
        filter.add(new OwnerIdPredicate(player.getId()));
        TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
        getBackMap.put(player.getId(), null);
        if (player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
            getBackMap.put(player.getId(), game.getCard(target.getFirstTarget()));
        }
    }
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        Card card = getBackMap.getOrDefault(player.getId(), null);
        if (card == null) {
            continue;
        }
        player.moveCards(card, Zone.HAND, source, game);
    }
    List<UUID> perms = new ArrayList<>();
    for (Player player : choice.getFoes()) {
        if (player == null) {
            continue;
        }
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, StaticFilters.FILTER_CONTROLLED_A_CREATURE, true);
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        perms.addAll(target.getTargets());
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) UUID(java.util.UUID)

Aggregations

ChooseFriendsAndFoes (mage.choices.ChooseFriendsAndFoes)5 Player (mage.players.Player)5 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)2 Permanent (mage.game.permanent.Permanent)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 ArrayList (java.util.ArrayList)1 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)1 ReturnToHandTargetEffect (mage.abilities.effects.common.ReturnToHandTargetEffect)1 SacrificeEffect (mage.abilities.effects.common.SacrificeEffect)1 TapAllEffect (mage.abilities.effects.common.TapAllEffect)1 Card (mage.cards.Card)1 CardsImpl (mage.cards.CardsImpl)1 FilterCard (mage.filter.FilterCard)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1