Search in sources :

Example 1 with UntapAllLandsControllerEffect

use of mage.abilities.effects.common.UntapAllLandsControllerEffect in project mage by magefree.

the class FieryGambitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        int flipsWon = 0;
        boolean controllerStopped = false;
        while (controller.flipCoin(source, game, true)) {
            ++flipsWon;
            if (!controller.chooseUse(outcome, "You won " + flipsWon + (flipsWon == 1 ? " flip." : " flips.") + " Flip another coin?", source, game)) {
                controllerStopped = true;
                break;
            }
            // AI workaround to stop flips on good result
            if (controller.isComputer() && flipsWon >= 3) {
                controllerStopped = true;
                break;
            }
        }
        if (controllerStopped) {
            Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
            if (creature != null) {
                creature.damage(3, source.getSourceId(), source, game, false, true);
            }
            if (flipsWon > 1) {
                new DamagePlayersEffect(6, TargetController.OPPONENT).apply(game, source);
            }
            if (flipsWon > 2) {
                controller.drawCards(9, source, game);
                new UntapAllLandsControllerEffect().apply(game, source);
            }
        } else {
            game.informPlayers(sourceObject.getIdName() + " had no effect");
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) UntapAllLandsControllerEffect(mage.abilities.effects.common.UntapAllLandsControllerEffect) MageObject(mage.MageObject) DamagePlayersEffect(mage.abilities.effects.common.DamagePlayersEffect)

Aggregations

MageObject (mage.MageObject)1 DamagePlayersEffect (mage.abilities.effects.common.DamagePlayersEffect)1 UntapAllLandsControllerEffect (mage.abilities.effects.common.UntapAllLandsControllerEffect)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)1