<s> from shinymud . models import Model , Column , model_list <EOL> from shinymud . models . shiny_types import * <EOL> from shinymud . data . config import * <EOL> import re <EOL> class RoomExit ( Model ) : <EOL> db_table_name = '<STR_LIT>' <EOL> db_columns = Model . db_columns + [ <EOL> Column ( '<STR_LIT>' , null = False ) , <EOL> Column ( '<STR_LIT>' , null = False ) , <EOL> Column ( '<STR_LIT>' , null = False , write = write_model ) , <EOL> Column ( '<STR_LIT>' , null = False ) , <EOL> Column ( '<STR_LIT>' ) , <EOL> Column ( '<STR_LIT>' , read = to_bool ) , <EOL> Column ( '<STR_LIT>' , read = to_bool ) , <EOL> Column ( '<STR_LIT>' , read = to_bool ) , <EOL> Column ( '<STR_LIT>' , read = to_bool ) , <EOL> Column ( '<STR_LIT>' ) , <EOL> Column ( '<STR_LIT>' ) <EOL> ] <EOL> db_extras = Model . db_extras + [ '<STR_LIT>' ] <EOL> def __init__ ( self , args = { } ) : <EOL> Model . __init__ ( self , args ) <EOL> self . _closed = self . closed <EOL> self . _locked = self . locked <EOL> if '<STR_LIT>' in args : <EOL> self . to_room = args . get ( '<STR_LIT>' ) <EOL> def save ( self , save_dict = None ) : <EOL> if not self . to_room : <EOL> return <EOL> Model . save ( self ) <EOL> def unlink ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . linked_exit : <EOL> self . linked_exit = None <EOL> self . to_room . linked_exit = None <EOL> def _resolve_to_room ( self ) : <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> return self . _to_room <EOL> try : <EOL> self . to_room = self . world . get_area ( str ( self . to_area ) ) . get_room ( str ( self . to_room_id ) ) <EOL> return self . _to_room <EOL> except : <EOL> return None <EOL> def _set_to_room ( self , to_room ) : <EOL> self . _to_room = to_room <EOL> if to_room : <EOL> self . to_area = to_room . area . name <EOL> self . to_room_id = to_room . id <EOL> to_room = property ( _resolve_to_room , _set_to_room ) <EOL> def _resolve_key ( self ) : <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> return self . _key <EOL> if self . key_area and self . key_id : <EOL> try : <EOL> self . key = self . world . get_area ( self . key_area ) . get_item ( self . key_id ) <EOL> return self . _key <EOL> except : <EOL> pass <EOL> return None <EOL> def _set_key ( self , key ) : <EOL> self . _key = key <EOL> if key : <EOL> self . key_area = key . area . name <EOL> self . key_id = key . id <EOL> else : <EOL> self . key_area = None <EOL> self . key_id = None <EOL> key = property ( _resolve_key , _set_key ) <EOL> def _str_key ( self ) : <EOL> if self . key : <EOL> return '<STR_LIT>' % ( self . key . name , self . key . id , self . key . area . name ) <EOL> else : <EOL> return '<STR_LIT:None>' <EOL> def __str__ ( self ) : <EOL> linked = "<STR_LIT:false>" <EOL> if self . linked_exit : <EOL> linked = "<STR_LIT:true>" <EOL> list_exit = "<STR_LIT>" % ( self . to_room . area . name , self . to_room . id , linked , <EOL> str ( self . openable ) , str ( self . closed ) , <EOL> str ( self . hidden ) , str ( self . locked ) , <EOL> self . _str_key ( ) ) <EOL> return list_exit <EOL> def reset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _closed = self . closed <EOL> self . _locked = self . locked <EOL> def close_me ( self , player ) : <EOL> if self . openable == False : <EOL> return '<STR_LIT>' <EOL> if self . _closed : <EOL> return '<STR_LIT>' <EOL> self . _closed = True <EOL> self . room . tell_room ( '<STR_LIT>' % ( player . fancy_name ( ) , self . direction ) , [ player . name ] ) <EOL> if self . linked_exit : <EOL> self . to_room . exits [ self . linked_exit ] . _closed = True <EOL> self . to_room . tell_room ( '<STR_LIT>' % self . linked_exit ) <EOL> return '<STR_LIT>' % self . direction <EOL> def open_me ( self , player ) : <EOL> if self . openable == False : <EOL> return '<STR_LIT>' <EOL> if not self . _closed : <EOL> return '<STR_LIT>' <EOL> r_msg = p_msg = '<STR_LIT>' <EOL> if self . key and self . _locked : <EOL> if player . permissions & GOD : <EOL> p_msg = '<STR_LIT>' % ( self . direction ) <EOL> r_msg = '<STR_LIT>' % ( self . direction , player . fancy_name ( ) ) <EOL> elif player . has_item ( self . key ) : <EOL> self . _locked = False <EOL> p_msg = '<STR_LIT>' % self . key . name <EOL> r_msg = '<STR_LIT>' % ( player . fancy_name ( ) , self . key . name ) <EOL> else : <EOL> return "<STR_LIT>" <EOL> self . _closed = False <EOL> r_msg += '<STR_LIT>' % ( player . fancy_name ( ) , self . direction ) <EOL> self . room . tell_room ( r_msg , [ player . name ] ) <EOL> if self . linked_exit : <EOL> self . to_room . exits [ self . linked_exit ] . _closed = False <EOL> self . to_room . tell_room ( '<STR_LIT>' % self . linked_exit ) <EOL> p_msg += '<STR_LIT>' % self . direction <EOL> return p_msg <EOL> def lock_me ( self , player ) : <EOL> if self . key and ( player . permissions & GOD or player . has_item ( self . key ) ) : <EOL> self . _locked = True <EOL> message = self . close_me ( player ) <EOL> self . room . tell_room ( '<STR_LIT>' % ( player . fancy_name ( ) , self . direction ) , [ player . name ] ) <EOL> if self . linked_exit : <EOL> self . to_room . exits [ self . linked_exit ] . _locked = True <EOL> self . to_room . tell_room ( '<STR_LIT>' % self . linked_exit ) <EOL> return message + "<STR_LIT>" <EOL> return "<STR_LIT>" <EOL> def build_set_closed ( self , args ) : <EOL> try : <EOL> boolean = to_bool ( args [ <NUM_LIT:0> ] ) <EOL> except Exception , e : <EOL> return str ( e ) <EOL> else : <EOL> self . closed = boolean <EOL> self . _closed = boolean <EOL> if self . linked_exit : <EOL> self . to_room . exits [ self . linked_exit ] . closed = boolean <EOL> self . to_room . exits [ self . linked_exit ] . _closed = boolean <EOL> self . to_room . exits [ self . linked_exit ] . save ( ) <EOL> self . save ( ) <EOL> return '<STR_LIT>' % str ( boolean ) <EOL> def build_set_openable ( self , args ) : <EOL> boolean = to_bool ( args [ <NUM_LIT:0> ] ) <EOL> if not boolean : <EOL> return '<STR_LIT>' <EOL> else : <EOL> self . openable = boolean <EOL> self . save ( ) <EOL> if self . linked_exit : <EOL> self . to_room . exits [ self . linked_exit ] . openable = boolean <EOL> self . to_room . exits [ self . linked_exit ] . save ( ) <EOL> return '<STR_LIT>' % str ( boolean ) <EOL> def build_set_hidden ( self , args ) : <EOL> try : <EOL> boolean = to_bool ( args [ <NUM_LIT:0> ] ) <EOL> except Exception , e : <EOL> return str ( e ) <EOL> else : <EOL> self . hidden = boolean <EOL> self . save ( ) <EOL> return '<STR_LIT>' % str ( boolean ) <EOL> def build_set_locked ( self , args ) : <EOL> try : <EOL> boolean = to_bool ( args [ <NUM_LIT:0> ] ) <EOL> except Exception , e : <EOL> return str ( e ) <EOL> else : <EOL> self . locked = boolean <EOL> self . _locked = boolean <EOL> self . save ( ) <EOL> if self . linked_exit : <EOL> self . to_room . exits [ self . linked_exit ] . locked = boolean <EOL> self . to_room . exits [ self . linked_exit ] . _locked = boolean <EOL> self . to_room . exits [ self . linked_exit ] . save ( ) <EOL> return '<STR_LIT>' % str ( boolean ) <EOL> def build_set_to ( self , args ) : <EOL> """<STR_LIT>""" <EOL> if not args : <EOL> return '<STR_LIT>' <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , '<STR_LIT>' . join ( args ) , re . I ) <EOL> if not match : <EOL> return '<STR_LIT>' <EOL> room_id , area_name = match . group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if area_name : <EOL> area = World . get_world ( ) . get_area ( area_name ) <EOL> if not area : <EOL> return '<STR_LIT>' <EOL> else : <EOL> area = self . room . area <EOL> room = area . get_room ( room_id ) <EOL> if not room : <EOL> return '<STR_LIT>' <EOL> if not room . linked_exit : <EOL> self . to_room = room <EOL> self . save ( ) <EOL> return '<STR_LIT>' % ( self . direction , <EOL> self . to_room . id , <EOL> self . to_room . area . name ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> def build_set_key ( self , args ) : <EOL> if not args : <EOL> return '<STR_LIT>' <EOL> exp = r'<STR_LIT>' <EOL> match = re . match ( exp , '<STR_LIT>' . join ( args ) , re . I ) <EOL> if not match : <EOL> return '<STR_LIT>' <EOL> key_id , area_name = match . group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if area_name : <EOL> area = self . world . get_area ( area_name ) <EOL> if not area : <EOL> return '<STR_LIT>' <EOL> else : <EOL> area = self . room . area <EOL> key = area . get_item ( key_id ) <EOL> if not key : <EOL> return '<STR_LIT>' <EOL> self . key = key <EOL> self . save ( ) <EOL> if self . linked_exit : <EOL> self . to_room . exits [ self . linked_exit ] . key = self . key <EOL> self . to_room . exits [ self . linked_exit ] . save ( ) <EOL> return '<STR_LIT>' % ( key . name . capitalize ( ) , <EOL> self . room . id , <EOL> self . direction ) <EOL> model_list . register ( RoomExit ) </s>
