<s> """<STR_LIT>""" <EOL> import collections <EOL> class EffectsCollection ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( ) . __init__ ( ) <EOL> self . handles = { } <EOL> self . effects = [ ] <EOL> def add_effect_handle ( self , handle ) : <EOL> """<STR_LIT>""" <EOL> assert handle is not None <EOL> handles = self . handles <EOL> trigger = handle . trigger <EOL> if not trigger in handles : <EOL> handles [ trigger ] = [ ] <EOL> handles [ trigger ] . append ( handle ) <EOL> def get_effect_handles ( self , trigger = None ) : <EOL> """<STR_LIT>""" <EOL> if trigger is None : <EOL> effects = [ ] <EOL> for key in self . handles : <EOL> for handle in self . handles [ key ] : <EOL> effects . append ( handle ) <EOL> else : <EOL> if trigger in self . handles : <EOL> effects = [ x for x in self . handles [ trigger ] ] <EOL> else : <EOL> effects = [ ] <EOL> return effects <EOL> def remove_effect_handle ( self , handle ) : <EOL> """<STR_LIT>""" <EOL> assert handle is not None <EOL> for key , value in self . handles . items ( ) : <EOL> if handle in value : <EOL> value . remove ( handle ) <EOL> def has_effect ( self , effect ) : <EOL> """<STR_LIT>""" <EOL> return effect . effect_name in [ x . effect_name for x in self . effects ] <EOL> def add_effect ( self , effect ) : <EOL> """<STR_LIT>""" <EOL> assert effect is not None <EOL> self . effects . append ( effect ) <EOL> def get_effects ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ x for x in self . effects ] <EOL> def get_expired_effects ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ x for x in self . effects <EOL> if x . duration is not None <EOL> and x . duration <= <NUM_LIT:0> ] <EOL> def remove_expired_effects ( self ) : <EOL> """<STR_LIT>""" <EOL> self . effects = [ x for x in self . effects <EOL> if x . duration > <NUM_LIT:0> ] <EOL> def get_charges_left ( self ) : <EOL> """<STR_LIT>""" <EOL> if len ( self . get_effect_handles ( ) ) == <NUM_LIT:0> : <EOL> return [ ] <EOL> return [ x . charges for x in self . get_effect_handles ( ) ] <EOL> def get_maximum_charges_left ( self ) : <EOL> """<STR_LIT>""" <EOL> charges = self . get_charges_left ( ) <EOL> if charges is not None : <EOL> if isinstance ( charges , collections . Sequence ) : <EOL> if len ( charges ) > <NUM_LIT:0> : <EOL> return max ( charges ) <EOL> else : <EOL> return None <EOL> else : <EOL> return charges <EOL> else : <EOL> return None <EOL> def get_minimum_charges_left ( self ) : <EOL> """<STR_LIT>""" <EOL> charges = self . get_charges_left ( ) <EOL> if charges is not None : <EOL> return min ( charges ) <EOL> else : <EOL> return None <EOL> def _repr_pretty_ ( self , p , cycle ) : <EOL> """<STR_LIT>""" <EOL> if cycle : <EOL> p . text ( '<STR_LIT>' ) <EOL> else : <EOL> p . text ( '<STR_LIT>' ) <EOL> for effect in self . effects : <EOL> p . pretty ( effect ) <EOL> p . breakable ( ) </s>
