Search in sources :

Example 6 with TurnMod

use of mage.game.turn.TurnMod 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 7 with TurnMod

use of mage.game.turn.TurnMod in project mage by magefree.

the class SageOfHoursEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        int countersRemoved = 0;
        for (Cost cost : source.getCosts()) {
            if (cost instanceof RemoveAllCountersSourceCost) {
                countersRemoved = ((RemoveAllCountersSourceCost) cost).getRemovedCounters();
            }
        }
        int turns = countersRemoved / 5;
        for (int i = 0; i < turns; i++) {
            game.getState().getTurnMods().add(new TurnMod(player.getId(), false));
        }
        game.informPlayers("Removed " + countersRemoved + " +1/+1 counters: " + player.getLogName() + " takes " + CardUtil.numberToText(turns, "an") + (turns > 1 ? " extra turns " : " extra turn ") + "after this one");
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) RemoveAllCountersSourceCost(mage.abilities.costs.common.RemoveAllCountersSourceCost) TurnMod(mage.game.turn.TurnMod) RemoveAllCountersSourceCost(mage.abilities.costs.common.RemoveAllCountersSourceCost) Cost(mage.abilities.costs.Cost)

Example 8 with TurnMod

use of mage.game.turn.TurnMod in project mage by magefree.

the class IllusionistsGambitRestrictionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> attackers = game.getCombat().getAttackers();
    for (UUID attackerId : attackers) {
        Permanent creature = game.getPermanent(attackerId);
        if (creature != null) {
            creature.removeFromCombat(game);
            creature.untap(game);
        }
    }
    if (!attackers.isEmpty()) {
        Phase phase = game.getTurn().getPhase();
        game.getState().getTurnMods().add(new TurnMod(game.getActivePlayerId(), TurnPhase.COMBAT, null, false));
        ContinuousEffect effect = new IllusionistsGambitRequirementEffect(attackers, phase);
        game.addEffect(effect, source);
        effect = new IllusionistsGambitRestrictionEffect(attackers, phase);
        game.addEffect(effect, source);
    }
    return true;
}
Also used : Phase(mage.game.turn.Phase) Permanent(mage.game.permanent.Permanent) TurnMod(mage.game.turn.TurnMod) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Example 9 with TurnMod

use of mage.game.turn.TurnMod in project mage by magefree.

the class DefaultCommander method init.

@Override
protected void init(UUID choosingPlayerId) {
    // move tiny leader to command zone
    for (UUID playerId : state.getPlayerList(startingPlayerId)) {
        Player player = getPlayer(playerId);
        if (player != null) {
            String commanderName = player.getMatchPlayer().getDeck().getName();
            Card commander = findCommander(this, player, commanderName);
            if (commander != null) {
                // already exists - just move to zone (example: game restart by Karn Liberated)
                commander.moveToZone(Zone.COMMAND, null, this, true);
            } else {
                // create new commander
                commander = getCommanderCard(commanderName, player.getId());
                if (commander != null) {
                    Set<Card> cards = new HashSet<>();
                    cards.add(commander);
                    this.loadCards(cards, playerId);
                    player.addCommanderId(commander.getId());
                    commander.moveToZone(Zone.COMMAND, null, this, true);
                    Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
                    ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary, false, "Commander"));
                    ability.addEffect(new CommanderCostModification(commander));
                    // Commander rule #4 was removed Jan. 18, 2016
                    // ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander)));
                    CommanderInfoWatcher watcher = new CommanderInfoWatcher("Commander", commander.getId(), false);
                    getState().addWatcher(watcher);
                    watcher.addCardInfoToCommander(this);
                    this.getState().addAbility(ability, null);
                } else {
                    // Test use case: create tiny game with random generated deck - game freezes with empty battlefield
                    throw new IllegalStateException("Commander card could not be created. Name: [" + player.getMatchPlayer().getDeck().getName() + ']');
                }
            }
        }
    }
    super.init(choosingPlayerId);
    if (startingPlayerSkipsDraw) {
        state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
    }
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) CommanderReplacementEffect(mage.abilities.effects.common.continuous.CommanderReplacementEffect) TurnMod(mage.game.turn.TurnMod) Card(mage.cards.Card) InfoEffect(mage.abilities.effects.common.InfoEffect) CommanderCostModification(mage.abilities.effects.common.cost.CommanderCostModification) UUID(java.util.UUID) CommanderInfoWatcher(mage.watchers.common.CommanderInfoWatcher) HashSet(java.util.HashSet)

Example 10 with TurnMod

use of mage.game.turn.TurnMod in project mage by magefree.

the class GameCanadianHighlanderImpl method init.

@Override
protected void init(UUID choosingPlayerId) {
    super.init(choosingPlayerId);
    state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}
Also used : TurnMod(mage.game.turn.TurnMod)

Aggregations

TurnMod (mage.game.turn.TurnMod)26 Player (mage.players.Player)13 UUID (java.util.UUID)6 Ability (mage.abilities.Ability)5 Permanent (mage.game.permanent.Permanent)5 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 InfoEffect (mage.abilities.effects.common.InfoEffect)3 TargetPlayer (mage.target.TargetPlayer)3 CardInfo (mage.cards.repository.CardInfo)2 MomirEmblem (mage.game.command.emblems.MomirEmblem)2 TargetPermanent (mage.target.TargetPermanent)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)1 Cost (mage.abilities.costs.Cost)1 RemoveAllCountersSourceCost (mage.abilities.costs.common.RemoveAllCountersSourceCost)1 ManaCosts (mage.abilities.costs.mana.ManaCosts)1 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)1