Search in sources :

Example 1 with ChoiceCreatureType

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

the class ElvishSoultillerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        Choice typeChoice = new ChoiceCreatureType(mageObject);
        if (controller.choose(outcome, typeChoice, game)) {
            if (!game.isSimulation()) {
                game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
            }
            Cards cardsToLibrary = new CardsImpl();
            FilterCreatureCard filter = new FilterCreatureCard();
            filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
            cardsToLibrary.addAll(controller.getGraveyard().getCards(filter, source.getSourceId(), source.getControllerId(), game));
            controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false);
            controller.shuffleLibrary(source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Choice(mage.choices.Choice) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 2 with ChoiceCreatureType

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

the class PeerPressureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Choice choice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
    if (controller != null && controller.choose(Outcome.GainControl, choice, game)) {
        String chosenType = choice.getChoice();
        game.informPlayers(controller.getLogName() + " has chosen " + chosenType);
        UUID playerWithMost = null;
        int maxControlled = 0;
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            FilterPermanent filter = new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType);
            filter.add(new ControllerIdPredicate(playerId));
            int controlled = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
            if (controlled > maxControlled) {
                maxControlled = controlled;
                playerWithMost = playerId;
            } else if (controlled == maxControlled) {
                // Do nothing in case of tie
                playerWithMost = null;
            }
        }
        if (playerWithMost != null && playerWithMost.equals(controller.getId())) {
            for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType), controller.getId(), source.getSourceId(), game)) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ChoiceCreatureType(mage.choices.ChoiceCreatureType) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Example 3 with ChoiceCreatureType

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

the class LuminescentRainEffect 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.BoostCreature, typeChoice, game)) {
        FilterControlledPermanent filter = new FilterControlledPermanent();
        filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
        return new GainLifeEffect(new PermanentsOnBattlefieldCount(filter, 2)).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceCreatureType(mage.choices.ChoiceCreatureType) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect)

Example 4 with ChoiceCreatureType

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

the class PatriarchsBiddingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Set<String> chosenTypes = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            Choice typeChoice = new ChoiceCreatureType(sourceObject);
            if (!player.choose(Outcome.PutCreatureInPlay, typeChoice, game)) {
                continue;
            }
            String chosenType = typeChoice.getChoice();
            game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + chosenType);
            chosenTypes.add(chosenType);
        }
        List<SubType.SubTypePredicate> predicates = new ArrayList<>();
        for (String type : chosenTypes) {
            predicates.add(SubType.byDescription(type).getPredicate());
        }
        FilterCard filter = new FilterCreatureCard();
        filter.add(Predicates.or(predicates));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.moveCards(player.getGraveyard().getCards(filter, game), Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) MageObject(mage.MageObject) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ChoiceCreatureType(mage.choices.ChoiceCreatureType)

Example 5 with ChoiceCreatureType

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

the class ChooseCreatureTypeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getPermanentEntering(source.getSourceId());
    if (mageObject == null) {
        mageObject = game.getObject(source.getSourceId());
    }
    if (controller != null && mageObject != null) {
        Choice typeChoice = new ChoiceCreatureType(mageObject);
        if (controller.choose(outcome, typeChoice, game)) {
            if (!game.isSimulation()) {
                game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
            }
            game.getState().setValue(source.getSourceId() + "_type", SubType.byDescription(typeChoice.getChoice()));
            if (mageObject instanceof Permanent) {
                ((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType)

Aggregations

ChoiceCreatureType (mage.choices.ChoiceCreatureType)29 Player (mage.players.Player)29 Choice (mage.choices.Choice)28 MageObject (mage.MageObject)15 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)13 Permanent (mage.game.permanent.Permanent)9 ContinuousEffect (mage.abilities.effects.ContinuousEffect)6 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)5 FixedTarget (mage.target.targetpointer.FixedTarget)5 BoostAllEffect (mage.abilities.effects.common.continuous.BoostAllEffect)4 FilterCard (mage.filter.FilterCard)4 UUID (java.util.UUID)3 Card (mage.cards.Card)3 CardsImpl (mage.cards.CardsImpl)3 FilterPermanent (mage.filter.FilterPermanent)3 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)3 FilterCreatureCard (mage.filter.common.FilterCreatureCard)3 HashSet (java.util.HashSet)2 DestroyAllEffect (mage.abilities.effects.common.DestroyAllEffect)2 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)2