Skip to main content

manabrew_engine/spellability/
optional_cost.rs

1//! Optional additional costs for spells.
2//!
3//! Mirrors Java's `OptionalCost.java` enum — represents additional costs
4//! that may be paid when casting a spell.
5
6use serde::{Deserialize, Serialize};
7
8/// Optional additional costs for spells.
9/// Mirrors Java's `OptionalCost.java` enum.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11pub enum OptionalCost {
12    /// First kicker cost was paid.
13    Kicker1,
14    /// Second kicker cost was paid (for cards with two kicker costs).
15    Kicker2,
16    /// Buyback cost was paid (return spell to hand on resolution).
17    Buyback,
18    /// Entwine cost was paid (choose all modes).
19    Entwine,
20    /// Bargain — sacrifice an artifact, enchantment, or token.
21    Bargain,
22    /// Promise of a gift — offer a card to an opponent.
23    PromiseGift,
24    /// Retrace — cast from graveyard by discarding a land.
25    Retrace,
26    /// Jumpstart — cast from graveyard by discarding a card.
27    Jumpstart,
28    /// Offering — sacrifice a creature of the specified type.
29    Offering,
30    /// Reduce white mana in cost.
31    ReduceW,
32    /// Reduce blue mana in cost.
33    ReduceU,
34    /// Reduce black mana in cost.
35    ReduceB,
36    /// Reduce red mana in cost.
37    ReduceR,
38    /// Reduce green mana in cost.
39    ReduceG,
40    /// Generic alternative cost.
41    AltCost,
42    /// Flash — cast at instant speed.
43    Flash,
44    /// Generic optional cost.
45    Generic,
46}
47
48impl OptionalCost {
49    /// Human-readable name for this optional cost.
50    /// Mirrors Java's `OptionalCost.getName()`.
51    pub fn name(&self) -> &str {
52        match self {
53            OptionalCost::Kicker1 => "Kicker",
54            OptionalCost::Kicker2 => "Kicker 2",
55            OptionalCost::Buyback => "Buyback",
56            OptionalCost::Entwine => "Entwine",
57            OptionalCost::Bargain => "Bargain",
58            OptionalCost::PromiseGift => "Promise of a Gift",
59            OptionalCost::Retrace => "Retrace",
60            OptionalCost::Jumpstart => "Jumpstart",
61            OptionalCost::Offering => "Offering",
62            OptionalCost::ReduceW => "Reduce W",
63            OptionalCost::ReduceU => "Reduce U",
64            OptionalCost::ReduceB => "Reduce B",
65            OptionalCost::ReduceR => "Reduce R",
66            OptionalCost::ReduceG => "Reduce G",
67            OptionalCost::AltCost => "Alternative Cost",
68            OptionalCost::Flash => "Flash",
69            OptionalCost::Generic => "Generic",
70        }
71    }
72
73    /// Mana pip abbreviation for this cost (used for display).
74    /// Mirrors Java's `OptionalCost.getPip()`.
75    pub fn pip(&self) -> &str {
76        match self {
77            OptionalCost::Kicker1 => "K",
78            OptionalCost::Kicker2 => "K2",
79            OptionalCost::Buyback => "BB",
80            OptionalCost::Entwine => "EN",
81            OptionalCost::Bargain => "BG",
82            OptionalCost::PromiseGift => "PG",
83            OptionalCost::Retrace => "RT",
84            OptionalCost::Jumpstart => "JS",
85            OptionalCost::Offering => "OF",
86            OptionalCost::ReduceW => "W",
87            OptionalCost::ReduceU => "U",
88            OptionalCost::ReduceB => "B",
89            OptionalCost::ReduceR => "R",
90            OptionalCost::ReduceG => "G",
91            OptionalCost::AltCost => "AC",
92            OptionalCost::Flash => "FL",
93            OptionalCost::Generic => "GN",
94        }
95    }
96}