Skip to main content

manabrew_engine/keyword/
equip.rs

1//! Equip keyword implementation.
2//!
3//! Ported from Java's `Equip.java` in `forge/game/keyword/`.
4
5use super::keyword_instance::Keyword;
6use super::keyword_with_cost::KeywordWithCost;
7
8/// Equip keyword data.
9/// Attach to target creature you control. Equip only as a sorcery.
10#[derive(Debug, Clone)]
11pub struct Equip {
12    pub inner: KeywordWithCost,
13    /// The type of permanent that can be equipped (default "creature").
14    pub equip_type: String,
15}
16
17impl Equip {
18    /// Create a new Equip keyword.
19    pub fn new(original: String) -> Self {
20        Self {
21            inner: KeywordWithCost::new(Keyword::Equip, original),
22            equip_type: "creature".to_string(),
23        }
24    }
25
26    /// Parse the details string.
27    pub fn parse(&mut self, details: &str) {
28        let k: Vec<&str> = details.split(':').collect();
29        self.inner.parse(k[0]);
30        if k.len() > 2 {
31            self.equip_type = k[2].to_string();
32        }
33    }
34
35    /// Get the valid description (the equip target type).
36    pub fn get_valid_description(&self) -> &str {
37        &self.equip_type
38    }
39
40    /// Format reminder text.
41    pub fn format_reminder_text(&self, reminder_text: &str) -> String {
42        reminder_text
43            .replace("%s", &self.inner.cost_string)
44            .replace("%1$s", &self.inner.cost_string)
45            .replace("%2$s", &self.equip_type)
46    }
47
48    /// Get the display title.
49    pub fn get_title(&self) -> String {
50        self.inner.get_title()
51    }
52}