pub struct ManaCost { /* private fields */ }Expand description
A complete mana cost (e.g. {2}{W}{U}).
Mirrors Java ManaCost. Immutable once constructed.
Implementations§
Source§impl ManaCost
impl ManaCost
Sourcepub fn parse(s: &str) -> Self
pub fn parse(s: &str) -> Self
Parse a mana cost string in Forge format (space-separated tokens). E.g. “2 W U”, “3 G G”, “X R”, “0”, “W/U W/U”.
pub fn cmc(&self) -> i32
pub fn color_profile(&self) -> u8
pub fn color_set(&self) -> ColorSet
pub fn generic_cost(&self) -> i32
pub fn shards(&self) -> &[ManaCostShard]
pub fn is_no_cost(&self) -> bool
pub fn is_zero(&self) -> bool
pub fn is_pure_generic(&self) -> bool
pub fn count_x(&self) -> usize
pub fn has_phyrexian(&self) -> bool
Sourcepub fn from_parts(shards: Vec<ManaCostShard>, generic_cost: i32) -> ManaCost
pub fn from_parts(shards: Vec<ManaCostShard>, generic_cost: i32) -> ManaCost
Build a ManaCost from explicit shards and generic cost.
Sourcepub fn without_x(&self) -> ManaCost
pub fn without_x(&self) -> ManaCost
Return a copy of this cost with all X shards removed. Used to compute the non-X portion for affordability checks.
Sourcepub fn without_phyrexian(&self) -> ManaCost
pub fn without_phyrexian(&self) -> ManaCost
Return a copy of this cost with all Phyrexian shards removed. Used for playability checks — Phyrexian shards can always be paid with 2 life.
Sourcepub fn phyrexian_to_colored(&self) -> ManaCost
pub fn phyrexian_to_colored(&self) -> ManaCost
Convert phyrexian shards to their colored equivalents (e.g. {B/P} → {B}). Non-phyrexian shards are kept as-is. Generic cost is preserved.
Sourcepub fn colored_to_phyrexian(&self, color_mask: u8) -> ManaCost
pub fn colored_to_phyrexian(&self, color_mask: u8) -> ManaCost
Convert mono-colored shards of the given color into their phyrexian variants. Used for effects like “you may pay 2 life rather than pay {B}”.
pub fn shard_count(&self, which: ManaCostShard) -> usize
Sourcepub fn add(&self, other: &ManaCost) -> ManaCost
pub fn add(&self, other: &ManaCost) -> ManaCost
Add another mana cost to this one, returning the combined cost.
Sourcepub fn reduce_generic(&self, amount: i32) -> ManaCost
pub fn reduce_generic(&self, amount: i32) -> ManaCost
Reduce the generic portion of this cost by amount (floor at 0).
Used for Emerge (cost reduced by sacrificed creature’s mana value).
Sourcepub fn with_generic(&self, generic: i32) -> ManaCost
pub fn with_generic(&self, generic: i32) -> ManaCost
Return a copy with the generic cost set to the given value.
Sourcepub fn has_color_shard(&self, atom: u16) -> bool
pub fn has_color_shard(&self, atom: u16) -> bool
Check if this cost has a mono-color shard matching the given ManaAtom.
Sourcepub fn remove_color_shard(&self, atom: u16) -> ManaCost
pub fn remove_color_shard(&self, atom: u16) -> ManaCost
Remove one mono-color shard matching the given ManaAtom. Returns new cost.
Sourcepub fn reduce_color(
&self,
color: Color,
count: i32,
ignore_generic: bool,
) -> ManaCost
pub fn reduce_color( &self, color: Color, count: i32, ignore_generic: bool, ) -> ManaCost
Remove up to count colored shards matching color from this cost.
If ignore_generic is true, only removes colored shards (never converts to generic reduction).
If ignore_generic is false and fewer matching shards exist than count, the remainder
reduces the generic portion instead.