Search in sources :

Example 36 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate 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 37 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class InstigatorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (player != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(new ControllerIdPredicate(player.getId()));
        RequirementEffect effect = new AttacksIfAbleAllEffect(filter, Duration.EndOfTurn);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : RequirementEffect(mage.abilities.effects.RequirementEffect) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) AttacksIfAbleAllEffect(mage.abilities.effects.common.combat.AttacksIfAbleAllEffect)

Example 38 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class NettlevineBlightEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent nettlevineBlight = game.getPermanent(source.getSourceId());
    Player newController = null;
    if (controller != null && nettlevineBlight != null) {
        Permanent enchantedPermanent = game.getPermanent(nettlevineBlight.getAttachedTo());
        if (enchantedPermanent != null) {
            newController = game.getPlayer(enchantedPermanent.getControllerId());
            enchantedPermanent.sacrifice(source, game);
        }
        if (newController != null) {
            FilterPermanent filter = new FilterPermanent("creature or land permanent you control");
            filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.LAND.getPredicate()));
            filter.add(new ControllerIdPredicate(newController.getId()));
            filter.add(new CanBeEnchantedByPredicate(nettlevineBlight));
            Target target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (target.canChoose(source.getSourceId(), newController.getId(), game) && newController.choose(outcome, target, source.getSourceId(), game)) {
                Permanent chosenPermanent = game.getPermanent(target.getFirstTarget());
                if (chosenPermanent != null) {
                    Card nettlevineBlightCard = game.getCard(source.getSourceId());
                    if (nettlevineBlightCard != null) {
                        game.getState().setValue("attachTo:" + nettlevineBlight.getId(), chosenPermanent);
                        chosenPermanent.addAttachment(nettlevineBlight.getId(), source, game);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) CanBeEnchantedByPredicate(mage.filter.predicate.permanent.CanBeEnchantedByPredicate) Card(mage.cards.Card)

Example 39 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class SomnophoreTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        Player opponent = game.getPlayer(event.getPlayerId());
        if (opponent != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
            filter.add(new ControllerIdPredicate(opponent.getId()));
            this.getTargets().clear();
            this.addTarget(new TargetCreaturePermanent(filter));
            return true;
        }
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Example 40 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class CallToArmsStateTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    UUID playerId = (UUID) game.getState().getValue(source.getSourceId() + ChooseOpponentEffect.VALUE_KEY);
    if (permanent != null) {
        Player opponent = game.getPlayer(playerId);
        if (opponent != null) {
            ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
            Condition condition = new MostCommonColorCondition(color, true, new ControllerIdPredicate(playerId));
            if (condition.apply(game, source)) {
                Effect effect = new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter, false);
                return effect.apply(game, source);
            }
        }
    }
    return false;
}
Also used : MostCommonColorCondition(mage.abilities.condition.common.MostCommonColorCondition) Condition(mage.abilities.condition.Condition) Player(mage.players.Player) MostCommonColorCondition(mage.abilities.condition.common.MostCommonColorCondition) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ObjectColor(mage.ObjectColor) ChooseColorEffect(mage.abilities.effects.common.ChooseColorEffect) Effect(mage.abilities.effects.Effect) ChooseOpponentEffect(mage.abilities.effects.common.ChooseOpponentEffect) SacrificeSourceEffect(mage.abilities.effects.common.SacrificeSourceEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect) UUID(java.util.UUID) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Aggregations

ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)153 Player (mage.players.Player)105 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)87 Permanent (mage.game.permanent.Permanent)70 UUID (java.util.UUID)53 TargetPermanent (mage.target.TargetPermanent)53 FilterPermanent (mage.filter.FilterPermanent)51 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)41 Target (mage.target.Target)29 FixedTarget (mage.target.targetpointer.FixedTarget)21 TargetPlayer (mage.target.TargetPlayer)16 ContinuousEffect (mage.abilities.effects.ContinuousEffect)15 Effect (mage.abilities.effects.Effect)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 FilterLandPermanent (mage.filter.common.FilterLandPermanent)13 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)11 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)9 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)9 MageObject (mage.MageObject)8 HashSet (java.util.HashSet)7