Skip to main content

manabrew_engine/ability/effects/
permanent_creature_effect.rs

1//! PermanentCreature — move host card to battlefield as a creature permanent.
2//! Ported from Java's PermanentCreatureEffect.
3
4use super::EffectContext;
5use crate::game::GameState;
6use crate::spellability::SpellAbility;
7
8/// Struct form of this effect so it can participate in the
9/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
10/// `PermanentCreatureEffect` class extending `SpellAbilityEffect`.
11#[manabrew_engine_macros::spell_effect(PermanentCreatureEffect)]
12fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
13    super::permanent_effect::resolve_permanent_common(ctx, sa);
14}
15
16/// Stack text formatted as `"{Name} - Creature {P}/{T}"`, mirroring Java
17/// `PermanentCreatureEffect.getStackDescription(SpellAbility)`.
18pub fn get_stack_description(game: &GameState, sa: &SpellAbility) -> String {
19    let Some(src_id) = sa.source else {
20        return String::new();
21    };
22    let card = game.card(src_id);
23    let power = sa
24        .ir
25        .set_power
26        .clone()
27        .or_else(|| card.base_power.map(|p| p.to_string()))
28        .unwrap_or_else(|| "*".to_string());
29    let toughness = sa
30        .ir
31        .set_toughness
32        .clone()
33        .or_else(|| card.base_toughness.map(|t| t.to_string()))
34        .unwrap_or_else(|| "*".to_string());
35    format!("{} - Creature {}/{}", card.card_name, power, toughness)
36}