[still bugged]Barbed Foliage vs. Jabari's Banner

Describe the Bug:
Flanking gained by a creature after Barbed Foliage activates (like from an activation of Jabari's Banner during the Before Blockers subphase) doesn't trigger.
Which card did behave improperly ?
Pretty sure the fault lies with Barbed Foliage. Though I guess it might be in granted_flanking() (and Sidewinder Sliver).
Which update are you using?(date,name)Which type(Duel,Gauntlet,Sealed Deck)
FRF.
What exactly should be the correct behavior/interaction ?
Declare Attackers:
Suq'Ata Lancer attacks opponent controlling Barbed Foliage.
Before Blockers:
Barbed Foliage's trigger makes Suq'Ata Lancer lose flanking until end of turn.
Player activates Jabari's Banner targeting Suq'Ata Lancer.
Suq'Ata Lancer gains a different instance of flanking until eot.
Declare Blockers:
Wall of Air blocks Suq'Ata Lancer.
After Blockers:
Wall of Air gets -1/-1 until eot.
Are any other cards possibly affected by this bug ?
Sidewinder Sliver, both due to its current implementation, and for a Sidewinder Sliver that gets put on the battlefield after Barbed Foliage triggers for other attacking slivers. I'm not positive whether those other slivers should have flanking in this case or not, though I tend to think so. Second opinions?
The horrible hack for Cavalry Master will need attention too. It already doesn't work right with Jabari's Banner (or multiple copies of Sidewinder Sliver) as is - control Suq'Ata Lancer (one instance of flanking) and a Cavalry Master (second instance on the Lancer), activate Jabari's Banner targeting lancer (third instance), and creatures blocking the Lancer get -4/-4 instead of -3/-3. (Same story for two Sidewinder Sliver and a Cavalry Master - something blocking one of the slivers will get -4/-4 instead of -3/-3.) Fiddling with Barbed Foliage is going to complicate it even more.
It's going to be very easy for a fix for this to accidentally make that Wall of Air in the testcase above get -2/-2 instead of -1/-1. Tentative suggestions:
Alternate solution:
Having implemented and tested this in Shandalar now, the key ideas turn out to be step 4 in the first method and 3 in the second. Barbed Foliage's effect card (still attaching to each creature, as it currently does) removes SF_KEYWORD_FLANKING during EVENT_ABILITIES. The equivalents of granted_flanking() and card_sidewinder_sliver() check whether there's a Barbed Foliage effect card attached to the creature with flanking; if so, it compares timestamps. If (Barbed Foliage effect card)->timestamp > (card that's adding flanking)->timestamp, that instance of flanking bails out.
Flanking added by Cavalry Master is a special case. So long as the SF_KEYWORD_FLANKING bit is present, it means there's at least one effect that added flanking after Barbed Foliage's trigger resolved, so Cavalry Master's continuous effect should still work, and therefore flanking granted by the Master doesn't check for Barbed Foliage effects. (At least, that's how I think it's supposed to work. Cavalry Master has a ruling saying that it doesn't work if the creature loses flanking, but doesn't address the more complex case where a creature loses flanking but gains a separate instance, both after Cavalry Master's timestamp.)
Flanking gained by a creature after Barbed Foliage activates (like from an activation of Jabari's Banner during the Before Blockers subphase) doesn't trigger.
Which card did behave improperly ?
Pretty sure the fault lies with Barbed Foliage. Though I guess it might be in granted_flanking() (and Sidewinder Sliver).
Which update are you using?(date,name)Which type(Duel,Gauntlet,Sealed Deck)
FRF.
What exactly should be the correct behavior/interaction ?
Declare Attackers:
Suq'Ata Lancer attacks opponent controlling Barbed Foliage.
Before Blockers:
Barbed Foliage's trigger makes Suq'Ata Lancer lose flanking until end of turn.
Player activates Jabari's Banner targeting Suq'Ata Lancer.
Suq'Ata Lancer gains a different instance of flanking until eot.
Declare Blockers:
Wall of Air blocks Suq'Ata Lancer.
After Blockers:
Wall of Air gets -1/-1 until eot.
Are any other cards possibly affected by this bug ?
Sidewinder Sliver, both due to its current implementation, and for a Sidewinder Sliver that gets put on the battlefield after Barbed Foliage triggers for other attacking slivers. I'm not positive whether those other slivers should have flanking in this case or not, though I tend to think so. Second opinions?
The horrible hack for Cavalry Master will need attention too. It already doesn't work right with Jabari's Banner (or multiple copies of Sidewinder Sliver) as is - control Suq'Ata Lancer (one instance of flanking) and a Cavalry Master (second instance on the Lancer), activate Jabari's Banner targeting lancer (third instance), and creatures blocking the Lancer get -4/-4 instead of -3/-3. (Same story for two Sidewinder Sliver and a Cavalry Master - something blocking one of the slivers will get -4/-4 instead of -3/-3.) Fiddling with Barbed Foliage is going to complicate it even more.
It's going to be very easy for a fix for this to accidentally make that Wall of Air in the testcase above get -2/-2 instead of -1/-1. Tentative suggestions:
Make SF_FLANKING_REMOVED only apply to continuous effects - creatures' static abilities and Sidewinder Sliver.Make Barbed Foliage destroy any effect cards from Jabari's Banner currently attached to creatures triggering it and remove SF_KEYWORD_FLANKING, in addition to its current addition of SF_FLANKING_REMOVED.- Remove the check for Cavalry Master in granted_flanking() and card_sidewinder_sliver(). Instead, pretend Cavalry Master reads "Flanking. Whenever another creature you control with flanking becomes blocked by a creature without flanking, the blocking creature gets -1/-1 until end of turn."
- For Sidewinder Sliver, I'm less certain. Maybe put an effect on the bf the first time each combat that Barbed Foliage triggers, and compare the effect's timestamp to each Sidewinder Sliver's?
Alternate solution:
- Make Barbed Foliage attach an effect card to each attacking creature with flanking whenever it triggers instead of doing anything else except damage (so no more SF_FLANKING_REMOVED).
When attaching the effect, count the current number of instances of flanking on the creature. Store it on the effect card.- Barbed Foliage's effect should remove SF_KEYWORD_FLANKING from the creature it's attached to during EVENT_ABILITIES (in normal timestamp order).
- In granted_flanking() and card_sidewinder_sliver(), check for the presence of Barbed Foliage's effect.
For each one found, remove the proper number of instances of flanking, and reset that number on the effect card to zero (so something with innate flanking and a Jabari's Banner effect that post-dates the Barbed Foliage effect doesn't apply the removals twice; but it's still removing SF_KEYWORD_FLANKING in proper timestamp order). - Still redo Cavalry Master as in #3 of the first solution.
Having implemented and tested this in Shandalar now, the key ideas turn out to be step 4 in the first method and 3 in the second. Barbed Foliage's effect card (still attaching to each creature, as it currently does) removes SF_KEYWORD_FLANKING during EVENT_ABILITIES. The equivalents of granted_flanking() and card_sidewinder_sliver() check whether there's a Barbed Foliage effect card attached to the creature with flanking; if so, it compares timestamps. If (Barbed Foliage effect card)->timestamp > (card that's adding flanking)->timestamp, that instance of flanking bails out.
Flanking added by Cavalry Master is a special case. So long as the SF_KEYWORD_FLANKING bit is present, it means there's at least one effect that added flanking after Barbed Foliage's trigger resolved, so Cavalry Master's continuous effect should still work, and therefore flanking granted by the Master doesn't check for Barbed Foliage effects. (At least, that's how I think it's supposed to work. Cavalry Master has a ruling saying that it doesn't work if the creature loses flanking, but doesn't address the more complex case where a creature loses flanking but gains a separate instance, both after Cavalry Master's timestamp.)