manabrew_engine/card/
alt_costs.rs1use super::Card;
7
8impl Card {
9 pub fn get_buyback_cost(&self) -> Option<String> {
13 self.get_keyword_cost("Buyback")
14 }
15
16 pub fn get_spectacle_cost(&self) -> Option<String> {
18 self.get_keyword_cost("Spectacle")
19 }
20
21 pub fn get_evoke_cost(&self) -> Option<String> {
23 self.get_keyword_cost("Evoke")
24 }
25
26 pub fn get_all_evoke_costs(&self) -> Vec<String> {
31 let prefix = "Evoke:";
32 let mut out = Vec::new();
33 for kw in self.keywords.iter_strings() {
34 if let Some(cost) = kw.strip_prefix(prefix) {
35 out.push(cost.to_string());
36 }
37 }
38 for kw in self.granted_keywords.iter_strings() {
39 if let Some(cost) = kw.strip_prefix(prefix) {
40 out.push(cost.to_string());
41 }
42 }
43 out
44 }
45
46 pub fn get_bestow_cost(&self) -> Option<String> {
48 self.get_keyword_cost("Bestow")
49 }
50
51 pub fn get_dash_cost(&self) -> Option<String> {
53 self.get_keyword_cost("Dash")
54 }
55
56 pub fn get_blitz_cost(&self) -> Option<String> {
58 self.get_keyword_cost("Blitz")
59 }
60
61 pub fn get_warp_cost(&self) -> Option<String> {
63 self.get_keyword_cost("Warp")
64 }
65
66 pub fn get_multikicker_cost(&self) -> Option<String> {
68 self.get_keyword_cost("Multikicker")
69 }
70
71 pub fn get_replicate_cost(&self) -> Option<String> {
73 self.get_keyword_cost("Replicate")
74 }
75
76 pub fn get_entwine_cost(&self) -> Option<String> {
78 self.get_keyword_cost("Entwine")
79 }
80
81 pub fn get_escalate_cost(&self) -> Option<String> {
83 self.get_keyword_cost("Escalate")
84 }
85
86 pub fn get_escape_cost(&self) -> Option<(String, i32)> {
89 crate::keyword::extract_escape(&self.keywords)
90 .or_else(|| crate::keyword::extract_escape(&self.granted_keywords))
91 .map(|info| (info.mana_cost, info.exile_count))
92 }
93
94 pub fn get_overload_cost(&self) -> Option<String> {
96 self.get_keyword_cost("Overload")
97 }
98
99 pub fn get_madness_cost(&self) -> Option<String> {
101 self.get_keyword_cost("Madness")
102 }
103
104 pub fn get_strive_cost(&self) -> Option<String> {
106 self.get_keyword_cost("Strive")
107 }
108
109 pub fn get_suspend_cost(&self) -> Option<crate::keyword::SuspendInfo> {
112 crate::keyword::extract_suspend(&self.keywords)
113 .or_else(|| crate::keyword::extract_suspend(&self.granted_keywords))
114 }
115
116 pub fn get_foretell_cost(&self) -> Option<String> {
118 self.get_keyword_cost("Foretell")
119 }
120
121 pub fn get_emerge_cost(&self) -> Option<String> {
123 self.get_keyword_cost("Emerge")
124 }
125
126 pub fn get_offering_type(&self) -> Option<String> {
128 self.get_keyword_cost("Offering")
129 }
130
131 pub fn get_keyword_cost(&self, keyword: &str) -> Option<String> {
134 crate::keyword::extract_keyword_cost_from_all(
135 [&self.keywords, &self.granted_keywords],
136 keyword,
137 )
138 }
139
140 pub fn get_keyword_amount(&self, keyword: &str) -> Option<usize> {
142 self.get_keyword_cost(keyword)
143 .and_then(|s| s.trim().parse::<usize>().ok())
144 }
145
146 pub fn get_ward_cost(&self) -> Option<String> {
148 self.get_keyword_cost("Ward")
149 }
150
151 pub fn get_flashback_cost(&self) -> Option<String> {
152 if let Some(cost) = self.get_keyword_cost("Flashback") {
153 return Some(cost);
154 }
155 if self.has_keyword("Flashback") && !self.mana_cost.is_no_cost() {
156 return Some(mana_cost_script_string(&self.mana_cost));
157 }
158 None
159 }
160
161 pub fn get_harmonize_cost(&self) -> Option<String> {
163 self.get_keyword_cost("Harmonize")
164 }
165
166 pub fn get_kicker_cost(&self) -> Option<String> {
168 self.get_keyword_cost("Kicker")
169 }
170}
171
172fn mana_cost_script_string(mc: &forge_foundation::ManaCost) -> String {
173 let mut tokens: Vec<String> = Vec::new();
174 for shard in mc.shards() {
175 if *shard == forge_foundation::ManaCostShard::X {
176 tokens.push("X".to_string());
177 }
178 }
179 if mc.generic_cost() > 0 {
180 tokens.push(mc.generic_cost().to_string());
181 }
182 for shard in mc.shards() {
183 if *shard != forge_foundation::ManaCostShard::X {
184 tokens.push(shard.short_string().to_string());
185 }
186 }
187 tokens.join(" ")
188}