Skip to main content

manabrew_engine/ability/effects/
block_effect.rs

1//! Block effect — force a creature to block a specific attacker.
2//!
3//! Ported from Java's `BlockEffect.java`.
4//! Target creature blocks target attacker this combat if able.
5
6use forge_foundation::ZoneType;
7
8use super::EffectContext;
9use crate::ability::ability_ir::DefinedRef;
10
11/// Struct form of this effect so it can participate in the
12/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
13/// `BlockEffect` class extending `SpellAbilityEffect`.
14#[manabrew_engine_macros::spell_effect(BlockEffect)]
15fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
16    let targets: Vec<crate::ids::CardId> = if sa.uses_targeting() {
17        sa.target_chosen.target_card.into_iter().collect()
18    } else if let Some(def) = sa.defined_ref() {
19        if matches!(def, DefinedRef::SelfCard) {
20            sa.source.into_iter().collect()
21        } else {
22            Vec::new()
23        }
24    } else {
25        Vec::new()
26    };
27
28    for card_id in targets {
29        if ctx.game.card(card_id).zone != ZoneType::Battlefield {
30            continue;
31        }
32        // Mark creature as "must block" — the combat system checks this flag
33        ctx.game.card_mut(card_id).set_must_block(true);
34    }
35}