Package horizons :: Package world :: Module player :: Class Player
[hide private]
[frames] | no frames]

Class Player

source code

component.componentholder.ComponentHolder --+
                                            |
   util.changelistener.ChangeListener --+   |
                                        |   |
             util.worldobject.WorldObject --+
                                            |
                                           Player

Class representing a player

Instance Methods [hide private]
 
__init__(self, session, worldid, name, color, clientid=None, difficulty_level=None) source code
 
initialize(self, inventory)
Has to be called every time a componentholder is created.
source code
 
__init(self, name, color, clientid, difficulty_level, max_tier_notification, settlerlevel=0) source code
 
is_local_player(self) source code
 
get_latest_stats(self) source code
 
settlements(self)
Calculate settlements dynamically to save having a redundant list here
source code
 
save(self, db) source code
 
_load(self, db, worldid)
This function makes it possible to load playerdata into an already allocated Player instance, which is used e.g.
source code
 
notify_settler_reached_level(self, message)
Settler calls this to notify the player.
source code
 
end(self) source code
 
get_balance_estimation(self)
This takes a while to calculate, so only do it every 2 seconds at most
source code
 
get_statistics(self)
Returns a namedtuple containing player-wide statistics
source code
    Inherited from component.componentholder.ComponentHolder
 
add_component(self, component)
Adds new component to holder and sets the instance attribute on the component
source code
 
get_component(self, component) source code
 
get_component_by_name(self, name) source code
 
has_component(self, component_class)
Check if holder has component with component name
source code
 
remove(self) source code
 
remove_component(self, component_class)
Removes component from holder.
source code
    Inherited from util.worldobject.WorldObject
 
__lt__(self, other) source code
    Inherited from util.changelistener.ChangeListener
 
_changed(self)
Calls every listener when an object changed
source code
 
add_change_listener(self, listener, call_listener_now=False, no_duplicates=False) source code
 
add_remove_listener(self, listener, no_duplicates=False)
A listener that listens for removal of the object
source code
 
clear_change_listeners(self)
Removes all change listeners
source code
 
discard_change_listener(self, listener)
Remove listener if it's there
source code
 
discard_remove_listener(self, listener) source code
 
has_change_listener(self, listener) source code
 
has_remove_listener(self, listener) source code
 
remove_change_listener(self, listener) source code
 
remove_remove_listener(self, listener) source code
Class Methods [hide private]
 
load(cls, session, db, worldid) source code
    Inherited from component.componentholder.ComponentHolder
 
get_component_template(cls, component)
Returns the component template data given a component NAME
source code
    Inherited from util.worldobject.WorldObject
 
get_object_by_id(cls, id)
Returns the worldobject with id id Throws WorldObjectNotFound with the worldid as arg.
source code
 
get_objs(cls) source code
 
reset(cls) source code
Class Variables [hide private]
  STATS_UPDATE_INTERVAL = 3
  regular_player = True
  component_templates = {'StorageComponent': {'PositiveStorage':...
    Inherited from component.componentholder.ComponentHolder
  class_mapping = {'AmbientSoundComponent': AmbientSoundComponen...
    Inherited from util.worldobject.WorldObject
  log = logging.getLogger("util.worldobject")
Method Details [hide private]

__init__(self, session, worldid, name, color, clientid=None, difficulty_level=None)
(Constructor)

source code 
Parameters:
  • session (horizons.session.Session) - Session instance
  • worldid - player's worldid
  • name - user-chosen name
  • color - color of player (as Color)
  • clientid - id of client
  • inventory - {res: value} that are put in the players inventory
Overrides: util.changelistener.ChangeListener.__init__

initialize(self, inventory)

source code 

Has to be called every time a componentholder is created. This is not in __init__() because we need to make sure that all other sub/parent classes have been inited, for example the ConcreteObject class. This is to ensure that all member variables of sub/parent classes are correctly set when we init the components. If someday all code is moved to components, this will not be necessary any more.

Overrides: component.componentholder.ComponentHolder.initialize
(inherited documentation)

is_local_player(self)

source code 
Decorators:
  • @property

settlements(self)

source code 

Calculate settlements dynamically to save having a redundant list here

Decorators:
  • @property

save(self, db)

source code 
Overrides: util.worldobject.WorldObject.save

load(cls, session, db, worldid)
Class Method

source code 
Overrides: util.changelistener.ChangeListener.load

_load(self, db, worldid)

source code 

This function makes it possible to load playerdata into an already allocated Player instance, which is used e.g. in Trader.load

end(self)

source code 
Overrides: util.changelistener.ChangeListener.end

get_balance_estimation(self)

source code 

This takes a while to calculate, so only do it every 2 seconds at most

Decorators:
  • @decorators.temporary_cachedmethod(timeout= STATS_UPDATE_INTERVAL)

get_statistics(self)

source code 

Returns a namedtuple containing player-wide statistics

Decorators:
  • @decorators.temporary_cachedmethod(timeout= STATS_UPDATE_INTERVAL)

Class Variable Details [hide private]

component_templates

Value:
{'StorageComponent': {'PositiveStorage': {}}},