1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use forge_foundation::ZoneType;
use super::{matches_valid_cards_for_sa, EffectContext};
use crate::ids::CardId;
/// End-of-turn revert for must-block. Mirrors the `GameCommand.run()` in Java
/// `MustBlockEffect` that clears the must-block flag when the effect expires.
pub fn run(game: &mut crate::game::GameState, card_id: crate::ids::CardId) {
if game.card(card_id).zone == ZoneType::Battlefield {
game.card_mut(card_id).set_must_block(false);
}
}
/// `SP$ MustBlock` — target creature must block this turn if able.
///
/// Mirrors Java's `MustBlockEffect.java` (simplified — sets flag only;
/// full "must block specific attacker" support deferred).
///
/// # Card script examples
/// ```text
/// A:SP$ MustBlock | ValidTgts$ Creature
/// A:SP$ MustBlock | Defined$ Targeted
/// A:SP$ MustBlock | ValidCards$ Creature.OppCtrl
/// ```
/// Struct form of this effect so it can participate in the
/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
/// `MustBlockEffect` class extending `SpellAbilityEffect`.
#[manabrew_engine_macros::spell_effect(MustBlockEffect)]
fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
// Targeted mode
if let Some(target) = sa.target_chosen.target_card {
if ctx.game.card(target).zone == ZoneType::Battlefield {
ctx.game.card_mut(target).set_must_block(true);
}
return;
}
// ValidCards$ mode (mass must-block)
if let Some(valid_filter) = sa.ir.valid_cards_text.as_deref() {
let valid_selector = sa.ir.valid_cards_selector.as_ref();
let player_ids = ctx.game.player_order.clone();
let mut targets: Vec<CardId> = Vec::new();
for &pid in &player_ids {
let zone_cards = ctx.game.cards_in_zone(ZoneType::Battlefield, pid).to_vec();
for cid in zone_cards {
if matches_valid_cards_for_sa(
ctx.game,
sa,
ctx.game.card(cid),
valid_selector,
valid_filter,
) {
targets.push(cid);
}
}
}
for cid in targets {
if ctx.game.card(cid).zone == ZoneType::Battlefield {
ctx.game.card_mut(cid).set_must_block(true);
}
}
return;
}
// Defined$ Self
if let Some(source) = sa.source {
if ctx.game.card(source).zone == ZoneType::Battlefield {
ctx.game.card_mut(source).set_must_block(true);
}
}
}