It is currently 10 Sep 2025, 21:19
   
Text Size

Adding support for "divided as you choose"

Post MTG Forge Related Programming Questions Here

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

Adding support for "divided as you choose"

Postby moomarc » 13 Mar 2012, 11:55

I'm trying to add support for "divided as you choose between any number of targets", specifically for DealDamage at this stage, but most of the affected code is common to all the AFs so it's just tweaking the AI targeting and stackDescription.

So far I've got it working well for the human (I'll tackle the AI afterwards) except that you can't select a target more than once. In spellability.TargetSelection.chooseValidInput is the code that (as far as I can tell) removes a card that's already been targeted from the list, but nothing I try seems to bypass it. Is there somewhere else that prevents a target being selected twice? Otherwise I can't see why this shouldn't work:
Code: Select all
final ArrayList<Card> targeted = tgt.getTargetCards();
if (!this.ability.getAbilityFactory().getMapParams().containsKey("DividedAsYouChoose")) {
    for (final Card c : targeted) {
        if (choices.contains(c)) {
            choices.remove(c);
        }
    }
}
I've tried putting a return in there to make sure that I've made the right function call, and that test was positive. So I'm out of ideas. :( Please help!

Edit: There's definitely something else preventing the selection. I tried commenting out that whole bit and I still couldn't select a creature twice. Maybe this is only for spells, not abilities. Back to the digging...
-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: Adding support for "divided as you choose"

Postby moomarc » 13 Mar 2012, 14:50

Ahhhhhh! ](*,) I think I've tried commenting out every block with choices.removes(object/card) and I still can't get it to allow targeting the same entity twice! So annoying #-o

I'll just have to wait for one of the gurus to point out some obvious thing that I'm doing wrong. [-o<
-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: Adding support for "divided as you choose"

Postby friarsol » 13 Mar 2012, 15:03

You have a fatal flaw. Targeting the same creature more than once is not the same as dividing damage as you choose. The key is targeting happens before a spell/ability is played and dividing as you choose happens during resolution. In addition, a singular ability can't target the same object more than once, it's just not how the rules work.

Here's how divided as you choose actually works:

We'll use Pyrotechnics since (I believe) it's the first card with this rules text. You target 1 to 4 creatures/players. Say a Savannah Lions, a Mother of Runes and the AI. The AI lets it resolve, now during resolution you get to choose who to deal damage to. Every target needs at least one damage, so the Lions, Mother and AI each get 1 damage. And then you put the additional damage on the AI.

Let's take the same example.
Instead of letting the Pyrotechnics resolve immediately, in response the Mother of Runes grants itself protection from red, making it an illegal target. If we were doing this "multi targeting" thing as you suggest, that extra damage would just disappear. Here however, as Pyrotechnics resolves Mother of Runes is removed from the targets list (Protection) and we're left with just a Savannah Lions and AI. We can then distribute the damage 1 to Lion 3 to AI.

Here's another example.
You have Death Pits of Rath in play and cast Pyrotechnics on a Grizzly Bear a Llanowar Elf and the Opponent.
When it resolves, you deal one damage to the Bear (triggering Death Pits), the Elf and 2 damage to the Opponent.

However, if your opponent cast Naturalize on your Death Pits in response to your Pyrotechnics. We see a similar issue: With the targeting system, the Grizzly Bear wouldn't die (1 dmg) and the Opponent would take an extra point of damage. But with distribution, you can still kill the Bear while just doing a single damage to the Opponent.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Adding support for "divided as you choose"

Postby moomarc » 13 Mar 2012, 15:14

Thanks Sol. I was working based on this ruling for Bogardan Hellkite:
Gatherer wrote:10.1.2009 - The number of targets chosen for the enters-the-battlefield ability must be at least 1 and at most 5. You divide the damage as you put the ability on the stack, not as it resolves. Each target must be assigned at least 1 damage.
I guess even the official ruling can be misleading :(

Edit: I just checked and Pyrotechnics got the same ruling in 2008, so is there maybe something to this? :looks hopeful:

Edit 2: I also figured it was the right way to do it seeing as that's how it's currently handled via subabilities for cards like Arc Lightning.

Edit 3: But it could be my understanding of Resolves that got me in trouble.
-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: Adding support for "divided as you choose"

Postby friarsol » 13 Mar 2012, 15:45

moomarc wrote:Thanks Sol. I was working based on this ruling for Bogardan Hellkite:
Gatherer wrote:10.1.2009 - The number of targets chosen for the enters-the-battlefield ability must be at least 1 and at most 5. You divide the damage as you put the ability on the stack, not as it resolves. Each target must be assigned at least 1 damage.
I guess even the official ruling can be misleading :(

Edit: I just checked and Pyrotechnics got the same ruling in 2008, so is there maybe something to this? :looks hopeful:

Edit 2: I also figured it was the right way to do it seeing as that's how it's currently handled via subabilities for cards like Arc Lightning.

Edit 3: But it could be my understanding of Resolves that got me in trouble.
Interesting, I didn't notice the ruling, so I guess it works differently than it used to (or perhaps I was misremembering). I'm not really sure the best way to handle this here, since multi-targeting isn't quite right (I know some people started scripting cards in this fashion) since i believe it interferes with on target triggers (like Angelic Protector and all these)
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Adding support for "divided as you choose"

Postby moomarc » 13 Mar 2012, 16:00

I missed those when I considered trying to add this. But at least I know the base idea was almost there. Perhaps we could still handle it the way I initially planned, just TriggerBecomesTarget.setTriggeringObjects will only run if it doesn't already contain that card?

Of course that's assuming we can get past the initial double targeting problem. Any idea if that can even be done?
-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: Adding support for "divided as you choose"

Postby friarsol » 13 Mar 2012, 17:14

moomarc wrote:I missed those when I considered trying to add this. But at least I know the base idea was almost there. Perhaps we could still handle it the way I initially planned, just TriggerBecomesTarget.setTriggeringObjects will only run if it doesn't already contain that card?

Of course that's assuming we can get past the initial double targeting problem. Any idea if that can even be done?
I haven't looked at the Target code in a while, but I'm guessing it's probably the UI code that's filtering out pre-existing cards, either that or the structure is a Set which only allows a single Unique object in it by definition.

Be careful with trying to code around the trigger stuff, not sure how well that plays with Seeds of Strength (which does allow you to target the same creature multiple times).
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Adding support for "divided as you choose"

Postby slowe » 14 Mar 2012, 00:51

The choice for dividing damage as you choose does indeed occur at the same time as target declaration. This is in contrast to "divided evenly", like in Fireball, which occurs on resolution.

As for implementing it in Forge, I don't know the relevant code, but I think you'll probably need to change how the targeting information is input from the UI. It's important to remember that selecting a target past the first time does something different than the first time, when it's chosen as a target. The way Arc Lightning and friends are currently scripted is incorrect (they don't interact properly with Urza's Armor, for example).

MTGO handles dividing as you choose by popping up a little spinner on each target as you declare it. The spinner has a number, initially 1, between an up arrow and a down arrow, which increase or decrease assigned damage by 1 each time they're clicked. A target stops being a target when you adjust damage assigned to it down to 0. This interface seems most user-friendly, though it might be a pain to implement. Alternatively, each time you select a target, Forge could display a (text field) prompt for number of damage to assign this target, or 0 to cancel selecting it. That seems like it's probably easier to implement and could be done without changing how targets are removed from the list of potential targets.
It's hard to say what method is objectively best.
slowe
 
Posts: 127
Joined: 05 Jan 2010, 14:04
Has thanked: 6 times
Been thanked: 10 times

Re: Adding support for "divided as you choose"

Postby moomarc » 15 Mar 2012, 11:53

I think I might have to give this up as a lost cause until I've learned a bit more java. This is just getting too complex for my skills.

My initial concept was basically:
Code: Select all
if ability containsKey "DividedAsYouChoose";
    if MaxTargets is not available
        set MaxTargets to NumDmg
    set damage amount = 1 instead of NumDmg value
    select targets (multiple times if wanted)
    apply damage
end
Now it looks something like this:
Code: Select all
if ability containsKey "DividedAsYouChoose"
    if NumDmg > 0
        create array list tgtsChosen
        create array list dmgDivided
        create Integer dmgRemaining = NumDmg
        //begin loop
        final dmgRemaining = dmgRemaining - (int value of dmgDivided)
        select target
            choose damage amount from GuiUtils.chooseOne(number range [zero] to[dmgRemaining])
            if chosenDmg != 0
                set target as Targeted
                add target to tgtsChosen
                add chosenDmg to dmgDivided
                if dmgRemaining != 0
                    restart loop
        //Then the part that I REALLY would have no idea how to do,
        //deal damage to each target based on its array position.
        //perhaps something like:
        for tgt(tgtsChosen[i])
            apply dmg(dmgDivided[i])
End
I could figure that much out, I just don't have the knowledge or knowhow to actually implement. One day I'll get back to it if no-one else has. :(

Edit: Realised that you wouldn't need a MaxTargets parameter for the new method as it's determined by the target selection loop. Removed.
-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


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 29 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 29 users online :: 0 registered, 0 hidden and 29 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 29 guests

Login Form