Search in sources :

Example 86 with MageObject

use of mage.MageObject in project mage by magefree.

the class MindBombEffect 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) {
        return false;
    }
    Map<UUID, Cards> cardsToDiscard = new HashMap<>();
    // choose
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Cards cards = new CardsImpl();
        Target target = new TargetDiscard(0, 3, new FilterCard(), playerId);
        player.chooseTarget(Outcome.Discard, target, source, game);
        cards.addAll(target.getTargets());
        cardsToDiscard.put(playerId, cards);
    }
    // discard
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            Cards cardsPlayer = cardsToDiscard.get(playerId);
            cardsToDiscard.put(playerId, player.discard(cardsPlayer, false, source, game));
        }
    }
    // damage
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Cards cardsPlayer = cardsToDiscard.get(playerId);
        if (cardsPlayer != null) {
            player.damage(3 - cardsPlayer.size(), source.getSourceId(), source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) MageObject(mage.MageObject) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 87 with MageObject

use of mage.MageObject in project mage by magefree.

the class MundaAmbushLeaderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Cards allCards = new CardsImpl();
        allCards.addAll(controller.getLibrary().getTopCards(game, 4));
        controller.lookAtCards(sourceObject.getIdName(), allCards, game);
        if (!allCards.isEmpty()) {
            Cards cardsToReveal = new CardsImpl();
            TargetCard target = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
            controller.chooseTarget(outcome, allCards, target, source, game);
            cardsToReveal.addAll(target.getTargets());
            if (!cardsToReveal.isEmpty()) {
                controller.revealCards(sourceObject.getIdName(), cardsToReveal, game, true);
                allCards.removeAll(cardsToReveal);
            }
            controller.putCardsOnTopOfLibrary(cardsToReveal, game, source, true);
        }
        if (!allCards.isEmpty()) {
            controller.putCardsOnBottomOfLibrary(allCards, game, source, true);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 88 with MageObject

use of mage.MageObject in project mage by magefree.

the class MultiformWonder2Effect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        String message = "Should " + sourceObject.getLogName() + " get -2/+2 instead of +2/-2?";
        if (controller.chooseUse(Outcome.Neutral, message, source, game)) {
            this.power *= -1;
            this.toughness *= -1;
        }
    }
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject)

Example 89 with MageObject

use of mage.MageObject in project mage by magefree.

the class NovijenHeartOfProgressEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
            if (permanent.getTurnsOnBattlefield() == 0) {
                permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts a +1/+1 counter on " + permanent.getLogName());
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject)

Example 90 with MageObject

use of mage.MageObject in project mage by magefree.

the class OathOfMagesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player firstPlayer = game.getPlayer(game.getActivePlayerId());
    Player secondPlayer = game.getPlayer(source.getFirstTarget());
    if (sourceObject == null || firstPlayer == null) {
        return false;
    }
    if (firstPlayer.chooseUse(Outcome.Benefit, "Deal one damage to " + secondPlayer.getLogName() + "?", source, game)) {
        secondPlayer.damage(1, source.getSourceId(), source, game);
    }
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) MageObject(mage.MageObject)

Aggregations

MageObject (mage.MageObject)738 Player (mage.players.Player)554 Permanent (mage.game.permanent.Permanent)239 UUID (java.util.UUID)224 Card (mage.cards.Card)210 FilterCard (mage.filter.FilterCard)113 CardsImpl (mage.cards.CardsImpl)106 TargetCard (mage.target.TargetCard)91 Cards (mage.cards.Cards)73 Spell (mage.game.stack.Spell)68 FixedTarget (mage.target.targetpointer.FixedTarget)66 HashSet (java.util.HashSet)56 Ability (mage.abilities.Ability)52 ContinuousEffect (mage.abilities.effects.ContinuousEffect)51 TargetPermanent (mage.target.TargetPermanent)48 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)48 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)46 Target (mage.target.Target)44 Effect (mage.abilities.effects.Effect)42 OneShotEffect (mage.abilities.effects.OneShotEffect)41