Search in sources :

Example 1 with ReplicateAbility

use of mage.abilities.keyword.ReplicateAbility in project mage by magefree.

the class DjinnIlluminatusGainReplicateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent djinn = game.getPermanent(source.getSourceId());
    if (djinn == null) {
        return false;
    }
    for (StackObject stackObject : game.getStack()) {
        // only spells cast, so no copies of spells
        if ((stackObject instanceof Spell) && !stackObject.isCopy() && stackObject.isControlledBy(source.getControllerId()) && // verify that the controller of the djinn cast that spell
        djinn.isControlledBy(source.getControllerId()) && !stackObject.getManaCost().isEmpty()) {
            // handle cases like Ancestral Vision
            Spell spell = (Spell) stackObject;
            if (filter.match(stackObject, game)) {
                ReplicateAbility replicateAbility = replicateAbilities.computeIfAbsent(spell.getId(), k -> new ReplicateAbility(spell.getCard(), spell.getSpellAbility().getManaCosts().getText()));
                // Do not copy because paid and # of activations state is handled in the baility
                game.getState().addOtherAbility(spell.getCard(), replicateAbility, false);
            }
        }
    }
    if (game.getStack().isEmpty()) {
        replicateAbilities.clear();
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) FilterInstantOrSorcerySpell(mage.filter.common.FilterInstantOrSorcerySpell) Spell(mage.game.stack.Spell) ReplicateAbility(mage.abilities.keyword.ReplicateAbility)

Aggregations

ReplicateAbility (mage.abilities.keyword.ReplicateAbility)1 FilterInstantOrSorcerySpell (mage.filter.common.FilterInstantOrSorcerySpell)1 Permanent (mage.game.permanent.Permanent)1 Spell (mage.game.stack.Spell)1 StackObject (mage.game.stack.StackObject)1