manabrew_engine/ability/effects/
unattach_effect.rs1use super::EffectContext;
7use crate::ability::ability_ir::DefinedRef;
8use crate::ids::CardId;
9use forge_foundation::ZoneType;
10
11#[manabrew_engine_macros::spell_effect(UnattachEffect)]
15fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
16 let cards: Vec<CardId> = if sa.uses_targeting() {
18 sa.target_chosen.target_card.into_iter().collect()
19 } else if let Some(defined) = sa.defined_ref() {
20 if matches!(defined, DefinedRef::SelfCard) {
21 sa.source.into_iter().collect()
22 } else {
23 Vec::new()
24 }
25 } else {
26 sa.source.into_iter().collect()
27 };
28
29 for card_id in cards {
30 if ctx.game.card(card_id).zone != ZoneType::Battlefield {
31 continue;
32 }
33
34 let attached_to = ctx.game.card(card_id).attached_to;
36 if let Some(host_id) = attached_to {
37 ctx.game.card_mut(host_id).remove_attachment(card_id);
39 ctx.game.card_mut(card_id).set_attached_to(None);
41 }
42 }
43}