<s> from shinymud . lib . world import World <EOL> from shinymud . data . config import * <EOL> from shinymud . commands . emotes import * <EOL> from shinymud . commands . attacks import * <EOL> from shinymud . commands import * <EOL> from shinymud . lib . battle import Battle <EOL> import re <EOL> command_list = CommandRegister ( ) <EOL> battle_commands = CommandRegister ( ) <EOL> class Quit ( BaseCommand ) : <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> self . pc . quit_flag = True <EOL> command_list . register ( Quit , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Quit . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class WorldEcho ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = ADMIN <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> self . world . tell_players ( self . args ) <EOL> command_list . register ( WorldEcho , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( WorldEcho . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class RoomEcho ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = DM | ADMIN <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> self . pc . location . tell_room ( self . args ) <EOL> command_list . register ( RoomEcho , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( RoomEcho . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Chat ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( "<STR_LIT>" ) <EOL> return <EOL> if not self . pc . channels [ '<STR_LIT>' ] : <EOL> self . pc . channels [ '<STR_LIT>' ] = True <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> exclude = [ player . name for player in self . world . player_list . values ( ) if not player . channels [ '<STR_LIT>' ] ] <EOL> if '<STR_LIT>' in self . pc . effects : <EOL> self . args = self . pc . effects [ '<STR_LIT>' ] . filter_speech ( self . args ) <EOL> message = '<STR_LIT>' % ( self . pc . fancy_name ( ) , self . args ) <EOL> self . world . tell_players ( message , exclude , chat_color ) <EOL> command_list . register ( Chat , [ '<STR_LIT>' , '<STR_LIT:c>' ] ) <EOL> command_help . register ( Chat . help , [ '<STR_LIT>' ] ) <EOL> class Channel ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> chnls = '<STR_LIT>' <EOL> for key , value in self . pc . channels . items ( ) : <EOL> if value : <EOL> chnls += '<STR_LIT>' + key + '<STR_LIT>' + '<STR_LIT>' <EOL> else : <EOL> chnls += '<STR_LIT>' + key + '<STR_LIT>' + '<STR_LIT>' <EOL> self . pc . update_output ( chnls ) <EOL> return <EOL> toggle = { '<STR_LIT>' : True , '<STR_LIT>' : False } <EOL> args = self . args . split ( ) <EOL> channel = args [ <NUM_LIT:0> ] . lower ( ) <EOL> choice = args [ <NUM_LIT:1> ] . lower ( ) <EOL> if channel in self . pc . channels . keys ( ) : <EOL> if choice in toggle . keys ( ) : <EOL> self . pc . channels [ channel ] = toggle [ choice ] <EOL> self . pc . update_output ( '<STR_LIT>' % ( channel , choice ) ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % channel ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Channel , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Channel . help , [ '<STR_LIT>' ] ) <EOL> class Build ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = BUILDER <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . enter_build_mode ( ) <EOL> elif self . args == '<STR_LIT>' : <EOL> if self . pc . get_mode ( ) == '<STR_LIT>' : <EOL> self . pc . set_mode ( '<STR_LIT>' ) <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> elif self . args == '<STR_LIT>' : <EOL> if self . pc . location : <EOL> self . edit ( self . pc . location . area , self . pc . location ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> area = self . world . get_area ( self . args ) <EOL> if not area : <EOL> self . pc . update_output ( '<STR_LIT>' % self . args ) <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> self . edit ( area ) <EOL> def enter_build_mode ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . pc . get_mode ( ) == '<STR_LIT>' : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> self . pc . set_mode ( '<STR_LIT>' ) <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> def edit ( self , area , room = None ) : <EOL> """<STR_LIT>""" <EOL> if self . pc . get_mode ( ) != '<STR_LIT>' : <EOL> self . enter_build_mode ( ) <EOL> if ( self . pc . name in area . builders ) or ( self . pc . permissions & GOD ) : <EOL> self . pc . mode . edit_area = area <EOL> self . pc . mode . edit_object = None <EOL> if room : <EOL> self . pc . mode . edit_object = room <EOL> self . pc . update_output ( '<STR_LIT>' % <EOL> ( room . id , area . name ) ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % area . name ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Build , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Build . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Look ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> message = '<STR_LIT>' <EOL> if not self . args : <EOL> message = self . look_at_room ( ) <EOL> else : <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if match : <EOL> thing1 , thing2 , place = match . group ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> thing = thing1 or thing2 <EOL> thing = thing . strip ( ) <EOL> if thing == '<STR_LIT>' : <EOL> message = self . look_at_room ( ) <EOL> else : <EOL> if place : <EOL> obj_desc = getattr ( self , '<STR_LIT>' + place ) ( thing ) <EOL> else : <EOL> obj_desc = self . look_in_room ( thing ) or self . look_in_inventory ( thing ) <EOL> if obj_desc : <EOL> message = obj_desc <EOL> self . pc . update_output ( message ) <EOL> def look_at_room ( self ) : <EOL> if self . pc . location : <EOL> return self . pc . look_at_room ( ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> def look_in_room ( self , keyword ) : <EOL> if self . pc . location : <EOL> obj = self . pc . location . check_for_keyword ( keyword ) <EOL> if obj : <EOL> if self . alias == '<STR_LIT>' : <EOL> return obj . description <EOL> message = "<STR_LIT>" % ( obj . name , obj . description ) <EOL> if hasattr ( obj , '<STR_LIT>' ) and obj . has_type ( '<STR_LIT>' ) : <EOL> message += '<STR_LIT:\n>' + obj . item_types . get ( '<STR_LIT>' ) . display_inventory ( ) <EOL> return message <EOL> return None <EOL> def look_in_inventory ( self , keyword ) : <EOL> item = self . pc . check_inv_for_keyword ( keyword ) <EOL> if item : <EOL> message = "<STR_LIT>" % ( item . name , item . description ) <EOL> if item . has_type ( '<STR_LIT>' ) : <EOL> message += '<STR_LIT:\n>' + item . item_types . get ( '<STR_LIT>' ) . display_inventory ( ) <EOL> return message <EOL> return None <EOL> command_list . register ( Look , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Look . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Goto ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = BUILDER | DM | ADMIN <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args . strip ( ) ) <EOL> message = '<STR_LIT>' <EOL> if not match : <EOL> self . pc . update_output ( message ) <EOL> return <EOL> name , area_name , room_id = match . group ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if name : <EOL> per = self . world . get_player ( name ) <EOL> if per : <EOL> if per . location : <EOL> self . pc . go ( per . location , self . pc . goto_appear , <EOL> self . pc . goto_disappear ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % per . fancy_name ( ) ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> elif room_id : <EOL> if area_name : <EOL> area = self . world . get_area ( area_name ) <EOL> if not area : <EOL> self . pc . update_output ( '<STR_LIT>' % area_name ) <EOL> return <EOL> else : <EOL> if not self . pc . location : <EOL> self . pc . update_output ( message ) <EOL> return <EOL> area = self . pc . location . area <EOL> room = area . get_room ( room_id ) <EOL> if room : <EOL> self . pc . go ( room , self . pc . goto_appear , <EOL> self . pc . goto_disappear ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % ( room_id , area . name ) ) <EOL> else : <EOL> self . pc . update_output ( message ) <EOL> command_list . register ( Goto , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Goto . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Go ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> dir_map = { '<STR_LIT:n>' : '<STR_LIT>' , '<STR_LIT:s>' : '<STR_LIT>' , '<STR_LIT:e>' : '<STR_LIT>' , '<STR_LIT:w>' : '<STR_LIT>' , <EOL> '<STR_LIT:u>' : '<STR_LIT>' , '<STR_LIT:d>' : '<STR_LIT>' <EOL> } <EOL> if self . alias == '<STR_LIT>' : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if self . args in dir_map : <EOL> direction = dir_map [ self . args ] <EOL> else : <EOL> direction = self . args <EOL> else : <EOL> if self . alias in dir_map : <EOL> direction = dir_map [ self . alias ] <EOL> else : <EOL> direction = self . alias <EOL> if self . pc . location : <EOL> go_exit = self . pc . location . exits . get ( direction ) <EOL> if go_exit : <EOL> if go_exit . _closed : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> if go_exit . to_room : <EOL> if go_exit . linked_exit : <EOL> arrives = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> tell_new = '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> arrives . get ( go_exit . linked_exit ) ) <EOL> else : <EOL> tell_new = '<STR_LIT>' % self . pc . fancy_name ( ) <EOL> tell_old = '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> go_exit . direction ) <EOL> self . pc . go ( go_exit . to_room , tell_new , tell_old ) <EOL> else : <EOL> self . world . log . critical ( '<STR_LIT>' % ( go_exit . direction , go_exit . room . id , go_exit . room . area . name ) ) <EOL> go_exit . destruct ( ) <EOL> self . pc . location . exits [ go_exit . direction ] = None <EOL> self . pc . location . tell_room ( '<STR_LIT>' % self . args ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Go , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:n>' , '<STR_LIT>' , '<STR_LIT:s>' , '<STR_LIT>' , '<STR_LIT:e>' , <EOL> '<STR_LIT>' , '<STR_LIT:w>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:u>' , '<STR_LIT:d>' ] ) <EOL> command_help . register ( Go . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:u>' , '<STR_LIT:d>' , '<STR_LIT:n>' , '<STR_LIT:e>' , '<STR_LIT:s>' , '<STR_LIT:w>' ] ) <EOL> class Say ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if self . args : <EOL> if self . pc . location : <EOL> if '<STR_LIT>' in self . pc . effects : <EOL> self . args = self . pc . effects [ '<STR_LIT>' ] . filter_speech ( self . args ) <EOL> message = '<STR_LIT>' % ( self . pc . fancy_name ( ) , self . args ) <EOL> message = say_color + message + clear_fcolor <EOL> self . pc . location . tell_room ( message , teller = self . pc ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Say , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Say . help , [ '<STR_LIT>' ] ) <EOL> class Load ( BaseCommand ) : <EOL> required_permissions = ADMIN | BUILDER | DM <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> help_message = '<STR_LIT>' <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if match : <EOL> obj_type , obj_id , area_name = match . group ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not obj_type or not obj_id : <EOL> self . pc . update_output ( help_message ) <EOL> else : <EOL> if not area_name and self . pc . location : <EOL> getattr ( self , '<STR_LIT>' + obj_type ) ( obj_id , self . pc . location . area ) <EOL> elif not area_name and self . pc . mode . edit_area : <EOL> getattr ( self , '<STR_LIT>' + obj_type ) ( obj_id , self . pc . mode . edit_area ) <EOL> elif area_name and self . world . area_exists ( area_name ) : <EOL> getattr ( self , '<STR_LIT>' + obj_type ) ( obj_id , self . world . get_area ( area_name ) ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> self . pc . update_output ( help_message ) <EOL> def load_npc ( self , npc_id , npc_area ) : <EOL> """<STR_LIT>""" <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> prototype = npc_area . get_npc ( npc_id ) <EOL> if prototype : <EOL> npc = prototype . load ( ) <EOL> npc . location = self . pc . location <EOL> self . pc . location . add_char ( npc ) <EOL> self . pc . update_output ( '<STR_LIT>' % npc . name ) <EOL> if self . alias == '<STR_LIT>' : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , npc . name ) , <EOL> [ self . pc . name ] , self . pc ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> def load_item ( self , item_id , item_area ) : <EOL> """<STR_LIT>""" <EOL> prototype = item_area . get_item ( item_id ) <EOL> if prototype : <EOL> item = prototype . load ( ) <EOL> self . pc . item_add ( item ) <EOL> self . pc . update_output ( '<STR_LIT>' % item . name ) <EOL> if self . pc . location and ( self . alias == '<STR_LIT>' ) : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , item . name ) , <EOL> [ self . pc . name ] , self . pc ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Load , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Load . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Inventory ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> i = '<STR_LIT>' % ( str ( self . pc . currency ) , CURRENCY ) <EOL> if not self . pc . inventory : <EOL> i += '<STR_LIT>' <EOL> else : <EOL> i += '<STR_LIT>' <EOL> for item in self . pc . inventory : <EOL> if item not in self . pc . isequipped : <EOL> i += item . name + '<STR_LIT:\n>' <EOL> self . pc . update_output ( i ) <EOL> command_list . register ( Inventory , [ '<STR_LIT:i>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Inventory . help , [ '<STR_LIT:i>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Give ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> elif not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> amount , thing , person = match . group ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> givee = self . pc . location . get_player ( person ) <EOL> if not givee : <EOL> givee = self . pc . location . get_npc_by_kw ( person ) <EOL> if not givee : <EOL> self . pc . update_output ( '<STR_LIT>' % person . capitalize ( ) ) <EOL> return <EOL> thing_name = '<STR_LIT>' <EOL> item = self . pc . check_inv_for_keyword ( thing ) <EOL> if item : <EOL> self . pc . item_remove ( item ) <EOL> givee . item_add ( item ) <EOL> thing_name = item . name <EOL> elif not item and thing == CURRENCY : <EOL> if not amount : <EOL> amount = <NUM_LIT:1> <EOL> else : <EOL> amount = int ( amount ) <EOL> if self . pc . currency < amount : <EOL> self . pc . update_output ( '<STR_LIT>' + CURRENCY + '<STR_LIT:.>' ) <EOL> return <EOL> else : <EOL> self . pc . currency -= amount <EOL> givee . currency += amount <EOL> thing_name = str ( amount ) + '<STR_LIT:U+0020>' + CURRENCY <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % thing ) <EOL> return <EOL> self . pc . update_output ( '<STR_LIT>' % ( thing_name , givee . fancy_name ( ) ) ) <EOL> givee . update_output ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , thing_name ) ) <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> thing_name , <EOL> givee . fancy_name ( ) ) , <EOL> [ self . pc . name , givee . name ] ) <EOL> if item and givee . is_npc ( ) : <EOL> givee . notify ( '<STR_LIT>' , { '<STR_LIT>' : self . pc , <EOL> '<STR_LIT>' : item } ) <EOL> def give_currency ( self , amount , givee ) : <EOL> if self . pc . currency < amount : <EOL> self . pc . update_output ( '<STR_LIT>' + CURRENCY + '<STR_LIT:.>' ) <EOL> else : <EOL> self . pc . currency -= amount <EOL> givee . currency += amount <EOL> curr = '<STR_LIT>' + CURRENCY <EOL> command_list . register ( Give , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Give . help , [ '<STR_LIT>' ] ) <EOL> class Drop ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> item = self . pc . check_inv_for_keyword ( self . args ) <EOL> if item : <EOL> self . pc . item_remove ( item ) <EOL> self . pc . update_output ( '<STR_LIT>' % item . name ) <EOL> if self . pc . location : <EOL> self . pc . location . item_add ( item ) <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> item . name ) , [ self . pc . name ] ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % item . name ) <EOL> item . destruct ( ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Drop , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Drop . help , [ '<STR_LIT>' ] ) <EOL> class Get ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> target_kw , source_kw , item_kw = match . group ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> if source_kw : <EOL> message = self . get_item_from_container ( source_kw , target_kw ) <EOL> else : <EOL> message = self . get_item_from_room ( item_kw ) <EOL> self . pc . update_output ( message ) <EOL> def get_item_from_container ( self , source_kw , target_kw ) : <EOL> c_item = self . pc . location . get_item_by_kw ( source_kw ) or self . pc . check_inv_for_keyword ( source_kw ) <EOL> if not c_item : <EOL> return '<STR_LIT>' % source_kw <EOL> if not c_item . has_type ( '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> container = c_item . item_types . get ( '<STR_LIT>' ) <EOL> if container . closed : <EOL> return '<STR_LIT>' % c_item . name . capitalize ( ) <EOL> item = container . get_item_by_kw ( target_kw ) <EOL> if not item : <EOL> return '<STR_LIT>' % target_kw . capitalize ( ) <EOL> if item . carryable or ( self . pc . permissions & GOD ) : <EOL> container . item_remove ( item ) <EOL> self . pc . item_add ( item ) <EOL> if self . pc . location : <EOL> room_tell = '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> item . name , c_item . name ) <EOL> self . pc . location . tell_room ( room_tell , [ self . pc . name ] ) <EOL> return '<STR_LIT>' % item . name <EOL> else : <EOL> return '<STR_LIT>' <EOL> def get_item_from_room ( self , item_kw ) : <EOL> if not self . pc . location : <EOL> return '<STR_LIT>' + '<STR_LIT>' <EOL> item = self . pc . location . get_item_by_kw ( item_kw ) <EOL> if not item : <EOL> return '<STR_LIT>' % item_kw <EOL> if item . carryable or ( self . pc . permissions & GOD ) : <EOL> self . pc . location . item_remove ( item ) <EOL> self . pc . item_add ( item ) <EOL> room_tell = '<STR_LIT>' % ( self . pc . fancy_name ( ) , item . name ) <EOL> self . pc . location . tell_room ( room_tell , [ self . pc . name ] ) <EOL> return '<STR_LIT>' % item . name <EOL> else : <EOL> return '<STR_LIT>' <EOL> command_list . register ( Get , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Get . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Put ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args . lower ( ) . strip ( ) ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> target_kw , preposition , cont_kw = match . group ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> target = self . pc . check_inv_for_keyword ( target_kw ) <EOL> if not target : <EOL> self . pc . update_output ( '<STR_LIT>' % target_kw ) <EOL> return <EOL> container = self . pc . check_inv_for_keyword ( cont_kw ) <EOL> if not container : <EOL> if self . pc . location : <EOL> container = self . pc . location . get_item_by_kw ( cont_kw ) <EOL> if not container : <EOL> self . pc . update_output ( '<STR_LIT>' % cont_kw ) <EOL> return <EOL> if not container . has_type ( '<STR_LIT>' ) : <EOL> self . pc . update_output ( '<STR_LIT>' % <EOL> container . name . capitalize ( ) ) <EOL> return <EOL> c_type = container . item_types [ '<STR_LIT>' ] <EOL> if c_type . closed : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if c_type . item_add ( target ) : <EOL> self . pc . update_output ( '<STR_LIT>' % ( target . name , <EOL> preposition , <EOL> container . name ) ) <EOL> if self . pc . location : <EOL> tr = '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> target . name , preposition , <EOL> container . name ) <EOL> self . pc . location . tell_room ( tr , [ self . pc . name ] ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % ( target . name . capitalize ( ) , <EOL> preposition , <EOL> container . name ) ) <EOL> command_list . register ( Put , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Put . help , [ '<STR_LIT>' ] ) <EOL> class Equip ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" ) <EOL> def execute ( self ) : <EOL> message = '<STR_LIT>' <EOL> if not self . args : <EOL> message = '<STR_LIT>' <EOL> for i , j in self . pc . equipped . iteritems ( ) : <EOL> message += '<STR_LIT:\n>' + i + '<STR_LIT>' <EOL> if j : <EOL> message += j . name <EOL> else : <EOL> message += '<STR_LIT>' <EOL> message += '<STR_LIT:\n>' <EOL> else : <EOL> item = self . pc . check_inv_for_keyword ( self . args ) <EOL> if not item : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> equip_type = item . item_types . get ( '<STR_LIT>' ) <EOL> if not equip_type : <EOL> message = '<STR_LIT>' <EOL> elif equip_type . equip_slot not in EQUIP_SLOTS : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> if self . pc . equipped . get ( equip_type . equip_slot ) : <EOL> self . pc . isequipped . remove ( item ) <EOL> self . pc . equipped [ equip_type . equip_slot ] = item <EOL> self . pc . isequipped += [ item ] <EOL> equip_type . on_equip ( ) <EOL> message = EQUIP_SLOTS [ equip_type . equip_slot ] . replace ( '<STR_LIT>' , item . name ) + '<STR_LIT:\n>' <EOL> self . pc . update_output ( message ) <EOL> command_list . register ( Equip , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Equip . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Unequip ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> item = self . pc . check_inv_for_keyword ( self . args ) <EOL> message = '<STR_LIT>' <EOL> if not self . args : <EOL> message = '<STR_LIT>' <EOL> elif not item : <EOL> message = '<STR_LIT>' <EOL> equip_type = item . item_types . get ( '<STR_LIT>' ) <EOL> if not equip_type : <EOL> message = '<STR_LIT>' <EOL> elif not self . pc . equipped [ equip_type . equip_slot ] : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> self . pc . equipped [ equip_type . equip_slot ] = '<STR_LIT>' <EOL> self . pc . isequipped . remove ( item ) <EOL> equip_type . on_unequip ( ) <EOL> message = '<STR_LIT>' + item . name + '<STR_LIT>' <EOL> self . pc . update_output ( message ) <EOL> command_list . register ( Unequip , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Unequip . help , [ '<STR_LIT>' ] ) <EOL> class Who ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> persons = [ per for per in self . world . player_list . values ( ) if isinstance ( per . name , basestring ) ] <EOL> message = '<STR_LIT>' . center ( <NUM_LIT:50> , '<STR_LIT:->' ) + '<STR_LIT:\n>' <EOL> for per in persons : <EOL> if per . permissions > PLAYER : <EOL> perm_list = get_permission_names ( per . permissions ) <EOL> if '<STR_LIT>' in perm_list : <EOL> perm_list . remove ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in perm_list : <EOL> perms = '<STR_LIT>' <EOL> else : <EOL> perms = '<STR_LIT:U+002CU+0020>' . join ( perm_list ) <EOL> message += '<STR_LIT>' % ( per . fancy_name ( ) , perms , per . title ) <EOL> else : <EOL> message += '<STR_LIT>' % ( per . fancy_name ( ) , per . title ) <EOL> message += '<STR_LIT:->' . center ( <NUM_LIT:50> , '<STR_LIT:->' ) <EOL> self . pc . update_output ( message ) <EOL> command_list . register ( Who , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Who . help , [ '<STR_LIT>' ] ) <EOL> class Enter ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> fail = '<STR_LIT>' % self . args <EOL> if self . pc . location : <EOL> obj = self . pc . location . get_item_by_kw ( self . args ) <EOL> if obj : <EOL> if '<STR_LIT>' in obj . item_types : <EOL> self . go_portal ( obj . item_types [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % obj . name . capitalize ( ) ) <EOL> else : <EOL> obj = self . pc . check_inv_for_keyword ( self . args ) <EOL> if obj : <EOL> if '<STR_LIT>' in obj . item_types : <EOL> Drop ( self . pc , self . args , '<STR_LIT>' ) . execute ( ) <EOL> self . go_portal ( obj . item_types [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' % obj . name . capitalize ( ) ) <EOL> else : <EOL> self . pc . update_output ( fail ) <EOL> def go_portal ( self , portal ) : <EOL> """<STR_LIT>""" <EOL> if portal . location : <EOL> if self . pc . location : <EOL> self . pc . location . tell_room ( self . personalize ( portal . leave_message , self . pc ) , <EOL> [ self . pc . name ] ) <EOL> self . pc . update_output ( self . personalize ( portal . entrance_message , self . pc ) ) <EOL> self . pc . go ( portal . location ) <EOL> self . pc . location . tell_room ( self . personalize ( portal . emerge_message , self . pc ) , <EOL> [ self . pc . name ] ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Enter , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Enter . help , [ '<STR_LIT>' ] ) <EOL> class Purge ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = BUILDER | DM | ADMIN <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> if self . pc . location : <EOL> self . pc . location . purge_room ( ) <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> elif self . args in [ '<STR_LIT:i>' , '<STR_LIT>' ] : <EOL> for i in range ( len ( self . pc . inventory ) ) : <EOL> item = self . pc . inventory [ <NUM_LIT:0> ] <EOL> self . pc . item_remove ( item ) <EOL> item . destruct ( ) <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Purge , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Purge . help , [ '<STR_LIT>' ] ) <EOL> class Areas ( BaseCommand ) : <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> """<STR_LIT>""" <EOL> the_areas = [ '<STR_LIT>' % ( area . title , area . level_range ) for area in self . world . areas . values ( ) ] <EOL> message = '<STR_LIT>' . center ( <NUM_LIT:50> , '<STR_LIT:->' ) + '<STR_LIT:\n>' <EOL> if not the_areas : <EOL> message += '<STR_LIT>' <EOL> else : <EOL> message += '<STR_LIT:\n>' . join ( the_areas ) <EOL> message += '<STR_LIT:\n>' + ( '<STR_LIT:->' * <NUM_LIT:50> ) <EOL> self . pc . update_output ( message ) <EOL> command_list . register ( Areas , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Areas . help , [ '<STR_LIT>' ] ) <EOL> class Emote ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> elist = "<STR_LIT>" + '<STR_LIT:\n>' . join ( EMOTES . keys ( ) ) <EOL> aliases = [ '<STR_LIT>' ] <EOL> aliases . extend ( EMOTES . keys ( ) ) <EOL> def execute ( self ) : <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> elif self . alias == '<STR_LIT>' : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> self . args ) , <EOL> teller = self . pc ) <EOL> else : <EOL> emote_list = EMOTES [ self . alias ] <EOL> if not self . args : <EOL> self . single_person_emote ( emote_list ) <EOL> elif self . args and not emote_list [ <NUM_LIT:1> ] : <EOL> self . single_person_emote ( emote_list ) <EOL> else : <EOL> victim = self . pc . location . get_player ( self . args . lower ( ) ) or self . pc . location . get_npc_by_kw ( self . args . lower ( ) ) or self . world . get_player ( self . args . lower ( ) ) <EOL> if not victim : <EOL> self . pc . update_output ( '<STR_LIT>' % <EOL> self . args . capitalize ( ) ) <EOL> elif victim == self . pc : <EOL> self . single_person_emote ( emote_list ) <EOL> else : <EOL> self . double_person_emote ( emote_list , victim ) <EOL> def single_person_emote ( self , emote_list ) : <EOL> """<STR_LIT>""" <EOL> actor_m = self . personalize ( emote_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , self . pc ) <EOL> room_m = self . personalize ( emote_list [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , self . pc ) <EOL> self . pc . update_output ( actor_m ) <EOL> self . pc . location . tell_room ( room_m , [ self . pc . name ] ) <EOL> def double_person_emote ( self , emote_list , victim ) : <EOL> """<STR_LIT>""" <EOL> actor = self . personalize ( emote_list [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , self . pc , victim ) <EOL> victimm = self . personalize ( emote_list [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , self . pc , victim ) <EOL> if victim . location == self . pc . location : <EOL> room_m = self . personalize ( emote_list [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] , self . pc , victim ) <EOL> self . pc . update_output ( actor ) <EOL> victim . update_output ( victimm ) <EOL> self . pc . location . tell_room ( room_m , [ self . pc . name , victim . name ] ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' + actor ) <EOL> victim . update_output ( '<STR_LIT>' + victimm ) <EOL> if victim . is_npc ( ) : <EOL> victim . notify ( '<STR_LIT>' , { '<STR_LIT>' : self . alias , '<STR_LIT>' : self . pc } ) <EOL> command_list . register ( Emote , Emote . aliases ) <EOL> command_help . register ( Emote . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Emote . elist , [ '<STR_LIT>' ] ) <EOL> class Bestow ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = GOD <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args . lower ( ) , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> perm , npc , player = match . group ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if npc : <EOL> error = '<STR_LIT>' <EOL> if not self . pc . location : <EOL> self . pc . update_output ( error ) <EOL> return <EOL> player = self . pc . location . get_npc_by_kw ( player ) <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> player = self . world . get_player ( player ) <EOL> permission = globals ( ) . get ( perm . upper ( ) ) <EOL> if not player : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not permission : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if player . permissions & permission : <EOL> self . pc . update_output ( '<STR_LIT>' % player . fancy_name ( ) ) <EOL> return <EOL> player . permissions = player . permissions | permission <EOL> if not player . is_npc ( ) : <EOL> player . save ( ) <EOL> self . world . play_log . info ( '<STR_LIT>' % ( <EOL> self . pc . fancy_name ( ) , perm . upper ( ) , player . fancy_name ( ) ) ) <EOL> self . pc . update_output ( '<STR_LIT>' % ( player . fancy_name ( ) , perm . upper ( ) ) ) <EOL> player . update_output ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , perm . upper ( ) ) ) <EOL> self . world . tell_players ( '<STR_LIT>' % <EOL> ( self . pc . fancy_name ( ) , perm . upper ( ) , player . fancy_name ( ) ) , <EOL> [ self . pc . name , player . name ] ) <EOL> command_list . register ( Bestow , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Bestow . help , [ '<STR_LIT>' ] ) <EOL> class Revoke ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = GOD <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args . lower ( ) , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> perm , player = match . group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . pc . location : <EOL> npc = self . pc . location . get_npc_by_kw ( player ) <EOL> player = self . world . get_player ( player ) or npc <EOL> permission = globals ( ) . get ( perm . upper ( ) ) <EOL> if not player : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not permission : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not ( player . permissions & permission ) : <EOL> self . pc . update_output ( '<STR_LIT>' % player . fancy_name ( ) ) <EOL> return <EOL> player . permissions = player . permissions ^ permission <EOL> self . world . play_log . info ( '<STR_LIT>' % ( <EOL> self . pc . fancy_name ( ) , player . fancy_name ( ) , perm . upper ( ) ) ) <EOL> self . pc . update_output ( '<STR_LIT>' % ( player . fancy_name ( ) , perm ) ) <EOL> player . update_output ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , perm ) ) <EOL> if not player . is_npc ( ) : <EOL> player . save ( ) <EOL> if player . get_mode ( ) == '<STR_LIT>' : <EOL> player . set_mode ( '<STR_LIT>' ) <EOL> player . update_output ( '<STR_LIT>' ) <EOL> command_list . register ( Revoke , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Revoke . help , [ '<STR_LIT>' ] ) <EOL> class Reset ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = DM | BUILDER | ADMIN <EOL> help = ( "<STR_LIT>" <EOL> """<STR_LIT>""" ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> if self . pc . location : <EOL> self . pc . location . reset ( ) <EOL> self . pc . update_output ( '<STR_LIT>' % self . pc . location . id ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> room_id , room_area , area = match . group ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if area : <EOL> reset_area = self . world . get_area ( area ) <EOL> if reset_area : <EOL> reset_area . reset ( ) <EOL> self . pc . update_output ( '<STR_LIT>' % reset_area . name ) <EOL> return <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if room_area : <EOL> area = self . world . get_area ( room_area ) <EOL> if not area : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> else : <EOL> if self . pc . location : <EOL> area = self . pc . location . area <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> room = area . get_room ( room_id ) <EOL> if not room : <EOL> self . pc . update_output ( '<STR_LIT>' % ( room_id , <EOL> area . name ) ) <EOL> room . reset ( ) <EOL> self . pc . update_output ( '<STR_LIT>' % ( room . id , area . name ) ) <EOL> command_list . register ( Reset , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Reset . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Help ( BaseCommand ) : <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( self . help ) <EOL> return <EOL> help = command_help [ self . args ] <EOL> if help : <EOL> help = help . replace ( '<STR_LIT>' , BOLD ) <EOL> help = help . replace ( '<STR_LIT>' , BLINK ) <EOL> help = help . replace ( '<STR_LIT>' , help_title ) . replace ( '<STR_LIT>' , <EOL> CLEAR + '<STR_LIT:\n>' ) <EOL> help = re . sub ( r'<STR_LIT>' , CLEAR , help ) <EOL> self . pc . update_output ( help ) <EOL> else : <EOL> self . pc . update_output ( "<STR_LIT>" ) <EOL> command_list . register ( Help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Help . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Clear ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> self . pc . update_output ( '<STR_LIT>' + '<STR_LIT>' ) <EOL> command_list . register ( Clear , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Clear . help , [ '<STR_LIT>' ] ) <EOL> class Set ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> else : <EOL> match = re . match ( r'<STR_LIT>' , self . args , re . I ) <EOL> if not match : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> func , _ , arg = match . groups ( ) <EOL> message = '<STR_LIT>' <EOL> if hasattr ( self . pc , '<STR_LIT>' + func ) : <EOL> message = ( getattr ( self . pc , '<STR_LIT>' + func ) ( arg ) ) <EOL> self . pc . update_output ( message ) <EOL> command_list . register ( Set , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Set . help , [ '<STR_LIT>' ] ) <EOL> class ToggleOpen ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args . lower ( ) , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> direction , kw = match . group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if direction : <EOL> message = self . toggle_door ( direction , self . alias ) <EOL> elif kw : <EOL> message = self . toggle_container ( kw , self . alias ) <EOL> self . pc . update_output ( message ) <EOL> def toggle_door ( self , direction , toggle ) : <EOL> if not self . pc . location : <EOL> return '<STR_LIT>' <EOL> exit = self . pc . location . exits . get ( direction ) <EOL> if not exit : <EOL> return '<STR_LIT>' <EOL> if toggle == '<STR_LIT>' or toggle == '<STR_LIT>' : <EOL> return exit . open_me ( self . pc ) <EOL> else : <EOL> return exit . close_me ( self . pc ) <EOL> def toggle_container ( self , kw , toggle ) : <EOL> obj = self . pc . check_inv_for_keyword ( kw ) <EOL> if not obj : <EOL> obj = self . pc . location . get_item_by_kw ( kw ) <EOL> if not obj : <EOL> return '<STR_LIT>' <EOL> if not obj . has_type ( '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> container = obj . item_types . get ( '<STR_LIT>' ) <EOL> if toggle == '<STR_LIT>' : <EOL> if not container . openable : <EOL> return '<STR_LIT>' % obj . name . capitalize ( ) <EOL> if container . closed : <EOL> return '<STR_LIT>' <EOL> container . closed = True <EOL> return '<STR_LIT>' % obj . name <EOL> else : <EOL> if not container . openable : <EOL> return '<STR_LIT>' % obj . name . capitalize ( ) <EOL> if not container . closed : <EOL> return '<STR_LIT>' <EOL> container . closed = False <EOL> return '<STR_LIT>' % obj . name <EOL> command_list . register ( ToggleOpen , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( ToggleOpen . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Lock ( BaseCommand ) : <EOL> help = ( <EOL> """<STR_LIT>""" ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> return "<STR_LIT>" <EOL> dir_map = { '<STR_LIT:n>' : '<STR_LIT>' , '<STR_LIT:s>' : '<STR_LIT>' , '<STR_LIT:e>' : '<STR_LIT>' , '<STR_LIT:w>' : '<STR_LIT>' , '<STR_LIT:u>' : '<STR_LIT>' , '<STR_LIT:d>' : '<STR_LIT>' } <EOL> direction = dir_map . get ( self . args [ <NUM_LIT:0> ] . lower ( ) ) <EOL> if not direction : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if self . pc . location . exits [ direction ] : <EOL> message = self . pc . location . exits [ direction ] . lock_me ( self . pc ) <EOL> self . pc . update_output ( message ) <EOL> return <EOL> self . pc . update_output ( "<STR_LIT>" ) <EOL> return <EOL> command_list . register ( Lock , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Lock . help , [ '<STR_LIT>' ] ) <EOL> class Version ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" % VERSION <EOL> ) <EOL> def execute ( self ) : <EOL> self . pc . update_output ( self . help ) <EOL> command_list . register ( Version , [ '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Version . help , [ '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Sit ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if self . pc . position [ <NUM_LIT:0> ] . find ( self . alias ) != - <NUM_LIT:1> : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not self . args : <EOL> if self . pc . position [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> if self . pc . location : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % self . pc . fancy_name ( ) , [ self . pc . name ] , self . pc ) <EOL> self . pc . change_position ( '<STR_LIT>' , self . pc . position [ <NUM_LIT:1> ] ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> if self . pc . location : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % self . pc . fancy_name ( ) , [ self . pc . name ] , self . pc ) <EOL> self . pc . change_position ( '<STR_LIT>' ) <EOL> else : <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> furn_kw = re . match ( exp , self . args . lower ( ) . strip ( ) ) . group ( '<STR_LIT>' ) <EOL> furn = self . pc . location . get_item_by_kw ( furn_kw ) <EOL> if not furn : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> f_obj = furn . item_types . get ( '<STR_LIT>' ) <EOL> if not f_obj : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not f_obj . player_add ( self . pc ) : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> else : <EOL> if self . pc . position [ <NUM_LIT:1> ] : <EOL> self . pc . position [ <NUM_LIT:1> ] . item_types [ '<STR_LIT>' ] . player_remove ( self . pc ) <EOL> f_obj . player_add ( self . pc ) <EOL> self . pc . position = ( '<STR_LIT>' , furn ) <EOL> self . pc . update_output ( '<STR_LIT>' % furn . name ) <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , furn . name ) , <EOL> [ self . pc . name ] , self . pc ) <EOL> command_list . register ( Sit , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Sit . help , [ '<STR_LIT>' ] ) <EOL> class Stand ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if self . pc . position [ <NUM_LIT:0> ] . find ( self . alias ) != - <NUM_LIT:1> : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if self . pc . position [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> if self . pc . location : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % self . pc . fancy_name ( ) , [ self . pc . name ] , self . pc ) <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> if self . pc . location : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % self . pc . fancy_name ( ) , [ self . pc . name ] , self . pc ) <EOL> self . pc . change_position ( '<STR_LIT>' ) <EOL> command_list . register ( Stand , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Stand . help , [ '<STR_LIT>' ] ) <EOL> class Sleep ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if self . pc . position [ <NUM_LIT:0> ] . find ( self . alias ) != - <NUM_LIT:1> : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> if self . pc . location : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % self . pc . fancy_name ( ) , [ self . pc . name ] , self . pc ) <EOL> self . pc . change_position ( '<STR_LIT>' , self . pc . position [ <NUM_LIT:1> ] ) <EOL> else : <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> furn_kw = re . match ( exp , self . args . lower ( ) . strip ( ) ) . group ( '<STR_LIT>' ) <EOL> furn = self . pc . location . get_item_by_kw ( furn_kw ) <EOL> if not furn : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> f_obj = furn . item_types . get ( '<STR_LIT>' ) <EOL> if not f_obj : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not f_obj . player_add ( self . pc ) : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> else : <EOL> self . pc . change_position ( '<STR_LIT>' , furn ) <EOL> self . pc . update_output ( '<STR_LIT>' % furn . name ) <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , furn . name ) , <EOL> [ self . pc . name ] , self . pc ) <EOL> command_list . register ( Sleep , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Sleep . help , [ '<STR_LIT>' ] ) <EOL> class Wake ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> if self . pc . position [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> if self . pc . location : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % self . pc . fancy_name ( ) , [ self . pc . name ] , self . pc ) <EOL> self . pc . change_position ( '<STR_LIT>' ) <EOL> else : <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> sleeper = self . pc . location . get_player ( self . args . lower ( ) . strip ( ) ) <EOL> if not sleeper : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if sleeper . position [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> self . pc . update_output ( '<STR_LIT>' % sleeper . fancy_name ( ) ) <EOL> return <EOL> sleeper . change_position ( '<STR_LIT>' ) <EOL> self . pc . update_output ( '<STR_LIT>' % sleeper . fancy_name ( ) ) <EOL> sleeper . update_output ( '<STR_LIT>' % self . pc . fancy_name ( ) ) <EOL> troom = '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> sleeper . fancy_name ( ) ) <EOL> self . pc . location . tell_room ( troom , [ self . pc . name , sleeper . name ] , <EOL> self . pc ) <EOL> command_list . register ( Wake , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Wake . help , [ '<STR_LIT>' ] ) <EOL> class Award ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> required_permissions = required_permissions = DM | ADMIN <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> item_kw , player_kw , actor , room = match . group ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> player = self . pc . location . get_player ( player_kw . lower ( ) ) <EOL> if not player : <EOL> self . pc . update_output ( '<STR_LIT>' % item_kw ) <EOL> return <EOL> item = self . pc . check_inv_for_keyword ( item_kw ) <EOL> if not item : <EOL> self . pc . update_output ( '<STR_LIT>' % item_kw ) <EOL> return <EOL> self . pc . item_remove ( item ) <EOL> player . item_add ( item ) <EOL> self . pc . update_output ( '<STR_LIT>' % ( player . fancy_name ( ) , <EOL> item . name ) ) <EOL> if actor : <EOL> message = self . personalize ( actor . strip ( '<STR_LIT>' ) , self . pc ) <EOL> player . update_output ( message ) <EOL> if room : <EOL> message = self . personalize ( room . strip ( '<STR_LIT>' ) , self . pc , player ) <EOL> self . pc . location . tell_room ( message , [ player . name ] , self . pc ) <EOL> command_list . register ( Award , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Award . help , [ '<STR_LIT>' ] ) <EOL> class Consume ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( "<STR_LIT>" % self . alias . capitalize ( ) ) <EOL> return <EOL> food = self . pc . check_inv_for_keyword ( self . args . lower ( ) . strip ( ) ) <EOL> if not food : <EOL> self . pc . update_output ( '<STR_LIT>' % self . args ) <EOL> return <EOL> food_obj = food . item_types . get ( '<STR_LIT>' ) <EOL> if not food_obj : <EOL> if self . pc . permissions & GOD : <EOL> self . pc . item_remove ( food ) <EOL> food . destruct ( ) <EOL> self . pc . update_output ( '<STR_LIT>' % food . name ) <EOL> if self . pc . location : <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> food . name ) , <EOL> [ self . pc . name ] , self . pc ) <EOL> return <EOL> else : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if '<STR_LIT>' in self . pc . effects : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> self . world . log . debug ( food_obj ) <EOL> self . pc . item_remove ( food ) <EOL> food . destruct ( ) <EOL> if food_obj . replace_obj : <EOL> self . pc . item_add ( food_obj . replace_obj . load ( ) ) <EOL> u_tell = self . personalize ( food_obj . get_actor_message ( ) , self . pc ) <EOL> self . pc . update_output ( u_tell ) <EOL> if self . pc . location : <EOL> r_tell = self . personalize ( food_obj . get_room_message ( ) , self . pc ) <EOL> self . pc . location . tell_room ( r_tell , [ self . pc . name ] , self . pc ) <EOL> self . world . log . debug ( '<STR_LIT>' ) <EOL> self . pc . effects_add ( food_obj . load_effects ( ) ) <EOL> command_list . register ( Consume , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Consume . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Attack ( BaseCommand ) : <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> target = self . pc . location . get_player ( self . args ) <EOL> if not target : <EOL> target = self . pc . location . get_npc_by_kw ( self . args ) <EOL> if not target : <EOL> self . pc . update_output ( "<STR_LIT>" ) <EOL> return <EOL> self . pc . battle_target = target <EOL> if not self . pc . battle : <EOL> self . world . log . debug ( "<STR_LIT>" % ( self . pc . fancy_name ( ) , target . fancy_name ( ) ) ) <EOL> self . pc . enter_battle ( ) <EOL> b = Battle ( ) <EOL> b . teamA . append ( self . pc ) <EOL> self . pc . battle = b <EOL> b . teamB . append ( target ) <EOL> target . battle = b <EOL> target . enter_battle ( ) <EOL> self . world . battle_add ( b ) <EOL> target . battle_target = self . pc <EOL> self . pc . free_attack ( ) <EOL> self . pc . update_output ( "<STR_LIT>" ) <EOL> class Run ( BaseCommand ) : <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if self . pc . battle : <EOL> direction = self . args . lower ( ) [ <NUM_LIT:0> ] if self . args else None <EOL> if direction == '<STR_LIT:e>' : <EOL> room = self . pc . location . exits . get ( '<STR_LIT>' ) <EOL> elif direction == '<STR_LIT:w>' : <EOL> room = self . pc . location . exits . get ( '<STR_LIT>' ) <EOL> elif direction == '<STR_LIT:n>' : <EOL> room = self . pc . location . exits . get ( '<STR_LIT>' ) <EOL> elif direction == '<STR_LIT:s>' : <EOL> room = self . pc . location . exits . get ( '<STR_LIT>' ) <EOL> elif direction == '<STR_LIT:u>' : <EOL> room = self . pc . location . exits . get ( '<STR_LIT>' ) <EOL> elif direction == '<STR_LIT:d>' : <EOL> room = self . pc . location . exits . get ( '<STR_LIT>' ) <EOL> else : <EOL> room = None <EOL> if not room : <EOL> room = [ _ for _ in self . pc . location . exits . values ( ) if _ is not None ] [ <NUM_LIT:0> ] <EOL> if not room : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> action = Action_list [ '<STR_LIT>' ] ( self . pc , ( room . to_room . area . name , room . to_room . id ) , self . pc . battle ) <EOL> self . pc . next_action = action <EOL> class Me ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> width = <NUM_LIT> <EOL> empty_line = '<STR_LIT:|>' + ( '<STR_LIT:U+0020>' * ( width - <NUM_LIT:2> ) ) + '<STR_LIT>' <EOL> effects = '<STR_LIT:U+002CU+0020>' . join ( [ str ( e ) for e in self . pc . effects . values ( ) ] ) <EOL> if not effects : <EOL> effects = '<STR_LIT>' <EOL> me = '<STR_LIT:|>' + ( '<STR_LIT>' % self . pc . fancy_name ( ) ) . center ( width - <NUM_LIT:2> , '<STR_LIT:->' ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + self . pc . title ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' % ( self . pc . currency , CURRENCY ) ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + self . pc . position [ <NUM_LIT:0> ] ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + effects ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> if self . pc . permissions > PLAYER : <EOL> me += '<STR_LIT:|>' + ( '<STR_LIT>' ) . center ( width - <NUM_LIT:2> , '<STR_LIT:->' ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( get_permission_names ( self . pc . permissions ) ) ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + self . pc . goto_appear ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + self . pc . goto_disappear ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += empty_line <EOL> me += '<STR_LIT:|>' + ( '<STR_LIT>' ) . center ( width - <NUM_LIT:2> , '<STR_LIT:->' ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + str ( self . pc . email ) ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += '<STR_LIT:|>' + ( '<STR_LIT>' ) . center ( width - <NUM_LIT:2> , '<STR_LIT:->' ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + str ( self . pc . hit . calculate ( ) ) ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += ( '<STR_LIT>' + str ( self . pc . evade . calculate ( ) ) ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> if self . pc . absorb : <EOL> me += '<STR_LIT>' . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> for key , val in self . pc . absorb . calculate ( ) . items ( ) : <EOL> me += ( '<STR_LIT>' % ( key , val ) ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> else : <EOL> me += '<STR_LIT>' . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> if self . pc . damage : <EOL> me += '<STR_LIT>' . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> for t , mn , mx in self . pc . damage . display ( ) : <EOL> me += ( '<STR_LIT>' % ( t , mn , mx ) ) . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> else : <EOL> me += '<STR_LIT>' . ljust ( width - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> me += '<STR_LIT:|>' + ( '<STR_LIT:->' * ( width - <NUM_LIT:2> ) ) + '<STR_LIT:|>' <EOL> self . pc . update_output ( me ) <EOL> command_list . register ( Me , [ '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Me . help , [ '<STR_LIT>' , '<STR_LIT:status>' ] ) <EOL> class Tell ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> syntax_error = '<STR_LIT>' <EOL> if not self . args : <EOL> self . pc . update_output ( syntax_error ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( syntax_error ) <EOL> return <EOL> target_name , message = match . group ( '<STR_LIT:target>' , '<STR_LIT:message>' ) <EOL> if self . pc . location : <EOL> r = self . pc . location <EOL> target = r . get_player ( target_name ) or r . get_npc_by_kw ( target_name ) <EOL> if target : <EOL> self . tell_msg ( target , message ) <EOL> return <EOL> pc = self . world . get_player ( target_name ) <EOL> if not pc : <EOL> self . pc . update_output ( '<STR_LIT>' % target_name ) <EOL> else : <EOL> self . tell_msg ( pc , message ) <EOL> def tell_msg ( self , target_char , message ) : <EOL> """<STR_LIT>""" <EOL> if target_char . is_npc ( ) : <EOL> pass <EOL> self . pc . update_output ( '<STR_LIT>' % ( target_char . fancy_name ( ) , message ) ) <EOL> target_char . update_output ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , message ) ) <EOL> command_list . register ( Tell , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Tell . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class ChangePassword ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if self . pc . mode : <EOL> self . pc . last_mode = self . pc . mode <EOL> self . pc . set_mode ( '<STR_LIT>' ) <EOL> command_list . register ( ChangePassword , [ '<STR_LIT:password>' , '<STR_LIT>' ] ) <EOL> command_help . register ( ChangePassword . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' ] ) <EOL> class Commands ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> l = '<STR_LIT>' + '<STR_LIT>' + ( '<STR_LIT:->' * <NUM_LIT:50> ) + '<STR_LIT>' <EOL> coms = [ ] <EOL> for alias , cmd in command_list . commands . items ( ) : <EOL> if cmd . required_permissions & PLAYER : <EOL> coms . append ( alias ) <EOL> l += '<STR_LIT:\n>' . join ( coms ) <EOL> self . pc . update_output ( l ) <EOL> command_list . register ( Commands , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Commands . help , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Buy ( BaseCommand ) : <EOL> help = ( <EOL> """<STR_LIT>""" % ( GAME_NAME , CURRENCY ) <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if ( not self . args ) or ( self . args == '<STR_LIT:list>' ) : <EOL> try : <EOL> merchant = self . verify_merchant ( None ) <EOL> except SaleFail as e : <EOL> self . pc . update_output ( str ( e ) ) <EOL> else : <EOL> self . pc . update_output ( merchant . ai_packs [ '<STR_LIT>' ] . player_sale_list ( ) ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> item_name , merchant_name = match . group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> merchant = self . verify_merchant ( merchant_name ) <EOL> item , price = self . verify_item ( item_name , merchant ) <EOL> except SaleFail as e : <EOL> self . pc . update_output ( str ( e ) ) <EOL> else : <EOL> self . pc . currency -= price <EOL> self . pc . save ( ) <EOL> self . pc . item_add ( item ) <EOL> self . pc . update_output ( '<STR_LIT>' % ( item . name , <EOL> merchant . name , str ( price ) , CURRENCY ) ) <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> item . name , merchant . name ) , <EOL> [ self . pc . name ] ) <EOL> def verify_item ( self , item_name , merchant ) : <EOL> item_n_price = merchant . ai_packs [ '<STR_LIT>' ] . get_item ( item_name ) <EOL> if not item_n_price : <EOL> raise SaleFail ( '<STR_LIT>' % ( merchant . name , item_name ) ) <EOL> if self . pc . currency < item_n_price [ <NUM_LIT:1> ] : <EOL> self . world . log . debug ( '<STR_LIT>' % ( str ( self . pc . currency ) , <EOL> str ( type ( self . pc . currency ) ) , <EOL> str ( item_n_price [ <NUM_LIT:1> ] ) , <EOL> str ( type ( item_n_price [ <NUM_LIT:1> ] ) ) ) ) <EOL> raise SaleFail ( '<STR_LIT>' % ( item_n_price [ <NUM_LIT:0> ] . name . capitalize ( ) , <EOL> str ( item_n_price [ <NUM_LIT:1> ] ) , CURRENCY , CURRENCY ) ) <EOL> item = item_n_price [ <NUM_LIT:0> ] . load ( ) <EOL> return [ item , item_n_price [ <NUM_LIT:1> ] ] <EOL> def verify_merchant ( self , merchant_name ) : <EOL> """<STR_LIT>""" <EOL> if merchant_name : <EOL> merchant = self . pc . location . get_npc_by_kw ( merchant_name ) <EOL> if not merchant : <EOL> raise SaleFail ( '<STR_LIT>' % merchant_name ) <EOL> elif not merchant . has_ai ( '<STR_LIT>' ) : <EOL> raise SaleFail ( '<STR_LIT>' % ( merchant . name ) ) <EOL> else : <EOL> return merchant <EOL> else : <EOL> merchant = None <EOL> for npc in self . pc . location . npcs : <EOL> if npc . has_ai ( '<STR_LIT>' ) : <EOL> merchant = npc <EOL> break <EOL> if not merchant : <EOL> raise SaleFail ( '<STR_LIT>' ) <EOL> else : <EOL> return merchant <EOL> command_list . register ( Buy , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Buy . help , [ '<STR_LIT>' ] ) <EOL> class Sell ( BaseCommand ) : <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , self . args , re . I ) <EOL> if not match : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> item_name , merchant_name = match . group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> item = self . verify_item ( item_name ) <EOL> merchant = self . verify_merchant ( merchant_name ) <EOL> except SaleFail as e : <EOL> self . pc . update_output ( str ( e ) ) <EOL> return <EOL> else : <EOL> if not merchant . ai_packs [ '<STR_LIT>' ] . will_buy ( item ) : <EOL> merchant . perform ( '<STR_LIT>' % ( self . pc . name , <EOL> merchant . ai_packs [ '<STR_LIT>' ] . tell_buy_types ( ) ) ) <EOL> return <EOL> sale_price = int ( ( item . base_value * merchant . ai_packs [ '<STR_LIT>' ] . markup ) + <NUM_LIT:0.5> ) or <NUM_LIT:1> <EOL> if self . alias in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> merchant . perform ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> str ( sale_price ) , CURRENCY , item . name ) ) <EOL> return <EOL> self . pc . item_remove ( item ) <EOL> item . destruct ( ) <EOL> self . pc . currency += sale_price <EOL> self . pc . save ( ) <EOL> self . pc . update_output ( '<STR_LIT>' % ( item . name , <EOL> str ( sale_price ) , <EOL> CURRENCY , <EOL> merchant . name ) ) <EOL> self . pc . location . tell_room ( '<STR_LIT>' % ( self . pc . fancy_name ( ) , <EOL> item . name , <EOL> merchant . name ) , <EOL> [ self . pc . name ] ) <EOL> def verify_item ( self , item_name ) : <EOL> item = self . pc . check_inv_for_keyword ( item_name ) <EOL> if not item : <EOL> raise SaleFail ( '<STR_LIT>' % item_name ) <EOL> return item <EOL> def verify_merchant ( self , merchant_name ) : <EOL> """<STR_LIT>""" <EOL> if merchant_name : <EOL> merchant = self . pc . location . get_npc_by_kw ( merchant_name ) <EOL> if not merchant : <EOL> raise SaleFail ( '<STR_LIT>' % merchant_name ) <EOL> elif not merchant . has_ai ( '<STR_LIT>' ) : <EOL> raise SaleFail ( '<STR_LIT>' % ( merchant . name ) ) <EOL> else : <EOL> return merchant <EOL> else : <EOL> merchant = None <EOL> for npc in self . pc . location . npcs : <EOL> if npc . has_ai ( '<STR_LIT>' ) : <EOL> merchant = npc <EOL> break <EOL> if not merchant : <EOL> raise SaleFail ( '<STR_LIT>' ) <EOL> else : <EOL> return merchant <EOL> command_list . register ( Sell , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( Sell . help , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Log ( BaseCommand ) : <EOL> required_permissions = BUILDER | DM | ADMIN <EOL> help = ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> def execute ( self ) : <EOL> if not self . args : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> if not self . pc . location : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> npc = self . pc . location . get_npc_by_kw ( self . args . lower ( ) . strip ( ) ) <EOL> if not npc : <EOL> self . pc . update_output ( '<STR_LIT>' ) <EOL> return <EOL> string = ( '<STR_LIT>' % npc . name ) . center ( <NUM_LIT:50> , '<STR_LIT:->' ) + '<STR_LIT:\n>' <EOL> perms = '<STR_LIT:U+002CU+0020>' . join ( get_permission_names ( npc . permissions ) ) <EOL> if npc . remember : <EOL> string += '<STR_LIT>' <EOL> string += '<STR_LIT:U+002CU+0020>' . join ( npc . remember ) + '<STR_LIT:\n>' <EOL> else : <EOL> string += '<STR_LIT>' <EOL> string += '<STR_LIT>' + perms + '<STR_LIT:\n>' <EOL> string += '<STR_LIT>' <EOL> if npc . actionq : <EOL> string += '<STR_LIT:\n>' . join ( [ a . strip ( '<STR_LIT:\n>' ) . strip ( '<STR_LIT:\r>' ) for a in npc . actionq ] ) <EOL> else : <EOL> string += '<STR_LIT>' <EOL> string += '<STR_LIT:\n>' + ( '<STR_LIT:->' * <NUM_LIT:50> ) <EOL> self . pc . update_output ( string ) <EOL> command_list . register ( Log , [ '<STR_LIT>' ] ) <EOL> command_help . register ( Log . help , [ '<STR_LIT>' ] ) <EOL> class SaleFail ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> command_help . register ( ( "<STR_LIT>" <EOL> """<STR_LIT>""" <EOL> ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( ( "<STR_LIT>" <EOL> """<STR_LIT>""" <EOL> ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> command_help . register ( ( "<STR_LIT>" <EOL> """<STR_LIT>""" <EOL> ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) </s>
