Page 1 of 1

Enumerating Targets

PostPosted: 18 Jan 2015, 20:14
by duncancmt
Hi!

I'm trying to implement Ink-Treader Nephilim. I'm having a hard time enumerating all the targets of modal spells like Cryptic Command. What's the interface for getting all the abilities and targets of a spell on the stack? Can spells have multiple SpellAbility's/Effect's?

I hope to be able to contribute a couple other cards to the project, but this one is giving me some trouble.

Thanks!

Re: Enumerating Targets

PostPosted: 18 Jan 2015, 22:41
by duncancmt
I think I figured it out. Is this approximately right?

Code: Select all
Spell spell;
for (SpellAbility sa: spell.getSpellAbilities()){
   Modes modes = sa.getModes();
   for (UUID mode : modes.getSelectedModes()) {
      for (Target targetInstance : modes.get(mode).getTargets()) {
         for (UUID target : targetInstance.getTargets()) {
            // do stuff
         }
      }
   }
}
It looks like I don't need to look through a Spell's Effect's. Is that right?

I have another question: how do I let a player control the order in which objects go on the stack?

Thanks a lot!

EDIT: Argh! I can't get my whitespace to format correctly :(

Re: Enumerating Targets

PostPosted: 19 Jan 2015, 08:19
by LevelX
duncancmt wrote:I think I figured it out. Is this approximately right?
Looks good.

duncancmt wrote:It looks like I don't need to look through a Spell's Effect's. Is that right?
You're right, for getting the targets you don't need to iterate through the effects.

duncancmt wrote:I have another question: how do I let a player control the order in which objects go on the stack?
They go to the stack in the order they are created and so added to the stack.
If more than one object is created at the same time (e.g. two trigger) the user selects the order by using the "select order of triggered effects" window that is popping up.

Or didn't I get the point of your question correctly?

Re: Enumerating Targets

PostPosted: 19 Jan 2015, 16:18
by duncancmt
LevelX wrote:They go to the stack in the order they are created and so added to the stack.
If more than one object is created at the same time (e.g. two trigger) the user selects the order by using the "select order of triggered effects" window that is popping up.

Or didn't I get the point of your question correctly?
The copies from Ink-Treader Nephilim's ability are all controlled by Ink-Treader's controller. Since they go on the stack with fixed targets, it's not like Storm where the copies can go on in any order, but the player can choose the targets after the fact. Basically, I don't know how to invoke the popup window from the effect. I took a look at Precursor Golem because that's a similar effect, and Precursor Golem just puts them on the stack in a random order without allowing the spells' controller to choose (which I believe is wrong).

Re: Enumerating Targets

PostPosted: 20 Jan 2015, 18:02
by LevelX
I guess such a dialog does not exist yet.

Maybe it's best to ask the caster of Ink-Treader Nephilim to set the order by clicking on the possible targets. If target was clicked, the spell copy is added to the stack and this target can't be used again.

Maybe with the option to set the targets automatically (ask the controller first).

Re: Enumerating Targets

PostPosted: 21 Jan 2015, 01:30
by duncancmt
LevelX wrote:I guess such a dialog does not exist yet.

Maybe it's best to ask the caster of Ink-Treader Nephilim to set the order by clicking on the possible targets. If target was clicked, the spell copy is added to the stack and this target can't be used again.

Maybe with the option to set the targets automatically (ask the controller first).
Here's what I've got right now. I make a bunch of copies, set their targets, then move them to the "pick" zone. I made a target class that chooses things out of the "pick" zone. However, when I invoke Player.choose on the "pick" zone target class, I get the text prompt, but no ability to actually click on anything to select an object. Any idea what's going on here? I could easily go back and just have them go on the stack in the order that the game creates them, but I'd rather be 100% correct.

Argh! The forum won't let me attach files, or link to my github. Take a look at <github>/duncant/mage/blob/ink_treader/Mage.Sets/src/mage/sets/guildpact/InkTreaderNephilim.java

Re: Enumerating Targets

PostPosted: 22 Jan 2015, 07:02
by duncancmt
LevelX wrote:Maybe it's best to ask the caster of Ink-Treader Nephilim to set the order by clicking on the possible targets. If target was clicked, the spell copy is added to the stack and this target can't be used again.

Maybe with the option to set the targets automatically (ask the controller first).
Ok. I figured it all out. I ended up doing what you suggested. I made a pull request with Ink-Treader Nephilim and a couple other cards that I've implemented. I also fixed up Precursor Golem so that it works correctly.

I hope it's useful!