Skip to main content

MagicStack

Struct MagicStack 

Source
pub struct MagicStack { /* private fields */ }
Expand description

The game stack. Spells and abilities are added to the top and resolve LIFO. Mirrors Java’s MagicStack class.

Implementations§

Source§

impl MagicStack

Source

pub fn new() -> Self

Source

pub fn push(&mut self, entry: StackEntry) -> u32

Source

pub fn begin_pending_cast(&mut self, entry: StackEntry) -> u32

Source

pub fn complete_pending_cast( &mut self, id: u32, entry: StackEntry, ) -> Option<&StackEntry>

Source

pub fn remove_pending_cast(&mut self, id: u32) -> Option<StackEntry>

Source

pub fn pop(&mut self) -> Option<StackEntry>

Source

pub fn peek(&self) -> Option<&StackEntry>

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn iter(&self) -> impl Iterator<Item = &StackEntry>

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut StackEntry>

Source

pub fn find_by_id(&self, id: u32) -> Option<&StackEntry>

Find a stack entry by ID without removing it. Also searches the short-lived LKI cache populated by Counter effects so that follow-up sub-abilities can still resolve Defined$ TargetedController after the target spell has been pulled off the stack.

Source

pub fn remove_by_id(&mut self, id: u32) -> Option<StackEntry>

Remove and return the stack entry with the given ID (for Counter effects). The removed entry is kept in a short-lived LKI cache so follow-up sub-abilities can still observe its metadata (see find_by_id).

Source

pub fn clear_recently_removed(&mut self)

Clear the LKI cache of recently-removed entries. Called at the end of each stack-resolution cycle so the cache doesn’t leak state.

Source

pub fn find_by_source_card(&self, card_id: CardId) -> Option<&StackEntry>

Find a stack entry by its source card ID (for Ward — finding the targeting spell).

Source

pub fn size(&self) -> usize

Number of items on the stack. Mirrors Java’s MagicStack.size().

Source

pub fn add(&mut self, entry: StackEntry) -> u32

Add a stack entry. Mirrors Java’s MagicStack.add().

Source

pub fn remove(&mut self, id: u32) -> Option<StackEntry>

Remove a specific entry by ID. Mirrors Java’s MagicStack.remove().

Source

pub fn clear(&mut self)

Clear all entries from the stack. Mirrors Java’s underlying clear().

Source

pub fn reset(&mut self)

Reset the stack completely. Mirrors Java’s MagicStack.reset().

Source

pub fn peek_ability(&self) -> Option<&SpellAbility>

Peek at the top ability. Mirrors Java’s MagicStack.peekAbility().

Source

pub fn has_source_on_stack(&self, card_id: CardId) -> bool

Check if any entry has the given source card. Mirrors Java’s MagicStack.hasSourceOnStack().

Check if the top entry has legal targeting (at least one target chosen). Mirrors Java’s MagicStack.hasLegalTargeting().

Source

pub fn remove_instances_controlled_by(&mut self, player: PlayerId)

Remove all entries controlled by the given player. Mirrors Java’s MagicStack.removeInstancesControlledBy().

Source

pub fn iterator(&self) -> impl Iterator<Item = &StackEntry>

Forward iterator. Mirrors Java’s MagicStack.iterator().

Source

pub fn reverse_iterator(&self) -> impl Iterator<Item = &StackEntry>

Reverse iterator (top to bottom). Mirrors Java’s MagicStack.reverseIterator().

Source

pub fn is_frozen(&self) -> bool

Whether the stack is currently frozen.

Source

pub fn freeze_stack(&mut self)

Freeze the stack. While frozen, new entries go to the frozen queue. Mirrors Java’s MagicStack.freezeStack().

Source

pub fn add_and_unfreeze(&mut self, entry: StackEntry) -> u32

Add an entry and unfreeze, flushing any queued frozen entries. Mirrors Java’s MagicStack.addAndUnfreeze().

Source

pub fn unfreeze_stack(&mut self)

Unfreeze the stack and flush all frozen entries onto the real stack. Mirrors Java’s MagicStack.unfreezeStack().

Source

pub fn clear_frozen(&mut self)

Clear all frozen entries without processing them. Mirrors Java’s MagicStack.clearFrozen().

Source

pub fn is_resolving(&self) -> bool

Whether the stack is currently resolving.

Source

pub fn set_resolving(&mut self, resolving: bool)

Source

pub fn set_cur_resolving_card(&mut self, card: Option<CardId>)

Source

pub fn cur_resolving_card(&self) -> Option<CardId>

Source

pub fn can_undo(&self, player: PlayerId) -> bool

Check if undo is available for the given player. Mirrors Java’s MagicStack.canUndo().

Source

pub fn undo(&mut self) -> bool

Undo the last undoable action. Returns true if successful. Mirrors Java’s MagicStack.undo().

Source

pub fn clear_undo_stack(&mut self)

Clear the undo stack entirely. Mirrors Java’s MagicStack.clearUndoStack().

Source

pub fn filter_undo_stack_by_host(&mut self, card_id: CardId)

Remove undo entries whose source matches the given card. Mirrors Java’s MagicStack.filterUndoStackByHost().

Source

pub fn record_undoable(&mut self, source: Option<CardId>, player: PlayerId)

Record an undoable action on the undo stack.

Source

pub fn has_simultaneous_stack_entries(&self) -> bool

Check if there are simultaneous stack entries waiting to be added. Mirrors Java’s MagicStack.hasSimultaneousStackEntries().

Source

pub fn clear_simultaneous_stack(&mut self)

Clear all simultaneous stack entries. Mirrors Java’s MagicStack.clearSimultaneousStack().

Source

pub fn add_simultaneous_stack_entry(&mut self, entry: StackEntry)

Queue a simultaneous stack entry (trigger) for later addition. Mirrors Java’s MagicStack.addSimultaneousStackEntry().

Source

pub fn add_all_triggered_abilities_to_stack(&mut self) -> bool

Move all queued simultaneous entries onto the real stack. Returns true if any were added. Mirrors Java’s MagicStack.addAllTriggeredAbilitiesToStack().

Source

pub fn has_state_trigger(&self) -> bool

Check if there’s a state trigger waiting in the simultaneous queue. Mirrors Java’s MagicStack.hasStateTrigger().

Source

pub fn has_state_trigger_id(&self, trigger_id: u32) -> bool

Check if a specific trigger id already exists in pending/active stack entries. Mirrors Java’s MagicStack.hasStateTrigger(triggerId) behavior.

Source

pub fn add_cast_command(&mut self, key: &str, command: String)

Register a command to run when a spell with the given key resolves. Mirrors Java’s MagicStack.addCastCommand().

Source

pub fn take_cast_commands(&mut self, key: &str) -> Vec<String>

Take and return any cast commands registered for the given key.

Source

pub fn resolve_stack(&mut self) -> Option<StackEntry>

Pop the top entry and begin resolution. Sets resolving state and tracks the resolving card. The actual effect resolution is driven by GameLoop::resolve_stack() which calls this to get the entry, then resolves it with full game context. Mirrors Java’s MagicStack.resolveStack().

Source

pub fn finish_resolving(&mut self)

Mark resolution as complete.

Source

pub fn on_next_turn(&mut self)

Called when a new turn begins. Rotates cast/activated tracking. Mirrors Java’s MagicStack.onNextTurn().

Source

pub fn record_spell_cast(&mut self, card_id: CardId)

Record that a spell was cast this turn (for storm count, etc.).

Source

pub fn spells_cast_this_turn(&self) -> usize

Get the number of spells cast this turn (storm count).

Source

pub fn get_spells_cast_this_turn(&self) -> &[CardId]

Get the list of spells cast this turn.

Source

pub fn get_spells_cast_last_turn(&self) -> &[CardId]

Get the list of spells cast last turn.

Source

pub fn add_ability_activated_this_turn(&mut self, sa: &SpellAbility)

Track an ability activation this turn. Mirrors Java’s MagicStack.addAbilityActivatedThisTurn().

Source

pub fn reset_max_distinct_sources(&mut self)

Reset max distinct sources counter. Mirrors Java’s MagicStack.resetMaxDistinctSources().

Source

pub fn get_max_distinct_sources(&self) -> usize

Get the max distinct sources seen on the stack this turn.

Source

pub fn get_instance_matching_spell_ability_id( &self, id: u32, ) -> Option<&StackEntry>

Find a stack entry whose spell ability ID matches the given stack entry ID. Mirrors Java’s MagicStack.getInstanceMatchingSpellAbilityID().

Source

pub fn get_spell_matching_host(&self, host: CardId) -> Option<&SpellAbility>

Find a spell on the stack whose host card matches the given card. Returns the spell ability if found. Mirrors Java’s MagicStack.getSpellMatchingHost().

Trait Implementations§

Source§

impl Clone for MagicStack

Source§

fn clone(&self) -> MagicStack

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MagicStack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MagicStack

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for MagicStack

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for MagicStack

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V