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;
}
Aggregations