manabrew_engine/spellability/
runtime_types.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4pub enum SpellAbilityMode {
5 Increase,
6 Decrease,
7 Transform,
8 Flip,
9 TurnFaceUp,
10 TurnFaceDown,
11 ThisDoor,
12 Unlock,
13 LockOrUnlock,
14 Unsupported(String),
15}
16
17impl SpellAbilityMode {
18 pub fn parse(raw: &str) -> Self {
19 match raw {
20 "Increase" => Self::Increase,
21 "Decrease" => Self::Decrease,
22 "Transform" => Self::Transform,
23 "Flip" => Self::Flip,
24 "TurnFaceUp" => Self::TurnFaceUp,
25 "TurnFaceDown" => Self::TurnFaceDown,
26 "ThisDoor" => Self::ThisDoor,
27 "Unlock" => Self::Unlock,
28 "LockOrUnlock" => Self::LockOrUnlock,
29 other => Self::Unsupported(other.to_string()),
30 }
31 }
32}
33
34impl std::fmt::Display for SpellAbilityMode {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 match self {
37 Self::Increase => write!(f, "Increase"),
38 Self::Decrease => write!(f, "Decrease"),
39 Self::Transform => write!(f, "Transform"),
40 Self::Flip => write!(f, "Flip"),
41 Self::TurnFaceUp => write!(f, "TurnFaceUp"),
42 Self::TurnFaceDown => write!(f, "TurnFaceDown"),
43 Self::ThisDoor => write!(f, "ThisDoor"),
44 Self::Unlock => write!(f, "Unlock"),
45 Self::LockOrUnlock => write!(f, "LockOrUnlock"),
46 Self::Unsupported(raw) => write!(f, "{raw}"),
47 }
48 }
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52pub enum AbilityDuration {
53 UntilHostLeavesPlay,
54 UntilHostLeavesPlayOrEot,
55 UntilLoseControlOfHost,
56 UntilUntaps,
57 UntilTargetedUntaps,
58 AsLongAsControl,
59 AsLongAsInPlay,
60 UntilYourNextTurn,
61 Permanent,
62 Perpetual,
63 Unsupported(String),
64}
65
66impl AbilityDuration {
67 pub fn parse(raw: &str) -> Self {
68 match raw {
69 "UntilHostLeavesPlay" => Self::UntilHostLeavesPlay,
70 "UntilHostLeavesPlayOrEOT" => Self::UntilHostLeavesPlayOrEot,
71 "UntilLoseControlOfHost" => Self::UntilLoseControlOfHost,
72 "UntilUntaps" => Self::UntilUntaps,
73 "UntilTargetedUntaps" => Self::UntilTargetedUntaps,
74 "AsLongAsControl" => Self::AsLongAsControl,
75 "AsLongAsInPlay" => Self::AsLongAsInPlay,
76 "UntilYourNextTurn" => Self::UntilYourNextTurn,
77 "Permanent" => Self::Permanent,
78 "Perpetual" => Self::Perpetual,
79 other => Self::Unsupported(other.to_string()),
80 }
81 }
82
83 pub fn needs_host_in_play_or_stack(&self) -> bool {
84 matches!(
85 self,
86 Self::UntilHostLeavesPlay
87 | Self::UntilHostLeavesPlayOrEot
88 | Self::UntilLoseControlOfHost
89 | Self::UntilUntaps
90 | Self::AsLongAsControl
91 | Self::AsLongAsInPlay
92 )
93 }
94
95 pub fn needs_host_not_phased_out(&self) -> bool {
96 matches!(self, Self::AsLongAsControl | Self::AsLongAsInPlay)
97 }
98
99 pub fn needs_host_control(&self) -> bool {
100 matches!(self, Self::UntilLoseControlOfHost | Self::AsLongAsControl)
101 }
102
103 pub fn needs_host_tapped(&self) -> bool {
104 matches!(self, Self::UntilUntaps)
105 }
106
107 pub fn needs_targeted_card_tapped(&self) -> bool {
108 matches!(self, Self::UntilTargetedUntaps)
109 }
110
111 pub fn returns_on_host_leave(&self) -> bool {
112 matches!(
113 self,
114 Self::UntilHostLeavesPlay | Self::UntilHostLeavesPlayOrEot | Self::UntilYourNextTurn
115 )
116 }
117}
118
119#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
120pub enum ReplaceDyingCondition {
121 Kicked,
122 Unsupported(String),
123}
124
125impl ReplaceDyingCondition {
126 pub fn parse(raw: &str) -> Self {
127 match raw {
128 "Kicked" => Self::Kicked,
129 other => Self::Unsupported(other.to_string()),
130 }
131 }
132}
133
134#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
135pub enum TriggerCondition {
136 Evolve,
137 LifePaid,
138 NoOpponentHasMoreLifeThanAttacked,
139 Sacrificed,
140 AttackedPlayerWithMostLife,
141 AttackerHasUnattackedOpp,
142 Unsupported(String),
143}
144
145impl TriggerCondition {
146 pub fn parse(raw: &str) -> Self {
147 match raw {
148 "Evolve" => Self::Evolve,
149 "LifePaid" => Self::LifePaid,
150 "NoOpponentHasMoreLifeThanAttacked" => Self::NoOpponentHasMoreLifeThanAttacked,
151 "Sacrificed" => Self::Sacrificed,
152 "AttackedPlayerWithMostLife" => Self::AttackedPlayerWithMostLife,
153 "AttackerHasUnattackedOpp" => Self::AttackerHasUnattackedOpp,
154 other => Self::Unsupported(other.to_string()),
155 }
156 }
157}