manabrew_engine/ability/effects/remove_from_combat_effect.rs
1use forge_foundation::ZoneType;
2
3use super::EffectContext;
4use crate::ability::ability_ir::DefinedRef;
5
6/// `SP$ RemoveFromCombat` — remove target creature from combat.
7///
8/// Mirrors Java's `RemoveFromCombatEffect.java`.
9/// Simply untaps the creature and removes all combat assignments.
10/// The game loop's combat state tracks attackers/blockers externally,
11/// so this effect sets the card's tapped state to false and the game loop
12/// handles the rest through CombatState filtering.
13///
14/// # Card script examples
15/// ```text
16/// A:SP$ RemoveFromCombat | ValidTgts$ Creature
17/// ```
18/// Struct form of this effect so it can participate in the
19/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
20/// `RemoveFromCombatEffect` class extending `SpellAbilityEffect`.
21#[manabrew_engine_macros::spell_effect(RemoveFromCombatEffect)]
22fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
23 let target = sa
24 .target_chosen
25 .target_card
26 .or_else(|| match sa.defined_ref() {
27 Some(DefinedRef::SelfCard) => sa.source,
28 Some(DefinedRef::ParentTarget) => ctx.parent_target_card,
29 _ => None,
30 });
31
32 if let Some(card_id) = target {
33 if ctx.game.card(card_id).zone == ZoneType::Battlefield {
34 // Untap the creature (removed from combat means it won't deal/receive combat damage)
35 ctx.game.card_mut(card_id).set_tapped(false);
36 }
37 }
38}