Search in sources :

Example 61 with Player

use of mage.players.Player in project mage by magefree.

the class DireFleetRavagerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    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) {
                int lifeToLose = (int) Math.ceil(player.getLife() / 3.0);
                player.loseLife(lifeToLose, game, source, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID)

Example 62 with Player

use of mage.players.Player in project mage by magefree.

the class DimensionalBreachReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(morSet.stream().map(mor -> mor.getCard(game)).filter(Objects::nonNull).filter(c -> c.isOwnedBy(game.getActivePlayerId())).collect(Collectors.toSet()));
    if (cards.isEmpty()) {
        return false;
    }
    if (cards.size() > 1) {
        TargetCard target = new TargetCardInExile(StaticFilters.FILTER_CARD);
        target.setNotTarget(true);
        player.choose(outcome, cards, target, game);
        cards.clear();
        cards.add(target.getFirstTarget());
    }
    return player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 63 with Player

use of mage.players.Player in project mage by magefree.

the class DiscordantDirgeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent discordantDirge = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (discordantDirge == null) {
        return false;
    }
    int verseCounters = discordantDirge.getCounters(game).getCount(CounterType.VERSE);
    Player targetOpponent = game.getPlayer(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (targetOpponent == null || controller == null) {
        return false;
    }
    controller.lookAtCards(targetOpponent.getName() + " hand", targetOpponent.getHand(), game);
    TargetCard target = new TargetCard(0, verseCounters, Zone.HAND, new FilterCard());
    target.setNotTarget(true);
    if (!controller.choose(Outcome.Benefit, targetOpponent.getHand(), target, game)) {
        return false;
    }
    targetOpponent.discard(new CardsImpl(target.getTargets()), false, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl)

Example 64 with Player

use of mage.players.Player in project mage by magefree.

the class DismalFailureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID targetId = source.getFirstTarget();
    Player controller = null;
    boolean countered = false;
    if (targetId != null) {
        controller = game.getPlayer(game.getControllerId(targetId));
    }
    if (targetId != null && game.getStack().counter(targetId, source, game)) {
        countered = true;
    }
    if (controller != null) {
        controller.discard(1, false, false, source, game);
    }
    return countered;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID)

Example 65 with Player

use of mage.players.Player in project mage by magefree.

the class ElevenTheMageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.drawCards(1, source, game);
    player.loseLife(1, game, source, false);
    if (player.getHand().size() < 11) {
        return true;
    }
    // TODO: change this to fit with changes made in https://github.com/magefree/mage/pull/8136 when merged
    Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
    if (!target.canChoose(source.getSourceId(), player.getId(), game) || !player.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery spell " + "from your hand without paying its mana cost?", source, game)) {
        return true;
    }
    Card cardToCast = null;
    boolean cancel = false;
    while (player.canRespond() && !cancel) {
        if (player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
            cardToCast = game.getCard(target.getFirstTarget());
            if (cardToCast != null) {
                if (cardToCast.getSpellAbility() == null) {
                    Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
                    cancel = true;
                }
                if (cardToCast.getSpellAbility().canChooseTarget(game, player.getId())) {
                    cancel = true;
                }
            }
        } else {
            cancel = true;
        }
    }
    if (cardToCast != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
        player.cast(player.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CastWithoutPayingManaCostEffect(mage.abilities.effects.common.cost.CastWithoutPayingManaCostEffect) Card(mage.cards.Card)

Aggregations

Player (mage.players.Player)3909 Permanent (mage.game.permanent.Permanent)1705 Card (mage.cards.Card)1099 UUID (java.util.UUID)962 MageObject (mage.MageObject)556 FilterCard (mage.filter.FilterCard)515 CardsImpl (mage.cards.CardsImpl)498 FixedTarget (mage.target.targetpointer.FixedTarget)387 TargetPermanent (mage.target.TargetPermanent)353 Cards (mage.cards.Cards)345 TargetCard (mage.target.TargetCard)328 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)317 TargetPlayer (mage.target.TargetPlayer)312 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)301 FilterPermanent (mage.filter.FilterPermanent)292 Target (mage.target.Target)289 OneShotEffect (mage.abilities.effects.OneShotEffect)230 ContinuousEffect (mage.abilities.effects.ContinuousEffect)227 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)207 Effect (mage.abilities.effects.Effect)170