NPC advanced AI does not know what to do when you're in fly state, dig state, or dive state most of the time. It will switch out the turn you're invincible.
Steps to reproduce:
1. Have an NPC with a team of 6
2. Have a fast Pokemon with fly
3. Use fly 1st turn >> Opponent will use a move and miss >> Opponent will switch out >> Your fly will hit
4. Use fly again >> Opponent will use a move and miss >> Opponent will switch out >> Your fly will hit
It does not always happen, but the switches seem to be random. It's not switching to a Pokemon that resists the attack either.
Another case is when you're in fly state, dig state or dive state, the NPC Advanced AI won't know your type and will just use their most powerful move. For example when I fly using Flygon:
1. Flygon uses fly
2. Zapdos will use discharge
3. Flygon's fly hits
4. Zapdos uses thunderbolt on flygon