Search in sources :

Example 56 with StackObject

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

the class Turn method endTurn.

/*protected void playExtraTurns(Game game) {
     while (game.getState().getTurnMods().extraTurn(activePlayerId)) {
     this.play(game, activePlayerId);
     }
     }*/
/**
 * Used for some spells with end turn effect (e.g. Time Stop).
 *
 * @param game
 * @param activePlayerId
 * @param source
 */
public void endTurn(Game game, UUID activePlayerId, Ability source) {
    // Ending the turn this way (Time Stop) means the following things happen in order:
    setEndTurnRequested(true);
    // It also includes spells and abilities that can't be countered.
    while (!game.hasEnded() && !game.getStack().isEmpty()) {
        StackObject stackObject = game.getStack().peekFirst();
        if (stackObject instanceof Spell) {
            ((Spell) stackObject).moveToExile(null, "", source, game);
        } else {
            // stack ability
            game.getStack().remove(stackObject, game);
        }
    }
    // 2) All attacking and blocking creatures are removed from combat.
    for (UUID attackerId : game.getCombat().getAttackers()) {
        Permanent permanent = game.getPermanent(attackerId);
        if (permanent != null) {
            permanent.removeFromCombat(game);
        }
        game.getCombat().removeAttacker(attackerId, game);
    }
    for (UUID blockerId : game.getCombat().getBlockers()) {
        Permanent permanent = game.getPermanent(blockerId);
        if (permanent != null) {
            permanent.removeFromCombat(game);
        }
    }
    // 3) State-based actions are checked. No player gets priority, and no triggered abilities are put onto the stack.
    // seems like trigger events have to be removed: http://tabakrules.tumblr.com/post/122350751009/days-undoing-has-been-officially-spoiled-on
    game.getState().clearTriggeredAbilities();
    // triggered effects don't go to stack because check of endTurnRequested
    game.checkStateAndTriggered();
// 4) The current phase and/or step ends.
// The game skips straight to the cleanup step. The cleanup step happens in its entirety.
// this is caused by the endTurnRequest state
}
Also used : Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 57 with StackObject

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

the class TrailOfTheMageRingsReboundEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Plane cPlane = game.getState().getCurrentPlane();
    if (cPlane == null) {
        return false;
    }
    if (!cPlane.getPlaneType().equals(Planes.PLANE_TRAIL_OF_THE_MAGE_RINGS)) {
        return false;
    }
    for (UUID playerId : game.getPlayers().keySet()) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            for (Card card : player.getHand().getCards(filter, game)) {
                addReboundAbility(card, source, game);
            }
            for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
                StackObject stackObject = iterator.next();
                if (stackObject instanceof Spell && stackObject.isControlledBy(source.getControllerId())) {
                    Spell spell = (Spell) stackObject;
                    Card card = spell.getCard();
                    if (card != null) {
                        addReboundAbility(card, source, game);
                    }
                }
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Plane(mage.game.command.Plane) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 58 with StackObject

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

the class WardAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!getSourceId().equals(event.getTargetId())) {
        return false;
    }
    StackObject stackObject = getTargetingObject(event, game);
    if (stackObject == null || !game.getOpponents(getControllerId()).contains(stackObject.getControllerId())) {
        return false;
    }
    getEffects().setTargetPointer(new FixedTarget(stackObject.getId(), game));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) StackObject(mage.game.stack.StackObject)

Example 59 with StackObject

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

the class HarshJudgmentEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (event.getTargetId().equals(source.getControllerId())) {
        Spell spell = null;
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        if (stackObject == null) {
            stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
        }
        if (stackObject instanceof Spell) {
            spell = (Spell) stackObject;
        }
        // Checks if damage is from a sorcery or instants and spell is of chosen color
        Permanent permanent = game.getPermanent(source.getSourceId());
        ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
        if (spell != null && instantOrSorceryFilter.match(spell.getCard(), game) && spell.getColor(game).contains(color)) {
            TargetPlayer target = new TargetPlayer();
            target.add(spell.getControllerId(), game);
            redirectTarget = target;
            return true;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) ObjectColor(mage.ObjectColor) Spell(mage.game.stack.Spell) TargetPlayer(mage.target.TargetPlayer)

Example 60 with StackObject

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

the class InduceParanoiaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell != null) {
        game.getStack().counter(spell.getId(), source, game);
        int spellCMC = spell.getManaValue();
        Player player = game.getPlayer(spell.getControllerId());
        if (player != null) {
            player.millCards(spellCMC, source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject)

Aggregations

StackObject (mage.game.stack.StackObject)130 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)57 Spell (mage.game.stack.Spell)41 MageObject (mage.MageObject)37 UUID (java.util.UUID)36 Card (mage.cards.Card)29 Target (mage.target.Target)17 TargetPermanent (mage.target.TargetPermanent)15 FilterCard (mage.filter.FilterCard)14 Ability (mage.abilities.Ability)13 FilterPermanent (mage.filter.FilterPermanent)13 StackAbility (mage.game.stack.StackAbility)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)11 HashSet (java.util.HashSet)10 Effect (mage.abilities.effects.Effect)9 Game (mage.game.Game)9 MageObjectReference (mage.MageObjectReference)8 Cost (mage.abilities.costs.Cost)8