Search in sources :

Example 61 with Choice

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

the class MaintenanceDroidEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose mode");
        choice.setChoices(choices);
        if (!controller.choose(outcome, choice, game)) {
            return false;
        }
        String chosen = choice.getChoice();
        switch(chosen) {
            case "Remove a repair counter":
                new RemoveCounterTargetEffect(CounterType.REPAIR.createInstance()).apply(game, source);
                break;
            default:
                // "Add another repair counter"
                new AddCountersTargetEffect(CounterType.REPAIR.createInstance()).apply(game, source);
                break;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) RemoveCounterTargetEffect(mage.abilities.effects.common.counter.RemoveCounterTargetEffect) ChoiceImpl(mage.choices.ChoiceImpl) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 62 with Choice

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

the class OutbreakEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
    if (player != null && player.choose(outcome, typeChoice, game)) {
        game.informPlayers(player.getLogName() + " has chosen " + typeChoice.getChoice());
        FilterCreaturePermanent filter = new FilterCreaturePermanent("All creatures of the chosen type");
        filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
        ContinuousEffect effect = new BoostAllEffect(-1, -1, Duration.WhileOnBattlefield, filter, false);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ChoiceCreatureType(mage.choices.ChoiceCreatureType) ContinuousEffect(mage.abilities.effects.ContinuousEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Example 63 with Choice

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

the class OrderOfSuccessionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<UUID, UUID> playerCreature = new HashMap<>(2);
        Choice choice = new ChoiceLeftOrRight();
        if (!controller.choose(Outcome.Neutral, choice, game)) {
            return false;
        }
        boolean left = choice.getChoice().equals("Left");
        PlayerList playerList = game.getState().getPlayerList().copy();
        // set playerlist to controller
        while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
            playerList.getNext();
        }
        Player currentPlayer = game.getPlayer(playerList.get());
        Player nextPlayer;
        UUID firstNextPlayer = null;
        while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer) && controller.canRespond()) {
            nextPlayer = game.getPlayer(playerList.get());
            if (nextPlayer == null) {
                return false;
            }
            // save first next player to check for iteration stop
            if (firstNextPlayer == null) {
                firstNextPlayer = nextPlayer.getId();
            }
            if (!nextPlayer.canRespond()) {
                continue;
            }
            // if player is in range they choose a creature to control
            if (currentPlayer != null && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent("creature controlled by " + nextPlayer.getLogName());
                filter.add(new ControllerIdPredicate(nextPlayer.getId()));
                Target target = new TargetCreaturePermanent(filter);
                target.setNotTarget(true);
                if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game)) {
                    if (currentPlayer.chooseTarget(outcome, target, source, game)) {
                        playerCreature.put(currentPlayer.getId(), target.getFirstTarget());
                    }
                }
            }
            currentPlayer = nextPlayer;
        }
        // change control of targets
        for (Map.Entry<UUID, UUID> entry : playerCreature.entrySet()) {
            Player player = game.getPlayer(entry.getKey());
            if (player != null) {
                Permanent creature = game.getPermanent(entry.getValue());
                if (creature != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, player.getId());
                    effect.setTargetPointer(new FixedTarget(creature.getId(), game));
                    game.addEffect(effect, source);
                    game.informPlayers(new StringBuilder(player.getLogName()).append(" gains control of ").append(creature.getName()).toString());
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) HashMap(java.util.HashMap) PlayerList(mage.players.PlayerList) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ChoiceLeftOrRight(mage.choices.ChoiceLeftOrRight) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 64 with Choice

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

the class StandardizeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    String chosenType = "";
    if (player != null && sourceObject != null) {
        Choice typeChoice = new ChoiceCreatureType(sourceObject);
        typeChoice.setMessage("Choose a creature type other than Wall");
        typeChoice.getChoices().remove("Wall");
        if (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
            return false;
        }
        game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
        chosenType = typeChoice.getChoice();
        if (chosenType != null && !chosenType.isEmpty()) {
            // ADD TYPE TO TARGET
            game.addEffect(new BecomesSubtypeAllEffect(Duration.EndOfTurn, Arrays.asList(SubType.byDescription(chosenType)), StaticFilters.FILTER_PERMANENT_CREATURE, true), source);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType) BecomesSubtypeAllEffect(mage.abilities.effects.common.continuous.BecomesSubtypeAllEffect)

Example 65 with Choice

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

the class TurnaboutEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || game.getPlayer(source.getFirstTarget()) == null) {
        return true;
    }
    Choice choiceImpl = new ChoiceImpl(true);
    choiceImpl.setMessage("Choose card type to tap or untap");
    choiceImpl.setChoices(choice);
    if (!controller.choose(Outcome.Neutral, choiceImpl, game)) {
        return false;
    }
    FilterPermanent filter;
    switch(choiceImpl.getChoice()) {
        case "Artifact":
            filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT;
            break;
        case "Land":
            filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND;
            break;
        case "Creature":
            filter = StaticFilters.FILTER_CONTROLLED_CREATURE;
            break;
        default:
            throw new IllegalArgumentException("Choice is required");
    }
    boolean tap = controller.chooseUse(Outcome.Neutral, "Tap or untap?", null, "Tap", "Untap", source, game);
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getFirstTarget(), source.getSourceId(), game)) {
        if (tap) {
            permanent.tap(source, game);
        } else {
            permanent.untap(game);
        }
    }
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl)

Aggregations

Choice (mage.choices.Choice)117 Player (mage.players.Player)114 ChoiceImpl (mage.choices.ChoiceImpl)67 Permanent (mage.game.permanent.Permanent)51 ChoiceCreatureType (mage.choices.ChoiceCreatureType)28 MageObject (mage.MageObject)27 Mana (mage.Mana)22 HashSet (java.util.HashSet)21 Card (mage.cards.Card)17 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)16 UUID (java.util.UUID)15 ContinuousEffect (mage.abilities.effects.ContinuousEffect)13 FilterPermanent (mage.filter.FilterPermanent)12 Ability (mage.abilities.Ability)10 ChoiceColor (mage.choices.ChoiceColor)10 Counter (mage.counters.Counter)10 TargetPermanent (mage.target.TargetPermanent)10 FilterCard (mage.filter.FilterCard)8 FixedTarget (mage.target.targetpointer.FixedTarget)8 CardType (mage.constants.CardType)7