Skip to main content

weiss_core/effects/
id.rs

1use serde::{Deserialize, Serialize};
2
3use crate::db::CardId;
4use crate::state::TargetSpec;
5
6/// Source category for an effect.
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum EffectSourceKind {
9    /// Trigger resolution.
10    Trigger,
11    /// Auto ability.
12    Auto,
13    /// Activated ability.
14    Activated,
15    /// Continuous modifier.
16    Continuous,
17    /// Event card play.
18    EventPlay,
19    /// Counter timing.
20    Counter,
21    /// Replacement effect.
22    Replacement,
23    /// System-generated effect.
24    System,
25}
26
27/// Stable identifier for an effect instance.
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
29pub struct EffectId {
30    /// Effect source category.
31    pub source_kind: EffectSourceKind,
32    /// Source card id (0 means none; see EffectSourceKind).
33    pub source_card: CardId,
34    /// Ability index on the source card.
35    pub ability_index: u8,
36    /// Effect index within the ability.
37    pub effect_index: u8,
38}
39
40impl EffectId {
41    /// Build an effect id from its components.
42    pub fn new(
43        source_kind: EffectSourceKind,
44        source_card: CardId,
45        ability_index: u8,
46        effect_index: u8,
47    ) -> Self {
48        Self {
49            source_kind,
50            source_card,
51            ability_index,
52            effect_index,
53        }
54    }
55}
56
57/// Fully specified effect with targeting metadata.
58#[derive(Clone, Debug, Hash, Serialize, Deserialize)]
59pub struct EffectSpec {
60    /// Stable effect id.
61    pub id: EffectId,
62    /// Effect kind.
63    pub kind: super::EffectKind,
64    /// Optional target specification.
65    pub target: Option<TargetSpec>,
66    /// Whether this effect is optional.
67    pub optional: bool,
68}