Search in sources :

Example 96 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class GripOfAmnesiaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(source.getFirstTarget());
    if (spell != null) {
        Player controller = game.getPlayer(spell.getControllerId());
        if (controller != null && controller.chooseUse(Outcome.Benefit, "Exile all cards from your graveyard? (Otherwise " + spell.getLogName() + " will be countered)", source, game)) {
            controller.moveCards(controller.getGraveyard(), Zone.EXILED, source, game);
            game.informPlayers(controller.getLogName() + " exiles all cards from their graveyard to prevent counter effect");
        } else {
            game.getStack().counter(spell.getId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 97 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class IceCaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (sourcePermanent != null && spell != null && controller != null) {
        Player spellController = game.getPlayer(spell.getControllerId());
        Cost cost = new ManaCostsImpl(spell.getSpellAbility().getManaCosts().getText());
        if (spellController != null) {
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null && !player.equals(spellController)) {
                    cost.clearPaid();
                    if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(outcome, "Pay " + cost.getText() + " to counter " + spell.getIdName() + '?', source, game)) {
                        if (cost.pay(source, game, source, playerId, false, null)) {
                            game.informPlayers(player.getLogName() + " pays" + cost.getText() + " to counter " + spell.getIdName() + '.');
                            game.getStack().counter(spell.getId(), source, game);
                            break;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Spell(mage.game.stack.Spell)

Example 98 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class IgniteTheFutureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) game.getStack().getStackObject(source.getSourceId());
    if (controller == null || spell == null) {
        return false;
    }
    Set<Card> cards = controller.getLibrary().getTopCards(game, 3);
    return PlayFromNotOwnHandZoneTargetEffect.exileAndPlayFromExile(game, source, cards, TargetController.YOU, Duration.UntilEndOfYourNextTurn, Zone.GRAVEYARD.equals(spell.getFromZone()), false, false);
}
Also used : Player(mage.players.Player) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 99 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class MagesContestEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        Player you = game.getPlayer(source.getControllerId());
        Player spellController = game.getPlayer(spell.getControllerId());
        if (you != null && spellController != null) {
            int highBid = 1;
            game.informPlayers(you.getLogName() + " has bet " + highBid + " life");
            Player winner = you;
            Player currentPlayer = spellController;
            do {
                if (currentPlayer.canRespond()) {
                    int newBid = 0;
                    if (currentPlayer.isComputer()) {
                        // AI hint
                        // make AI evaluate value of the spell to decide on bidding, should be reworked
                        int maxBid = Math.min(RandomUtil.nextInt(Math.max(currentPlayer.getLife(), 1)) + RandomUtil.nextInt(Math.max(spell.getManaValue(), 1)), currentPlayer.getLife());
                        if (highBid + 1 < maxBid) {
                            newBid = highBid + 1;
                        }
                    } else if (currentPlayer.chooseUse(Outcome.Benefit, winner.getLogName() + " has bet " + highBid + " life. Top the bid?", source, game)) {
                        // Human choose
                        newBid = currentPlayer.getAmount(highBid + 1, Integer.MAX_VALUE, "Choose bid", game);
                    }
                    if (newBid > highBid) {
                        highBid = newBid;
                        winner = currentPlayer;
                        game.informPlayers(currentPlayer.getLogName() + " has bet " + newBid + " life");
                        currentPlayer = (winner == you ? spellController : you);
                    } else {
                        break;
                    }
                }
            } while (!Objects.equals(currentPlayer, winner));
            game.informPlayers(winner.getLogName() + " has won the contest with a high bid of " + highBid + " life");
            winner.loseLife(highBid, game, source, false);
            if (winner == you) {
                game.getStack().counter(spell.getId(), source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 100 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class MageHunterTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Spell spell = game.getSpell(event.getTargetId());
    if (spell == null || !game.getOpponents(getControllerId()).contains(spell.getControllerId()) || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    getEffects().setTargetPointer(new FixedTarget(spell.getControllerId()));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Spell(mage.game.stack.Spell)

Aggregations

Spell (mage.game.stack.Spell)311 Player (mage.players.Player)155 Permanent (mage.game.permanent.Permanent)90 UUID (java.util.UUID)79 MageObject (mage.MageObject)69 Card (mage.cards.Card)51 TargetSpell (mage.target.TargetSpell)48 StackObject (mage.game.stack.StackObject)42 FilterCard (mage.filter.FilterCard)38 FilterSpell (mage.filter.FilterSpell)36 FixedTarget (mage.target.targetpointer.FixedTarget)33 MageObjectReference (mage.MageObjectReference)24 Effect (mage.abilities.effects.Effect)22 OneShotEffect (mage.abilities.effects.OneShotEffect)22 Target (mage.target.Target)22 Ability (mage.abilities.Ability)20 SpellAbility (mage.abilities.SpellAbility)16 FilterPermanent (mage.filter.FilterPermanent)15 TargetCard (mage.target.TargetCard)15 TargetPlayer (mage.target.TargetPlayer)14