Search in sources :

Example 6 with ControllerIdPredicate

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

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

the class SabaccGameEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
        if (targetPermanent != null) {
            Player opponent = game.getPlayer(targetPermanent.getControllerId());
            if (opponent != null) {
                FilterPermanent filter = new FilterPermanent("permanent controlled by " + controller.getName());
                filter.add(new ControllerIdPredicate(controller.getId()));
                TargetPermanent target = new TargetPermanent(1, 1, filter, true);
                Permanent chosenPermanent = null;
                if (target.chooseTarget(outcome, opponent.getId(), source, game)) {
                    chosenPermanent = game.getPermanent(target.getFirstTarget());
                }
                boolean flipWin = controller.flipCoin(source, game, true);
                if (flipWin) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, controller.getId());
                    effect.setTargetPointer(new FixedTarget(targetPermanent, game));
                    game.addEffect(effect, source);
                } else if (chosenPermanent != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
                    effect.setTargetPointer(new FixedTarget(chosenPermanent, game));
                    game.addEffect(effect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) 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) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 8 with ControllerIdPredicate

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

the class RustmouthOgreTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
    if (damageEvent.isCombatDamage() && event.getSourceId().equals(this.getSourceId())) {
        FilterArtifactPermanent filter = new FilterArtifactPermanent("artifact that player controls");
        filter.add(new ControllerIdPredicate(event.getPlayerId()));
        filter.setMessage("artifact controlled by " + game.getPlayer(event.getTargetId()).getLogName());
        this.getTargets().clear();
        this.addTarget(new TargetPermanent(filter));
        return true;
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent) TargetPermanent(mage.target.TargetPermanent)

Example 9 with ControllerIdPredicate

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

the class SkymarkRocAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls with toughness 2 or less");
        UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
        filter.add(new ControllerIdPredicate(defenderId));
        filter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, 3));
        this.getTargets().clear();
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 10 with ControllerIdPredicate

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

the class TragicArroganceffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Permanent> choosenPermanent = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterArtifactPermanent filterArtifactPermanent = new FilterArtifactPermanent("an artifact of " + player.getName());
                filterArtifactPermanent.add(new ControllerIdPredicate(playerId));
                Target target1 = new TargetArtifactPermanent(1, 1, filterArtifactPermanent, true);
                FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent("a creature of " + player.getName());
                filterCreaturePermanent.add(new ControllerIdPredicate(playerId));
                Target target2 = new TargetPermanent(1, 1, filterCreaturePermanent, true);
                FilterEnchantmentPermanent filterEnchantmentPermanent = new FilterEnchantmentPermanent("an enchantment of " + player.getName());
                filterEnchantmentPermanent.add(new ControllerIdPredicate(playerId));
                Target target3 = new TargetPermanent(1, 1, filterEnchantmentPermanent, true);
                FilterPlaneswalkerPermanent filterPlaneswalkerPermanent = new FilterPlaneswalkerPermanent("a planeswalker of " + player.getName());
                filterPlaneswalkerPermanent.add(new ControllerIdPredicate(playerId));
                Target target4 = new TargetPermanent(1, 1, filterPlaneswalkerPermanent, true);
                if (target1.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target1, source, game);
                    Permanent artifact = game.getPermanent(target1.getFirstTarget());
                    if (artifact != null) {
                        choosenPermanent.add(artifact);
                    }
                    target1.clearChosen();
                }
                if (target2.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target2, source, game);
                    Permanent creature = game.getPermanent(target2.getFirstTarget());
                    if (creature != null) {
                        choosenPermanent.add(creature);
                    }
                    target2.clearChosen();
                }
                if (target3.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target3, source, game);
                    Permanent enchantment = game.getPermanent(target3.getFirstTarget());
                    if (enchantment != null) {
                        choosenPermanent.add(enchantment);
                    }
                    target3.clearChosen();
                }
                if (target4.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target4, source, game);
                    Permanent planeswalker = game.getPermanent(target4.getFirstTarget());
                    if (planeswalker != null) {
                        choosenPermanent.add(planeswalker);
                    }
                    target4.clearChosen();
                }
            }
        }
        // Then each player sacrifices all other nonland permanents they control
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENTS_NON_LAND, playerId, game)) {
                    if (!choosenPermanent.contains(permanent)) {
                        permanent.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

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