Search in sources :

Example 76 with MageObject

use of mage.MageObject in project mage by magefree.

the class FaithsShieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        if (FatefulHourCondition.instance.apply(game, source)) {
            ChoiceColor choice = new ChoiceColor();
            if (!controller.choose(Outcome.Protect, choice, game)) {
                return false;
            }
            if (choice.getColor() != null) {
                game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
                FilterCard filter = new FilterCard();
                filter.add(new ColorPredicate(choice.getColor()));
                filter.setMessage(choice.getChoice());
                Ability ability = new ProtectionAbility(filter);
                game.addEffect(new GainAbilityControlledEffect(ability, Duration.EndOfTurn), source);
                game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
                return true;
            }
        } else {
            game.addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn), source);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) GainProtectionFromColorTargetEffect(mage.abilities.effects.common.continuous.GainProtectionFromColorTargetEffect) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) MageObject(mage.MageObject) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ChoiceColor(mage.choices.ChoiceColor) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect)

Example 77 with MageObject

use of mage.MageObject in project mage by magefree.

the class GrenzoHavocRaiserEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player damagedPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
        if (damagedPlayer != null) {
            MageObject sourceObject = game.getObject(source.getSourceId());
            UUID exileId = CardUtil.getCardExileZoneId(game, source);
            Card card = damagedPlayer.getLibrary().getFromTop(game);
            if (card != null && sourceObject != null) {
                // move card to exile
                controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source, game, Zone.LIBRARY, true);
                // Add effects only if the card has a spellAbility (e.g. not for lands).
                if (card.getSpellAbility() != null) {
                    // allow to cast the card
                    // and you may spend mana as though it were mana of any color to cast it
                    CardUtil.makeCardPlayable(game, source, card, Duration.EndOfTurn, true);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) Card(mage.cards.Card)

Example 78 with MageObject

use of mage.MageObject in project mage by magefree.

the class GrenzosRuffiansEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID damagedOpponent = this.getTargetPointer().getFirst(game, source);
    int amount = (Integer) getValue("damage");
    MageObject object = game.getObject(source.getSourceId());
    if (object != null && amount > 0 && damagedOpponent != null) {
        for (UUID playerId : game.getOpponents(source.getControllerId())) {
            if (!Objects.equals(playerId, damagedOpponent)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null) {
                    int dealtDamage = opponent.damage(amount, source.getSourceId(), source, game);
                    game.informPlayers(object.getLogName() + " deals " + dealtDamage + " damage to " + opponent.getLogName());
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID)

Example 79 with MageObject

use of mage.MageObject in project mage by magefree.

the class GrimReminderWatcher 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) {
        TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_NON_LAND);
        if (controller.searchLibrary(target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                Cards cardsToReveal = new CardsImpl(card);
                controller.revealCards(sourceObject.getIdName(), cardsToReveal, game);
                String cardName = card.getName();
                GrimReminderWatcher watcher = game.getState().getWatcher(GrimReminderWatcher.class);
                if (watcher != null) {
                    for (UUID playerId : watcher.getPlayersCastSpell(cardName)) {
                        Player player = game.getPlayer(playerId);
                        if (player != null) {
                            player.loseLife(6, game, source, false);
                        }
                    }
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 80 with MageObject

use of mage.MageObject in project mage by magefree.

the class HellishRebukeTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject mageObject = source.getSourceObject(game);
    game.addEffect(new GainAbilityAllEffect(new HellishRebukeTriggeredAbility(source, game), Duration.EndOfTurn, StaticFilters.FILTER_OPPONENTS_PERMANENT), source);
    return true;
}
Also used : MageObject(mage.MageObject) GainAbilityAllEffect(mage.abilities.effects.common.continuous.GainAbilityAllEffect)

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