Search in sources :

Example 86 with Spell

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

the class SorcererClassWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = (Spell) getValue("spellCast");
    if (spell == null) {
        return false;
    }
    int count = SorcererClassWatcher.spellCount(source.getControllerId(), game);
    if (count < 1) {
        return false;
    }
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        player.damage(count, spell.getId(), source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 87 with Spell

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

the class StringOfDisappearancesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    Player affectedPlayer = game.getPlayer(permanent.getControllerId());
    new ReturnToHandTargetEffect().apply(game, source);
    if (affectedPlayer == null) {
        return false;
    }
    if (!affectedPlayer.chooseUse(Outcome.Copy, "Pay {U}{U} to copy the spell?", source, game)) {
        return true;
    }
    Cost cost = new ManaCostsImpl("{U}{U}");
    if (!cost.pay(source, game, source, affectedPlayer.getId(), false, null)) {
        return true;
    }
    Spell spell = game.getStack().getSpell(source.getSourceId());
    if (spell == null) {
        return true;
    }
    spell.createCopyOnStack(game, source, affectedPlayer.getId(), true);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Spell(mage.game.stack.Spell)

Example 88 with Spell

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

the class TemporalExtortionCounterSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null) {
        for (UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.chooseUse(outcome, "Pay half your life, rounded up to counter " + sourceObject.getIdName() + '?', source, game)) {
                int amount = (int) Math.ceil(player.getLife() / 2f);
                player.loseLife(amount, game, source, false);
                game.informPlayers(player.getLogName() + " pays half their life, rounded up to counter " + sourceObject.getIdName() + '.');
                Spell spell = game.getStack().getSpell(source.getSourceId());
                if (spell != null) {
                    game.getStack().counter(spell.getId(), source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 89 with Spell

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

the class AbilityImpl method getMessageText.

protected String getMessageText(Game game) {
    StringBuilder sb = threadLocalBuilder.get();
    MageObject object = game.getObject(this.sourceId);
    if (object != null) {
        if (object instanceof StackAbility) {
            Card card = game.getCard(((StackAbility) object).getSourceId());
            if (card != null) {
                sb.append(GameLog.getColoredObjectIdName(card));
            } else {
                sb.append(GameLog.getColoredObjectIdName(object));
            }
        } 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(GameLog.getColoredObjectIdName(object));
        }
    } else {
        sb.append("unknown");
    }
    if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) {
        if (((Spell) object).getSpellAbility().getSpellAbilityType() == 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().isEmpty()) {
                    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));
                    } else {
                        sb.append(spellAbility.name);
                    }
                }
                sb.append(getTargetDescriptionForLog(spellAbility.getTargets(), game));
            }
        }
    } else if (object instanceof Spell && ((Spell) object).getSpellAbility().getModes().size() > 1) {
        Modes spellModes = ((Spell) object).getSpellAbility().getModes();
        for (UUID selectedModeId : spellModes.getSelectedModes()) {
            Mode selectedMode = spellModes.get(selectedModeId);
            int item = 0;
            for (Mode mode : spellModes.values()) {
                item++;
                if (mode.getId().equals(selectedMode.getId())) {
                    sb.append(" (mode ").append(item).append(')');
                    sb.append(getTargetDescriptionForLog(selectedMode.getTargets(), game));
                    break;
                }
            }
        }
    } else {
        sb.append(getTargetDescriptionForLog(getTargets(), game));
    }
    return sb.toString();
}
Also used : Target(mage.target.Target) ThreadLocalStringBuilder(mage.util.ThreadLocalStringBuilder) MageObject(mage.MageObject) UUID(java.util.UUID) StackAbility(mage.game.stack.StackAbility) Spell(mage.game.stack.Spell) Hint(mage.abilities.hint.Hint) SplitCard(mage.cards.SplitCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 90 with Spell

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

the class AdventureCastFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Spell spell = game.getStack().getSpell(source.getId());
        if (spell != null) {
            Card spellCard = spell.getCard();
            if (spellCard instanceof AdventureCardSpell) {
                UUID exileId = adventureExileId(controller.getId(), game);
                game.getExile().createZone(exileId, "On an Adventure from " + controller.getName());
                AdventureCardSpell adventureSpellCard = (AdventureCardSpell) spellCard;
                Card parentCard = adventureSpellCard.getParentCard();
                if (controller.moveCardsToExile(parentCard, source, game, true, exileId, "On an Adventure from " + controller.getName())) {
                    ContinuousEffect effect = new AdventureCastFromExileEffect();
                    effect.setTargetPointer(new FixedTarget(parentCard, game));
                    game.addEffect(effect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AdventureCardSpell(mage.cards.AdventureCardSpell) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) Spell(mage.game.stack.Spell) AdventureCardSpell(mage.cards.AdventureCardSpell) 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