mage/Mage.Sets/src/mage/cards/p/PleaForPower.java
Evan Kranzler 1cbbcddcc6
Improving implementation of cards which use voting (WIP) (#7566)
* created interface for handling voting

* created class for two choice votes, refactored a card to use it

* refactored all cards which use two choice votes

* updated VoteHandler to an abstract class to encapsulate more of its functions

* refactored cards which vote for more than two things

* [CNS] Implemented Brago's Representative

* [CN2] Implemented Ballot Broker

* [CN2] Implemented Illusion of Choice

* [CNS] Implemented Grudge Keeper

* added vote outcomes

* updated implementation of Illusion of Choice to work correctly in multiples

* added test for voting

* updated implementation of extra votes

* simplified vote message handling

* Improved names, additional comments

* Votes: fixed not working getMostVoted

* Votes: added final vote results to game logs;

* Votes: added additional info for the vote choices;

* Votes: added vote step info in choose dialogs, added AI support example for Tyrant's Choice;

Co-authored-by: Oleg Agafonov <jaydi85@gmail.com>
2021-03-20 18:32:54 +04:00

76 lines
2.5 KiB
Java

package mage.cards.p;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.turn.AddExtraTurnControllerEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.choices.TwoChoiceVote;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
* @author emerald000, TheElk801
*/
public final class PleaForPower extends CardImpl {
public PleaForPower(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{3}{U}");
// Will of the council - Starting with you, each player votes for time or knowledge. If time gets more votes, take an extra turn after this one. If knowledge gets more votes or the vote is tied, draw three cards.
this.getSpellAbility().addEffect(new PleaForPowerEffect());
}
private PleaForPower(final PleaForPower card) {
super(card);
}
@Override
public PleaForPower copy() {
return new PleaForPower(this);
}
}
class PleaForPowerEffect extends OneShotEffect {
PleaForPowerEffect() {
super(Outcome.Benefit);
this.staticText = "<i>Will of the council</i> &mdash; Starting with you, " +
"each player votes for time or knowledge. If time gets more votes, take an extra turn after this one. " +
"If knowledge gets more votes or the vote is tied, draw three cards";
}
private PleaForPowerEffect(final PleaForPowerEffect effect) {
super(effect);
}
@Override
public PleaForPowerEffect copy() {
return new PleaForPowerEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// Outcome.Detriment - AI will draw cards all the time (Knowledge choice)
// TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
TwoChoiceVote vote = new TwoChoiceVote("Time (extra turn)", "Knowledge (draw 3 cards)", Outcome.Detriment);
vote.doVotes(source, game);
int timeCount = vote.getVoteCount(true);
int knowledgeCount = vote.getVoteCount(false);
if (timeCount > knowledgeCount) {
return new AddExtraTurnControllerEffect().apply(game, source);
} else {
return controller.drawCards(3, source, game) > 0;
}
}
}