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);
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations