Package mage.game.stack

Examples of mage.game.stack.Spell


        this.onlyOneTarget = effect.onlyOneTarget;
    }

    @Override
    public boolean apply(Game game, Ability source) {
        Spell spell = game.getStack().getSpell(source.getFirstTarget());
        if (spell != null) {
            return spell.chooseNewTargets(game, source.getControllerId(), forceChange, onlyOneTarget);
        }
        return false;
    }
View Full Code Here


    @Override
    public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) {
        if (targets.choose(Outcome.Exile, controllerId, sourceId, game)) {
            Player player = game.getPlayer(controllerId);
            for (UUID targetId: targets.get(0).getTargets()) {
                Spell spellToExile = game.getStack().getSpell(targetId);
                if (spellToExile == null) {
                    return false;
                }
                paid |= spellToExile.moveToExile(null, "", ability.getSourceId(), game);
                if (paid) {
                    game.informPlayers(player.getName() + " exiles " + spellToExile.getName() +" (as costs)");
                }
            }
        }
        return paid;
    }
View Full Code Here

        }

        //Only 'install' the effect on a successfully cast spell otherwise the user
        //may cancel before paying its costs and potentially having two copies rebound
        if (event.getType() == EventType.SPELL_CAST && this.installReboundEffect) {
            Spell spell = game.getStack().getSpell(event.getTargetId());
            if (spell != null && spell.getSourceId().equals(this.getSourceId())) {
                Effect reboundEffect = new ReboundEffect();
                boolean found = false;
                for (Effect effect : spell.getSpellAbility().getEffects()) {
                    if (effect instanceof ReboundEffect) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    spell.getSpellAbility().addEffect(reboundEffect);
                }
                this.installReboundEffect = false;
            }
        }
        return false;
View Full Code Here

    }

    @Override
    public boolean checkTrigger(GameEvent event, Game game) {
        if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getPlayerId().equals(this.getControllerId())) {
            Spell spell = game.getStack().getSpell(event.getTargetId());
            if (checkSpell(spell, game)) {
                return true;
            }
        }
        return false;
View Full Code Here

        super(effect);
    }

    @Override
    public boolean apply(Game game, Ability source) {
        Spell sourceSpell = (Spell) game.getObject(source.getId());
        if (sourceSpell == null || !sourceSpell.isCopiedSpell()) {
            MageObject mageObject = game.getObject(source.getSourceId());
            if (mageObject instanceof StackObject) {
                StackObject sourceCard = (StackObject) mageObject;
                ReboundEffectCastFromExileDelayedTrigger trigger = new ReboundEffectCastFromExileDelayedTrigger(sourceCard.getSourceId(), sourceCard.getSourceId());
                trigger.setControllerId(source.getControllerId());
View Full Code Here

        return new ReboundCastFromHandReplacementEffect(this);
    }

    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
        Spell sourceSpell = (Spell) game.getObject(source.getId());
        if (sourceSpell != null && sourceSpell.isCopiedSpell()) {
            return false;
        } else {
            Card sourceCard = (Card) game.getObject(source.getSourceId());
            Player player = game.getPlayer(sourceCard.getOwnerId());
            if (player != null) {
View Full Code Here

                Permanent targetPermanent = (Permanent)targetCard;
                controller = game.getPlayer(targetPermanent.getControllerId());
            }
            //Handles interaction with spells that were on the stack.
            else if ( targetCard instanceof Spell ) {
                Spell targetSpell = (Spell)targetCard;
                controller = game.getPlayer(targetSpell.getControllerId());
            }

            if ( controller != null ) {
                controller.loseLife(amount, game);
                return true;
View Full Code Here

        if (card != null) {
            if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId))) {
                int bookmark = game.bookmarkState();
                Zone fromZone = game.getState().getZone(card.getId());
                card.cast(game, fromZone, ability, playerId);
                Spell spell = game.getStack().getSpell(ability.getId());
                // some effects set sourceId to cast without paying mana costs
                if (ability.getSourceId().equals(getCastSourceIdWithoutMana())) {
                    noMana = true;
                }
                setCastSourceIdWithoutMana(null);
                if (spell.activate(game, noMana)) {
                    GameEvent event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId);
                    event.setZone(fromZone);
                    game.fireEvent(event);
                    game.informPlayers(new StringBuilder(name).append(spell.getActivatedMessage(game)).toString());
                    game.removeBookmark(bookmark);
                    resetStoredBookmark(game);
                    return true;
                }
                game.restoreState(bookmark, ability.getRule());
View Full Code Here

    @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()) {
                        if (ability instanceof ReplicateAbility) {
                            if (((ReplicateAbility) ability).isActivated()) {
                                ((ReplicateAbility) ability).resetReplicate();
                            }
                        }
                    }
                }
                // create the copies
                for (int i = 0; i < replicateCount; i++) {
                    Spell copy = spell.copySpell();
                    copy.setControllerId(source.getControllerId());
                    copy.setCopiedSpell(true);
                    game.getStack().push(copy);
                    copy.chooseNewTargets(game, source.getControllerId());
                    game.informPlayers(new StringBuilder(controller.getName()).append(copy.getActivatedMessage(game)).toString());
                }
                return true;
            }

        }
View Full Code Here

                } else {
                    sb.append(object.getName());
                }
            } else {
                if (object instanceof Spell) {
                    Spell spell = (Spell) object;
                    String castText = spell.getSpellCastText(game);
                    sb.append((castText.startsWith("Cast ") ? castText.substring(5):castText));
                    if (spell.getFromZone() == Zone.GRAVEYARD) {
                        sb.append(" from graveyard");
                    }
                    sb.append(getOptionalTextSuffix(game, spell));
                } else {
                    sb.append(object.getLogName());
                }
            }
        } else {
            sb.append("unknown");
        }
        if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) {
            if (((Spell) object).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) {
                Spell spell = (Spell) object;
                int i = 0;
                for (SpellAbility spellAbility : spell.getSpellAbilities()) {
                    i++;
                    String half;
                    if (i == 1) {
                        half = " left";
                    } else {
                        half = " right";
                    }
                    if (spellAbility.getTargets().size() > 0) {
                        sb.append(half).append(" half targeting ");
                        for (Target target: spellAbility.getTargets()) {
                            sb.append(target.getTargetedName(game));
                        }
                    }
                }
            } else {
                Spell spell = (Spell) object;
                int i = 0;
                for (SpellAbility spellAbility : spell.getSpellAbilities()) {
                    i++;
                    if ( i > 1) {
                        sb.append(" splicing ");
                        if (spellAbility.name.length() > 5 && spellAbility.name.startsWith("Cast ")) {
                            sb.append(spellAbility.name.substring(5));
View Full Code Here

TOP

Related Classes of mage.game.stack.Spell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.