manabrew_engine/spellability/ability_static.rs
1//! AbilityStatic -- helper functions for static abilities (e.g. morph face-up).
2//! Mirrors Java's `AbilityStatic.java`.
3//! Static abilities are special actions that don't use the stack (like turning
4//! a morph face-up).
5
6use forge_foundation::ZoneType;
7
8use crate::game::GameState;
9use crate::spellability::SpellAbility;
10
11/// Type alias for SpellAbility when used as a static ability.
12/// In Java, `AbilityStatic` is a subclass; in Rust it's the same struct.
13pub type AbilityStatic = super::SpellAbility;
14
15/// Whether this static ability can currently be played.
16/// Mirrors Java's `AbilityStatic.canPlay()`.
17///
18/// The primary use case is morph/megamorph turn-face-up: the card must be
19/// face-down on the battlefield, and the player must be able to pay the cost.
20pub fn can_play(sa: &SpellAbility, game: &GameState) -> bool {
21 let card_id = match sa.source {
22 Some(id) => id,
23 None => return false,
24 };
25
26 let card = game.card(card_id);
27
28 // For morph turn-face-up: card must be face-down on the battlefield
29 if sa.ir.morph || sa.ir.morph_up || sa.ir.megamorph {
30 // Must be on the battlefield
31 if !game.card_is_in_zone(card_id, ZoneType::Battlefield) {
32 return false;
33 }
34 // Must be face-down
35 if !card.face_down {
36 return false;
37 }
38 }
39
40 // Split second does NOT prevent special actions like turning morphs face-up
41 // (rule 702.37a: "Split second doesn't prevent special actions")
42
43 // General restriction check
44 sa.can_play(game)
45}