It is currently 07 Jul 2021, 11:45
   
Text Size

Need for a new object reference

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

Need for a new object reference

Postby LevelX » 25 May 2014, 09:29

Need for a new object reference

During the game there is often a reference to the a specific object instance needed (e.g. permanent, card in graveyard ...). For that reason we use the zoneChangeCounter and check if the number is the same. But therefore the number has to be saved and currently this is not done automatically. If for example you enchant a permanent, the reference goes to the sourceId. But if the enchanted permanent goes to gravevard and returns, the effect can't know if the current permanent was the permanent the enchantment enchanted before.

Plopman gave a good practical example where this problem causes bugs:
1) You have a Safehold Elite (2/2 with Persists) on the battlefield.
2) You enchant it with Murder Investigation (When enchanted creature dies, put X 1/1 white Soldier creature tokens onto the battlefield, where X is its power).
3) The Safehold Elite dies by damage (e.g. gets 3 damage from a Lightning Bolt).
4) This generates two triggred effects:
* Persists to return the Safehold Elite with one -1/-1 counter
* Murder Investigation ability to bring tokens into play.
5) If you choose to resolve the Undying trigger to resolve first, the Safehold Elite returns with -1/-1 counter and the after that resolving Murder Investigation effect creates only one token instead of two what would be correct.

The reason is clear. It's because the Murder Investigation is only checking with the sourceID if there is a permanent on the battlefield and uses the power of that permanent. But it has to know, that this was not the enchanted permanent and take from "last known information" the permanent taht died before with a power of 2.

So I guess a possible solution would be to create a new UUID, I would call it for example instanceId. This Id must be created and updated for an object always if the object changes zone.

Or we create a new object called objectReference that has the sourceId and the zoneChangeCounter as attributes and is used instead of sourceId to save a reference to an object.

Both solutions will need a lot of changes if we will use it for reference.

Any other suggestions or ideas concerning this issue?
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Need for a new object reference

Postby quercitron » 29 May 2014, 17:02

I looked at the problem, and how I see it: during resolving of effects in the stack an object can be removed from some zone and then returned back to this zone, and we have not enough information to understand did this happen or not (because we know only objectId).

Another small connected issue I found: if the object is removed from the same zone several times, we keep in LKI only information about last zone change.

I agree that the solution can be update of the object’s key every time it changes the zone. About implementation approaches described earlier:

1. Change objectId after each change of zone. While it solves the problem, in my opinion it can bring some difficulties with explicit control of object (e.g. in cases when the object changes the zone multiple times during the effect resolving). I think it's good to have some ID that would never be changed.

2. Use two fields as a key: objectId (that is always the same) and some value that is changed when the object changes the zone (we can use current zoneChangeCounter or replace it with another random UUID field). We can use such reference key everywhere we need the reference to an object. At the same time we can leave old functionality that operates only with objectId to use it in effects implementation (not 100% sure it's good idea).

So far I don’t see big shortcomings of the second approach except that it needs great amount of work to be implemented (because it affects not only framework, but also existing cards). So I think we have to be absolutely sure that new approach is right before we start to implement it.
quercitron
 
Posts: 17
Joined: 09 Nov 2011, 08:32
Has thanked: 0 time
Been thanked: 1 time

Re: Need for a new object reference

Postby North » 29 May 2014, 20:19

I do not think we need such a thing. In this particular example, Murder Investigation isn't correctly implemented. It should remember the value of the power when it is being put on the stack.

As such, many effects like this should remember the state of the relevant object when being put on the stack. There are some exceptions like: <source> deals 1 damage to target player. In this case the source on the battlefield is used. If it is not there, LKI is used. But this is because the source is an actor in the effect resolution.
North
DEVELOPER
 
Posts: 93
Joined: 15 May 2011, 08:20
Has thanked: 8 times
Been thanked: 15 times

Re: Need for a new object reference

Postby quercitron » 29 May 2014, 22:29

Many effects check values on resolution.

For example Trostani, Selesnya's Voice is on the battlefield.
Grizzly Bears comes into play, and the Trostani, Selesnya's Voice trigger is put on the stack.
Then Giant Growth is cast on the Grizzly Bears.
Then Grizzly Bears is flickered with Cloudshift.
Another Trostani, Selesnya's Voice trigger is put on the stack.
Then both Trostani, Selesnya's Voice triggered effects resolve.

Player should receive 5 life from first effect and 2 life from second effect, but in current implementation player receives two times 2 life. Effect cannot remember value when it's put on the stack, and on resolution effect doesn't know that Grizzly Bears on the battlefield is new one, and the first Grizzly Bears left battlefield.
quercitron
 
Posts: 17
Joined: 09 Nov 2011, 08:32
Has thanked: 0 time
Been thanked: 1 time

Re: Need for a new object reference

Postby LevelX » 29 May 2014, 23:00

North wrote:I do not think we need such a thing. In this particular example, Murder Investigation isn't correctly implemented. It should remember the value of the power when it is being put on the stack.
As Quercitron already pointed out it won't work correctly to remember the value when the ability/spell goes to stack.
The power of Safehold Elite can change after Murder Investigation went to stack e.g. by a boost spell. And if Safehold Elite is destroyed later the boosted power counts for Murder Investigation.
Code: Select all
Ruling for Murder Investigation
24.01.2013    To determine how many Soldier tokens are created, use the power of the enchanted creature as it last existed on the battlefield.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Need for a new object reference

Postby noxx » 30 May 2014, 14:12

As for me I agree we need to add objectReferenceId that is sourceId + zoneChangeCounter.
And store the LKI for objectReferenceIds not for sourceIds.

For sure, it should be covered by tests.
noxx
DEVELOPER
 
Posts: 110
Joined: 25 Mar 2012, 08:13
Has thanked: 3 times
Been thanked: 37 times

Re: Need for a new object reference

Postby LevelX » 23 Aug 2014, 16:13

I created a new class MageObjectReference to handle a object reference including the zone change counter.
I used it now to handle the damaged objects of DamagedByWatcher and changed the cards using it according.
The needed changes are inluded in this commit.

I guess there is room for improvements in the future.
Maybe it's useful to add a getMageObjectReference method to card (and permanent).

So if you creating new classes/functions take it into account and use it if object reference is needed.

Any suggestions or discussion are welcome.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times


Return to Developers Talk

Who is online

Users browsing this forum: No registered users and 3 guests

cron

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests (based on users active over the past 10 minutes)
Most users ever online was 1922 on 07 Jun 2021, 06:01

Users browsing this forum: No registered users and 3 guests

Login Form