Search in sources :

Example 6 with Spell

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

the class ChefsKissApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getSpell(source.getFirstTarget());
    if (spell == null) {
        return false;
    }
    spell.setControllerId(source.getControllerId());
    List<UUID> possibleTargets = new ArrayList<>(game.getState().getPlayersInRange(source.getControllerId(), game));
    possibleTargets.remove(source.getControllerId());
    game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(p -> !p.isControlledBy(source.getControllerId())).map(MageItem::getId).forEach(possibleTargets::add);
    possibleTargets.removeIf(uuid -> !spell.canTarget(game, uuid));
    StackObjectCopyApplier applier;
    MageObjectReferencePredicate predicate;
    if (possibleTargets.isEmpty()) {
        applier = null;
        predicate = null;
    } else {
        applier = new ChefsKissApplier(possibleTargets.get(RandomUtil.nextInt(possibleTargets.size())), game);
        predicate = new MageObjectReferencePredicate(new MageObjectReference(possibleTargets.get(RandomUtil.nextInt(possibleTargets.size())), game));
    }
    spell.createCopyOnStack(game, source, source.getControllerId(), false, 1, applier);
    if (predicate != null) {
        spell.chooseNewTargets(game, source.getControllerId(), true, true, predicate);
    }
    return true;
}
Also used : MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) StackObjectCopyApplier(mage.util.functions.StackObjectCopyApplier) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) MageObjectReference(mage.MageObjectReference)

Example 7 with Spell

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

the class CounterbalanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
        if (spell != null) {
            Card topcard = controller.getLibrary().getFromTop(game);
            if (topcard != null) {
                CardsImpl cards = new CardsImpl();
                cards.add(topcard);
                controller.revealCards(sourcePermanent.getName(), cards, game);
                if (topcard.getManaValue() == spell.getManaValue()) {
                    return game.getStack().counter(spell.getId(), source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Spell(mage.game.stack.Spell) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 8 with Spell

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

the class DeflectingPalmEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionData = preventDamageAction(event, source, game);
    this.used = true;
    // only one use
    this.discard();
    if (preventionData.getPreventedDamage() > 0) {
        MageObject damageDealingObject = game.getObject(target.getFirstTarget());
        UUID objectControllerId = null;
        if (damageDealingObject instanceof Permanent) {
            objectControllerId = ((Permanent) damageDealingObject).getControllerId();
        } else if (damageDealingObject instanceof Ability) {
            objectControllerId = ((Ability) damageDealingObject).getControllerId();
        } else if (damageDealingObject instanceof Spell) {
            objectControllerId = ((Spell) damageDealingObject).getControllerId();
        }
        if (objectControllerId != null) {
            Player objectController = game.getPlayer(objectControllerId);
            if (objectController != null) {
                objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
            }
        }
    }
    return true;
}
Also used : Ability(mage.abilities.Ability) PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 9 with Spell

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

the class IncreasingSavageryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int amount = 5;
    Spell spell = (Spell) game.getStack().getStackObject(source.getSourceId());
    if (spell != null) {
        if (spell.getFromZone() == Zone.GRAVEYARD) {
            amount = 10;
        }
        Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
        if (permanent != null) {
            permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Spell(mage.game.stack.Spell)

Example 10 with Spell

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

the class IncreasingDevotionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int amount = 5;
    Spell spell = (Spell) game.getStack().getStackObject(source.getSourceId());
    if (spell != null) {
        if (spell.getFromZone() == Zone.GRAVEYARD) {
            amount = 10;
        }
        token.putOntoBattlefield(amount, game, source, source.getControllerId());
        return true;
    }
    return false;
}
Also used : 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