manabrew_engine/ability/spell_api_based.rs
1//! SpellApiBased — spell abilities backed by an API type.
2//!
3//! Mirrors Java's `SpellApiBased.java`.
4//! A spell (as opposed to an activated ability) whose resolution is
5//! dispatched through the effect system based on its `ApiType`.
6
7use crate::spellability::SpellAbility;
8
9/// Marker trait for API-based spell abilities.
10///
11/// In Java, `SpellApiBased extends Spell` and holds a reference to
12/// `SpellAbilityEffect`. In Rust the dispatch is centralized in
13/// `effect_dispatch!`, so this provides structural parity.
14pub trait SpellApiBased {
15 /// The API type string (e.g. "DealDamage", "GainLife").
16 fn api_type(&self) -> &str;
17
18 /// Whether this spell is intrinsic to its card.
19 fn is_intrinsic(&self) -> bool {
20 true
21 }
22
23 /// Resolve this spell by dispatching to the effect system.
24 fn resolve(&self, sa: &SpellAbility);
25}
26
27/// Build a spell ability for an API-based spell.
28/// Mirrors Java's `SpellApiBased` constructor which creates a Spell with
29/// an associated SpellAbilityEffect.
30///
31/// In the Rust engine, this delegates to `ability_factory::build_spell_ability`
32/// since the effect dispatch is centralized.
33pub fn build_spell_ability(
34 game: &crate::game::GameState,
35 card_id: crate::ids::CardId,
36 ability_text: &str,
37 player: crate::ids::PlayerId,
38) -> SpellAbility {
39 crate::ability::ability_factory::build_spell_ability(game, card_id, ability_text, player)
40}
41
42/// Resolve an API-based spell ability.
43/// Mirrors Java's `SpellApiBased.resolve()` which delegates to its SpellAbilityEffect.
44///
45/// In the Rust engine, resolution is centralized in `effects::resolve_effect`.
46pub fn resolve(ctx: &mut crate::ability::effects::EffectContext, sa: &SpellAbility) {
47 crate::ability::effects::resolve_effect(ctx, sa);
48}