Spells and cards moving to the stack
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
5 posts
• Page 1 of 1
Spells and cards moving to the stack
by 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.
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.
-

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
by 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
by Sloth » 01 Nov 2011, 14:25
Yes. We can track that. And we should make sure everything is reversible when a card moves to the stack, which means: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?
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.
-

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
by friarsol » 01 Nov 2011, 14:43
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.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 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
by Sloth » 01 Nov 2011, 15:30
I didn't know that. Sounds well planned then.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.
Here is the code: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.
- | 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;
}
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).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.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 9 guests