Skip to main content

manabrew_engine/keyword/
hexproof.rs

1//! Hexproof keyword implementation.
2//!
3//! Ported from Java's `Hexproof.java` in `forge/game/keyword/`.
4
5use super::keyword_instance::Keyword;
6use super::keyword_with_type::KeywordWithType;
7
8/// Hexproof keyword data.
9/// This can't be the target of spells or abilities opponents control.
10/// Can be qualified with "from" a type (e.g. "Hexproof from black").
11#[derive(Debug, Clone)]
12pub struct Hexproof {
13    pub inner: KeywordWithType,
14}
15
16impl Hexproof {
17    /// Create a new Hexproof keyword.
18    pub fn new(original: String) -> Self {
19        Self {
20            inner: KeywordWithType::new(Keyword::Hexproof, original),
21        }
22    }
23
24    /// Parse the details string.
25    pub fn parse(&mut self, details: &str) {
26        self.inner.parse(details);
27    }
28
29    /// Get the display title.
30    pub fn get_title(&self) -> String {
31        if self.inner.type_str.is_empty() {
32            "Hexproof".to_string()
33        } else {
34            format!("Hexproof from {}", self.inner.desc_type)
35        }
36    }
37
38    /// Format reminder text.
39    pub fn format_reminder_text(&self, reminder_text: &str) -> String {
40        if self.inner.type_str.is_empty() {
41            "This can't be the target of spells or abilities your opponents control.".to_string()
42        } else {
43            reminder_text.replace("%s", &self.inner.desc_type)
44        }
45    }
46}