It is currently 01 Nov 2025, 14:28
   
Text Size

Spells and cards moving to the stack

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins

Spells and cards moving to the stack

Postby Sloth » 01 Nov 2011, 10:19

I would like to streamline how the moving of spells and cards to the stack is handled:

add(final SpellAbility sp) puts the spell on the stack, the corresponding card is moved by moveToStack which is mostly called just beforehand. In some places though, moveToStack is called, but the spell is not added to the stack until later in other functions (for example fillRequirements).

Calling moveToStack in the add function of MagicStack would not only remove some duplicate code, but would enable us to make the SpellCast trigger be usable on Burning Vengeance and River Kelpie and be generally more accurate by adding last known information.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Spells and cards moving to the stack

Postby friarsol » 01 Nov 2011, 11:58

Where is add in MagicStack? If that's the case it's too late, since the Spell should be added to the Stack as it's announced (in FillRequirements). If you have a spell that also forces you to discard a card, could you then discard a card to pay for its own cost? Maybe it'd be easier to just keep track of the last zone a card was in?
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Spells and cards moving to the stack

Postby Sloth » 01 Nov 2011, 14:25

friarsol wrote:Where is add in MagicStack? If that's the case it's too late, since the Spell should be added to the Stack as it's announced (in FillRequirements). If you have a spell that also forces you to discard a card, could you then discard a card to pay for its own cost? Maybe it'd be easier to just keep track of the last zone a card was in?
Yes. We can track that. And we should make sure everything is reversible when a card moves to the stack, which means:
1. No triggers should trigger when cards are moving to the stack.
2. The card object should be left unchanged (and not use copyCard).

Another (slightly related) problem here is that the timing of checkStateEffects doesn't work well with the "CastSpell" triggers. It has to be applied between the moving and the triggering.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Spells and cards moving to the stack

Postby friarsol » 01 Nov 2011, 14:43

Sloth wrote:Yes. We can track that. And we should make sure everything is reversible when a card moves to the stack, which means:
1. No triggers should trigger when cards are moving to the stack.
I don't have the code right in front of me, but this is the idea of FrozenStack. While something is being added to the Stack, anything that would trigger goes onto the Frozen Stack. Once the spell's requirements are paid for all of the rest of the FrozenStack is placed on top of it. If the Spell is canceled, the FrozenStack is cleared out.

I noticed the other day that getCardsInGame() doesn't return cards on the Stack. Is there any reason for this? That seems wrong to me.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Spells and cards moving to the stack

Postby Sloth » 01 Nov 2011, 15:30

friarsol wrote:I don't have the code right in front of me, but this is the idea of FrozenStack. While something is being added to the Stack, anything that would trigger goes onto the Frozen Stack. Once the spell's requirements are paid for all of the rest of the FrozenStack is placed on top of it. If the Spell is canceled, the FrozenStack is cleared out.
I didn't know that. Sounds well planned then. :D

friarsol wrote:I noticed the other day that getCardsInGame() doesn't return cards on the Stack. Is there any reason for this? That seems wrong to me.
Here is the code:
| Open
Code: Select all
    public static CardList getCardsInGame() {
        CardList all = new CardList();
        for (Player player : AllZone.getPlayersInGame()) {
            all.addAll(player.getZone(Zone.Graveyard).getCards());
            all.addAll(player.getZone(Zone.Hand).getCards());
            all.addAll(player.getZone(Zone.Library).getCards()); // not sure if
                                                                 // library
                                                                 // should be
                                                                 // included.
            all.addAll(player.getZone(Zone.Battlefield).getCards(false));
            all.addAll(player.getZone(Zone.Exile).getCards()); // Spawnsire of
                                                               // Ulamog plays
                                                               // spells from
                                                               // here?
        }
        all.addAll(AllZone.getStackZone().getCards());
        return all;
    }
Does "all.addAll(AllZone.getStackZone().getCards());" not work?

2. The card object should be left unchanged (and not use copyCard).

Another (slightly related) problem here is that the timing of checkStateEffects doesn't work well with the "CastSpell" triggers. It has to be applied between the moving and the triggering.
After thinking about it, I guess most problems with "CastSpell" triggers will disappear if the card objects stay the same (at least Changelings and Conspiracy).
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 9 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 9 users online :: 0 registered, 0 hidden and 9 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 9 guests

Login Form