Skip to main content

manabrew_engine/keyword/
mayhem.rs

1//! Mayhem keyword implementation.
2//!
3//! Ported from Java's `Mayhem.java` in `forge/game/keyword/`.
4
5use super::keyword_instance::Keyword;
6use super::keyword_with_cost::KeywordWithCost;
7
8/// Mayhem keyword data.
9/// You may cast this card from your graveyard for its cost if you discarded it this turn.
10#[derive(Debug, Clone)]
11pub struct Mayhem {
12    pub inner: KeywordWithCost,
13    /// Whether there is no cost (play for free from graveyard).
14    pub no_cost: bool,
15}
16
17impl Mayhem {
18    /// Create a new Mayhem keyword.
19    pub fn new(original: String) -> Self {
20        Self {
21            inner: KeywordWithCost::new(Keyword::Mayhem, original),
22            no_cost: false,
23        }
24    }
25
26    /// Parse the details string.
27    pub fn parse(&mut self, details: &str) {
28        if details.is_empty() {
29            self.no_cost = true;
30        } else {
31            self.inner.parse(details);
32        }
33    }
34
35    /// Get the display title.
36    pub fn get_title(&self) -> String {
37        if self.no_cost {
38            self.inner.base.keyword.display_name().to_string()
39        } else {
40            self.inner.get_title()
41        }
42    }
43
44    /// Format reminder text.
45    pub fn format_reminder_text(&self, reminder_text: &str) -> String {
46        if self.no_cost {
47            "You may play this card from your graveyard if you discarded it this turn. Timing rules still apply.".to_string()
48        } else {
49            self.inner.format_reminder_text(reminder_text)
50        }
51    }
52}