I'm not sure the criteria for your regen, but maybe the following will give you an idea:
Syntax: Select all
from listeners.tick import TickRepeat
from players.entity import PlayerEntity
from players.helpers import index_from_userid
class PlayerDictionary(dict):
def __missing__(self, userid):
value = self[userid] = Player(userid)
def __delitem__(self, userid):
if userid in self:
self[userid].repeat.stop()
def clear(self):
for userid in list(self):
del self[userid]
class Player(PlayerEntity):
def __new__(cls, userid):
self = super(Player, cls).__new__(cls, index_from_userid(userid))
return self
def __init__(self, userid):
self._repeat = TickRepeat(self.regen_loop)
@property
def repeat(self):
return self._repeat
def regen_loop(self):
...
If you would be more specific as to when players are supposed to start regen'ing, the max health to regen to, the max time to regen, the max health to regen per regen cycle, etc..., we could help you further.
For the example above, you might want to look at some of the properties of a TickRepeat instance (specifically
count):
http://wiki.sourcepython.com/pages/listeners.tick#TickRepeatAlso, don't forget that using 0 for the limit argument in
TickRepeat.start causes the repeat to be infinite and only stop when explicitly stopped.