Skip to main content

manabrew_engine/spellability/
ability_sub.rs

1//! AbilitySub -- helper functions for sub-abilities in the chain.
2//! Mirrors Java's `AbilitySub.java`.
3//! Sub-abilities are chained via SpellAbility.sub_ability and resolve
4//! sequentially after their parent.
5
6use crate::spellability::SpellAbility;
7
8/// Sub-abilities cannot be played independently -- they are always part of a
9/// chain triggered by a parent spell or ability.
10/// Mirrors Java's `AbilitySub.canPlay()` which returns false.
11pub fn can_play() -> bool {
12    false
13}
14
15/// Build a stack description for this sub-ability from its params.
16/// Mirrors Java's `AbilitySub.getStackDescription()`.
17///
18/// Uses the `SpDesc` or `StackDescription` param if available, otherwise
19/// falls back to the ability text.
20pub fn resolve(sa: &SpellAbility) -> String {
21    // Prefer explicit stack description
22    if !sa.stack_description.is_empty() {
23        return sa.stack_description.clone();
24    }
25
26    // Try SpDesc param
27    if let Some(desc) = sa.ir.sp_desc_text.as_deref() {
28        return desc.to_string();
29    }
30
31    // Try StackDescription param
32    if let Some(desc) = sa.ir.stack_description_text.as_deref() {
33        return desc.to_string();
34    }
35
36    // Fall back to the ability text
37    if !sa.ability_text.is_empty() {
38        return sa.ability_text.clone();
39    }
40
41    // Last resort: describe via API type
42    match sa.api {
43        Some(api) => format!("{api:?} (sub-ability)"),
44        None => "Sub-ability".to_string(),
45    }
46}