Search in sources :

Example 26 with Spell

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

the class ReturnToHandSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    MageObject mageObject;
    if (returnFromNextZone && game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter() + 1) {
        mageObject = game.getObject(source.getSourceId());
    } else {
        mageObject = source.getSourceObjectIfItStillExists(game);
    }
    if (mageObject == null) {
        return true;
    }
    switch(game.getState().getZone(mageObject.getId())) {
        case BATTLEFIELD:
            Permanent permanent = game.getPermanent(source.getSourceId());
            if (permanent != null && permanent.isPhasedIn()) {
                return controller.moveCards(permanent, Zone.HAND, source, game);
            }
            break;
        case GRAVEYARD:
            Card card = (Card) mageObject;
            return !fromBattlefieldOnly && controller.moveCards(card, Zone.HAND, source, game);
        case STACK:
            Spell spell = game.getSpell(source.getSourceId());
            return !fromBattlefieldOnly && spell != null && controller.moveCards(spell.getMainCard(), Zone.HAND, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 27 with Spell

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

the class ReturnToHandTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<UUID> copyIds = new ArrayList<>();
    Set<Card> cards = new LinkedHashSet<>();
    if (multitargetHandling) {
        for (Target target : source.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                MageObject mageObject = game.getObject(targetId);
                if (mageObject instanceof Spell && mageObject.isCopy()) {
                    copyIds.add(targetId);
                } else if (mageObject instanceof Card) {
                    cards.add((Card) mageObject);
                }
            }
        }
    } else {
        for (UUID targetId : targetPointer.getTargets(game, source)) {
            MageObject mageObject = game.getObject(targetId);
            if (mageObject != null) {
                if (mageObject instanceof Spell && mageObject.isCopy()) {
                    copyIds.add(targetId);
                } else if (mageObject instanceof Card) {
                    cards.add((Card) mageObject);
                }
            }
        }
    }
    for (UUID copyId : copyIds) {
        game.getStack().remove(game.getSpell(copyId), game);
    }
    return controller.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 28 with Spell

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

the class ImproviseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Spell spell = game.getStack().getSpell(source.getSourceId());
    if (controller != null && spell != null) {
        for (UUID artifactId : this.getTargetPointer().getTargets(game, source)) {
            Permanent perm = game.getPermanent(artifactId);
            if (perm == null) {
                continue;
            }
            if (!perm.isTapped() && perm.tap(source, game)) {
                ManaPool manaPool = controller.getManaPool();
                manaPool.addMana(Mana.ColorlessMana(1), game, source);
                manaPool.unlockManaType(ManaType.COLORLESS);
                if (!game.isSimulation()) {
                    game.informPlayers("Improvise: " + controller.getLogName() + " taps " + perm.getLogName() + " to pay {1}");
                }
                // can't use mana abilities after that (improvise cost must be payed after mana abilities only)
                spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.AFTER);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ManaPool(mage.players.ManaPool) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 29 with Spell

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

the class ReboundCastSpellFromExileEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Spell sourceSpell = game.getStack().getSpell(source.getSourceId());
    if (sourceSpell != null && sourceSpell.isCopy()) {
        return false;
    } else {
        Card sourceCard = game.getCard(source.getSourceId());
        if (sourceCard != null) {
            Player player = game.getPlayer(sourceCard.getOwnerId());
            if (player != null) {
                // Add the delayed triggered effect
                ReboundEffectCastFromExileDelayedTrigger trigger = new ReboundEffectCastFromExileDelayedTrigger(source.getSourceId(), source.getSourceId());
                game.addDelayedTriggeredAbility(trigger, source);
                player.moveCardToExileWithInfo(sourceCard, sourceCard.getId(), player.getName() + " Rebound", source, game, Zone.STACK, true);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 30 with Spell

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

the class ReplicateCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Spell spell = (Spell) this.getValue("ReplicateSpell");
        int replicateCount = (Integer) this.getValue("ReplicateCount");
        if (spell != null && replicateCount > 0) {
            // reset replicate now so the copies don't report x times Replicate
            Card card = game.getCard(spell.getSourceId());
            if (card != null) {
                for (Ability ability : card.getAbilities(game)) {
                    if (ability instanceof ReplicateAbility) {
                        if (ability.isActivated()) {
                            ((ReplicateAbility) ability).resetReplicate();
                        }
                    }
                }
            }
            // create the copies
            spell.createCopyOnStack(game, source, source.getControllerId(), true, replicateCount);
            return true;
        }
    }
    return false;
}
Also used : StaticAbility(mage.abilities.StaticAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

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