Search in sources :

Example 36 with Player

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

the class CounterbalanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
        if (spell != null) {
            Card topcard = controller.getLibrary().getFromTop(game);
            if (topcard != null) {
                CardsImpl cards = new CardsImpl();
                cards.add(topcard);
                controller.revealCards(sourcePermanent.getName(), cards, game);
                if (topcard.getManaValue() == spell.getManaValue()) {
                    return game.getStack().counter(spell.getId(), source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Spell(mage.game.stack.Spell) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 37 with Player

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

the class CourtOfAmbitionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int discardCount = source.isControlledBy(game.getMonarchId()) ? 2 : 1;
    String message = "Discard " + CardUtil.numberToText(discardCount, "a") + " card" + (discardCount > 1 ? 's' : "") + "? If not you lose " + (discardCount * 3) + " life";
    Map<UUID, Cards> discardMap = new HashMap<>();
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        if (player.getHand().size() < discardCount || !player.chooseUse(Outcome.LoseLife, message, source, game)) {
            player.loseLife(discardCount * 3, game, source, false);
            continue;
        }
        TargetDiscard target = new TargetDiscard(discardCount, StaticFilters.FILTER_CARD, playerId);
        player.choose(Outcome.Discard, target, source.getSourceId(), game);
        discardMap.put(playerId, new CardsImpl(target.getTargets()));
    }
    for (Map.Entry<UUID, Cards> entry : discardMap.entrySet()) {
        Player player = game.getPlayer(entry.getKey());
        if (player != null) {
            player.discard(entry.getValue(), false, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) HashMap(java.util.HashMap) Map(java.util.Map) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 38 with Player

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

the class CounterlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (stackObject != null && controller != null) {
        game.getStack().counter(source.getFirstTarget(), source, game);
        if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
            FilterCard filter = new FilterCard();
            List<Predicate<MageObject>> types = new ArrayList<>();
            for (CardType type : stackObject.getCardType(game)) {
                if (type != CardType.LAND) {
                    types.add(type.getPredicate());
                }
            }
            filter.add(Predicates.or(types));
            TargetCardInHand target = new TargetCardInHand(filter);
            if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                Card card = controller.getHand().get(target.getFirstTarget(), game);
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) ArrayList(java.util.ArrayList) Predicate(mage.filter.predicate.Predicate) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 39 with Player

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

the class CountermandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean countered = false;
    StackObject stackObject = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (game.getStack().counter(source.getFirstTarget(), source, game)) {
        countered = true;
    }
    if (stackObject != null) {
        Player controller = game.getPlayer(stackObject.getControllerId());
        if (controller != null) {
            controller.millCards(4, source, game);
        }
    }
    return countered;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject)

Example 40 with Player

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

the class CorruptedGrafstoneManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Mana types = getManaTypesInGraveyard(game, source);
    Choice choice = new ChoiceColor(true);
    choice.getChoices().clear();
    choice.setMessage("Pick a mana color");
    if (types.getBlack() > 0) {
        choice.getChoices().add("Black");
    }
    if (types.getRed() > 0) {
        choice.getChoices().add("Red");
    }
    if (types.getBlue() > 0) {
        choice.getChoices().add("Blue");
    }
    if (types.getGreen() > 0) {
        choice.getChoices().add("Green");
    }
    if (types.getWhite() > 0) {
        choice.getChoices().add("White");
    }
    if (!choice.getChoices().isEmpty()) {
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            if (choice.getChoices().size() == 1) {
                choice.setChoice(choice.getChoices().iterator().next());
            } else {
                if (!player.choose(outcome, choice, game)) {
                    return mana;
                }
            }
            switch(choice.getChoice()) {
                case "Black":
                    mana.setBlack(1);
                    break;
                case "Blue":
                    mana.setBlue(1);
                    break;
                case "Red":
                    mana.setRed(1);
                    break;
                case "Green":
                    mana.setGreen(1);
                    break;
                case "White":
                    mana.setWhite(1);
                    break;
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) ChoiceColor(mage.choices.ChoiceColor)

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