Skip to main content

manabrew_engine/ability/effects/
detached_card_effect.rs

1//! DetachedCardEffect — card effect data structure.
2//!
3//! Mirrors Java's `DetachedCardEffect.java`.
4//! Represents an effect that acts as its own card instead of being attached
5//! to a card. Examples include Commander Effects and Emblem effects.
6
7use crate::ids::{CardId, PlayerId};
8
9/// A detached card effect — an effect card that is not attached to
10/// any permanent but acts independently (e.g., commander zone effects, emblems).
11#[derive(Debug, Clone)]
12pub struct DetachedCardEffect {
13    /// The ID of this effect "card" in the game state.
14    pub id: CardId,
15    /// The card this effect is linked to (if any).
16    pub linked_card: Option<CardId>,
17    /// The owner/controller of this effect.
18    pub owner: PlayerId,
19    /// Display name for this effect.
20    pub name: String,
21}
22
23impl DetachedCardEffect {
24    /// Create a new detached card effect linked to a source card.
25    pub fn new(id: CardId, linked_card: CardId, owner: PlayerId, name: String) -> Self {
26        Self {
27            id,
28            linked_card: Some(linked_card),
29            owner,
30            name,
31        }
32    }
33
34    /// Create a new detached card effect with no linked card.
35    pub fn new_unlinked(id: CardId, owner: PlayerId, name: String) -> Self {
36        Self {
37            id,
38            linked_card: None,
39            owner,
40            name,
41        }
42    }
43
44    /// Get the card to display in the UI (the linked card, if any).
45    pub fn card_for_ui(&self) -> Option<CardId> {
46        self.linked_card
47    }
48}