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