/ /   = = U s e r S c r i p t = = 
 
 / /   @ n a m e                 E n s i n g m 2   S a l i e n   G a m e   I d l e r 
 
 / /   @ n a m e s p a c e         h t t p s : / / g i t h u b . c o m / e n s i n g m 2 / s a l i e n g a m e _ i d l e r 
 
 / /   @ v e r s i o n                 0 . 0 . 1 _ r u   ( 0 1 . 0 7 . 2 0 1 8 ) 
 
 / /   @ a u t h o r                 e n s i n g m 2 
 
 / /   @ m a t c h                 * : / / s t e a m c o m m u n i t y . c o m / s a l i e n g a m e / p l a y 
 
 / /   @ m a t c h                 * : / / s t e a m c o m m u n i t y . c o m / s a l i e n g a m e / p l a y / 
 
 / /   @ g r a n t                 n o n e 
 
 / /   = = / U s e r S c r i p t = = 
 
 
 
 / /   T h i s   i s   t h e   z o n e   y o u   w a n t   t o   a t t a c k   ( O p t i o n a l ,   o t h e r w i s e   p i c k s   o n e   f o r   y o u ) . 
 
 v a r   t a r g e t _ z o n e   =   - 1 ; 
 
 
 
 / /   V a r i a b l e s .   D o n ' t   c h a n g e   t h e s e   u n l e s s   y o u   k n o w   w h a t   y o u ' r e   d o i n g . 
 
 v a r   r e a l _ r o u n d _ l e n g t h   =   1 2 0 ;   / /   R o u n d   L e n g t h   o f   a   r e a l   g a m e   ( I n   S e c o n d s ,   f o r   c a l c u l a t i n g   s c o r e ) 
 
 v a r   r e s e n d _ f r e q u e n c y   =   1 1 0 ;   / /   F r e q u e n c y   a t   w h i c h   w e   c a n   s a y   w e   f i n i s h e d   a   r o u n d   ( M a y   b e   d i f f e r e n t   t h a n   r e a l   l e n g t h ) 
 
 v a r   u p d a t e _ l e n g t h   =   1 ;   / /   H o w   l o n g   t o   w a i t   b e t w e e n   u p d a t e s   ( I n   S e c o n d s ) 
 
 v a r   l o o p _ r o u n d s   =   t r u e ; 
 
 v a r   l a n g u a g e   =   " e n g l i s h " ;   / /   U s e d   w h e n   P O S T i n g   s c o r e s 
 
 v a r   a c c e s s _ t o k e n   =   " " ; 
 
 v a r   a c c o u n t _ i d   =   u n d e f i n e d ;   / /   U s e d   t o   g e t   d a t a   b a c k   i n   b o s s   b a t t l e s 
 
 v a r   c u r r e n t _ g a m e _ i d   =   u n d e f i n e d ; 
 
 v a r   c u r r e n t _ g a m e _ s t a r t   =   u n d e f i n e d ;   / /   T i m e s t a m p   f o r   w h e n   t h e   c u r r e n t   g a m e   s t a r t e d 
 
 v a r   t i m e _ p a s s e d _ m s   =   0 ; 
 
 v a r   c u r r e n t _ t i m e o u t   =   u n d e f i n e d ; 
 
 v a r   m a x _ r e t r y   =   5 ;   / /   M a x   n u m b e r   o f   r e t r i e s   t o   s e n d   r e q u e s t s 
 
 v a r   a u t o _ f i r s t _ j o i n   =   t r u e ;   / /   A u t o m a t i c a l l y   j o i n   t h e   b e s t   z o n e   a t   f i r s t 
 
 v a r   c u r r e n t _ p l a n e t _ i d   =   u n d e f i n e d ; 
 
 v a r   l a s t _ u p d a t e _ g r i d   =   u n d e f i n e d ;   / /   L a s t   t i m e   w e   u p d a t e d   t h e   g r i d   ( t o   a v o i d   t o o   f r e q u e n t   c a l l s ) 
 
 v a r   c h e c k _ g a m e _ s t a t e   =   u n d e f i n e d ;   / /   C h e c k   t h e   s t a t e   o f   t h e   g a m e   s c r i p t   a n d   u n l o c k   i t   i f   n e e d e d   ( s e t I n t e r v a l ) 
 
 v a r   a u t o _ s w i t c h _ p l a n e t   =   { 
 
         " a c t i v e " :   t r u e ,   / /   A u t o m a t i c a l l y   s w i t c h   t o   t h e   b e s t   p l a n e t   a v a i l a b l e   ( t r u e   :   y e s ,   f a l s e   :   n o ) 
 
         " c u r r e n t _ d i f f i c u l t y " :   u n d e f i n e d , 
 
         " r o u n d s _ b e f o r e _ c h e c k " :   1 ,   / /   W e   s t a r t   a   p l a n e t s   c h e c k   i n   t h i s   a m o u n t   o f   r o u n d s 
 
         " c u r r e n t _ r o u n d " :   0 
 
 } ; 
 
 v a r   g u i ;   / / l o c a l   g u i   v a r i a b l e 
 
 v a r   s t a r t _ b u t t o n   =   f a l s e ;   / /   i s   s t a r t   b u t t o n   a l r e a d y   p r e s s e d ? 
 
 v a r   a n i m a t i o n s _ e n a b l e d   =   t r u e ; 
 
 v a r   b o s s _ o p t i o n s   =   { 
 
         " u p d a t e _ f r e q " :   5 ,   / /   N u m b e r   o f   s e c o n d s   b e t w e e n   c a l l s   t o   R e p o r t B o s s D a m a g e 
 
         " r e p o r t _ i n t e r v a l " :   u n d e f i n e d , 
 
         " e r r o r _ c o u n t " :   0 , 
 
         " l a s t _ h e a l " :   u n d e f i n e d , 
 
         " l a s t _ r e p o r t " :   u n d e f i n e d   / /   U s e d   i n   t h e   c h e c k   o f   t h e   g a m e   s c r i p t   s t a t e   a n d   u n l o c k   i t   i f   n e e d e d 
 
 } 
 
 v a r   c u r r e n t _ g a m e _ i s _ b o s s   =   f a l s e ;   / /   S t a t e   i f   w e ' r e   e n t e r i n g   /   i n   a   b o s s   b a t t l e   o r   n o t 
 
 v a r   a v o i d _ b o s s   =   f a l s e ;   / /   W e ' l l   s e t   i t   t o   t r u e   i f   y o u ' r e   a l m o s t   l e v e l   2 5   s o   y o u   c a n   g e t   y o u r   r e m a i n i n g   l e v e l - b a s e d   i t e m s . 
 
 
 
 c l a s s   B o t G U I   { 
 
         c o n s t r u c t o r ( s t a t e )   { 
 
                 c o n s o l e . l o g ( ' G U I   H a s   b e e n   c r e a t e d ' ) ; 
 
 
 
                 t h i s . s t a t e   =   s t a t e ; 
 
               
 
                 t h i s . c r e a t e S t a t u s W i n d o w ( ) ; 
 
                 t h i s . c r e a t e P r o g r e s s B a r ( ) ; 
 
         } 
 
 
 
         c r e a t e S t a t u s W i n d o w ( )   { 
 
                 i f ( d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ g u i ' ) )   { 
 
                         r e t u r n   f a l s e ; 
 
                 } 
 
 
 
                 v a r   $ s t a t u s W i n d o w   =   $ J ( [ 
 
                         ' < d i v   i d = " s a l i e n b o t _ g u i "   s t y l e = " b a c k g r o u n d :   # 1 9 1 9 1 9 ;   z - i n d e x :   1 ;   b o r d e r :   3 p x   s o l i d   # 8 3 d 6 7 4 ;   p a d d i n g :   1 0 p x ;   m a r g i n :   5 p x ;   w i d t h :   3 0 0 p x ;   t r a n s f o r m :   t r a n s l a t e ( 0 ,   0 ) ; " > ' , 
 
                                 ' < h 1 > < a   h r e f = " h t t p s : / / g i t h u b . c o m / e n s i n g m 2 / s a l i e n g a m e _ i d l e r / " > S a l i e n   G a m e   I d l e r < / a > < / h 1 > ' , 
 
                                 ' < p   s t y l e = " m a r g i n - t o p :   - . 8 e m " > < s p a n   i d = " s a l i e n b o t _ s t a t u s " > < / s p a n > < / p > ' ,   / /   R u n n i n g   o r   s t o p p e d 
 
                                 ' < p > < b > 040G0: < / b >   < s p a n   i d = " s a l i e n b o t _ t a s k " > =8F80;870F8O< / s p a n > < / p > ' ,   / /   C u r r e n t   t a s k 
 
                                 ` < p > < b > >=0: < / b >   < s p a n   i d = " s a l i e n b o t _ z o n e " >  < / s p a n > < / p > ` , 
 
                                 ` < p   s t y l e = " d i s p l a y :   n o n e ; "   i d = " s a l i e n b o t _ z o n e _ d i f f i c u l t y _ d i v " > < b > !;>6=>ABL: < / b >   < s p a n   i d = " s a l i e n b o t _ z o n e _ d i f f i c u l t y " > < / s p a n >   ( < s p a n   i d = " s a l i e n b o t _ z o n e _ s c o r e " > < / s p a n > X P / @0C=4) < / p > ` , 
 
                                 ' < p > < b > #@>25=L: < / b >   < s p a n   i d = " s a l i e n b o t _ l e v e l " > '   +   t h i s . s t a t e . l e v e l   +   ' < / s p a n >   & n b s p ; & n b s p ; & n b s p ; & n b s p ;   < b > ?KB: < / b >   < s p a n   i d = " s a l i e n b o t _ e x p " > '   +   t h i s . s t a t e . e x p   +   "   /   "   +   t h i s . s t a t e . n e x t _ l e v e l _ e x p   +   ' < / s p a n > < / p > ' , 
 
                                 ' < p > < b > >  0?0: < / b >   < s p a n   i d = " s a l i e n b o t _ e s t x p " > '   +   ( t h i s . s t a t e . n e x t _ l e v e l _ e x p   -   t h i s . s t a t e . e x p )   +   ' < / s p a n > X P   ( < s p a n   i d = " s a l i e n b o t _ e s t t i m l v l " > < / s p a n > ) < / p > ' , 
 
                                 ' < p > < i n p u t   i d = " p l a n e t S w i t c h C h e c k b o x "   t y p e = " c h e c k b o x " / >   2B><0B8G5A:0O  A<5=0  ?;0=5BK< / p > ' , 
 
                                 ' < p > < i n p u t   i d = " a n i m a t i o n s C h e c k b o x "   t y p e = " c h e c k b o x " / >   !:@KBL  83@C  ( C<5=LH05B  =03@C7:C) < / p > ' , 
 
                         ' < / d i v > ' 
 
                 ] . j o i n ( ' ' ) ) 
 
 
 
                 $ J ( ' # s a l i e n _ g a m e _ p l a c e h o l d e r ' ) . a p p e n d (   $ s t a t u s W i n d o w   ) 
 
         } 
 
 
 
         c r e a t e P r o g r e s s B a r ( )   { 
 
                 t h i s . p r o g r e s s b a r   =   n e w   C P r o g r e s s B a r ( 6 3 ) ; 
 
                 t h i s . p r o g r e s s b a r . x   =   2 
 
                 t h i s . p r o g r e s s b a r . y   =   4 8 
 
         } 
 
 
 
         u p d a t e S t a t u s ( r u n n i n g )   { 
 
                 c o n s t   s t a t u s T x t   =   r u n n i n g   ?   ' < s p a n   s t y l e = " c o l o r :   l i m e ; " > '   01>B05B< / s p a n > '   :   ' < s p a n   s t y l e = " c o l o r :   r e d ; " > '  AB0=>2;5=< / s p a n > ' ; 
 
 
 
                 $ J ( ' # s a l i e n b o t _ s t a t u s ' ) . h t m l ( s t a t u s T x t ) ; 
 
         } 
 
 
 
         u p d a t e T a s k ( s t a t u s ,   l o g _ t o _ c o n s o l e )   { 
 
                 i f ( l o g _ t o _ c o n s o l e   | |   l o g _ t o _ c o n s o l e   = = =   u n d e f i n e d ) 
 
                         c o n s o l e . l o g ( s t a t u s ) ; 
 
                 d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ t a s k ' ) . i n n e r T e x t   =   s t a t u s ; 
 
         } 
 
 
 
         u p d a t e E x p ( e x p )   { 
 
                 d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ e x p ' ) . i n n e r T e x t   =   e x p ; 
 
         } 
 
         u p d a t e E s t E x p ( e x p )   { 
 
                 d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ e s t x p ' ) . i n n e r T e x t   =   e x p ; 
 
         } 
 
 
 
         u p d a t e L e v e l ( l e v e l )   { 
 
                 d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ l e v e l ' ) . i n n e r T e x t   =   l e v e l ; 
 
         } 
 
 
 
         u p d a t e E s t i m a t e d T i m e ( s e c o n d s L e f t )   { 
 
                 l e t   d a t e   =   n e w   D a t e ( n u l l ) ; 
 
                 d a t e . s e t S e c o n d s ( s e c o n d s L e f t ) ; 
 
                 v a r   r e s u l t   =   d a t e . t o I S O S t r i n g ( ) . s u b s t r ( 8 ,   1 1 ) . s p l i t ( / [ T : ] / ) ; 
 
 
 
                 v a r   d a y s   =   r e s u l t [ 0 ] - 1 ; 
 
                 v a r   h o u r s   =   r e s u l t [ 1 ] ; 
 
                 v a r   m i n u t e s   =   r e s u l t [ 2 ] ; 
 
                 v a r   s e c o n d s   =   r e s u l t [ 3 ] ; 
 
 
 
                 v a r   t i m e T x t   =   " " ; 
 
                 i f ( d a y s   >   0 ) 
 
                         t i m e T x t   + =   d a y s   +   " 4  " ; 
 
                 i f ( h o u r s   >   0   | |   t i m e T x t . l e n g t h   >   0 ) 
 
                         t i m e T x t   + =   h o u r s   +   " G  " ; 
 
                 i f ( m i n u t e s   >   0   | |   t i m e T x t . l e n g t h   >   0 ) 
 
                         t i m e T x t   + =   m i n u t e s   +   " <  " ; 
 
 
 
                 t i m e T x t   + =   s e c o n d s   +   " A" ; 
 
 
 
                 d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ e s t t i m l v l ' ) . i n n e r T e x t   =   t i m e T x t ; 
 
         } 
 
 
 
         u p d a t e Z o n e ( z o n e ,   p r o g r e s s ,   d i f f i c u l t y ,   i s _ b o s s _ b a t t l e )   { 
 
                 v a r   p r i n t S t r i n g   =   z o n e ; 
 
                 i f ( i s _ b o s s _ b a t t l e   = = =   u n d e f i n e d ) 
 
                         i s _ b o s s _ b a t t l e   =   f a l s e ; 
 
                 i f ( p r o g r e s s   ! = =   u n d e f i n e d ) 
 
                         p r i n t S t r i n g   + =   "   ( "   +   ( p r o g r e s s   *   1 0 0 ) . t o F i x e d ( 2 )   +   " %   2K?>;=5=>) " 
 
                 i f ( p r o g r e s s   = = =   u n d e f i n e d )   { 
 
                         $ J ( " # s a l i e n b o t _ z o n e _ d i f f i c u l t y _ d i v " ) . h i d e ( ) ; 
 
                         d i f f i c u l t y   =   " " ; 
 
                 } 
 
                 e l s e   { 
 
                         $ J ( " # s a l i e n b o t _ z o n e _ d i f f i c u l t y _ d i v " ) . s h o w ( ) ; 
 
                         g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ t a r g e t _ z o n e ] . a d d C h i l d ( t h i s . p r o g r e s s b a r ) ; 
 
                       
 
                         d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ z o n e _ s c o r e ' ) . i n n e r T e x t   =   g e t _ m a x _ s c o r e ( z o n e ) ; 
 
                 } 
 
 
 
                 d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ z o n e ' ) . i n n e r T e x t   =   p r i n t S t r i n g ; 
 
 
 
                 i f ( i s _ b o s s _ b a t t l e ) 
 
                         d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ z o n e _ d i f f i c u l t y ' ) . i n n e r T e x t   =   d i f f i c u l t y   +   " [ B O S S ] " ; 
 
                 e l s e 
 
                         d o c u m e n t . g e t E l e m e n t B y I d ( ' s a l i e n b o t _ z o n e _ d i f f i c u l t y ' ) . i n n e r T e x t   =   d i f f i c u l t y ; 
 
         } 
 
 } ; 
 
 
 
 f u n c t i o n   i n i t G U I ( ) { 
 
         i f   ( ! g G a m e . m _ S t a t e   | |   g G a m e . m _ S t a t e   i n s t a n c e o f   C B o o t S t a t e   | |   g G a m e . m _ I s S t a t e L o a d i n g ) { 
 
                 i f ( g G a m e . m _ S t a t e   & &   ! g G a m e . m _ I s S t a t e L o a d i n g   & &   ! s t a r t _ b u t t o n ) { 
 
                         s t a r t _ b u t t o n   =   t r u e ; 
 
                         c o n s o l e . l o g ( " c l i c k i n g   b u t t o n " ) ; 
 
                         g G a m e . m _ S t a t e . b u t t o n . c l i c k ( ) ; 
 
                 } 
 
                 s e t T i m e o u t ( f u n c t i o n ( )   {   i n i t G U I ( ) ;   } ,   1 0 0 ) ; 
 
         }   e l s e   { 
 
                 c o n s o l e . l o g ( g G a m e ) ; 
 
                 g u i   =   n e w   B o t G U I ( { 
 
                         l e v e l :   g P l a y e r I n f o . l e v e l , 
 
                         e x p :   g P l a y e r I n f o . s c o r e , 
 
                         n e x t _ l e v e l _ e x p :   g P l a y e r I n f o . n e x t _ l e v e l _ s c o r e 
 
                 } ) ; 
 
 
 
                 / /   S e t   o u r   o n c l i c k s 
 
               
 
                 $ J ( ' # a n i m a t i o n s C h e c k b o x ' ) . c h a n g e ( f u n c t i o n ( )   { 
 
                         I N J E C T _ t o g g l e _ a n i m a t i o n s ( ! t h i s . c h e c k e d ) ; 
 
                 } ) ; 
 
                 $ J ( ' # a n i m a t i o n s C h e c k b o x ' ) . p r o p ( ' c h e c k e d ' ,   ! a n i m a t i o n s _ e n a b l e d ) ; 
 
               
 
                 $ J ( ' # p l a n e t S w i t c h C h e c k b o x ' ) . c h a n g e ( f u n c t i o n ( )   { 
 
                         a u t o _ s w i t c h _ p l a n e t . a c t i v e   =   t h i s . c h e c k e d ; 
 
                 } ) ; 
 
                 $ J ( ' # p l a n e t S w i t c h C h e c k b o x ' ) . p r o p ( ' c h e c k e d ' ,   a u t o _ s w i t c h _ p l a n e t . a c t i v e ) ; 
 
               
 
 
 
                 / /   R u n   t h e   g l o b a l   i n i t i a l i z e r ,   w h i c h   w i l l   c a l l   t h e   f u n c t i o n   f o r   w h i c h e v e r   s c r e e n   y o u ' r e   i n 
 
                 I N J E C T _ i n i t ( ) ; 
 
         } 
 
 } ; 
 
 
 
 f u n c t i o n   c a l c u l a t e T i m e T o N e x t L e v e l ( )   {     
 
         c o n s t   n e x t S c o r e A m o u n t   =   g e t _ m a x _ s c o r e ( t a r g e t _ z o n e ) ;     
 
         c o n s t   m i s s i n g E x p   =   M a t h . c e i l ( ( g P l a y e r I n f o . n e x t _ l e v e l _ s c o r e   -   g P l a y e r I n f o . s c o r e )   /   n e x t S c o r e A m o u n t )   *   n e x t S c o r e A m o u n t ; 
 
         c o n s t   r o u n d T i m e   =   r e s e n d _ f r e q u e n c y   +   u p d a t e _ l e n g t h ; 
 
 
 
         c o n s t   s e c o n d s L e f t   =   m i s s i n g E x p   /   n e x t S c o r e A m o u n t   *   r o u n d T i m e   -   t i m e _ p a s s e d _ m s   /   1 0 0 0 ; 
 
 
 
         r e t u r n   s e c o n d s L e f t ; 
 
 } 
 
 
 
 / /   H a n d l e   A J A X   e r r o r s   t o   a v o i d   t h e   s c r i p t   t o   b e   l o c k e d   b y   a   s i n g l e   A P I   e r r o r 
 
 f u n c t i o n   a j a x E r r o r H a n d l i n g ( a j a x O b j ,   p a r a m s ,   m e s s a g e s A r r a y )   { 
 
         a j a x O b j . t r y C o u n t + + ; 
 
         i f   ( a j a x O b j . t r y C o u n t   < =   a j a x O b j . r e t r y L i m i t )   { 
 
                 v a r   c u r r e n t T a s k   =   " R e t r y i n g   i n   5 s   t o   "   +   m e s s a g e s A r r a y [ 0 ]   +   "   ( >?KB:0  # "   +   a j a x O b j . t r y C o u n t   +   " ) .   H81:0:   "   +   p a r a m s . x h r . s t a t u s   +   " :   "   +   p a r a m s . t h r o w n E r r o r ; 
 
                 g u i . u p d a t e T a s k ( c u r r e n t T a s k ) ; 
 
                 s e t T i m e o u t ( f u n c t i o n ( )   {   $ J . a j a x ( a j a x O b j ) ;   } ,   5 0 0 0 ) ; 
 
         } 
 
         e l s e   { 
 
                 v a r   c u r r e n t T a s k   =   " H81:0  "   +   m e s s a g e s A r r a y [ 1 ]   +   " :   "   +   p a r a m s . x h r . s t a t u s   +   " :   "   +   p a r a m s . t h r o w n E r r o r   +   "   ( ;8<8B  ?>?KB>:  8AG5@?0=) . " ; 
 
                 g u i . u p d a t e T a s k ( c u r r e n t T a s k ) ; 
 
         } 
 
 } 
 
 
 
 / /   C h e c k   t h e   s t a t e   o f   t h e   g a m e   s c r i p t   a n d   u n l o c k   i t   i f   n e e d e d 
 
 f u n c t i o n   c h e c k U n l o c k G a m e S t a t e ( )   { 
 
         i f   ( c u r r e n t _ g a m e _ s t a r t   = = =   u n d e f i n e d   | |   ( c u r r e n t _ g a m e _ i s _ b o s s   = =   t r u e   & &   b o s s _ o p t i o n s . l a s t _ r e p o r t   = = =   u n d e f i n e d ) ) 
 
                 r e t u r n ; 
 
         v a r   n o w   =   n e w   D a t e ( ) . g e t T i m e ( ) ; 
 
         i f   ( c u r r e n t _ g a m e _ i s _ b o s s )   { 
 
                 v a r   t i m e D i f f   =   ( n o w   -   b o s s _ o p t i o n s . l a s t _ r e p o r t )   /   1 0 0 0 ; 
 
         }   e l s e   { 
 
                 v a r   t i m e D i f f   =   ( n o w   -   c u r r e n t _ g a m e _ s t a r t )   /   1 0 0 0 ; 
 
         } 
 
         v a r   m a x W a i t   =   3 0 0 ;   / /   T i m e   ( i n   s e c o n d s )   t o   w a i t   u n t i l   w e   t r y   t o   u n l o c k   t h e   s c r i p t 
 
         i f   ( t i m e D i f f   <   m a x W a i t ) 
 
                 r e t u r n ; 
 
         g u i . u p d a t e T a s k ( " D e t e c t e d   t h e   g a m e   s c r i p t   i s   l o c k e d .   T r y i n g   t o   u n l o c k   i t . " ) ; 
 
         i f   ( a u t o _ s w i t c h _ p l a n e t . a c t i v e   = =   t r u e )   { 
 
                 C h e c k S w i t c h B e t t e r P l a n e t ( t r u e ) ; 
 
         }   e l s e   { 
 
                 S w i t c h N e x t Z o n e ( 0 ,   t r u e ) ; 
 
         } 
 
 } 
 
 
 
 / /   G r a b   t h e   u s e r ' s   a c c e s s   t o k e n 
 
 v a r   I N J E C T _ g e t _ a c c e s s _ t o k e n   =   f u n c t i o n ( )   { 
 
         $ J . a j a x ( { 
 
                 a s y n c :   f a l s e , 
 
                 t y p e :   " G E T " , 
 
                 u r l :   " h t t p s : / / s t e a m c o m m u n i t y . c o m / s a l i e n g a m e / g e t t o k e n " , 
 
                 s u c c e s s :   f u n c t i o n ( d a t a )   { 
 
                         i f ( d a t a . t o k e n   ! =   u n d e f i n e d )   { 
 
                                 c o n s o l e . l o g ( " G o t   a c c e s s   t o k e n :   "   +   d a t a . t o k e n ) ; 
 
                                 a c c e s s _ t o k e n   =   d a t a . t o k e n ; 
 
                         } 
 
                         e l s e   { 
 
                                 c o n s o l e . l o g ( " F a i l e d   t o   r e t r i e v e   a c c e s s   t o k e n . " ) 
 
                                 a c c e s s _ t o k e n   =   u n d e f i n e d ; 
 
                         } 
 
                 } 
 
         } ) ; 
 
 } 
 
 
 
 / /   M a k e   t h e   c a l l   t o   s t a r t   a   r o u n d ,   a n d   k i c k - o f f   t h e   i d l e   p r o c e s s 
 
 v a r   I N J E C T _ s t a r t _ r o u n d   =   f u n c t i o n ( z o n e ,   a c c e s s _ t o k e n ,   a t t e m p t _ n o ,   i s _ b o s s _ b a t t l e )   { 
 
         i f ( a t t e m p t _ n o   = = =   u n d e f i n e d ) 
 
                 a t t e m p t _ n o   =   0 ; 
 
         i f ( i s _ b o s s _ b a t t l e   = = =   u n d e f i n e d ) 
 
                 i s _ b o s s _ b a t t l e   =   f a l s e ; 
 
 
 
         / /   L e a v e   t h e   g a m e   i f   w e ' r e   a l r e a d y   i n   o n e . 
 
         i f ( c u r r e n t _ g a m e _ i d   ! = =   u n d e f i n e d )   { 
 
                 g u i . u p d a t e T a s k ( " 1=0@C65=0  ?@54K4CI0O  83@0.   025@H05<  5Q. " ,   t r u e ) ; 
 
                 I N J E C T _ l e a v e _ r o u n d ( ) ; 
 
         } 
 
 
 
         v a r   p o s t U R L   =   " h t t p s : / / c o m m u n i t y . s t e a m - a p i . c o m / I T e r r i t o r y C o n t r o l M i n i g a m e S e r v i c e / J o i n Z o n e / v 0 0 0 1 / " ; 
 
         i f ( i s _ b o s s _ b a t t l e ) 
 
                 p o s t U R L   =   " h t t p s : / / c o m m u n i t y . s t e a m - a p i . c o m / I T e r r i t o r y C o n t r o l M i n i g a m e S e r v i c e / J o i n B o s s Z o n e / v 0 0 0 1 / " 
 
         / /   S e n d   t h e   P O S T   t o   j o i n   t h e   g a m e . 
 
         $ J . a j a x ( { 
 
                 a s y n c :   f a l s e , 
 
                 t y p e :   " P O S T " , 
 
                 u r l :   p o s t U R L , 
 
                 d a t a :   {   a c c e s s _ t o k e n :   a c c e s s _ t o k e n ,   z o n e _ p o s i t i o n :   z o n e   } , 
 
                 t r y C o u n t   :   0 , 
 
                 r e t r y L i m i t   :   m a x _ r e t r y , 
 
                 s u c c e s s :   f u n c t i o n ( d a t a ,   t e x t S t a t u s ,   j q X H R )   { 
 
                         i f (   $ J . i s E m p t y O b j e c t ( d a t a . r e s p o n s e )   )   { 
 
                                 / /   C h e c k   i f   t h e   z o n e   i s   c o m p l e t e d 
 
                                 I N J E C T _ u p d a t e _ g r i d ( f a l s e ) ;   / /   E r r o r   h a n d l i n g   s e t   t o   f a l s e   t o   a v o i d   t o o   m u c h   p a r a l l e l   c a l l s   w i t h   t h e   s e t T i m e o u t   b e l o w 
 
                                 i f ( w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ z o n e ] . I n f o . c a p t u r e d   | |   a t t e m p t _ n o   > =   m a x _ r e t r y )   { 
 
                                         i f   ( a u t o _ s w i t c h _ p l a n e t . a c t i v e   = =   t r u e ) 
 
                                                 C h e c k S w i t c h B e t t e r P l a n e t ( ) ; 
 
                                         e l s e 
 
                                                 S w i t c h N e x t Z o n e ( ) ; 
 
                                 } 
 
                                 e l s e   { 
 
                                         / /   C h e c k   h e a d e r   e r r o r   f o r   a n   e v e n t u a l   l o c k   i n s i d e   a   g a m e   a r e a 
 
                                         v a r   e r r o r I d   =   j q X H R . g e t R e s p o n s e H e a d e r ( ' x - e r e s u l t ' ) ; 
 
                                         i f   ( e r r o r I d   = =   1 1 )   { 
 
                                                 v a r   g a m e I d S t u c k   =   j q X H R . g e t R e s p o n s e H e a d e r ( ' x - e r r o r _ m e s s a g e ' ) . m a t c h ( / \ d + / ) [ 0 ] ; 
 
 
 
                                                 c o n s o l e . l o g ( " 3@0  >:>=G5=0.   >:8405<  5Q. " ) ; 
 
                                                 c u r r e n t _ g a m e _ i d   =   g a m e I d S t u c k ; 
 
                                                 I N J E C T _ l e a v e _ r o u n d ( ) ; 
 
                                         }   e l s e   { 
 
                                                 c o n s o l e . l o g ( " E r r o r   g e t t i n g   z o n e   r e s p o n s e   ( o n   s t a r t ) : " , d a t a ) ; 
 
                                         } 
 
                                         g u i . u p d a t e T a s k ( " 68405<  5 A  4>  A;54CNI59  ?>?KB:8  ?5@5709B8  ( >?KB:0  # "   +   ( a t t e m p t _ n o   +   1 )   +   " ) . " ) ; 
 
                                         c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
                                         c u r r e n t _ t i m e o u t   =   s e t T i m e o u t ( f u n c t i o n ( )   {   I N J E C T _ s t a r t _ r o u n d ( z o n e ,   a c c e s s _ t o k e n ,   a t t e m p t _ n o + 1 ,   c u r r e n t _ g a m e _ i s _ b o s s ) ;   } ,   5 0 0 0 ) ; 
 
                                 } 
 
                         } 
 
                         e l s e   { 
 
                                 c o n s o l e . l o g ( " R o u n d   s u c c e s s f u l l y   s t a r t e d   i n   z o n e   # "   +   z o n e ) ; 
 
                                 c o n s o l e . l o g ( d a t a ) ; 
 
 
 
                                 / /   S e t   t a r g e t 
 
                                 t a r g e t _ z o n e   =   z o n e ; 
 
                                 c u r r e n t _ g a m e _ i s _ b o s s   =   w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ t a r g e t _ z o n e ] . I n f o . b o s s ; 
 
                               
 
                                 / /   U p d a t e   t h e   G U I 
 
                                 g u i . u p d a t e S t a t u s ( t r u e ) ; 
 
                                 g u i . u p d a t e Z o n e ( z o n e ,   d a t a . r e s p o n s e . z o n e _ i n f o . c a p t u r e _ p r o g r e s s ,   d a t a . r e s p o n s e . z o n e _ i n f o . d i f f i c u l t y ,   i s _ b o s s _ b a t t l e ) ; 
 
                                 g u i . u p d a t e E s t i m a t e d T i m e ( c a l c u l a t e T i m e T o N e x t L e v e l ( ) ) ; 
 
               
 
                                 c u r r e n t _ g a m e _ i d   =   d a t a . r e s p o n s e . z o n e _ i n f o . g a m e i d ; 
 
                                 c u r r e n t _ g a m e _ s t a r t   =   n e w   D a t e ( ) . g e t T i m e ( ) ; 
 
 
 
                                 i f   ( a u t o _ s w i t c h _ p l a n e t . a c t i v e   = =   t r u e   & &   ! i s _ b o s s _ b a t t l e )   { 
 
                                         i f   ( a u t o _ s w i t c h _ p l a n e t . c u r r e n t _ d i f f i c u l t y   ! =   d a t a . r e s p o n s e . z o n e _ i n f o . d i f f i c u l t y ) 
 
                                                 a u t o _ s w i t c h _ p l a n e t . c u r r e n t _ r o u n d   =   0 ;   / /   D i f f i c u l t y   c h a n g e d ,   r e s e t   r o u n d s   c o u n t e r   b e f o r e   n e w   p l a n e t   c h e c k 
 
 
 
                                         a u t o _ s w i t c h _ p l a n e t . c u r r e n t _ d i f f i c u l t y   =   d a t a . r e s p o n s e . z o n e _ i n f o . d i f f i c u l t y ; 
 
 
 
                                         i f   ( a u t o _ s w i t c h _ p l a n e t . c u r r e n t _ r o u n d   > =   a u t o _ s w i t c h _ p l a n e t . r o u n d s _ b e f o r e _ c h e c k )   { 
 
                                                 a u t o _ s w i t c h _ p l a n e t . c u r r e n t _ r o u n d   =   0 ; 
 
                                                 C h e c k S w i t c h B e t t e r P l a n e t ( t r u e ) ; 
 
                                         }   e l s e   { 
 
                                                 a u t o _ s w i t c h _ p l a n e t . c u r r e n t _ r o u n d + + ; 
 
                                         } 
 
                                 } 
 
                               
 
                                 i f ( i s _ b o s s _ b a t t l e )   { 
 
                                         b o s s _ o p t i o n s . e r r o r _ c o u n t   =   0 ; 
 
                                         b o s s _ o p t i o n s . r e p o r t _ i n t e r v a l   =   s e t I n t e r v a l ( f u n c t i o n ( )   {   I N J E C T _ r e p o r t _ b o s s _ d a m a g e ( ) ;   } ,   b o s s _ o p t i o n s . u p d a t e _ f r e q * 1 0 0 0 ) ; 
 
                                 }   e l s e   { 
 
                                         I N J E C T _ w a i t _ f o r _ e n d ( r e s e n d _ f r e q u e n c y ) ; 
 
                                 } 
 
                         } 
 
                 } , 
 
                 e r r o r :   f u n c t i o n   ( x h r ,   a j a x O p t i o n s ,   t h r o w n E r r o r )   { 
 
                         v a r   m e s s a g e s A r r a y   =   [ " s t a r t   t h e   r o u n d " ,   " s t a r t i n g   r o u n d " ] ; 
 
                         v a r   a j a x P a r a m s   =   { 
 
                                 x h r :   x h r , 
 
                                 a j a x O p t i o n s :   a j a x O p t i o n s , 
 
                                 t h r o w n E r r o r :   t h r o w n E r r o r 
 
                         } ; 
 
                         a j a x E r r o r H a n d l i n g ( t h i s ,   a j a x P a r a m s ,   m e s s a g e s A r r a y ) ; 
 
                 } 
 
         } ) ; 
 
 } 
 
 
 
 v a r   I N J E C T _ r e p o r t _ b o s s _ d a m a g e   =   f u n c t i o n ( )   { 
 
         f u n c t i o n   s u c c e s s ( r e s u l t s )   { 
 
                 b o s s _ o p t i o n s . l a s t _ r e p o r t   =   n e w   D a t e ( ) . g e t T i m e ( ) ; 
 
                 i f   ( r e s u l t s . r e s p o n s e . g a m e _ o v e r ) 
 
                         e n d _ g a m e ( ) ; 
 
                 i f   ( r e s u l t s . r e s p o n s e . w a i t i n g _ f o r _ p l a y e r s   = =   t r u e )   { 
 
                         g u i . u p d a t e T a s k ( " W a i t i n g   f o r   p l a y e r s . . . " ) ; 
 
                 }   e l s e   { 
 
                         r e s u l t s . r e s p o n s e . b o s s _ s t a t u s . b o s s _ p l a y e r s . f o r E a c h (   f u n c t i o n ( p l a y e r )   { 
 
                                 i f   ( p l a y e r . a c c o u n t i d   = =   a c c o u n t _ i d )   { 
 
                                         i f   ( p l a y e r . h p   >   0 )   { 
 
                                                 i f   ( ( p a r s e I n t ( g P l a y e r I n f o . s c o r e )   +   p a r s e I n t ( p l a y e r . x p _ e a r n e d ) )   > =   2 6 3 9 0 0 0 0 )   { 
 
                                                         a v o i d _ b o s s   =   t r u e ; 
 
                                                         g u i . u p d a t e T a s k ( " K  1;87:8  :  ?>;CG5=8N  2 5 ;2;0.   E x i t i n g   b o s s   f i g h t   t o   p r e v e n t   y o u   t o   n o t   g e t   l e v e l - b a s e d   i t e m s . " ) ; 
 
                                                         e n d _ g a m e ( ) ; 
 
                                                 }   e l s e   { 
 
                                                         g u i . u p d a t e T a s k ( " 8B20  A  1>AA><.   %  1>AA0:   "   +   r e s u l t s . r e s p o n s e . b o s s _ s t a t u s . b o s s _ h p   +   " .   ?KB:   "   +   p l a y e r . x p _ e a r n e d   +   " .   %:   "   +   p l a y e r . h p ) ; 
 
                                                 } 
 
                                         }   e l s e   { 
 
                                                 g u i . u p d a t e T a s k ( " K  ?>381;8,   70:0=G8205<  18B2C  A  1>AA><.   %  1>AA0:   "   +   r e s u l t s . r e s p o n s e . b o s s _ s t a t u s . b o s s _ h p   +   " .   ?KB:   "   +   p l a y e r . x p _ e a r n e d ) ; 
 
                                                 e n d _ g a m e ( ) ; 
 
                                         } 
 
                                         i f   ( p l a y e r . t i m e _ l a s t _ h e a l   ! = =   u n d e f i n e d ) 
 
                                                 b o s s _ o p t i o n s . l a s t _ h e a l   =   p l a y e r . t i m e _ l a s t _ h e a l ; 
 
                                 } 
 
                         } ) ; 
 
                         g u i . p r o g r e s s b a r . S e t V a l u e ( ( r e s u l t s . r e s p o n s e . b o s s _ s t a t u s . b o s s _ m a x _ h p   -   r e s u l t s . r e s p o n s e . b o s s _ s t a t u s . b o s s _ h p )   /   r e s u l t s . r e s p o n s e . b o s s _ s t a t u s . b o s s _ m a x _ h p ) ; 
 
                 } 
 
         } 
 
         f u n c t i o n   e r r o r ( r e s u l t s ,   e r e s u l t )   { 
 
                 i f   ( e r e s u l t   = =   1 1   | |   b o s s _ o p t i o n s . e r r o r _ c o u n t   > =   m a x _ r e t r y ) 
 
                         e n d _ g a m e ( ) ; 
 
                 e l s e 
 
                         b o s s _ o p t i o n s . e r r o r _ c o u n t + + ; 
 
         } 
 
         f u n c t i o n   e n d _ g a m e ( )   { 
 
                 g u i . u p d a t e T a s k ( " 8B20  A  1>AA><  7025@H5=0.   I5<  =>2CN  ?;0=5BC  /   7>=C. " ) ; 
 
                 c l e a r I n t e r v a l ( b o s s _ o p t i o n s . r e p o r t _ i n t e r v a l ) ; 
 
                 b o s s _ o p t i o n s . r e p o r t _ i n t e r v a l   =   u n d e f i n e d ; 
 
                 b o s s _ o p t i o n s . l a s t _ h e a l   =   u n d e f i n e d ; 
 
                 b o s s _ o p t i o n s . l a s t _ r e p o r t   =   u n d e f i n e d ; 
 
                 c u r r e n t _ g a m e _ i s _ b o s s   =   f a l s e ; 
 
                 I N J E C T _ l e a v e _ r o u n d ( ) ; 
 
               
 
                 i f   ( a u t o _ s w i t c h _ p l a n e t . a c t i v e   = =   t r u e ) 
 
                         C h e c k S w i t c h B e t t e r P l a n e t ( ) ; 
 
                 e l s e 
 
                         S w i t c h N e x t Z o n e ( ) ; 
 
         } 
 
 
 
         v a r   d a m a g e D o n e   =   M a t h . f l o o r ( M a t h . r a n d o m ( )   *   4 0 ) ; 
 
         v a r   d a m a g e T a k e n   =   0 ; 
 
         v a r   n o w   =   ( n e w   D a t e ( ) . g e t T i m e ( ) )   /   1 0 0 0 ; 
 
         i f   ( b o s s _ o p t i o n s . l a s t _ h e a l   = = =   u n d e f i n e d ) 
 
                 b o s s _ o p t i o n s . l a s t _ h e a l   =   n o w   -   M a t h . f l o o r ( M a t h . r a n d o m ( )   *   4 0 ) ; 
 
         v a r   h e a l D i f f   =   n o w   -   b o s s _ o p t i o n s . l a s t _ h e a l ; 
 
         v a r   u s e H e a l i n g   =   ( h e a l D i f f   > =   1 2 0 )   ?   1   :   0 ; 
 
         g S e r v e r . R e p o r t B o s s D a m a g e ( d a m a g e D o n e ,   d a m a g e T a k e n ,   u s e H e a l i n g ,   s u c c e s s ,   e r r o r ) ; 
 
 } 
 
 
 
 / /   U p d a t e   t i m e   r e m a i n i n g ,   a n d   w a i t   f o r   t h e   r o u n d   t o   c o m p l e t e . 
 
 v a r   I N J E C T _ w a i t _ f o r _ e n d   =   f u n c t i o n ( )   { 
 
         v a r   n o w   =   n e w   D a t e ( ) . g e t T i m e ( ) ; 
 
         t i m e _ p a s s e d _ m s   =   n o w   -   c u r r e n t _ g a m e _ s t a r t ; 
 
         v a r   t i m e _ r e m a i n i n g _ m s   =   ( r e s e n d _ f r e q u e n c y * 1 0 0 0 )   -   t i m e _ p a s s e d _ m s ; 
 
         v a r   t i m e _ r e m a i n i n g   =   M a t h . r o u n d ( t i m e _ r e m a i n i n g _ m s / 1 0 0 0 ) ; 
 
 
 
         / /   U p d a t e   G U I 
 
         g u i . u p d a t e T a s k ( " 68405<  "   +   M a t h . m a x ( t i m e _ r e m a i n i n g ,   0 )   +   " A  4>  >:>=G0=8O  @0C=40" ,   f a l s e ) ; 
 
         g u i . u p d a t e S t a t u s ( t r u e ) ; 
 
         i f   ( t a r g e t _ z o n e   ! =   - 1 ) 
 
                 g u i . u p d a t e E s t i m a t e d T i m e ( c a l c u l a t e T i m e T o N e x t L e v e l ( ) ) ; 
 
         g u i . p r o g r e s s b a r . S e t V a l u e ( t i m e _ p a s s e d _ m s / ( r e s e n d _ f r e q u e n c y * 1 0 0 0 ) ) ; 
 
 
 
         / /   W a i t 
 
         v a r   w a i t _ t i m e   =   u p d a t e _ l e n g t h * 1 0 0 0 ; 
 
         v a r   c a l l b a c k ; 
 
       
 
         / /   u s e   a b s o l u t e   t i m e s t a m p s   t o   c a l c u l a t e   i f   t h e   g a m e   i s   o v e r ,   s i n c e   s e t T i m e o u t   t i m i n g s   a r e   n o t   a l w a y s   r e l i a b l e 
 
         i f ( t i m e _ r e m a i n i n g _ m s   < =   0 )   { 
 
                 c a l l b a c k   =   f u n c t i o n ( )   {   I N J E C T _ e n d _ r o u n d ( ) ;   } ; 
 
         } 
 
         e l s e   { 
 
                 c a l l b a c k   =   f u n c t i o n ( )   {   I N J E C T _ w a i t _ f o r _ e n d ( ) ;   } ; 
 
         } 
 
       
 
         / /   S e t   t h e   t i m e o u t 
 
         c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
         c u r r e n t _ t i m e o u t   =   s e t T i m e o u t ( c a l l b a c k ,   w a i t _ t i m e ) ; 
 
 } 
 
 
 
 / /   S e n d   t h e   c a l l   t o   e n d   a   r o u n d ,   a n d   r e s t a r t   i f   n e e d e d . 
 
 v a r   I N J E C T _ e n d _ r o u n d   =   f u n c t i o n ( a t t e m p t _ n o )   { 
 
         i f ( a t t e m p t _ n o   = = =   u n d e f i n e d ) 
 
                 a t t e m p t _ n o   =   0 ; 
 
 
 
         / /   G r a b   t h e   m a x   s c o r e   w e ' r e   a l l o w e d   t o   s e n d 
 
         v a r   s c o r e   =   g e t _ m a x _ s c o r e ( ) ; 
 
       
 
         / /   U p d a t e   g u i 
 
         g u i . u p d a t e T a s k ( " 025@H05<  @0C=4" ) ; 
 
 
 
         / /   P o s t   o u r   " Y a y   w e   b e a t   t h e   l e v e l "   c a l l 
 
         $ J . a j a x ( { 
 
                 a s y n c :   f a l s e , 
 
                 t y p e :   " P O S T " , 
 
                 u r l :   " h t t p s : / / c o m m u n i t y . s t e a m - a p i . c o m / I T e r r i t o r y C o n t r o l M i n i g a m e S e r v i c e / R e p o r t S c o r e / v 0 0 0 1 / " , 
 
                 d a t a :   {   a c c e s s _ t o k e n :   a c c e s s _ t o k e n ,   s c o r e :   s c o r e ,   l a n g u a g e :   l a n g u a g e   } , 
 
                 t r y C o u n t   :   0 , 
 
                 r e t r y L i m i t   :   m a x _ r e t r y , 
 
                 s u c c e s s :   f u n c t i o n ( d a t a )   { 
 
                         i f (   $ J . i s E m p t y O b j e c t ( d a t a . r e s p o n s e )   )   { 
 
                                 / /   C h e c k   i f   t h e   z o n e   i s   c o m p l e t e d 
 
                                 I N J E C T _ u p d a t e _ g r i d ( f a l s e ) ;   / /   E r r o r   h a n d l i n g   s e t   t o   f a l s e   t o   a v o i d   t o o   m u c h   p a r a l l e l   c a l l s   w i t h   t h e   s e t T i m e o u t   b e l o w 
 
                                 i f ( w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ t a r g e t _ z o n e ] . I n f o . c a p t u r e d   | |   a t t e m p t _ n o   > =   m a x _ r e t r y )   { 
 
                                         i f   ( a u t o _ s w i t c h _ p l a n e t . a c t i v e   = =   t r u e ) 
 
                                                 C h e c k S w i t c h B e t t e r P l a n e t ( ) ; 
 
                                         e l s e 
 
                                                 S w i t c h N e x t Z o n e ( ) ; 
 
                                 } 
 
                                 e l s e   { 
 
                                         c o n s o l e . l o g ( " E r r o r   g e t t i n g   z o n e   r e s p o n s e   ( o n   e n d ) : " , d a t a ) ; 
 
                                         g u i . u p d a t e T a s k ( " 68405<  5 A  8  ?>2B>@=>  >B?@02;O5<  AGQB  ( >?KB:0  # "   +   ( a t t e m p t _ n o   +   1 )   +   " ) . " ) ; 
 
                                         c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
                                         c u r r e n t _ t i m e o u t   =   s e t T i m e o u t ( f u n c t i o n ( )   {   I N J E C T _ e n d _ r o u n d ( a t t e m p t _ n o + 1 ) ;   } ,   5 0 0 0 ) ; 
 
                                 } 
 
                         } 
 
                         e l s e   { 
 
                                 c o n s o l e . l o g ( " S u c c e s s f u l l y   f i n i s h e d   t h e   r o u n d   a n d   g o t   e x p e c t e d   d a t a   b a c k : " ) ; 
 
                                 c o n s o l e . l o g ( " L e v e l :   " ,   d a t a . r e s p o n s e . n e w _ l e v e l ,   " \ n E X P :   " ,   d a t a . r e s p o n s e . n e w _ s c o r e ) ; 
 
                                 c o n s o l e . l o g ( d a t a ) ; 
 
 
 
                                 / /   U p d a t e   t h e   p l a y e r   i n f o 
 
                                 I N J E C T _ u p d a t e _ p l a y e r _ i n f o ( ) ; 
 
 
 
                                 / /   U p d a t e   G U I 
 
                                 g u i . u p d a t e L e v e l ( d a t a . r e s p o n s e . n e w _ l e v e l ) ; 
 
                                 g u i . u p d a t e E x p ( d a t a . r e s p o n s e . n e w _ s c o r e   +   "   /   "   +   d a t a . r e s p o n s e . n e x t _ l e v e l _ s c o r e ) ; 
 
                                 g u i . u p d a t e E s t i m a t e d T i m e ( c a l c u l a t e T i m e T o N e x t L e v e l ( ) ) ; 
 
                                 g u i . u p d a t e E s t E x p ( ( d a t a . r e s p o n s e . n e x t _ l e v e l _ s c o r e   -   d a t a . r e s p o n s e . n e w _ s c o r e ) ) ; 
 
                                 g u i . u p d a t e Z o n e ( "  " ) ; 
 
                               
 
                                 / /   A v o i d   b o s s e s   i f   w e ' r e   n e a r   l e v e l   2 5 
 
                                 a v o i d _ b o s s   =   ( g P l a y e r I n f o . s c o r e   > =   2 6 3 9 0 0 0 0   & &   g P l a y e r I n f o . s c o r e   <   2 6 4 0 0 0 0 0 ) ; 
 
 
 
                                 / /   R e s t a r t   t h e   r o u n d   i f   w e   h a v e   t h a t   v a r i a b l e   s e t 
 
                                 i f ( l o o p _ r o u n d s )   { 
 
                                         c u r r e n t _ g a m e _ i d   =   u n d e f i n e d ; 
 
                                         S w i t c h N e x t Z o n e ( ) ; 
 
                                 } 
 
                         } 
 
                 } , 
 
                 e r r o r :   f u n c t i o n   ( x h r ,   a j a x O p t i o n s ,   t h r o w n E r r o r )   { 
 
                         v a r   m e s s a g e s A r r a y   =   [ " e n d   t h e   r o u n d " ,   " e n d i n g   r o u n d " ] ; 
 
                         v a r   a j a x P a r a m s   =   { 
 
                                 x h r :   x h r , 
 
                                 a j a x O p t i o n s :   a j a x O p t i o n s , 
 
                                 t h r o w n E r r o r :   t h r o w n E r r o r 
 
                         } ; 
 
                         a j a x E r r o r H a n d l i n g ( t h i s ,   a j a x P a r a m s ,   m e s s a g e s A r r a y ) ; 
 
                 } 
 
         } ) ; 
 
 } 
 
 
 
 / /   L e a v e   a n   e x i s t i n g   g a m e 
 
 v a r   I N J E C T _ l e a v e _ r o u n d   =   f u n c t i o n ( )   { 
 
         i f ( c u r r e n t _ g a m e _ i d   = = =   u n d e f i n e d ) 
 
                 r e t u r n ; 
 
 
 
         c o n s o l e . l o g ( " L e a v i n g   g a m e :   "   +   c u r r e n t _ g a m e _ i d ) ; 
 
 
 
         / /   C a n c e l   t i m e o u t s 
 
         c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
 
 
         / /   P O S T   t o   t h e   e n d p o i n t 
 
         $ J . a j a x ( { 
 
                 a s y n c :   f a l s e , 
 
                 t y p e :   " P O S T " , 
 
                 u r l :   " h t t p s : / / c o m m u n i t y . s t e a m - a p i . c o m / I M i n i G a m e S e r v i c e / L e a v e G a m e / v 0 0 0 1 / " , 
 
                 d a t a :   {   a c c e s s _ t o k e n :   a c c e s s _ t o k e n ,   g a m e i d :   c u r r e n t _ g a m e _ i d   } , 
 
                 t r y C o u n t   :   0 , 
 
                 r e t r y L i m i t   :   m a x _ r e t r y , 
 
                 s u c c e s s :   f u n c t i o n ( d a t a )   { } , 
 
                 e r r o r :   f u n c t i o n   ( x h r ,   a j a x O p t i o n s ,   t h r o w n E r r o r )   { 
 
                         v a r   m e s s a g e s A r r a y   =   [ " l e a v e   t h e   r o u n d " ,   " l e a v i n g   r o u n d " ] ; 
 
                         v a r   a j a x P a r a m s   =   { 
 
                                 x h r :   x h r , 
 
                                 a j a x O p t i o n s :   a j a x O p t i o n s , 
 
                                 t h r o w n E r r o r :   t h r o w n E r r o r 
 
                         } ; 
 
                         a j a x E r r o r H a n d l i n g ( t h i s ,   a j a x P a r a m s ,   m e s s a g e s A r r a y ) ; 
 
                 } 
 
         } ) ; 
 
 
 
         / /   C l e a r   t h e   c u r r e n t   g a m e   I D   v a r 
 
         c u r r e n t _ g a m e _ i d   =   u n d e f i n e d ; 
 
 
 
         / /   U p d a t e   t h e   G U I 
 
         g u i . u p d a t e T a s k ( " >:8405<  7>=C  # "   +   t a r g e t _ z o n e ) ; 
 
         g u i . u p d a t e S t a t u s ( f a l s e ) ; 
 
 
 
         t a r g e t _ z o n e   =   - 1 ; 
 
 } 
 
 
 
 / /   r e t u r n s   0   f o r   e a s y ,   1   f o r   m e d i u m ,   2   f o r   h a r d 
 
 v a r   I N J E C T _ g e t _ d i f f i c u l t y   =   f u n c t i o n ( z o n e _ i d )   { 
 
         r e t u r n   w i n d o w . g G a m e . m _ S t a t e . m _ P l a n e t D a t a . z o n e s [ z o n e _ i d ] . d i f f i c u l t y ; 
 
 } 
 
 
 
 / /   U p d a t e s   t h e   p l a y e r   i n f o 
 
 / /   C u r r e n t l y   u n u s e d .   T h i s   w a s   m e a n t   t o   h o p e f u l l y   u p d a t e   t h e   U I . 
 
 v a r   I N J E C T _ u p d a t e _ p l a y e r _ i n f o   =   f u n c t i o n ( )   { 
 
         g S e r v e r . G e t P l a y e r I n f o ( 
 
                 f u n c t i o n (   r e s u l t s   )   { 
 
                         g P l a y e r I n f o   =   r e s u l t s . r e s p o n s e ; 
 
                 } , 
 
                 f u n c t i o n ( ) { } 
 
         ) ; 
 
 } 
 
 
 
 / /   U p d a t e   t h e   z o n e s   o f   t h e   g r i d   ( m a p )   o n   t h e   c u r r e n t   p l a n e t 
 
 v a r   I N J E C T _ u p d a t e _ g r i d   =   f u n c t i o n ( e r r o r _ h a n d l i n g )   { 
 
         i f ( c u r r e n t _ p l a n e t _ i d   = = =   u n d e f i n e d ) 
 
                 r e t u r n ; 
 
         i f   ( e r r o r _ h a n d l i n g   = = =   u n d e f i n e d ) 
 
                 e r r o r _ h a n d l i n g   =   t r u e ; 
 
       
 
         / /   S k i p   u p d a t e   i f   a   p r e v i o u s   s u c c e s s f u l   o n e   h a p p e n e d   i n   t h e   l a s t   8 s 
 
         i f   ( l a s t _ u p d a t e _ g r i d   ! = =   u n d e f i n e d )   { 
 
                 v a r   l a s t _ u p d a t e _ d i f f   =   n e w   D a t e ( ) . g e t T i m e ( )   -   l a s t _ u p d a t e _ g r i d ; 
 
                 i f   ( ( l a s t _ u p d a t e _ d i f f   /   1 0 0 0 )   <   8 ) 
 
                         r e t u r n ; 
 
         } 
 
 
 
         g u i . u p d a t e T a s k ( ' 1=>2;5=85  A5B:8' ,   t r u e ) ; 
 
 
 
         / /   G E T   t o   t h e   e n d p o i n t 
 
         $ J . a j a x ( { 
 
                 a s y n c :   f a l s e , 
 
                 t y p e :   " G E T " , 
 
                 u r l :   " h t t p s : / / c o m m u n i t y . s t e a m - a p i . c o m / I T e r r i t o r y C o n t r o l M i n i g a m e S e r v i c e / G e t P l a n e t / v 0 0 0 1 / " , 
 
                 d a t a :   {   i d :   c u r r e n t _ p l a n e t _ i d   } , 
 
                 t r y C o u n t   :   0 , 
 
                 r e t r y L i m i t   :   m a x _ r e t r y , 
 
                 s u c c e s s :   f u n c t i o n ( d a t a )   { 
 
                         w i n d o w . g G a m e . m _ S t a t e . m _ P l a n e t D a t a   =   d a t a . r e s p o n s e . p l a n e t s [ 0 ] ; 
 
                         w i n d o w . g G a m e . m _ S t a t e . m _ P l a n e t D a t a . z o n e s . f o r E a c h (   f u n c t i o n   (   z o n e   )   { 
 
                                 w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ z o n e . z o n e _ p o s i t i o n ] . I n f o . p r o g r e s s   =   z o n e . c a p t u r e _ p r o g r e s s ; 
 
                                 w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ z o n e . z o n e _ p o s i t i o n ] . I n f o . c a p t u r e d   =   z o n e . c a p t u r e d ; 
 
                                 w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ z o n e . z o n e _ p o s i t i o n ] . I n f o . d i f f i c u l t y   =   z o n e . d i f f i c u l t y ; 
 
                                 w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ z o n e . z o n e _ p o s i t i o n ] . I n f o . b o s s   =   z o n e . b o s s _ a c t i v e ; 
 
                         } ) ; 
 
                         l a s t _ u p d a t e _ g r i d   =   n e w   D a t e ( ) . g e t T i m e ( ) ; 
 
                         c o n s o l e . l o g ( " S u c c e s s f u l l y   u p d a t e d   m a p   d a t a   o n   p l a n e t :   "   +   c u r r e n t _ p l a n e t _ i d ) ; 
 
                 } , 
 
                 e r r o r :   f u n c t i o n   ( x h r ,   a j a x O p t i o n s ,   t h r o w n E r r o r )   { 
 
                         i f   ( e r r o r _ h a n d l i n g   = =   t r u e )   { 
 
                                 v a r   m e s s a g e s A r r a y   =   [ " u p d a t e   t h e   g r i d " ,   " u p d a t i n g   t h e   g r i d " ] ; 
 
                                 v a r   a j a x P a r a m s   =   { 
 
                                         x h r :   x h r , 
 
                                         a j a x O p t i o n s :   a j a x O p t i o n s , 
 
                                         t h r o w n E r r o r :   t h r o w n E r r o r 
 
                                 } ; 
 
                                 a j a x E r r o r H a n d l i n g ( t h i s ,   a j a x P a r a m s ,   m e s s a g e s A r r a y ) ; 
 
                         } 
 
                 } 
 
         } ) ; 
 
 } 
 
 
 
 / /   D e f a u l t s   t o   m a x   s c o r e   o f   c u r r e n t   z o n e   &   f u l l   r o u n d   d u r a t i o n   i f   n o   p a r a m s   a r e   g i v e n 
 
 f u n c t i o n   g e t _ m a x _ s c o r e ( z o n e ,   r o u n d _ d u r a t i o n )   { 
 
         / /   d e f a u l t s 
 
         i f ( z o n e   = = =   u n d e f i n e d ) 
 
                 z o n e   =   t a r g e t _ z o n e ; 
 
         i f ( r o u n d _ d u r a t i o n   = = =   u n d e f i n e d ) 
 
                 r o u n d _ d u r a t i o n   =   r e a l _ r o u n d _ l e n g t h ; 
 
 
 
         v a r   d i f f i c u l t y   =   I N J E C T _ g e t _ d i f f i c u l t y ( z o n e ) ; 
 
         v a r   s c o r e   =   5   *   r o u n d _ d u r a t i o n   *   M a t h . p o w ( 2 ,   ( d i f f i c u l t y - 1 ) ) ; 
 
 
 
         r e t u r n   s c o r e ; 
 
 } 
 
 
 
 / /   G e t   t h e   b e s t   z o n e   a v a i l a b l e 
 
 f u n c t i o n   G e t B e s t Z o n e ( )   { 
 
         v a r   b e s t Z o n e ; 
 
         v a r   h i g h e s t D i f f i c u l t y   =   - 1 ; 
 
 
 
         g u i . u p d a t e T a s k ( ' I5<  ;CGHCN  7>=C' ) ; 
 
 
 
         f o r   ( v a r   i d x   =   0 ;   i d x   <   w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s . l e n g t h ;   i d x + + )   { 
 
                 v a r   z o n e   =   w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ i d x ] . I n f o ; 
 
                 i f   ( ! z o n e . c a p t u r e d   & &   z o n e . p r o g r e s s   >   0 )   { 
 
                         i f   ( z o n e . b o s s   & &   ! a v o i d _ b o s s )   { 
 
                                 c o n s o l e . l o g ( " Z o n e   "   +   i d x   +   "   w i t h   b o s s .   S w i t c h i n g   t o   i t . " ) ; 
 
                                 r e t u r n   [ i d x ,   z o n e . b o s s ] ; 
 
                         } 
 
 
 
                         i f ( z o n e . d i f f i c u l t y   >   h i g h e s t D i f f i c u l t y )   { 
 
                                 h i g h e s t D i f f i c u l t y   =   z o n e . d i f f i c u l t y ; 
 
                                 m a x P r o g r e s s   =   z o n e . p r o g r e s s ; 
 
                                 b e s t Z o n e   =   [ i d x ,   z o n e . b o s s ] ; 
 
                         }   e l s e   i f ( z o n e . d i f f i c u l t y   <   h i g h e s t D i f f i c u l t y )   c o n t i n u e ; 
 
 
 
                         i f ( z o n e . p r o g r e s s   <   m a x P r o g r e s s )   { 
 
                                 m a x P r o g r e s s   =   z o n e . p r o g r e s s ; 
 
                                 b e s t Z o n e   =   [ i d x ,   z o n e . b o s s ] ; 
 
                         } 
 
                 } 
 
         } 
 
 
 
         i f ( b e s t Z o n e   ! = =   u n d e f i n e d )   { 
 
                 c o n s o l e . l o g ( ` $ { w i n d o w . g G a m e . m _ S t a t e . m _ P l a n e t D a t a . s t a t e . n a m e }   -   Z o n e   $ { b e s t Z o n e [ 0 ] }   P r o g r e s s :   $ { w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ b e s t Z o n e [ 0 ] ] . I n f o . p r o g r e s s }   D i f f i c u l t y :   $ { w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ b e s t Z o n e [ 0 ] ] . I n f o . d i f f i c u l t y } ` ) ; 
 
         } 
 
 
 
         r e t u r n   b e s t Z o n e ; 
 
 } 
 
 
 
 / /   G e t   t h e   b e s t   p l a n e t   a v a i l a b l e 
 
 f u n c t i o n   G e t B e s t P l a n e t ( )   { 
 
         v a r   b e s t P l a n e t I d   =   u n d e f i n e d ; 
 
         v a r   a c t i v e P l a n e t s S c o r e   =   [ ] ; 
 
         v a r   p l a n e t s M a x D i f f i c u l t y   =   [ ] ; 
 
         v a r   m a x S c o r e   =   0 ; 
 
         v a r   n u m b e r E r r o r s   =   0 ; 
 
         v a r   b o s s S p a w n e d   =   f a l s e ; 
 
       
 
         g u i . u p d a t e S t a t u s ( ' I5<  ;CGHCN  ?;0=5BC' ) ; 
 
       
 
         / /   G E T   t o   t h e   e n d p o i n t 
 
         $ J . a j a x ( { 
 
                 a s y n c :   f a l s e , 
 
                 t y p e :   " G E T " , 
 
                 u r l :   " h t t p s : / / c o m m u n i t y . s t e a m - a p i . c o m / I T e r r i t o r y C o n t r o l M i n i g a m e S e r v i c e / G e t P l a n e t s / v 0 0 0 1 / " , 
 
                 t r y C o u n t   :   0 , 
 
                 r e t r y L i m i t   :   m a x _ r e t r y , 
 
                 s u c c e s s :   f u n c t i o n ( d a t a )   { 
 
                         d a t a . r e s p o n s e . p l a n e t s . f o r E a c h (   f u n c t i o n ( p l a n e t )   { 
 
                                 i f   ( p l a n e t . s t a t e . a c t i v e   = =   t r u e   & &   p l a n e t . s t a t e . c a p t u r e d   = =   f a l s e ) 
 
                                         a c t i v e P l a n e t s S c o r e [ p l a n e t . i d ]   =   0 ; 
 
                                         p l a n e t s M a x D i f f i c u l t y [ p l a n e t . i d ]   =   0 ; 
 
                         } ) ; 
 
                 } , 
 
                 e r r o r :   f u n c t i o n   ( x h r ,   a j a x O p t i o n s ,   t h r o w n E r r o r )   { 
 
                         v a r   m e s s a g e s A r r a y   =   [ " g e t   a c t i v e   p l a n e t s " ,   " g e t t i n g   a c t i v e   p l a n e t s " ] ; 
 
                         v a r   a j a x P a r a m s   =   { 
 
                                 x h r :   x h r , 
 
                                 a j a x O p t i o n s :   a j a x O p t i o n s , 
 
                                 t h r o w n E r r o r :   t h r o w n E r r o r 
 
                         } ; 
 
                         a j a x E r r o r H a n d l i n g ( t h i s ,   a j a x P a r a m s ,   m e s s a g e s A r r a y ) ; 
 
                 } 
 
         } ) ; 
 
       
 
         / /   G E T   t h e   s c o r e   o f   e a c h   a c t i v e   p l a n e t 
 
         O b j e c t . k e y s ( a c t i v e P l a n e t s S c o r e ) . f o r E a c h   (   f u n c t i o n   ( p l a n e t _ i d )   { 
 
                 / /   G E T   t o   t h e   e n d p o i n t 
 
                 $ J . a j a x ( { 
 
                         a s y n c :   f a l s e , 
 
                         t y p e :   " G E T " , 
 
                         u r l :   " h t t p s : / / c o m m u n i t y . s t e a m - a p i . c o m / I T e r r i t o r y C o n t r o l M i n i g a m e S e r v i c e / G e t P l a n e t / v 0 0 0 1 / " , 
 
                         d a t a :   {   i d :   p l a n e t _ i d   } , 
 
                         s u c c e s s :   f u n c t i o n ( d a t a )   { 
 
                                 d a t a . r e s p o n s e . p l a n e t s [ 0 ] . z o n e s . f o r E a c h (   f u n c t i o n   (   z o n e   )   { 
 
                                         i f   ( z o n e . d i f f i c u l t y   > =   1   & &   z o n e . d i f f i c u l t y   < =   7   & &   z o n e . c a p t u r e d   = =   f a l s e )   { 
 
                                                 v a r   z o n e P r o g r e s s   =   ( z o n e . c a p t u r e _ p r o g r e s s   = = =   u n d e f i n e d )   ?   0   :   z o n e . c a p t u r e _ p r o g r e s s ; 
 
                                                 v a r   z o n e S c o r e   =   M a t h . c e i l ( M a t h . p o w ( 1 0 ,   ( z o n e . d i f f i c u l t y   -   1 )   *   2 )   *   ( 1   -   z o n e P r o g r e s s ) )   +   ( ( z o n e . b o s s _ a c t i v e   & &   ! a v o i d _ b o s s )   ?   1 0 0 0 0 0 0 0 0 0 0   :   0 ) ; 
 
                                                 a c t i v e P l a n e t s S c o r e [ p l a n e t _ i d ]   + =   i s N a N ( z o n e S c o r e )   ?   0   :   z o n e S c o r e ; 
 
                                                 i f   ( z o n e . b o s s _ a c t i v e   = =   t r u e   & &   ! a v o i d _ b o s s ) 
 
                                                         b o s s S p a w n e d   =   t r u e ; 
 
                                                 i f   ( z o n e . d i f f i c u l t y   >   p l a n e t s M a x D i f f i c u l t y [ p l a n e t _ i d ] ) 
 
                                                         p l a n e t s M a x D i f f i c u l t y [ p l a n e t _ i d ]   =   z o n e . d i f f i c u l t y ; 
 
                                         } 
 
                                 } ) ; 
 
                         } , 
 
                         e r r o r :   f u n c t i o n ( )   { 
 
                                 n u m b e r E r r o r s + + ; 
 
                         } 
 
                 } ) ; 
 
                 i f   ( a c t i v e P l a n e t s S c o r e [ p l a n e t _ i d ]   >   m a x S c o r e )   { 
 
                         m a x S c o r e   =   a c t i v e P l a n e t s S c o r e [ p l a n e t _ i d ] ; 
 
                         b e s t P l a n e t I d   =   p l a n e t _ i d ; 
 
                 } 
 
         } ) ; 
 
         c o n s o l e . l o g ( a c t i v e P l a n e t s S c o r e ) ; 
 
       
 
         / /   C h e c k   i f   t h e   m a x i m u m   d i f f i c u l t y   a v a i l a b l e   o n   t h e   b e s t   p l a n e t   i s   t h e   s a m e   a s   t h e   c u r r e n t   o n e   a n d   n o   b o s s   s p a w n e d 
 
         / /   I f   y e s ,   n o   n e e d   t o   m o v e .   E x c e p t   i f   m a x   d i f f i c u l t y   =   1   a n d   s c o r e   < =   2 0 ,   w e ' l l   r u s h   i t   f o r   a   n e w   p l a n e t 
 
         i f   ( ( c u r r e n t _ p l a n e t _ i d   i n   a c t i v e P l a n e t s S c o r e )   & &   p l a n e t s M a x D i f f i c u l t y [ b e s t P l a n e t I d ]   < =   a u t o _ s w i t c h _ p l a n e t . c u r r e n t _ d i f f i c u l t y   & &   b o s s S p a w n e d   = =   f a l s e )   { 
 
                 v a r   l o w S c o r e P l a n e t   =   a c t i v e P l a n e t s S c o r e . f i n d I n d e x ( f u n c t i o n ( s c o r e )   {   r e t u r n   s c o r e   < =   2 0 ;   } ) ; 
 
                 i f   ( p l a n e t s M a x D i f f i c u l t y [ b e s t P l a n e t I d ]   = =   1   & &   l o w S c o r e P l a n e t   ! = =   - 1 )   { 
 
                         r e t u r n   l o w S c o r e P l a n e t ; 
 
                 }   e l s e   { 
 
                         r e t u r n   c u r r e n t _ p l a n e t _ i d ; 
 
                 } 
 
         } 
 
       
 
         / /   P r e v e n t   a   p l a n e t   s w i t c h   i f   : 
 
         / /   ( t h e r e   w e r e   > =   2   e r r o r s   w h i l e   f e t c h i n g   p l a n e t s   O R   i f   t h e r e ' s   a n   e r r o r   w h i l e   f e t c h i n g   t h e   c u r r e n t   p l a n e t   s c o r e ) 
 
         / /   A N D   t h e   m a x   d i f f i c u l t y   a v a i l a b l e   o n   b e s t   p l a n e t   f o u n d   i s   < =   c u r r e n t   d i f f i c u l t y 
 
         i f   ( ( n u m b e r E r r o r s   > =   2   | |   ( ( c u r r e n t _ p l a n e t _ i d   i n   a c t i v e P l a n e t s S c o r e )   & &   a c t i v e P l a n e t s S c o r e [ c u r r e n t _ p l a n e t _ i d ]   = =   0 ) )   & &   p l a n e t s M a x D i f f i c u l t y [ b e s t P l a n e t I d ]   < =   a u t o _ s w i t c h _ p l a n e t . c u r r e n t _ d i f f i c u l t y   & &   b o s s S p a w n e d   = =   f a l s e ) 
 
                 r e t u r n   n u l l ; 
 
       
 
         r e t u r n   b e s t P l a n e t I d ; 
 
 } 
 
 
 
 / /   S w i t c h   t o   t h e   n e x t   z o n e   w h e n   o n e   i s   c o m p l e t e d 
 
 f u n c t i o n   S w i t c h N e x t Z o n e ( a t t e m p t _ n o ,   p l a n e t _ c a l l )   { 
 
         i f ( a t t e m p t _ n o   = = =   u n d e f i n e d ) 
 
                 a t t e m p t _ n o   =   0 ; 
 
         i f   ( p l a n e t _ c a l l   = = =   u n d e f i n e d ) 
 
                 p l a n e t _ c a l l   =   f a l s e ; 
 
 
 
         I N J E C T _ u p d a t e _ g r i d ( ) ; 
 
         v a r   c u r r e n t B e s t Z o n e   =   G e t B e s t Z o n e ( ) ; 
 
         v a r   n e x t _ z o n e   =   c u r r e n t B e s t Z o n e [ 0 ] ; 
 
 
 
         i f   ( n e x t _ z o n e   ! = =   u n d e f i n e d )   { 
 
                 i f   ( n e x t _ z o n e   ! =   t a r g e t _ z o n e )   { 
 
                         c o n s o l e . l o g ( " F o u n d   n e w   b e s t   z o n e :   "   +   n e x t _ z o n e ) ; 
 
                         c u r r e n t _ g a m e _ i s _ b o s s   =   c u r r e n t B e s t Z o n e [ 1 ] ; 
 
                         I N J E C T _ s t a r t _ r o u n d ( n e x t _ z o n e ,   a c c e s s _ t o k e n ,   a t t e m p t _ n o ,   c u r r e n t _ g a m e _ i s _ b o s s ) ; 
 
                 }   e l s e   { 
 
                         c o n s o l e . l o g ( " C u r r e n t   z o n e   # "   +   t a r g e t _ z o n e   +   "   i s   a l r e a d y   t h e   b e s t .   N o   n e e d   t o   s w i t c h . " ) ; 
 
                         c u r r e n t _ g a m e _ i s _ b o s s   =   c u r r e n t B e s t Z o n e [ 1 ] ; 
 
                         I N J E C T _ s t a r t _ r o u n d ( t a r g e t _ z o n e ,   a c c e s s _ t o k e n ,   a t t e m p t _ n o ,   c u r r e n t _ g a m e _ i s _ b o s s ) ; 
 
                 } 
 
         }   e l s e   { 
 
                 i f   ( a u t o _ s w i t c h _ p l a n e t . a c t i v e   = =   t r u e )   { 
 
                         c o n s o l e . l o g ( " T h e r e   a r e   n o   m o r e   z o n e s ,   t h e   p l a n e t   m u s t   b e   c o m p l e t e d .   S e a r c h i n g   a   n e w   o n e . " ) ; 
 
                         C h e c k S w i t c h B e t t e r P l a n e t ( ) ; 
 
                 }   e l s e   { 
 
                         I N J E C T _ l e a v e _ r o u n d ( ) ; 
 
                         I N J E C T _ u p d a t e _ g r i d ( ) ; 
 
                         c o n s o l e . l o g ( " T h e r e   a r e   n o   m o r e   z o n e s ,   t h e   p l a n e t   m u s t   b e   c o m p l e t e d .   Y o u ' l l   n e e d   t o   c h o o s e   a n o t h e r   p l a n e t ! " ) ; 
 
                         t a r g e t _ z o n e   =   - 1 ; 
 
                         I N J E C T _ l e a v e _ p l a n e t ( ) ; 
 
                 } 
 
         } 
 
 } 
 
 
 
 / /   C h e c k   &   s w i t c h   f o r   a   p o t e n t i a l l y   b e t t e r   p l a n e t ,   s t a r t   t o   t h e   b e s t   a v a i l a b l e   z o n e 
 
 f u n c t i o n   C h e c k S w i t c h B e t t e r P l a n e t ( d i f f i c u l t y _ c a l l )   { 
 
         i f   ( d i f f i c u l t y _ c a l l   = = =   u n d e f i n e d ) 
 
                 d i f f i c u l t y _ c a l l   =   f a l s e ; 
 
 
 
         v a r   b e s t _ p l a n e t   =   G e t B e s t P l a n e t ( ) ; 
 
       
 
         v a r   n o w   =   n e w   D a t e ( ) . g e t T i m e ( ) ; 
 
         v a r   l a s t G a m e S t a r t   =   ( c u r r e n t _ g a m e _ s t a r t   = = =   u n d e f i n e d )   ?   n o w   :   c u r r e n t _ g a m e _ s t a r t ; 
 
         v a r   t i m e D i f f   =   ( n o w   -   l a s t G a m e S t a r t )   /   1 0 0 0 ; 
 
 
 
         i f   ( b e s t _ p l a n e t   ! = =   u n d e f i n e d   & &   b e s t _ p l a n e t   ! = =   n u l l   & &   b e s t _ p l a n e t   ! =   c u r r e n t _ p l a n e t _ i d )   { 
 
                 c o n s o l e . l o g ( " P l a n e t   # "   +   b e s t _ p l a n e t   +   "   h a s   h i g h e r   X P   p o t e n t i a l .   S w i t c h i n g   t o   i t .   B y e   p l a n e t   # "   +   c u r r e n t _ p l a n e t _ i d ) ; 
 
                 I N J E C T _ s w i t c h _ p l a n e t ( b e s t _ p l a n e t ,   f u n c t i o n ( )   { 
 
                         S w i t c h N e x t Z o n e ( 0 ,   d i f f i c u l t y _ c a l l ) ; 
 
                 } ) ; 
 
         }   e l s e   i f   ( b e s t _ p l a n e t   = =   c u r r e n t _ p l a n e t _ i d )   { 
 
                 i f   ( ( t i m e D i f f   > =   8   & &   d i f f i c u l t y _ c a l l   = =   t r u e )   | |   d i f f i c u l t y _ c a l l   = =   f a l s e ) 
 
                         S w i t c h N e x t Z o n e ( 0 ,   d i f f i c u l t y _ c a l l ) ; 
 
         }   e l s e   i f   ( b e s t _ p l a n e t   = = =   n u l l )   { 
 
                 c o n s o l e . l o g ( " T o o   m a n y   e r r o r s   w h i l e   s e a r c h i n g   a   b e t t e r   p l a n e t .   L e t ' s   c o n t i n u e   o n   t h e   c u r r e n t   z o n e . " ) ; 
 
                 i f   ( ( t i m e D i f f   > =   8   & &   d i f f i c u l t y _ c a l l   = =   t r u e )   | |   d i f f i c u l t y _ c a l l   = =   f a l s e ) 
 
                         I N J E C T _ s t a r t _ r o u n d ( t a r g e t _ z o n e ,   a c c e s s _ t o k e n ,   0 ,   c u r r e n t _ g a m e _ i s _ b o s s ) ; 
 
         }   e l s e   { 
 
                 c o n s o l e . l o g ( " T h e r e ' s   n o   p l a n e t   b e t t e r   t h a n   t h e   c u r r e n t   o n e . " ) ; 
 
         } 
 
 } 
 
 
 
 v a r   I N J E C T _ s w i t c h _ p l a n e t   =   f u n c t i o n ( p l a n e t _ i d ,   c a l l b a c k )   { 
 
         / /   O N L Y   u s a b l e   f r o m   b a t t l e   s e l e c t i o n ,   i f   a t   p l a n e t   s e l e c t i o n ,   r u n   j o i n   i n s t e a d 
 
         i f ( g G a m e . m _ S t a t e   i n s t a n c e o f   C P l a n e t S e l e c t i o n S t a t e ) 
 
                 j o i n _ p l a n e t _ h e l p e r ( p l a n e t _ i d ) ; 
 
         i f ( ! ( g G a m e . m _ S t a t e   i n s t a n c e o f   C B a t t l e S e l e c t i o n S t a t e ) ) 
 
                 r e t u r n ; 
 
 
 
         g u i . u p d a t e T a s k ( " KB05<AO  ?5@5<5AB8BLAO  =0  ?;0=5BC  # "   +   p l a n e t _ i d ) ; 
 
 
 
         / /   L e a v e   o u r   c u r r e n t   r o u n d   i f   w e   h a v e n ' t . 
 
         I N J E C T _ l e a v e _ r o u n d ( ) ; 
 
 
 
         / /   L e a v e   t h e   p l a n e t 
 
         I N J E C T _ l e a v e _ p l a n e t ( f u n c t i o n ( )   { 
 
                 / /   J o i n   P l a n e t 
 
                 j o i n _ p l a n e t _ h e l p e r ( p l a n e t _ i d ) ; 
 
         } ) ; 
 
 
 
         f u n c t i o n   w a i t _ f o r _ s t a t e _ l o a d ( )   { 
 
                 i f ( g G a m e . m _ I s S t a t e L o a d i n g   | |   g G a m e . m _ S t a t e   i n s t a n c e o f   C P l a n e t S e l e c t i o n S t a t e )   { 
 
                         c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
                         c u r r e n t _ t i m e o u t   =   s e t T i m e o u t ( f u n c t i o n ( )   {   w a i t _ f o r _ s t a t e _ l o a d ( ) ;   } ,   5 0 ) ; 
 
                 } 
 
                 e l s e 
 
                         c a l l b a c k ( ) ; 
 
         } 
 
 
 
         f u n c t i o n   j o i n _ p l a n e t _ h e l p e r ( p l a n e t _ i d )   { 
 
                 / /   M a k e   s u r e   t h e   p l a n e t _ i d   i s   v a l i d   ( o r   w e ' l l   e r r o r   o u t ) 
 
                 v a r   v a l i d _ p l a n e t s   =   g G a m e . m _ S t a t e . m _ r g P l a n e t s ; 
 
                 v a r   f o u n d   =   f a l s e ; 
 
                 f o r ( v a r   i = 0 ;   i < v a l i d _ p l a n e t s . l e n g t h ;   i + + ) 
 
                         i f   ( v a l i d _ p l a n e t s [ i ] . i d   = =   p l a n e t _ i d ) 
 
                                         f o u n d   =   t r u e ; 
 
                 i f ( ! f o u n d )   { 
 
                         g u i . u p d a t e T a s k ( " >?KB:0  ?5@5:;NG8BLAO  =0  =5459AB28B5;L=CN  ?;0=5BC.   K15@8B5  A;54CNICN. " ) ; 
 
                         g u i . u p d a t e S t a t u s ( f a l s e ) ; 
 
                         r e t u r n ; 
 
                 } 
 
 
 
                 I N J E C T _ j o i n _ p l a n e t ( p l a n e t _ i d , 
 
                         f u n c t i o n   (   r e s p o n s e   )   { 
 
                                 g G a m e . C h a n g e S t a t e (   n e w   C B a t t l e S e l e c t i o n S t a t e (   p l a n e t _ i d   )   ) ; 
 
                                 w a i t _ f o r _ s t a t e _ l o a d ( ) ; 
 
                         } , 
 
                         f u n c t i o n   (   r e s p o n s e   )   { 
 
                                 S h o w A l e r t D i a l o g (   ' H81:0  ?5@5<5I5=8O  =0  ?;0=5BC' ,   ' 5  C40;>AL  ?5@5<5AB8BLAO  =0  ?;0=5BC.   5@570?CAB8B5  83@C  8;8  ?>2B>@8B5  ?>?KB:C. '   ) ; 
 
                         } ) ; 
 
         } 
 
 } 
 
 
 
 / /   L e a v e   t h e   p l a n e t 
 
 v a r   I N J E C T _ l e a v e _ p l a n e t   =   f u n c t i o n ( c a l l b a c k )   { 
 
         i f ( t y p e o f   c a l l b a c k   ! = =   ' f u n c t i o n ' ) 
 
                 c a l l b a c k   =   f u n c t i o n ( )   { } ; 
 
 
 
         f u n c t i o n   w a i t _ f o r _ s t a t e _ l o a d ( )   { 
 
                 i f ( g G a m e . m _ I s S t a t e L o a d i n g   | |   g G a m e . m _ S t a t e   i n s t a n c e o f   C B a t t l e S e l e c t i o n S t a t e )   { 
 
                         c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
                         c u r r e n t _ t i m e o u t   =   s e t T i m e o u t ( f u n c t i o n ( )   {   w a i t _ f o r _ s t a t e _ l o a d ( ) ;   } ,   5 0 ) ; 
 
                 } 
 
                 e l s e   { 
 
                         / /   C l e a r   t h e   c u r r e n t   p l a n e t   I D   v a r 
 
                         c u r r e n t _ p l a n e t _ i d   =   u n d e f i n e d ; 
 
 
 
                         I N J E C T _ i n i t ( ) ; 
 
 
 
                         / /   R e s t o r e   o l d   a n i m a t i o n   s t a t e 
 
                         I N J E C T _ t o g g l e _ a n i m a t i o n s ( a n i m _ s t a t e ) ; 
 
 
 
                         c a l l b a c k ( ) ; 
 
                 } 
 
         } 
 
 
 
         / /   C a n c e l   t i m e o u t s 
 
         c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
 
 
         / /   L e a v e   o u r   c u r r e n t   r o u n d   i f   w e   h a v e n ' t . 
 
         I N J E C T _ l e a v e _ r o u n d ( ) ; 
 
 
 
         / /   T e m p o r a r i l y   e n a b l e   a n i m a t i o n s 
 
         v a r   a n i m _ s t a t e   =   a n i m a t i o n s _ e n a b l e d ; 
 
         I N J E C T _ t o g g l e _ a n i m a t i o n s ( t r u e ) ; 
 
 
 
         / /   ( M o d i f i e d )   D e f a u l t   C o d e 
 
         g A u d i o M a n a g e r . P l a y S o u n d (   ' u i _ s e l e c t _ b a c k w a r d s '   ) ; 
 
         g S e r v e r . L e a v e G a m e I n s t a n c e ( 
 
                 g G a m e . m _ S t a t e . m _ P l a n e t D a t a . i d , 
 
                 f u n c t i o n ( )   { 
 
                         g G a m e . C h a n g e S t a t e (   n e w   C P l a n e t S e l e c t i o n S t a t e ( )   ) ; 
 
                         / /   W a i t   f o r   t h e   n e w   s t a t e   t o   l o a d ,   t h e n   h o o k   i n 
 
                         w a i t _ f o r _ s t a t e _ l o a d ( ) ; 
 
                 } 
 
         ) ; 
 
 } 
 
 
 
 v a r   I N J E C T _ j o i n _ p l a n e t   =   f u n c t i o n ( p l a n e t _ i d ,   s u c c e s s _ c a l l b a c k ,   e r r o r _ c a l l b a c k )   { 
 
         i f ( t y p e o f   s u c c e s s _ c a l l b a c k   ! = =   ' f u n c t i o n ' ) 
 
                 s u c c e s s _ c a l l b a c k   =   f u n c t i o n ( )   { } ; 
 
         i f ( t y p e o f   e r r o r _ c a l l b a c k   ! = =   ' f u n c t i o n ' ) 
 
                 e r r o r _ c a l l b a c k   =   f u n c t i o n ( )   { } ; 
 
 
 
         f u n c t i o n   w a i t _ f o r _ s t a t e _ l o a d ( )   { 
 
                 i f ( g G a m e . m _ I s S t a t e L o a d i n g   | |   g G a m e . m _ S t a t e   i n s t a n c e o f   C P l a n e t S e l e c t i o n S t a t e )   { 
 
                         c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
                         c u r r e n t _ t i m e o u t   =   s e t T i m e o u t ( f u n c t i o n ( )   {   w a i t _ f o r _ s t a t e _ l o a d ( ) ;   } ,   5 0 ) ; 
 
                 } 
 
                 e l s e   { 
 
                         c u r r e n t _ p l a n e t _ i d   =   p l a n e t _ i d ; 
 
                         I N J E C T _ i n i t ( ) ; 
 
 
 
                         / /   R e s t o r e   o l d   a n i m a t i o n   s t a t e 
 
                         I N J E C T _ t o g g l e _ a n i m a t i o n s ( a n i m _ s t a t e ) ; 
 
                 } 
 
         } 
 
 
 
         / /   M o d i f i e d   D e f a u l t   c o d e 
 
         v a r   r g P a r a m s   =   { 
 
                 i d :   p l a n e t _ i d , 
 
                 a c c e s s _ t o k e n :   a c c e s s _ t o k e n 
 
         } ; 
 
 
 
         / /   T e m p o r a r i l y   e n a b l e   a n i m a t i o n s 
 
         v a r   a n i m _ s t a t e   =   a n i m a t i o n s _ e n a b l e d ; 
 
         I N J E C T _ t o g g l e _ a n i m a t i o n s ( t r u e ) ; 
 
 
 
         $ J . a j a x ( { 
 
                 a s y n c :   f a l s e , 
 
                 u r l :   w i n d o w . g S e r v e r . m _ W e b A P I . B u i l d U R L (   ' I T e r r i t o r y C o n t r o l M i n i g a m e S e r v i c e ' ,   ' J o i n P l a n e t ' ,   t r u e   ) , 
 
                 m e t h o d :   ' P O S T ' , 
 
                 d a t a :   r g P a r a m s 
 
         } ) . s u c c e s s (   f u n c t i o n (   r e s u l t s ,   t e x t S t a t u s ,   r e q u e s t   )   { 
 
                 i f   (   r e q u e s t . g e t R e s p o n s e H e a d e r (   ' x - e r e s u l t '   )   = =   1   )   { 
 
                         s u c c e s s _ c a l l b a c k (   r e s u l t s   ) ; 
 
                         / /   W a i t   f o r   t h e   n e w   s t a t e   t o   l o a d ,   t h e n   h o o k   i n 
 
                         w a i t _ f o r _ s t a t e _ l o a d ( ) ; 
 
                 } 
 
                 e l s e   { 
 
                         c o n s o l e . l o g ( r e s u l t s ,   t e x t S t a t u s ,   r e q u e s t ) ; 
 
                         e r r o r _ c a l l b a c k ( ) ; 
 
                 } 
 
         } ) . f a i l (   e r r o r _ c a l l b a c k   ) ; 
 
 } 
 
 
 
 v a r   I N J E C T _ i n i t _ b a t t l e _ s e l e c t i o n   =   f u n c t i o n ( )   { 
 
         / /   U p d a t e   t h e   G U I 
 
         g u i . u p d a t e S t a t u s ( t r u e ) ; 
 
         g u i . u p d a t e T a s k ( " =8F80;870F8O  <5=N  2K1>@0  18B2K. " ) ; 
 
 
 
         / /   C h e c k   t h e   g a m e   s t a t e   f o r   h a n g u p s   o c c a s i o n a l l y 
 
         i f   ( c h e c k _ g a m e _ s t a t e   ! = =   u n d e f i n e d ) 
 
                 c l e a r I n t e r v a l ( c h e c k _ g a m e _ s t a t e ) ; 
 
         c h e c k _ g a m e _ s t a t e   =   s e t I n t e r v a l ( c h e c k U n l o c k G a m e S t a t e ,   6 0 0 0 0 ) ; 
 
       
 
         / /   A u t o   j o i n   b e s t   z o n e   a t   f i r s t 
 
         i f   ( a u t o _ f i r s t _ j o i n   = =   t r u e )   { 
 
                 f i r s t J o i n ( ) ; 
 
                 f u n c t i o n   f i r s t J o i n ( )   { 
 
                         / /   W a i t   f o r   s t a t e   &   a c c e s s _ t o k e n 
 
                         i f ( a c c e s s _ t o k e n   = = =   u n d e f i n e d   | |   g G a m e   = = =   u n d e f i n e d   | |   g G a m e . m _ I s S t a t e L o a d i n g   | |   g G a m e . m _ S t a t e   i n s t a n c e o f   C P l a n e t S e l e c t i o n S t a t e )   { 
 
                                 c l e a r T i m e o u t ( c u r r e n t _ t i m e o u t ) ; 
 
                                 c u r r e n t _ t i m e o u t   =   s e t T i m e o u t ( f u n c t i o n ( )   {   f i r s t J o i n ( ) ;   } ,   1 0 0 ) ; 
 
                                 c o n s o l e . l o g ( " w a i t i n g " ) ; 
 
                                 r e t u r n ; 
 
                         } 
 
 
 
                         c u r r e n t _ p l a n e t _ i d   =   w i n d o w . g G a m e . m _ S t a t e . m _ P l a n e t D a t a . i d ; 
 
                       
 
                         i f ( a c c e s s _ t o k e n   = = =   u n d e f i n e d ) 
 
                                 I N J E C T _ g e t _ a c c e s s _ t o k e n ( ) ; 
 
 
 
                         v a r   f i r s t _ z o n e ; 
 
                         i f ( t a r g e t _ z o n e   = = =   - 1 )   { 
 
                                 S w i t c h N e x t Z o n e ( ) ; 
 
                         }   e l s e   { 
 
                                 f i r s t _ z o n e   =   t a r g e t _ z o n e ; 
 
                                 c u r r e n t _ g a m e _ i s _ b o s s   =   w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ f i r s t _ z o n e ] . I n f o . b o s s ; 
 
                                 I N J E C T _ s t a r t _ r o u n d ( f i r s t _ z o n e ,   a c c e s s _ t o k e n ,   0 ,   c u r r e n t _ g a m e _ i s _ b o s s ) ; 
 
                         } 
 
                 } 
 
         } 
 
 
 
         / /   O v e r w r i t e   j o i n   f u n c t i o n   s o   c l i c k i n g   o n   a   g r i d   s q u a r e   w i l l   r u n   o u r   c o d e   i n s t e a d 
 
         g S e r v e r . J o i n Z o n e   =   f u n c t i o n   ( z o n e _ i d ,   c a l l b a c k ,   e r r o r _ c a l l b a c k )   { 
 
                 c u r r e n t _ p l a n e t _ i d   =   w i n d o w . g G a m e . m _ S t a t e . m _ P l a n e t D a t a . i d ; 
 
                 c u r r e n t _ g a m e _ i s _ b o s s   =   w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ z o n e _ i d ] . I n f o . b o s s ; 
 
                 I N J E C T _ s t a r t _ r o u n d ( z o n e _ i d ,   a c c e s s _ t o k e n ,   0 ,   c u r r e n t _ g a m e _ i s _ b o s s ) ; 
 
         } 
 
 
 
         / /   H o o k   t h e   G r i d   c l i c k   f u n c t i o n 
 
         v a r   g r i d _ c l i c k _ d e f a u l t   =   g G a m e . m _ S t a t e . m _ G r i d . c l i c k ; 
 
         g G a m e . m _ S t a t e . m _ G r i d . c l i c k   =   f u n c t i o n ( t i l e X ,   t i l e Y )   { 
 
                 / /   G e t   t h e   s e l e c t e d   z o n e   I D 
 
                 v a r   z o n e I d x   =   _ G e t T i l e I d x (   t i l e X ,   t i l e Y   ) ; 
 
 
 
                 / /   R e t u r n   i f   i t ' s   t h e   c u r r e n t   z o n e   ( D o n ' t   w a n t   c l i c k i n g   o n   s a m e   z o n e   t o   l e a v e / r e j o i n ) 
 
                 i f ( t a r g e t _ z o n e   = = =   z o n e I d x ) 
 
                         r e t u r n ; 
 
 
 
                 / /   R e t u r n   i f   i t ' s   a   c o m p l e t e d   z o n e 
 
                 i f ( w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ z o n e I d x ] . I n f o . c a p t u r e d )   { 
 
                         c o n s o l e . l o g ( " M a n u a l l y   s e l e c t e d   z o n e   a l r e a d y   c a p t u r e d .   R e t u r n i n g . " ) ; 
 
                         r e t u r n ; 
 
                 } 
 
 
 
                 / /   U p d a t e   t h e   G U I 
 
                 g u i . u p d a t e T a s k ( " >?KB:0  @CG=>3>  ?5@5:;NG5=8O  =0  7>=C  # "   +   z o n e I d x ) ; 
 
                 g u i . p r o g r e s s b a r . p a r e n t . r e m o v e C h i l d ( g u i . p r o g r e s s b a r ) ; 
 
 
 
                 / /   L e a v e   e x i s t i n g   r o u n d 
 
                 I N J E C T _ l e a v e _ r o u n d ( ) ; 
 
 
 
                 / /   J o i n   n e w   r o u n d 
 
                 c u r r e n t _ g a m e _ i s _ b o s s   =   w i n d o w . g G a m e . m _ S t a t e . m _ G r i d . m _ T i l e s [ z o n e I d x ] . I n f o . b o s s ; 
 
                 I N J E C T _ s t a r t _ r o u n d ( z o n e I d x ,   a c c e s s _ t o k e n ,   0 ,   c u r r e n t _ g a m e _ i s _ b o s s ) ; 
 
         } 
 
 
 
         / /   H o o k   t h e   L e a v e   P l a n e t   B u t t o n 
 
         g G a m e . m _ S t a t e . m _ L e a v e B u t t o n . c l i c k   =   f u n c t i o n ( b t n )   { 
 
                 I N J E C T _ l e a v e _ p l a n e t ( ) ; 
 
         } ; 
 
 } 
 
 
 
 v a r   I N J E C T _ i n i t _ p l a n e t _ s e l e c t i o n   =   f u n c t i o n ( )   { 
 
         g u i . u p d a t e S t a t u s ( t r u e ) ; 
 
         g u i . u p d a t e T a s k ( " =8F80;870F8O  <5=N  2K1>@0  ?;0=5BK. " ) ; 
 
 
 
         / /   H o o k   t h e   J o i n   P l a n e t   F u n c t i o n 
 
         g S e r v e r . J o i n P l a n e t   =   f u n c t i o n ( p l a n e t _ i d ,   s u c c e s s _ c a l l b a c k ,   e r r o r _ c a l l b a c k )   { 
 
                 I N J E C T _ j o i n _ p l a n e t ( p l a n e t _ i d ,   s u c c e s s _ c a l l b a c k ,   e r r o r _ c a l l b a c k ) ; 
 
         } 
 
 
 
         / /   U p d a t e   G U I 
 
         g u i . u p d a t e S t a t u s ( f a l s e ) ; 
 
         g u i . u p d a t e T a s k ( " K1>@  ?;0=5BK" ) ; 
 
         g u i . u p d a t e Z o n e ( "  " ) ; 
 
 } ; 
 
 
 
 v a r   I N J E C T _ i n i t   =   f u n c t i o n ( )   { 
 
         / /   S e t   A c c o u n t   I D 
 
         a c c o u n t _ i d   =   g A c c o u n t I D ; 
 
       
 
         / /   A v o i d   b o s s e s   i f   w e ' r e   n e a r   l e v e l   2 5 
 
         a v o i d _ b o s s   =   ( g P l a y e r I n f o . s c o r e   > =   2 6 3 9 0 0 0 0   & &   g P l a y e r I n f o . s c o r e   <   2 6 4 0 0 0 0 0 ) ; 
 
       
 
         i f   ( g G a m e . m _ S t a t e   i n s t a n c e o f   C B a t t l e S e l e c t i o n S t a t e ) 
 
                 I N J E C T _ i n i t _ b a t t l e _ s e l e c t i o n ( ) ; 
 
         e l s e   i f   ( g G a m e . m _ S t a t e   i n s t a n c e o f   C P l a n e t S e l e c t i o n S t a t e ) 
 
                 I N J E C T _ i n i t _ p l a n e t _ s e l e c t i o n ( ) ; 
 
 } ; 
 
 
 
 v a r   I N J E C T _ t o g g l e _ a n i m a t i o n s   =   f u n c t i o n ( e n a b l e d )   { 
 
 
 
         i f ( e n a b l e d ) 
 
         { 
 
                 / /   S h o w   c a n v a s 
 
                 $ J ( " c a n v a s " ) . s h o w ( ) ; 
 
                 / /   E n a b l e   a n i m a t i o n s 
 
                 g A p p . t i c k e r . s t a r t ( ) ; 
 
         } 
 
         e l s e 
 
         { 
 
                 / /   H i d e   c a n v a s 
 
                 $ J ( " c a n v a s " ) . h i d e ( ) ; 
 
                 / /   D i s a b l e   a n i m a t i o n s 
 
                 g A p p . t i c k e r . s t o p ( ) ; 
 
         } 
 
         a n i m a t i o n s _ e n a b l e d = e n a b l e d ; 
 
 } ; 
 
 
 
 / /   R u n   i n i t i a l i z a t i o n   c o d e   o n   l o a d 
 
 $ J ( d o c u m e n t ) . r e a d y ( f u n c t i o n ( )   { 
 
         / /   A u t o - g r a b   t h e   a c c e s s   t o k e n 
 
         I N J E C T _ g e t _ a c c e s s _ t o k e n ( ) ; 
 
       
 
         / /   C a l l   o u r   g l o b a l   i n i t   f u n c t i o n 
 
         i n i t G U I ( ) ; 
 
 } ) 