It is currently 19 Apr 2024, 11:26
   
Text Size

Card, Spell, Ability, and Stack basics

Post MTG Forge Related Programming Questions Here

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

Card, Spell, Ability, and Stack basics

Postby pfps » 12 Jan 2015, 17:19

Is there a good description of how the innards of Forge work?

In particular, I'm wondering why resetTargets is called so often. Is there something that requires this, or is it just being done out of caution?
pfps
 
Posts: 53
Joined: 09 Jan 2015, 14:34
Has thanked: 0 time
Been thanked: 7 times

Re: Card, Spell, Ability, and Stack basics

Postby friarsol » 12 Jan 2015, 18:10

I'm not at my codebase, so this might not be 100% accurate but it generally goes like this:

(I'm just going to use activate everywhere instead of both activate and cast for the appropriate word)

0. Select a card to activate any potential SpellAbilities from the Zone it's in. If multiple SpellAbilities are available (spells in your hand with cycling, or permanents with multiple abilities that pass their timing restrictions), popup an input for the user to select one.

1. Initiate activating of the SpellAbility. Place the SA on the Stack, determine X values, select targets. All of this is happening on the reusable SpellAbility class.

2. Pay costs of the SA until completion.

3. Finalizing the activation, spawn off all relevant data points (target, costs paid, etc) and create a new SpellAbilityStackInstance. Resetting the initial SA so it's completely fresh the next time someone wants to try to activate it, or the next time a StackInstance is resolving and needs to use the SA.

4. Start resolving, take the StackInstance, and load it back into the SpellAbility. Then check if the SA has fizzled. If not, resolve the SA (as best as we can) by running through the appropriate Ability Effects

I don't know think too much of that has changed recently, but I know about 3-4 years ago that was implemented because certain cards that are often activated multiple times in the same Stack were either concatenating or overwriting their targets. (Masticore and Umezawa's Jitte are the two prime examples)


Does that count as good description?
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Card, Spell, Ability, and Stack basics

Postby moomarc » 12 Jan 2015, 19:29

I worked on this project for so long, but never quite needed to track that whole sequence. I feel like a few things I tried would have been more successful if I had understood how StackInstances fitted in properly... But then again, maybe not.

Howdee everyone!
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times

Re: Card, Spell, Ability, and Stack basics

Postby pfps » 12 Jan 2015, 23:32

That helps, thanks.

I think that there are a couple of glitches in the code that may have happened because of the way that the split between SAs (which are really neither spells nor abilities) and SpellAbilityStackInstances (which are the real spells and abilities) are done. First, the resetting of SAs appears to affect copying of spells (and allows the AI to have Pacts of Negation with no targets). Second, counterspells don't check that their target is on the stack at resolution.

I think that copying a spell should copy a SpellAbilityStackInstance, including targets, etc., which is then modified as necessary. A "may choose new targets" would be an explicit action after the copy. Only if the new targets are valid would they replace the previous targets.

Fixing counterspell needs the ability to determine whether a SASI is still on the stack, and is thus really still a spell.

Ideally, I think that it should be SASIs that resolve, not SAs. This might require too much refactoring of code to be viable at the moment, however.

Comments? Is there a better way to make copies of spells? Is there a better way to check counterspell targeting on resolution?
pfps
 
Posts: 53
Joined: 09 Jan 2015, 14:34
Has thanked: 0 time
Been thanked: 7 times


Return to Developer's Corner

Who is online

Users browsing this forum: Baidu [Spider] and 61 guests


Who is online

In total there are 62 users online :: 1 registered, 0 hidden and 61 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: Baidu [Spider] and 61 guests

Login Form