Skip to main content

manabrew_engine/keyword/
partner.rs

1//! Partner keyword implementation.
2//!
3//! Ported from Java's `Partner.java` in `forge/game/keyword/`.
4
5use super::keyword_instance::{Keyword, KeywordInstanceData};
6
7/// Partner keyword data.
8/// You can have two commanders if both have partner.
9/// Also used for "Choose a Background", "Doctor's companion", etc.
10#[derive(Debug, Clone)]
11pub struct Partner {
12    pub base: KeywordInstanceData,
13    /// The specific partner name (for "Partner with X").
14    pub with: Option<String>,
15}
16
17impl Partner {
18    /// Create a new Partner keyword.
19    pub fn new(keyword: Keyword, original: String) -> Self {
20        Self {
21            base: KeywordInstanceData::new(keyword, original),
22            with: None,
23        }
24    }
25
26    /// Parse the details string.
27    pub fn parse(&mut self, details: &str) {
28        if !details.is_empty() {
29            self.with = Some(details.to_string());
30        }
31    }
32
33    /// Get the display title.
34    pub fn get_title(&self) -> String {
35        if let Some(ref with) = self.with {
36            format!("Partner \u{2014} {}", with)
37        } else {
38            self.base.keyword.display_name().to_string()
39        }
40    }
41
42    /// Format reminder text.
43    pub fn format_reminder_text(&self, reminder_text: &str) -> String {
44        if self.with.is_some() {
45            "You can have two commanders if both have this ability.".to_string()
46        } else {
47            reminder_text.to_string()
48        }
49    }
50}