Card isInZone function
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
3 posts
• Page 1 of 1
Card isInZone function
by Sloth » 06 Aug 2013, 14:26
The isInZone function in the card class is not really doing what it's supposed to do.
It's used a lot to test whether a card is still on the battlefield (or in a nother zone). When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.
When i search for "isInPlay()" in our code i get 73 results and nearly all of them do not function properly with this isInZone function.
@Max: What was the reason to change the isInZone function (r22432)?
For reference, here is the old version:
It's used a lot to test whether a card is still on the battlefield (or in a nother zone). When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.
When i search for "isInPlay()" in our code i get 73 results and nearly all of them do not function properly with this isInZone function.
@Max: What was the reason to change the isInZone function (r22432)?
For reference, here is the old version:
- Code: Select all
public boolean isInZone(final ZoneType zone) {
return getGame().isCardInZone(this, zone);
}
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Card isInZone function
by Max mtg » 07 Aug 2013, 09:24
Then it's the problem in code that does not update the Card instance with new zone.Sloth wrote: When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.
It is the card that may belong to one and only zone (or none at all). Lists of cards present an opportunity to hold a single card in several zones at once, that is nonsense.
There are also some code routines that iterate over cardlist and need to know the zone each card belongs to. Using the previous implementation would lead to quadruple loop (1st loop is over card list, 2nd one is over players, 3rd over zones of current player and 4th is the lookup inside zone for a certain card)
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Card isInZone function
by Sloth » 07 Aug 2013, 11:09
The problem is that a card moving from the battlefield to any other zone will create a new card object and the old card object (lingering around as source of a spell/ability or triggering object) will have the wrong currentZone variable.Max mtg wrote:Then it's the problem in code that does not update the Card instance with new zone.Sloth wrote: When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.
r22822 fixes most of the issues, but there is still the corner case that a card can change zones multiple times while something on the stack refers to it.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 70 guests