I am playing a Rogue who is planning on dipping 1-5 levels into fighter. If I get to level 3 of Fighter, I will take the Battle Master archetype and take the Parry, Riposte and Feinting attack maneuvers.
Our group uses the "Optional Rule: Flanking" from the DMG.
Say it is my turn and I am currently flanking an enemy with a friendly PC. When I move directly away from the enemy, they may attempt to hit me with an opportunity attack. If it hits, I use Parry and reduce the damage. If it misses, I use my reaction to Riposte to hit him back.
Would I have advantage on the attack from Riposte because I am still flanking? Or because I started moving away, would I no longer be flanking?
My party uses the optional rules of flanking and playing on a grid. (We're still working on getting custom miniatures, so we are using extra coloured D6s to represent enemies and PCs.)
Side note: I started thinking about this because I wanted to maximise my Sneak Attack damage. I can do Sneak Attack when I get hit outside of my turn and use Riposte. So I thought maybe I could trigger an attack so I could cause double Sneak Attack damage reliably. But then I realised it would still be on my turn, and the description for Sneak Attack is quite specific when it says "once per turn". I continued wondering about the flanking/advantage bit, though.