Search in sources :

Example 1 with TwoChoiceVote

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

the class SplitDecisionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
    if (spell == null) {
        return false;
    }
    // Outcome.Benefit - AI will use counter all the time (Denial choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Denial (counter " + spell.getIdName() + ")", "Duplication (copy " + spell.getIdName() + ")", Outcome.Benefit);
    vote.doVotes(source, game);
    int denialCount = vote.getVoteCount(true);
    int duplicationCount = vote.getVoteCount(false);
    if (denialCount > duplicationCount) {
        return game.getStack().counter(spell.getId(), source, game);
    } else {
        return new CopyTargetSpellEffect().apply(game, source);
    }
}
Also used : CopyTargetSpellEffect(mage.abilities.effects.common.CopyTargetSpellEffect) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) TwoChoiceVote(mage.choices.TwoChoiceVote)

Example 2 with TwoChoiceVote

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

the class CoercivePortalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Outcome.Detriment - AI will draw a card all the time (Homage choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Carnage (sacrifice and destroy)", "Homage (draw a card)", Outcome.Detriment);
    vote.doVotes(source, game);
    int carnageCount = vote.getVoteCount(true);
    int homageCount = vote.getVoteCount(false);
    if (carnageCount > homageCount) {
        // carnage
        Permanent permanent = source.getSourcePermanentIfItStillExists(game);
        if (permanent != null && permanent.isControlledBy(source.getControllerId())) {
            permanent.sacrifice(source, game);
        }
        new DestroyAllEffect(StaticFilters.FILTER_PERMANENT_NON_LAND).apply(game, source);
    } else {
        // homage or tied
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            player.drawCards(1, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TwoChoiceVote(mage.choices.TwoChoiceVote) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 3 with TwoChoiceVote

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

the class ExpropriateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    // Outcome.Detriment - AI will gain control all the time (Money choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Time (extra turn)", "Money (gain control)", Outcome.Detriment);
    vote.doVotes(source, game);
    // extra turn
    int timeCount = vote.getVoteCount(true);
    for (int i = 0; i < timeCount; i++) {
        game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
    }
    // gain control
    if (vote.getVoteCount(false) < 1) {
        return true;
    }
    List<Permanent> toSteal = new ArrayList<>();
    for (UUID playerId : vote.getVotedFor(false)) {
        int moneyCount = vote.getVotes(playerId).stream().mapToInt(x -> x ? 0 : 1).sum();
        FilterPermanent filter = new FilterPermanent();
        filter.add(new ControllerIdPredicate(playerId));
        moneyCount = Math.min(game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game), moneyCount);
        if (moneyCount == 0) {
            continue;
        }
        TargetPermanent target = new TargetPermanent(moneyCount, filter);
        target.setNotTarget(true);
        player.choose(Outcome.GainControl, target, source.getSourceId(), game);
        target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(toSteal::add);
    }
    game.addEffect(new GainControlTargetEffect(Duration.Custom, true, source.getControllerId()).setTargetPointer(new FixedTargets(toSteal, game)), source);
    return true;
}
Also used : GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) ArrayList(java.util.ArrayList) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) ExileSpellEffect(mage.abilities.effects.common.ExileSpellEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FixedTargets(mage.target.targetpointer.FixedTargets) TurnMod(mage.game.turn.TurnMod) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) TurnMod(mage.game.turn.TurnMod) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 4 with TwoChoiceVote

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

the class SelvalasStampedeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    // Outcome.Detriment - AI will use library will the time (Free choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Wild (from library to battlefield)", "Free (from hand to battlefield)", Outcome.Detriment);
    vote.doVotes(source, game);
    int wildCount = vote.getVoteCount(true);
    int freeCount = vote.getVoteCount(false);
    // Reveal cards from the top of your library until you reveal a creature card for each wild vote.
    // Put those creature cards onto the battlefield, then shuffle the rest into your library.
    Cards toReveal = new CardsImpl();
    Cards creatureCards = new CardsImpl();
    for (Card card : player.getLibrary().getCards(game)) {
        if (creatureCards.size() >= wildCount) {
            break;
        }
        if (card.isCreature(game)) {
            creatureCards.add(card);
        }
        toReveal.add(card);
    }
    if (toReveal.size() > 0) {
        player.revealCards(source, toReveal, game);
    }
    if (creatureCards.size() > 0) {
        player.moveCards(creatureCards, Zone.BATTLEFIELD, source, game);
    }
    player.shuffleLibrary(source, game);
    // You may put a permanent card from your hand onto the battlefield for each free vote
    if (freeCount > 0) {
        TargetCardInHand target = new TargetCardInHand(0, freeCount, StaticFilters.FILTER_CARD_PERMANENT);
        player.choose(Outcome.PutCreatureInPlay, player.getHand(), target, game);
        creatureCards.clear();
        creatureCards.addAll(target.getTargets());
        player.moveCards(creatureCards, Zone.BATTLEFIELD, source, game);
    }
    return wildCount + freeCount > 0;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) TwoChoiceVote(mage.choices.TwoChoiceVote)

Example 5 with TwoChoiceVote

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

the class TyrantsChoiceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    TwoChoiceVote vote = new TwoChoiceVote("Death (sacrifice a creature)", "Torture (lose 4 life)", Outcome.Benefit);
    vote.doVotes(source, game, (voteHandler, aiPlayer, aiDecidingPlayer, aiSource, aiGame) -> {
        // ai hint
        if (aiSource.isControlledBy(aiDecidingPlayer.getId())) {
            // best for controller - lose life
            return Boolean.FALSE;
        } else {
            // best for opponent - sacrifice
            return Boolean.TRUE;
        }
    });
    int deathCount = vote.getVoteCount(true);
    int tortureCount = vote.getVoteCount(false);
    if (deathCount > tortureCount) {
        return new SacrificeOpponentsEffect(StaticFilters.FILTER_CONTROLLED_CREATURE_SHORT_TEXT).apply(game, source);
    } else {
        return new LoseLifeOpponentsEffect(4).apply(game, source);
    }
}
Also used : SacrificeOpponentsEffect(mage.abilities.effects.common.SacrificeOpponentsEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) LoseLifeOpponentsEffect(mage.abilities.effects.common.LoseLifeOpponentsEffect)

Aggregations

TwoChoiceVote (mage.choices.TwoChoiceVote)12 Player (mage.players.Player)8 Permanent (mage.game.permanent.Permanent)5 Objects (java.util.Objects)2 UUID (java.util.UUID)2 Ability (mage.abilities.Ability)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 DestroyAllEffect (mage.abilities.effects.common.DestroyAllEffect)2 SacrificeOpponentsEffect (mage.abilities.effects.common.SacrificeOpponentsEffect)2 DiscardEachPlayerEffect (mage.abilities.effects.common.discard.DiscardEachPlayerEffect)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 CardType (mage.constants.CardType)2 Outcome (mage.constants.Outcome)2 FilterPermanent (mage.filter.FilterPermanent)2 Game (mage.game.Game)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 MageInt (mage.MageInt)1