Search in sources :

Example 26 with Player

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

the class ChecksAndBalancesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null) {
                if (player.getHand().isEmpty()) {
                    game.informPlayers(player.getLogName() + " doesn't have a card in hand to discard to counter " + spell.getLogName() + ", effect aborted.");
                    return true;
                }
            }
        }
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null) {
                if (!player.chooseUse(outcome, "Discard a card to counter " + spell.getLogName() + '?', source, game)) {
                    game.informPlayers(player.getLogName() + " refuses to discard a card to counter " + spell.getLogName());
                    return true;
                } else {
                    game.informPlayers(player.getLogName() + " agrees to discard a card to counter " + spell.getLogName());
                }
            }
        }
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null && !player.getHand().isEmpty()) {
                TargetCardInHand target = new TargetCardInHand();
                if (player.choose(Outcome.Discard, target, source.getSourceId(), game)) {
                    Card card = game.getCard(target.getFirstTarget());
                    player.discard(card, false, source, game);
                }
            }
        }
        game.getStack().counter(spell.getId(), source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 27 with Player

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

the class ChaosLordEffect method checkInterveningIfClause.

@Override
public boolean checkInterveningIfClause(Game game) {
    Condition condition = new ControlsPermanentsComparedToOpponentsCondition(ComparisonType.EQUAL_TO, new FilterPermanent());
    Player controller = game.getPlayer(controllerId);
    if (controller != null && condition.apply(game, this)) {
        return super.checkInterveningIfClause(game);
    }
    return false;
}
Also used : ControlsPermanentsComparedToOpponentsCondition(mage.abilities.condition.common.ControlsPermanentsComparedToOpponentsCondition) Condition(mage.abilities.condition.Condition) ControlsPermanentsComparedToOpponentsCondition(mage.abilities.condition.common.ControlsPermanentsComparedToOpponentsCondition) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent)

Example 28 with Player

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

the class ChaosMoonEvenReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int permanentsInPlay = game.getBattlefield().count(StaticFilters.FILTER_PERMANENT, source.getSourceId(), source.getControllerId(), game);
    // Odd
    if (permanentsInPlay % 2 == 1) {
        game.addEffect(new BoostAllEffect(1, 1, Duration.EndOfTurn, filter, false), source);
        new CreateDelayedTriggeredAbilityEffect(new ChaosMoonOddTriggeredAbility()).apply(game, source);
    } else // Even
    {
        game.addEffect(new BoostAllEffect(-1, -1, Duration.EndOfTurn, filter, false), source);
        game.addEffect(new ChaosMoonEvenReplacementEffect(), source);
    }
    return true;
}
Also used : Player(mage.players.Player) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Example 29 with Player

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

the class ChanneledForceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int xValue = GetXValue.instance.calculate(game, source, this);
    if (xValue == 0) {
        return false;
    }
    Player player = game.getPlayer(source.getTargets().get(0).getFirstTarget());
    if (player != null) {
        player.drawCards(xValue, source, game);
    }
    game.damagePlayerOrPlaneswalker(source.getTargets().get(1).getFirstTarget(), xValue, source.getSourceId(), source, game, false, true);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player)

Example 30 with Player

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

the class ChaosWandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (controller == null || opponent == null) {
        return false;
    }
    Cards cardsToShuffle = new CardsImpl();
    while (opponent.canRespond() && opponent.getLibrary().hasCards()) {
        Card card = opponent.getLibrary().getFromTop(game);
        if (card == null) {
            break;
        }
        opponent.moveCards(card, Zone.EXILED, source, game);
        controller.revealCards(source, new CardsImpl(card), game);
        if (card.isInstantOrSorcery(game)) {
            boolean cardWasCast = false;
            if (controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
            }
            if (!cardWasCast) {
                cardsToShuffle.add(card);
            }
            break;
        } else {
            cardsToShuffle.add(card);
        }
    }
    return opponent.putCardsOnBottomOfLibrary(cardsToShuffle, game, source, false);
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject)

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