manabrew_engine/ability/effects/control_spell_effect.rs
1//! ControlSpell effect — gain control of a spell on the stack.
2//!
3//! Ported from Java's `ControlSpellEffect.java`.
4//! Gain control of target spell. You may choose new targets for it.
5
6use super::EffectContext;
7use crate::spellability::SpellAbility;
8
9/// Configure the spell ability during construction.
10/// Mirrors Java `ControlSpellEffect.buildSpellAbility` — sets the target zone
11/// to Stack so the ability targets spells on the stack.
12pub fn build_spell_ability(sa: &mut SpellAbility) {
13 if sa.uses_targeting() {
14 if let Some(ref mut tr) = sa.target_restrictions {
15 tr.tgt_zone = vec![forge_foundation::ZoneType::Stack];
16 }
17 }
18}
19
20/// Struct form of this effect so it can participate in the
21/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
22/// `ControlSpellEffect` class extending `SpellAbilityEffect`.
23#[manabrew_engine_macros::spell_effect(ControlSpellEffect)]
24fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
25 let controller = sa.activating_player;
26
27 // Find the targeted spell on the stack and change its controller
28 if let Some(target_card) = sa.target_chosen.target_card {
29 if ctx.game.card(target_card).zone == forge_foundation::ZoneType::Stack {
30 ctx.game.card_mut(target_card).set_controller(controller);
31 // The stack entry's activating_player should also change
32 // but MagicStack doesn't expose mutable entries easily.
33 // The controller change on the card handles most game mechanics.
34 }
35 }
36}