It is currently 26 Apr 2024, 04:26
   
Text Size

Enumerating Targets

Moderators: North, BetaSteward, noxx, jeffwadsworth, JayDi, TheElk801, LevelX, CCGHQ Admins

Enumerating Targets

Postby duncancmt » 18 Jan 2015, 20:14

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!
duncancmt
 
Posts: 7
Joined: 18 Jan 2015, 19:55
Has thanked: 0 time
Been thanked: 0 time

Re: Enumerating Targets

Postby duncancmt » 18 Jan 2015, 22:41

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 :(
duncancmt
 
Posts: 7
Joined: 18 Jan 2015, 19:55
Has thanked: 0 time
Been thanked: 0 time

Re: Enumerating Targets

Postby LevelX » 19 Jan 2015, 08:19

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?
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Enumerating Targets

Postby duncancmt » 19 Jan 2015, 16:18

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).
duncancmt
 
Posts: 7
Joined: 18 Jan 2015, 19:55
Has thanked: 0 time
Been thanked: 0 time

Re: Enumerating Targets

Postby LevelX » 20 Jan 2015, 18:02

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).
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Enumerating Targets

Postby duncancmt » 21 Jan 2015, 01:30

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
duncancmt
 
Posts: 7
Joined: 18 Jan 2015, 19:55
Has thanked: 0 time
Been thanked: 0 time

Re: Enumerating Targets

Postby duncancmt » 22 Jan 2015, 07:02

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!
duncancmt
 
Posts: 7
Joined: 18 Jan 2015, 19:55
Has thanked: 0 time
Been thanked: 0 time


Return to Developers Talk

Who is online

Users browsing this forum: No registered users and 13 guests


Who is online

In total there are 13 users online :: 0 registered, 0 hidden and 13 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: No registered users and 13 guests

Login Form