ETB Replacement
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
23 posts
• Page 1 of 2 • 1, 2
ETB Replacement
by Hellfish » 24 Aug 2012, 18:23
Alright, got a spouse-less weekend ahead of me so it's project time!
I'm thinking of turning our static ETB triggers into the proper ETB replacement effects they should be, mainly to interact correctly with eachother (and Essence of the Wild </ulterior motive>). I'd convert etbCounter and add a macro to eliminate quite a bit of boilerplate.
This would give the card a "Moved" replacement that replaces the card ETB'ing with resolving the ability in the referenced SVar and THEN ETB'ing.
I have run into a little problem,though. There seems to be some contradiction between gatherer and comprules which is sowing the foul seeds of doubt.
The problem is with Essence of the Wild (Or really, if any two copy effects try to replace a single event). The gatherer ruling states that a creature will enter the battlefield as a copy of EotW even if it's a cloner. Why would it do so if you chose to apply the cloners effect last?
I'm thinking of turning our static ETB triggers into the proper ETB replacement effects they should be, mainly to interact correctly with eachother (and Essence of the Wild </ulterior motive>). I'd convert etbCounter and add a macro to eliminate quite a bit of boilerplate.
- Code: Select all
K:ETBReplacement:<Type>:<SVarReference>
This would give the card a "Moved" replacement that replaces the card ETB'ing with resolving the ability in the referenced SVar and THEN ETB'ing.
I have run into a little problem,though. There seems to be some contradiction between gatherer and comprules which is sowing the foul seeds of doubt.
- Comprules | Open
- 616. Interaction of Replacement and/or Prevention Effects
616.1. If two or more replacement and/or prevention effects are attempting to modify the way an event affects an object or player, the affected object's controller (or its owner if it has no controller) or the affected player chooses one to apply, following the steps listed below. If two or more players have to make these choices at the same time, choices are made in APNAP order (see rule 101.4).
616.1a. If any of the replacement and/or prevention effects are self-replacement effects (see rule 614.15), one of them must be chosen. If not, proceed to rule 616.1b.
616.1b. If any of the replacement and/or prevention effects would modify under whose control an object would enter the battlefield, one of them must be chosen. If not, proceed to rule 616.1c.
616.1c. If any of the replacement and/or prevention effects would cause an object to become a copy of another object as it enters the battlefield, one of them must be chosen. If not, proceed to rule 616.1d.
616.1d. Any of the applicable replacement and/or prevention effects may be chosen.
616.1e. Once the chosen effect has been applied, this process is repeated (taking into account only replacement or prevention effects that would now be applicable) until there are no more left to apply.
Example: Two permanents are on the battlefield. One is an enchantment that reads "If a card would be put into a graveyard from anywhere, instead exile it," and the other is a creature that reads "If [this creature] would be put into a graveyard from the battlefield, instead shuffle it into its owner's library." If the creature is destroyed, its controller decides which replacement to apply first; the other does nothing.
Example: Essence of the Wild reads "Creatures you control enter the battlefield as a copy of Essence of the Wild." A player who controls Essence of the Wild casts Rusted Sentinel, which normally enters the battlefield tapped. As it enters the battlefield, the copy effect from Essence of the Wild is applied first. As a result, it no longer has the ability that causes it to enter the battlefield tapped. Rusted Sentinel will enter the battlefield as an untapped copy of Essence of the Wild.
616.2. A replacement or prevention effect can become applicable to an event as the result of another replacement or prevention effect that modifies the event.
Example: One effect reads "If you would gain life, draw that many cards instead," and another reads "If you would draw a card, return a card from your graveyard to your hand instead." Both effects combine (regardless of the order they came into existence): Instead of gaining 1 life, the player puts a card from his or her graveyard into his or her hand
Hand: 1. A zone. A player's hand is where that player holds cards he or she has drawn but not played yet. 2. All the cards in a player's hand. See rule 402, "Hand."
402. Hand
.
- Gatherer Ruling | Open
- If a creature such as Clone is entering the battlefield under your control, there will be two copy effects to apply: the creature's own and Essence of the Wild's. No matter what order these effects are applied, the creature will be a copy of Essence of the Wild when it enters the battlefield.
The problem is with Essence of the Wild (Or really, if any two copy effects try to replace a single event). The gatherer ruling states that a creature will enter the battlefield as a copy of EotW even if it's a cloner. Why would it do so if you chose to apply the cloners effect last?
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: ETB Replacement
by Sloth » 24 Aug 2012, 18:34
This example explains it. The Clone effect is no longer there if the Clone became Essence of the Wild.Example: Essence of the Wild reads "Creatures you control enter the battlefield as a copy of Essence of the Wild." A player who controls Essence of the Wild casts Rusted Sentinel, which normally enters the battlefield tapped. As it enters the battlefield, the copy effect from Essence of the Wild is applied first. As a result, it no longer has the ability that causes it to enter the battlefield tapped. Rusted Sentinel will enter the battlefield as an untapped copy of Essence of the Wild.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: ETB Replacement
by Hellfish » 24 Aug 2012, 18:39
But the clone effect is a copy effect just like the eotw effect so you should choose which to apply first,shouldn't you?
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: ETB Replacement
by Sloth » 24 Aug 2012, 18:59
Yes, but if the clone effect is applied first it gets overridden by the Essence of the Wild effect. If the Essence of the Wild effect is applied first, the Clone effect will no longer apply. In the end Essence of the Wild will always win.Hellfish wrote:But the clone effect is a copy effect just like the eotw effect so you should choose which to apply first,shouldn't you?
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: ETB Replacement
by Hellfish » 24 Aug 2012, 19:08
Ah, I see! Thanks!
*Gets stuck in*

So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: ETB Replacement
by ArsenalNut » 24 Aug 2012, 22:39
I am glad you're looking at this. I have noticed some minor bugs with the clones due to the static ETB triggers, e.g. clones of Geralf's Messenger do not come into play tapped because they technically already on the battlefield when the static trigger fires. I could probably come up with some hacky fix but I think reworking things to be a proper ETB effect would be better.Hellfish wrote:Alright, got a spouse-less weekend ahead of me so it's project time!
I'm thinking of turning our static ETB triggers into the proper ETB replacement effects they should be, mainly to interact correctly with eachother (and Essence of the Wild </ulterior motive>). I'd convert etbCounter and add a macro to eliminate quite a bit of boilerplate.<Type> is one of: "Control","Copy","Other".
- Code: Select all
K:ETBReplacement:<Type>:<SVarReference>
This would give the card a "Moved" replacement that replaces the card ETB'ing with resolving the ability in the referenced SVar and THEN ETB'ing.
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: ETB Replacement
by Hellfish » 31 Aug 2012, 22:02
Well, got Clones and Essence of the Wild seemingly working and interacting correctly.Working on "ETB tapped" and with counters now. Counters might need a bit of work because of some conditionals they can have.
Took double the weekends I hoped for but hey,
Took double the weekends I hoped for but hey,

So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: ETB Replacement
by friarsol » 31 Aug 2012, 22:27
While you are in there, do you want to see how easy an optional etbCounters like the new RtR mechanic Unleash has? http://forums.mtgsalvation.com/attachme ... 1346430641Hellfish wrote:Well, got Clones and Essence of the Wild seemingly working and interacting correctly.Working on "ETB tapped" and with counters now. Counters might need a bit of work because of some conditionals they can have.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: ETB Replacement
by Hellfish » 31 Aug 2012, 22:50
Shouldn't be more work than adding a parameter, since the replacement system already has facilities for it. 
EDIT:

EDIT:
- Code: Select all
Name:Grim Roustabout
ManaCost:1 B
Types:Creature Skeleton Warrior
Text:no text
PT:1/1
K:ETBReplacement:Other:Unleash:Optional
SVar:Unleash:DB$ PutCounter | Defined$ Self | CounterType$ P1P1 | CounterNum$ 1 | SpellDescription$ Unleash (You may have this creature enter the battlefield with a +1/+1 counter on it.It can't block as long as it has a +1/+1 counter on it.)
A:AB$ Regenerate | Cost$ 1 B | Defined$ Self | SpellDescription$ Regenerate CARDNAME.
S:Mode$ Continuous | Affected$ Card.Self | AddHiddenKeyword$ HIDDEN CARDNAME can't block. | CheckSVar$ X | SVarCompare$ GE1 | References$ X
SVar:X:Count$NumCounters.P1P1
End
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: ETB Replacement
by Sloth » 02 Sep 2012, 12:35
Cards with K:etbCounter do not work anymore. Do they need to be converted now?
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: ETB Replacement
by Hellfish » 02 Sep 2012, 14:42
Whoops, that was an accident
I just restored that functionality.

I just restored that functionality.
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: ETB Replacement
by ArsenalNut » 03 Sep 2012, 16:08
There appears to be a problem with clones entering the battlefield from a zone other than the stack. I tested the following cases:
1) Kill a Clone copying a creature with Undying, e.g. Geralf's Messenger
2) Flick a clone with Restoration Angel
3) Return a Phantasmal Image to play with Sun Titan
The user gets all the choices to pick a card to copy but the copy doesn't appear. In the case of an Undying clone, the user gets a 1/1 clone.
I tried running it down in the debugger. I think the problem is that replacement effect is running the AF's associated with the Card object that was first put into play and not the Card that is being moved back into play. For example when I cast Phantasmal Image, it's Card object had an ID = 601 and both forge.GameAction.changeZone and the the Clone AF were using this object. When the Phantasmal Image was returning due to Undying, the Card object ID was 634 but the Clone AF that ran still had the Card object with ID=601 as it's host. The wrong object get changed which results in Card (634) being put into play as Phantasmal Image with +1/+1 counter on it.
I am not sure how to fix the issue though.
1) Kill a Clone copying a creature with Undying, e.g. Geralf's Messenger
2) Flick a clone with Restoration Angel
3) Return a Phantasmal Image to play with Sun Titan
The user gets all the choices to pick a card to copy but the copy doesn't appear. In the case of an Undying clone, the user gets a 1/1 clone.
I tried running it down in the debugger. I think the problem is that replacement effect is running the AF's associated with the Card object that was first put into play and not the Card that is being moved back into play. For example when I cast Phantasmal Image, it's Card object had an ID = 601 and both forge.GameAction.changeZone and the the Clone AF were using this object. When the Phantasmal Image was returning due to Undying, the Card object ID was 634 but the Clone AF that ran still had the Card object with ID=601 as it's host. The wrong object get changed which results in Card (634) being put into play as Phantasmal Image with +1/+1 counter on it.
I am not sure how to fix the issue though.
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: ETB Replacement
by Hellfish » 06 Sep 2012, 18:02
Whoop whoop, that was easier than I feared! (No jinx, no jinx...)
Should be good now, thanks!
Should be good now, thanks!
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: ETB Replacement
by ArsenalNut » 07 Sep 2012, 14:28
I ran through all my clone tests I looked at previously with your fixes. Everything worked perfectly. Thanks.Hellfish wrote:Whoop whoop, that was easier than I feared! (No jinx, no jinx...)
Should be good now, thanks!
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: ETB Replacement
by Hellfish » 11 Sep 2012, 21:12
etbCounter cards should be okay now, with slight changes. Instead of the special case conditions, that part of the keyword is now taken as extra parameters straight into the etb replacement effect. This lets you put CheckSVar parameters and really, anything else, there.
I'll probably turn "CARDNAME enters the battlefield tapped" into a macro too rather than replace all instance of it with ETBReplacements. It's "just" 171 cards, I'm lazy that way.
I'll probably turn "CARDNAME enters the battlefield tapped" into a macro too rather than replace all instance of it with ETBReplacements. It's "just" 171 cards, I'm lazy that way.
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
23 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 39 guests