Search in sources :

Example 1 with TargetPlayer

use of mage.target.TargetPlayer in project mage by magefree.

the class BookBurningMillEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null) {
        boolean millCards = true;
        for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.chooseUse(Outcome.Detriment, "Have " + sourceObject.getLogName() + " deal 6 damage to you?", source, game)) {
                millCards = false;
                player.damage(6, source.getSourceId(), source, game);
                game.informPlayers(player.getLogName() + " has " + sourceObject.getLogName() + " deal 6 damage to them");
            }
        }
        if (millCards) {
            Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
            if (targetPlayer != null) {
                targetPlayer.moveCards(targetPlayer.getLibrary().getTopCards(game, 6), Zone.GRAVEYARD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID)

Example 2 with TargetPlayer

use of mage.target.TargetPlayer in project mage by magefree.

the class ChaoticBacklashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null) {
        int amount = 2 * game.getBattlefield().countAll(filter, targetPlayer.getId(), game);
        targetPlayer.damage(amount, source.getSourceId(), source, game);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player)

Example 3 with TargetPlayer

use of mage.target.TargetPlayer in project mage by magefree.

the class CranialArchiveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (targetPlayer != null) {
            for (Card card : targetPlayer.getGraveyard().getCards(game)) {
                targetPlayer.moveCardToLibraryWithInfo(card, source, game, Zone.GRAVEYARD, true, true);
            }
            targetPlayer.shuffleLibrary(source, game);
        }
        controller.drawCards(1, source, game);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Card(mage.cards.Card)

Example 4 with TargetPlayer

use of mage.target.TargetPlayer in project mage by magefree.

the class JuxtaposeEffect method init.

@Override
public void init(Ability source, Game game) {
    Player you = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (you != null && targetPlayer != null) {
        Permanent permanent1 = chooseOnePermanentsWithTheHighestCMC(game, you, filter);
        Permanent permanent2 = chooseOnePermanentsWithTheHighestCMC(game, targetPlayer, filter);
        if (permanent1 != null && permanent2 != null) {
            // exchange works only for two different controllers
            if (permanent1.isControlledBy(permanent2.getControllerId())) {
                // discard effect if controller of both permanents is the same
                discard();
                return;
            }
            this.lockedControllers.put(permanent1.getId(), permanent2.getControllerId());
            this.zoneChangeCounter.put(permanent1.getId(), permanent1.getZoneChangeCounter(game));
            this.lockedControllers.put(permanent2.getId(), permanent1.getControllerId());
            this.zoneChangeCounter.put(permanent2.getId(), permanent2.getZoneChangeCounter(game));
            permanent1.changeControllerId(targetPlayer.getId(), game, source);
            permanent2.changeControllerId(you.getId(), game, source);
            MageObject sourceObject = game.getCard(source.getSourceId());
            game.informPlayers((sourceObject != null ? sourceObject.getLogName() : "") + ": " + you.getLogName() + " and " + targetPlayer.getLogName() + " exchange control of " + permanent1.getLogName() + " and " + permanent2.getName());
        } else {
            // discard if there are less than 2 permanents
            discard();
        }
    }
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) MageObject(mage.MageObject)

Example 5 with TargetPlayer

use of mage.target.TargetPlayer in project mage by magefree.

the class LoxodonPeacekeeperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent sourcePermanent = game.getPermanent(source.getSourceId());
        if (sourcePermanent != null) {
            int lowLife = Integer.MAX_VALUE;
            Set<UUID> tiedPlayers = new HashSet<>();
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    if (player.getLife() < lowLife) {
                        lowLife = player.getLife();
                    }
                }
            }
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    if (player.getLife() == lowLife) {
                        tiedPlayers.add(playerId);
                    }
                }
            }
            if (tiedPlayers.size() > 0) {
                UUID newControllerId = null;
                if (tiedPlayers.size() > 1) {
                    FilterPlayer filter = new FilterPlayer("a player tied for lowest life total");
                    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                        if (!tiedPlayers.contains(playerId)) {
                            filter.add(Predicates.not(new PlayerIdPredicate(playerId)));
                        }
                    }
                    TargetPlayer target = new TargetPlayer(1, 1, true, filter);
                    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
                        while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
                            controller.chooseTarget(outcome, target, source, game);
                        }
                    } else {
                        return false;
                    }
                    newControllerId = game.getPlayer(target.getFirstTarget()).getId();
                } else {
                    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                        if (tiedPlayers.contains(playerId)) {
                            newControllerId = playerId;
                            break;
                        }
                    }
                }
                if (newControllerId != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newControllerId);
                    effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
                    game.addEffect(effect, source);
                    game.informPlayers(game.getPlayer(newControllerId).getLogName() + " has gained control of " + sourcePermanent.getLogName());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) Permanent(mage.game.permanent.Permanent) FilterPlayer(mage.filter.FilterPlayer) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetPlayer(mage.target.TargetPlayer) HashSet(java.util.HashSet)

Aggregations

TargetPlayer (mage.target.TargetPlayer)134 Player (mage.players.Player)129 Card (mage.cards.Card)38 Permanent (mage.game.permanent.Permanent)32 FilterCard (mage.filter.FilterCard)27 UUID (java.util.UUID)25 MageObject (mage.MageObject)16 CardsImpl (mage.cards.CardsImpl)16 FilterPlayer (mage.filter.FilterPlayer)16 TargetCard (mage.target.TargetCard)13 Cards (mage.cards.Cards)12 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)12 ObjectSourcePlayer (mage.filter.predicate.ObjectSourcePlayer)10 Target (mage.target.Target)10 FixedTarget (mage.target.targetpointer.FixedTarget)10 Spell (mage.game.stack.Spell)9 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 TargetPermanent (mage.target.TargetPermanent)7 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)5