Multiple buffs/debuffs with various times
Posted: Sun Jan 11, 2015 5:12 am
As a continuation of my other thread, I would like to create a timer for various effects for players. Effects include things like healing, poisons, slows, etc etc. I think I've found an effective way to accomplish this and would like input on my implementation and API.
Syntax: Select all
statusEffectsList = ['drug','regen','stun']
statusEffects = {}
for status in statusEffectsList:
statusEffects[status] = []
def heal(player, amount):
# player is a PlayerEntity/dndPlayer object
player.health += amount
if player.health > player.maxhp:
player.health = player.maxhp
def stun():
raise NotImplementedError('Not yet included')
def drug():
raise NotImplementedError('Not yet included')
def dndTick():
for players in PlayerGenerator():
myPlayer = dndPlayerDictionary[userid_from_playerinfo(players)]
if not myPlayer.isdead:
for item in myPlayer.statusEffects:
for instance in myPlayer.statusEffects[item]
if myPlayer.statusEffects[item][instance]['effect']:
if dndTimer.count >= myPlayer.statusEffects[item][instance]['duration'] and dndTimer.count % myPlayer.statusEffects[item][instance]['duration'] == 0:
if myPlayer.statusEffects[item][instance]['iteration'] != None
if myPlayer.statusEffects[item][instance]['iteration'] > 0:
myPlayer.statusEffects[item][instance]['iteration'] -= 1
globals()[item]()
else:
myPlayer.statusEffects[item][instance].pop
else:
globals()[item]()
@Event
def player_spawn(game_event):
dndTimer.reset()
spawnee_userid = game_event.get_int('userid')
spawnee = dndPlayerDictionary[spawnee_userid]
#This just sets all attributes of PlayerEntity() to their default value, i.e. max health is 100 and speed is 100%
#dndPlayer object also has an attribute of statusEffects and dndPlayer.reset sets all keys to an empty list
spawnee.reset()
if spawnee.someAttribute = True:
#Player should regenerate 1 health every 4 seconds
spawnee.statusEffects['regen'].append({'duration':3,'effect':5,'intervals':3})
#Player should regenerate 5 health every 3 seconds, but only for 3 intervals
spawnee.statusEffects['regen'].append({'duration':3,'effect':5,'intervals':3})
dndTimer = TickRepeat(dndTick)
dndTimer.start(1,0)