Fix core/client/ai

core/client/ai didn't work well when WNEXT_APPEARED comes after GROUNDED.
We fixed that bug and re-arranged the core/client/ai more understandable.