<s> class CommandRegister ( object ) : <EOL> def __init__ ( self ) : <EOL> self . commands = { } <EOL> def __getitem__ ( self , key ) : <EOL> return self . commands . get ( key ) <EOL> def register ( self , func , aliases ) : <EOL> for alias in aliases : <EOL> self . commands [ alias ] = func <EOL> class ModelRegister ( object ) : <EOL> def __init__ ( self ) : <EOL> self . models = { } <EOL> def register ( self , model ) : <EOL> self . models [ model . db_table_name ] = model <EOL> def values ( self ) : <EOL> return self . models . values ( ) <EOL> def get ( self , key , default = None ) : <EOL> return self . models . get ( key , default ) <EOL> class IntRegister ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . things = { } <EOL> self . next_id = <NUM_LIT:0> <EOL> self . changed = True <EOL> self . _calculated = None <EOL> def evaluate ( self , thing ) : <EOL> return int ( thing ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . things . get ( key ) <EOL> def __setitem__ ( self , key , val ) : <EOL> self . things [ key ] = val <EOL> self . changed = True <EOL> def append ( self , val ) : <EOL> this_id = self . next_id <EOL> self . things [ this_id ] = val <EOL> self . next_id += <NUM_LIT:1> <EOL> self . changed = True <EOL> return this_id <EOL> def __delitem__ ( self , key ) : <EOL> if key in self . things : <EOL> del self . things [ key ] <EOL> self . changed = True <EOL> def calculate ( self ) : <EOL> if self . changed : <EOL> self . _calculated = <NUM_LIT:0> <EOL> for val in self . things . values ( ) : <EOL> self . _calculated += self . evaluate ( val ) <EOL> self . changed = False <EOL> return self . _calculated <EOL> class DictRegister ( IntRegister ) : <EOL> """<STR_LIT>""" <EOL> def evaluate ( self , thing ) : <EOL> return thing <EOL> def calculate ( self ) : <EOL> if self . changed : <EOL> self . _calculated = { } <EOL> for value in self . things . values ( ) : <EOL> key , val = self . evaluate ( value ) <EOL> self . _calculated [ key ] = self . _calculated . get ( key , <NUM_LIT:0> ) + val <EOL> return self . _calculated <EOL> class DamageRegister ( DictRegister ) : <EOL> """<STR_LIT>""" <EOL> changed = property ( ( lambda x : True ) , ( lambda x , y : None ) ) <EOL> def evaluate ( self , thing ) : <EOL> key = thing . type <EOL> if thing . probability == <NUM_LIT:100> or thing . probability <= randint ( <NUM_LIT:1> , <NUM_LIT:100> ) : <EOL> val = randint ( thing . range [ <NUM_LIT:0> ] , thing . range [ <NUM_LIT:1> ] ) <EOL> else : <EOL> val = <NUM_LIT:0> <EOL> return key , val <EOL> def display ( self ) : <EOL> types = { } <EOL> mins = { } <EOL> maxs = { } <EOL> for value in self . things . values ( ) : <EOL> mins [ value . type ] = mins . get ( value . type , <NUM_LIT:0> ) + value . range [ <NUM_LIT:0> ] <EOL> maxs [ value . type ] = maxs . get ( value . type , <NUM_LIT:0> ) + value . range [ <NUM_LIT:1> ] <EOL> types [ value . type ] = True <EOL> return [ ( t , mins [ t ] , maxs [ t ] ) for t in types . keys ( ) ] </s>
