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
impl MagicStack
pub fn new() -> Self
pub fn push(&mut self, entry: StackEntry) -> u32
pub fn begin_pending_cast(&mut self, entry: StackEntry) -> u32
pub fn complete_pending_cast( &mut self, id: u32, entry: StackEntry, ) -> Option<&StackEntry>
pub fn remove_pending_cast(&mut self, id: u32) -> Option<StackEntry>
pub fn pop(&mut self) -> Option<StackEntry>
pub fn peek(&self) -> Option<&StackEntry>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn iter(&self) -> impl Iterator<Item = &StackEntry>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut StackEntry>
Sourcepub fn find_by_id(&self, id: u32) -> Option<&StackEntry>
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.
Sourcepub fn remove_by_id(&mut self, id: u32) -> Option<StackEntry>
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).
Sourcepub fn clear_recently_removed(&mut self)
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.
Sourcepub fn find_by_source_card(&self, card_id: CardId) -> Option<&StackEntry>
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).
Sourcepub fn add(&mut self, entry: StackEntry) -> u32
pub fn add(&mut self, entry: StackEntry) -> u32
Add a stack entry. Mirrors Java’s MagicStack.add().
Sourcepub fn remove(&mut self, id: u32) -> Option<StackEntry>
pub fn remove(&mut self, id: u32) -> Option<StackEntry>
Remove a specific entry by ID. Mirrors Java’s MagicStack.remove().
Sourcepub fn peek_ability(&self) -> Option<&SpellAbility>
pub fn peek_ability(&self) -> Option<&SpellAbility>
Peek at the top ability. Mirrors Java’s MagicStack.peekAbility().
Sourcepub fn has_source_on_stack(&self, card_id: CardId) -> bool
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().
pub fn has_source_chapter_on_stack( &self, game: &GameState, card_id: CardId, ) -> bool
Sourcepub fn has_legal_targeting(&self) -> bool
pub fn has_legal_targeting(&self) -> bool
Check if the top entry has legal targeting (at least one target chosen).
Mirrors Java’s MagicStack.hasLegalTargeting().
Sourcepub fn remove_instances_controlled_by(&mut self, player: PlayerId)
pub fn remove_instances_controlled_by(&mut self, player: PlayerId)
Remove all entries controlled by the given player.
Mirrors Java’s MagicStack.removeInstancesControlledBy().
Sourcepub fn iterator(&self) -> impl Iterator<Item = &StackEntry>
pub fn iterator(&self) -> impl Iterator<Item = &StackEntry>
Forward iterator. Mirrors Java’s MagicStack.iterator().
Sourcepub fn reverse_iterator(&self) -> impl Iterator<Item = &StackEntry>
pub fn reverse_iterator(&self) -> impl Iterator<Item = &StackEntry>
Reverse iterator (top to bottom). Mirrors Java’s MagicStack.reverseIterator().
Sourcepub fn freeze_stack(&mut self)
pub fn freeze_stack(&mut self)
Freeze the stack. While frozen, new entries go to the frozen queue.
Mirrors Java’s MagicStack.freezeStack().
Sourcepub fn add_and_unfreeze(&mut self, entry: StackEntry) -> u32
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().
Sourcepub fn unfreeze_stack(&mut self)
pub fn unfreeze_stack(&mut self)
Unfreeze the stack and flush all frozen entries onto the real stack.
Mirrors Java’s MagicStack.unfreezeStack().
Sourcepub fn clear_frozen(&mut self)
pub fn clear_frozen(&mut self)
Clear all frozen entries without processing them.
Mirrors Java’s MagicStack.clearFrozen().
Sourcepub fn is_resolving(&self) -> bool
pub fn is_resolving(&self) -> bool
Whether the stack is currently resolving.
pub fn set_resolving(&mut self, resolving: bool)
pub fn set_resolving_fizzled(&mut self, fizzled: bool)
pub fn resolving_fizzle(&self, card: CardId) -> Option<bool>
pub fn set_cur_resolving_card(&mut self, card: Option<CardId>)
pub fn cur_resolving_card(&self) -> Option<CardId>
pub fn set_resolving_entry(&mut self, entry: Option<StackEntry>)
Sourcepub fn can_undo(&self, player: PlayerId) -> bool
pub fn can_undo(&self, player: PlayerId) -> bool
Check if undo is available for the given player.
Mirrors Java’s MagicStack.canUndo().
Sourcepub fn undo(&mut self) -> bool
pub fn undo(&mut self) -> bool
Undo the last undoable action. Returns true if successful.
Mirrors Java’s MagicStack.undo().
Sourcepub fn clear_undo_stack(&mut self)
pub fn clear_undo_stack(&mut self)
Clear the undo stack entirely.
Mirrors Java’s MagicStack.clearUndoStack().
Sourcepub fn filter_undo_stack_by_host(&mut self, card_id: CardId)
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().
Sourcepub fn record_undoable(&mut self, source: Option<CardId>, player: PlayerId)
pub fn record_undoable(&mut self, source: Option<CardId>, player: PlayerId)
Record an undoable action on the undo stack.
Sourcepub fn has_simultaneous_stack_entries(&self) -> bool
pub fn has_simultaneous_stack_entries(&self) -> bool
Check if there are simultaneous stack entries waiting to be added.
Mirrors Java’s MagicStack.hasSimultaneousStackEntries().
Sourcepub fn clear_simultaneous_stack(&mut self)
pub fn clear_simultaneous_stack(&mut self)
Clear all simultaneous stack entries.
Mirrors Java’s MagicStack.clearSimultaneousStack().
Sourcepub fn add_simultaneous_stack_entry(&mut self, entry: StackEntry)
pub fn add_simultaneous_stack_entry(&mut self, entry: StackEntry)
Queue a simultaneous stack entry (trigger) for later addition.
Mirrors Java’s MagicStack.addSimultaneousStackEntry().
Sourcepub fn add_all_triggered_abilities_to_stack(&mut self) -> bool
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().
Sourcepub fn has_state_trigger(&self) -> bool
pub fn has_state_trigger(&self) -> bool
Check if there’s a state trigger waiting in the simultaneous queue.
Mirrors Java’s MagicStack.hasStateTrigger().
Sourcepub fn has_state_trigger_id(&self, trigger_id: u32) -> bool
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.
Sourcepub fn add_cast_command(&mut self, key: &str, command: String)
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().
Sourcepub fn take_cast_commands(&mut self, key: &str) -> Vec<String>
pub fn take_cast_commands(&mut self, key: &str) -> Vec<String>
Take and return any cast commands registered for the given key.
Sourcepub fn resolve_stack(&mut self) -> Option<StackEntry>
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().
Sourcepub fn finish_resolving(&mut self)
pub fn finish_resolving(&mut self)
Mark resolution as complete.
Sourcepub fn on_next_turn(&mut self)
pub fn on_next_turn(&mut self)
Called when a new turn begins. Rotates cast/activated tracking.
Mirrors Java’s MagicStack.onNextTurn().
Sourcepub fn record_spell_cast(&mut self, card_id: CardId)
pub fn record_spell_cast(&mut self, card_id: CardId)
Record that a spell was cast this turn (for storm count, etc.).
Sourcepub fn spells_cast_this_turn(&self) -> usize
pub fn spells_cast_this_turn(&self) -> usize
Get the number of spells cast this turn (storm count).
Sourcepub fn get_spells_cast_this_turn(&self) -> &[CardId]
pub fn get_spells_cast_this_turn(&self) -> &[CardId]
Get the list of spells cast this turn.
Sourcepub fn get_spells_cast_last_turn(&self) -> &[CardId]
pub fn get_spells_cast_last_turn(&self) -> &[CardId]
Get the list of spells cast last turn.
Sourcepub fn add_ability_activated_this_turn(&mut self, sa: &SpellAbility)
pub fn add_ability_activated_this_turn(&mut self, sa: &SpellAbility)
Track an ability activation this turn.
Mirrors Java’s MagicStack.addAbilityActivatedThisTurn().
Sourcepub fn reset_max_distinct_sources(&mut self)
pub fn reset_max_distinct_sources(&mut self)
Reset max distinct sources counter.
Mirrors Java’s MagicStack.resetMaxDistinctSources().
Sourcepub fn get_max_distinct_sources(&self) -> usize
pub fn get_max_distinct_sources(&self) -> usize
Get the max distinct sources seen on the stack this turn.
Sourcepub fn get_instance_matching_spell_ability_id(
&self,
id: u32,
) -> Option<&StackEntry>
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().
Sourcepub fn get_spell_matching_host(&self, host: CardId) -> Option<&SpellAbility>
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().