Search in sources :

Example 51 with TargetControlledCreaturePermanent

use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.

the class RagingRiverEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> left = new ArrayList<>();
        List<Permanent> right = new ArrayList<>();
        for (UUID defenderId : game.getCombat().getPlayerDefenders(game)) {
            Player defender = game.getPlayer(defenderId);
            if (defender != null) {
                List<Permanent> leftLog = new ArrayList<>();
                List<Permanent> rightLog = new ArrayList<>();
                FilterControlledCreaturePermanent filterBlockers = new FilterControlledCreaturePermanent("creatures without flying you control to assign to the \"left\" pile (creatures not chosen will be assigned to the \"right\" pile)");
                filterBlockers.add(Predicates.not(new AbilityPredicate(FlyingAbility.class)));
                Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filterBlockers, true);
                if (target.canChoose(source.getSourceId(), defenderId, game)) {
                    if (defender.chooseTarget(Outcome.Neutral, target, source, game)) {
                        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), defenderId, game)) {
                            if (target.getTargets().contains(permanent.getId())) {
                                left.add(permanent);
                                leftLog.add(permanent);
                            } else if (filterBlockers.match(permanent, source.getSourceId(), defenderId, game)) {
                                right.add(permanent);
                                rightLog.add(permanent);
                            }
                        }
                    }
                    // it could be nice to invoke some graphic indicator of which creature is Left or Right in this spot
                    StringBuilder sb = new StringBuilder("Left pile of ").append(defender.getLogName()).append(": ");
                    sb.append(leftLog.stream().map(MageObject::getLogName).collect(Collectors.joining(", ")));
                    game.informPlayers(sb.toString());
                    sb = new StringBuilder("Right pile of ").append(defender.getLogName()).append(": ");
                    sb.append(rightLog.stream().map(MageObject::getLogName).collect(Collectors.joining(", ")));
                    game.informPlayers(sb.toString());
                }
            }
        }
        for (UUID attackers : game.getCombat().getAttackers()) {
            Permanent attacker = game.getPermanent(attackers);
            if (attacker != null && Objects.equals(attacker.getControllerId(), controller.getId())) {
                CombatGroup combatGroup = game.getCombat().findGroup(attacker.getId());
                if (combatGroup != null) {
                    FilterCreaturePermanent filter = new FilterCreaturePermanent();
                    Player defender = game.getPlayer(combatGroup.getDefendingPlayerId());
                    if (defender != null) {
                        if (left.isEmpty() && right.isEmpty()) {
                            // shortcut in case of no labeled blockers available
                            filter.add(Predicates.not(new AbilityPredicate(FlyingAbility.class)));
                        } else {
                            List<Permanent> leftLog = left.stream().filter(permanent -> permanent.getControllerId() != null).filter(permanent -> permanent.isControlledBy(defender.getId())).collect(Collectors.toList());
                            List<Permanent> rightLog = right.stream().filter(permanent -> permanent.getControllerId() != null).filter(permanent -> permanent.isControlledBy(defender.getId())).collect(Collectors.toList());
                            if (controller.choosePile(outcome, attacker.getName() + ": attacking " + defender.getName(), leftLog, rightLog, game)) {
                                filter.add(Predicates.not(Predicates.or(new AbilityPredicate(FlyingAbility.class), new PermanentInListPredicate(left))));
                                game.informPlayers(attacker.getLogName() + ": attacks left (" + defender.getLogName() + ")");
                            } else {
                                filter.add(Predicates.not(Predicates.or(new AbilityPredicate(FlyingAbility.class), new PermanentInListPredicate(right))));
                                game.informPlayers(attacker.getLogName() + ": attacks right (" + defender.getLogName() + ")");
                            }
                        }
                        RestrictionEffect effect = new CantBeBlockedByAllTargetEffect(filter, Duration.EndOfCombat);
                        effect.setTargetPointer(new FixedTarget(attacker.getId(), game));
                        game.addEffect(effect, source);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Target(mage.target.Target) RestrictionEffect(mage.abilities.effects.RestrictionEffect) CantBeBlockedByAllTargetEffect(mage.abilities.effects.common.combat.CantBeBlockedByAllTargetEffect) Predicates(mage.filter.predicate.Predicates) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) ArrayList(java.util.ArrayList) AttacksWithCreaturesTriggeredAbility(mage.abilities.common.AttacksWithCreaturesTriggeredAbility) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CombatGroup(mage.game.combat.CombatGroup) FlyingAbility(mage.abilities.keyword.FlyingAbility) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FlyingAbility(mage.abilities.keyword.FlyingAbility) UUID(java.util.UUID) RestrictionEffect(mage.abilities.effects.RestrictionEffect) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate) CombatGroup(mage.game.combat.CombatGroup) CantBeBlockedByAllTargetEffect(mage.abilities.effects.common.combat.CantBeBlockedByAllTargetEffect)

Example 52 with TargetControlledCreaturePermanent

use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.

the class RichesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        Cards creaturesToSteal = new CardsImpl();
        // For each opponent, get the creature to steal
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (controller.hasOpponent(playerId, game)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null) {
                    TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
                    target.setNotTarget(true);
                    if (opponent.choose(Outcome.Detriment, target, source.getSourceId(), game)) {
                        creaturesToSteal.add(target.getTargets().get(0));
                    }
                }
            }
        }
        // controller depends on another creatures controller.
        for (UUID target : creaturesToSteal) {
            GainControlTargetEffect eff = new GainControlTargetEffect(Duration.EndOfGame, true);
            eff.setTargetPointer(new FixedTarget(target, game));
            game.addEffect(eff, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 53 with TargetControlledCreaturePermanent

use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.

the class SyphonFleshEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> perms = new ArrayList<>();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && !playerId.equals(source.getControllerId())) {
                TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
                target.setNotTarget(true);
                if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                    player.chooseTarget(Outcome.Sacrifice, target, source, game);
                    perms.addAll(target.getTargets());
                }
            }
        }
        for (UUID permID : perms) {
            Permanent permanent = game.getPermanent(permID);
            if (permanent != null) {
                permanent.sacrifice(source, game);
            }
        }
        int sacrificedAmount = perms.isEmpty() ? 0 : perms.size();
        if (sacrificedAmount > 0) {
            ZombieToken token = new ZombieToken();
            token.putOntoBattlefield(sacrificedAmount, game, source, source.getControllerId());
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ZombieToken(mage.game.permanent.token.ZombieToken) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 54 with TargetControlledCreaturePermanent

use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.

the class TimeWipeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Target target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (player.choose(outcome, target, source.getSourceId(), game)) {
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            player.moveCards(permanent, Zone.HAND, source, game);
        }
    }
    return new DestroyAllEffect(StaticFilters.FILTER_PERMANENT_A_CREATURE).apply(game, source);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 55 with TargetControlledCreaturePermanent

use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.

the class WoebringerDemonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player currentPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (currentPlayer != null) {
            TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
            target.setNotTarget(true);
            if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game)) {
                currentPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    permanent.sacrifice(source, game);
                    return true;
                }
            }
        }
        Permanent sourceObject = game.getPermanent(source.getSourceId());
        if (sourceObject != null && sourceObject.getZoneChangeCounter(game) == source.getSourceObjectZoneChangeCounter()) {
            sourceObject.sacrifice(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Aggregations

TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)78 Player (mage.players.Player)73 Permanent (mage.game.permanent.Permanent)64 Target (mage.target.Target)41 UUID (java.util.UUID)29 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)27 TargetPermanent (mage.target.TargetPermanent)18 ArrayList (java.util.ArrayList)14 Cost (mage.abilities.costs.Cost)10 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)9 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)8 FixedTarget (mage.target.targetpointer.FixedTarget)8 Ability (mage.abilities.Ability)6 FilterPermanent (mage.filter.FilterPermanent)6 MageObject (mage.MageObject)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)5 OneShotEffect (mage.abilities.effects.OneShotEffect)4 Card (mage.cards.Card)4 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3