Search in sources :

Example 1 with FilterPlaneswalkerPermanent

use of mage.filter.common.FilterPlaneswalkerPermanent 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)

Example 2 with FilterPlaneswalkerPermanent

use of mage.filter.common.FilterPlaneswalkerPermanent in project mage by magefree.

the class QuestingBeastTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player opponent = game.getPlayer(event.getPlayerId());
    if (opponent == null || !event.getSourceId().equals(this.getSourceId()) || !opponent.hasOpponent(this.getControllerId(), game) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    this.getEffects().clear();
    this.addEffect(new DamageTargetEffect(event.getAmount()));
    FilterPermanent filter = new FilterPlaneswalkerPermanent("planeswalker " + opponent.getLogName() + " controls");
    filter.add(new ControllerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetPermanent(filter));
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) DamagedEvent(mage.game.events.DamagedEvent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent)

Example 3 with FilterPlaneswalkerPermanent

use of mage.filter.common.FilterPlaneswalkerPermanent in project mage by magefree.

the class VialSmasherTheFierceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int damage = (Integer) getValue("VialSmasherTheFierceCMC");
        if (damage > 0) {
            List<Player> opponents = game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).filter(o -> !o.hasLost()).filter(o -> !o.hasLeft()).collect(Collectors.toList());
            if (opponents.isEmpty()) {
                return false;
            }
            Collections.shuffle(opponents);
            Player opponent = opponents.get(0);
            game.informPlayers(opponent.getLogName() + " was chosen at random.");
            if (game.getBattlefield().getAllActivePermanents(new FilterPlaneswalkerPermanent(), opponent.getId(), game).size() > 0) {
                if (controller.chooseUse(Outcome.Damage, "Redirect to a planeswalker controlled by " + opponent.getLogName() + "?", source, game)) {
                    FilterPlaneswalkerPermanent filter = new FilterPlaneswalkerPermanent("a planeswalker controlled by " + opponent.getLogName());
                    filter.add(new ControllerIdPredicate(opponent.getId()));
                    TargetPermanent target = new TargetPermanent(1, 1, filter, false);
                    if (target.choose(Outcome.Damage, controller.getId(), source.getSourceId(), game)) {
                        Permanent permanent = game.getPermanent(target.getFirstTarget());
                        if (permanent != null) {
                            return permanent.damage(damage, source.getSourceId(), source, game, false, true) > 0;
                        }
                    }
                }
            }
            opponent.damage(damage, source.getSourceId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : SpellCastControllerTriggeredAbility(mage.abilities.common.SpellCastControllerTriggeredAbility) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) SubType(mage.constants.SubType) Player(mage.players.Player) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) CardType(mage.constants.CardType) Spell(mage.game.stack.Spell) PartnerAbility(mage.abilities.keyword.PartnerAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) List(java.util.List) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) Effect(mage.abilities.effects.Effect) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) Collections(java.util.Collections) SuperType(mage.constants.SuperType) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent)

Example 4 with FilterPlaneswalkerPermanent

use of mage.filter.common.FilterPlaneswalkerPermanent in project mage by magefree.

the class CurseOfThePiercedHeartEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller == null || opponent == null) {
        return false;
    }
    if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), opponent.getId(), game) < 1 || !controller.chooseUse(Outcome.Damage, "Redirect to a planeswalker controlled by " + opponent.getLogName() + "?", source, game)) {
        return opponent.damage(1, source.getSourceId(), source, game) > 0;
    }
    FilterPermanent filter = new FilterPlaneswalkerPermanent("a planeswalker controlled by " + opponent.getLogName());
    filter.add(new ControllerIdPredicate(opponent.getId()));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    controller.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent != null) {
        return permanent.damage(1, source.getSourceId(), source, game, false, true) > 0;
    }
    return opponent.damage(1, source.getSourceId(), source, game) > 0;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent)

Aggregations

FilterPlaneswalkerPermanent (mage.filter.common.FilterPlaneswalkerPermanent)4 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)4 Player (mage.players.Player)4 TargetPermanent (mage.target.TargetPermanent)4 Permanent (mage.game.permanent.Permanent)3 UUID (java.util.UUID)2 FilterPermanent (mage.filter.FilterPermanent)2 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 MageInt (mage.MageInt)1 Ability (mage.abilities.Ability)1 SpellCastControllerTriggeredAbility (mage.abilities.common.SpellCastControllerTriggeredAbility)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)1 PartnerAbility (mage.abilities.keyword.PartnerAbility)1 CardImpl (mage.cards.CardImpl)1