@@ -776,6 +776,12 @@ def showname_else_char_showname(self) -> str:
776776 return self .showname
777777 return self .char_showname
778778
779+ def has_character (self , char_id : int = None ) -> bool :
780+ if char_id is None :
781+ char_id = self .char_id
782+
783+ return char_id is not None and char_id >= 0
784+
779785 def change_character (self , char_id : int , force : bool = False ,
780786 target_area : AreaManager .Area = None ,
781787 announce_zwatch : bool = True ):
@@ -812,7 +818,8 @@ def change_character(self, char_id: int, force: bool = False,
812818 # Code after this comment assumes the character change will be successful
813819 self .ever_chose_character = True
814820
815- if old_char_id < 0 and char_id >= 0 : # No longer spectator?
821+ if not self .has_character () and self .has_character (char_id = char_id ):
822+ # No longer spectator?
816823 # Now bound by AFK rules
817824 self .server .tasker .create_task (self , ['as_afk_kick' , self .area .afk_delay ,
818825 self .area .afk_sendto ])
@@ -826,7 +833,8 @@ def change_character(self, char_id: int, force: bool = False,
826833 f'and you are not logged in.' )
827834 self .unfollow_user ()
828835
829- elif old_char_id >= 0 and char_id < 0 : # Now a spectator?
836+ elif self .has_character () and not self .has_character (char_id = char_id ):
837+ # Now a spectator?
830838 # No longer bound to AFK rules
831839 try :
832840 self .server .tasker .remove_task (self , ['as_afk_kick' ])
@@ -958,7 +966,7 @@ def notify_change_area(self, area: AreaManager.Area, old_char: str,
958966 just_me = just_me )
959967
960968 def check_lurk (self ):
961- if self .area .lurk_length > 0 and not self .is_staff () and self .char_id >= 0 :
969+ if self .area .lurk_length > 0 and not self .is_staff () and self .has_character () :
962970 self .server .tasker .create_task (self , ['as_lurk' , self .area .lurk_length ])
963971 else : # Otherwise, end any existing lurk, if there is one
964972 try :
@@ -1600,8 +1608,7 @@ def refresh_char_list(self):
16001608 for x in unusable_ids :
16011609 char_list [x ] = - 1
16021610
1603- # If not spectator
1604- if self .char_id is not None and self .char_id >= 0 :
1611+ if self .has_character ():
16051612 char_list [self .char_id ] = 0 # Self is always available
16061613 self .send_command_dict ('CharsCheck' , {
16071614 'chars_status_ao2_list' : char_list ,
@@ -1610,7 +1617,7 @@ def refresh_char_list(self):
16101617 def refresh_visible_char_list (self ):
16111618 char_list = [0 ] * len (self .server .char_list )
16121619 unusable_ids = {c .char_id for c in self .get_visible_clients (self .area )
1613- if c .char_id >= 0 }
1620+ if c .has_character () }
16141621 if not self .is_staff ():
16151622 unusable_ids |= {self .server .char_list .index (name )
16161623 for name in self .area .restricted_chars }
@@ -1619,7 +1626,7 @@ def refresh_visible_char_list(self):
16191626 char_list [x ] = - 1
16201627
16211628 # Self is always available
1622- if self .char_id is not None and self . char_id >= 0 :
1629+ if self .has_character () :
16231630 char_list [self .char_id ] = 0
16241631 self .send_command_dict ('CharsCheck' , {
16251632 'chars_status_ao2_list' : char_list ,
@@ -1889,9 +1896,6 @@ def get_char_name(self, char_id: int = None) -> str:
18891896 return self .server .server_select_name
18901897 return self .server .char_list [char_id ]
18911898
1892- def has_character (self ) -> bool :
1893- return self .char_id not in [- 1 , None ]
1894-
18951899 def get_showname_history (self ) -> str :
18961900 info = '== Showname history of client {} ==' .format (self .id )
18971901
0 commit comments