本文整理汇总了Python中evennia.TICKER_HANDLER类的典型用法代码示例。如果您正苦于以下问题:Python TICKER_HANDLER类的具体用法?Python TICKER_HANDLER怎么用?Python TICKER_HANDLER使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TICKER_HANDLER类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: die
def die(self, killers):
"""
The monster is killed. Reborn in settings.NPC_REBORN_CD seconds.
"""
try:
super(MudderyMonster, self).die(killers)
# delete itself and notify its location
location = self.location
if settings.NPC_REBORN_CD <= 0:
# Can not reborn.
delete_object(self.dbref)
else:
# Remove from its location.
self.move_to(None, quiet=True, to_none=True)
# Set reborn timer.
TICKER_HANDLER.add(self, settings.NPC_REBORN_CD, hook_key="reborn")
if location:
for content in location.contents:
if content.has_player:
content.show_location()
except Exception, e:
logger.log_tracemsg("die error: %s" % e)
示例2: _set_ticker
def _set_ticker(self, interval, hook_key, stop=False):
"""
Set how often the given hook key should
be "ticked".
Args:
interval (int): The number of seconds
between ticks
hook_key (str): The name of the method
(on this mob) to call every interval
seconds.
stop (bool, optional): Just stop the
last ticker without starting a new one.
With this set, the interval and hook_key
arguments are unused.
In order to only have one ticker
running at a time, we make sure to store the
previous ticker subscription so that we can
easily find and stop it before setting a
new one. The tickerhandler is persistent so
we need to remember this across reloads.
"""
idstring = "tutorial_mob" # this doesn't change
last_interval = self.db.last_ticker_interval
if last_interval:
# we have a previous subscription, kill this first.
TICKER_HANDLER.remove(self, last_interval, idstring)
self.db.last_ticker_interval = interval
if not stop:
# set the new ticker
TICKER_HANDLER.add(self, interval, idstring, hook_key)
示例3: cast_combat_skill
def cast_combat_skill(self, skill, target):
"""
Cast a skill in combat.
"""
if not self.owner:
return
if not self.owner.ndb.combat_handler:
# Onwer is not in combat.
return
if self.GLOBAL_COOLING_DOWN:
# In GCD.
self.owner.msg({"msg":LS("This skill is not ready yet!")})
return
if self.skills[skill].is_cooling_down():
# Skill is cooling down.
self.owner.msg({"msg":LS("This skill is not ready yet!")})
return
# Cast skill.
result = self.owner.ndb.combat_handler.cast_skill(skill, self.owner.dbref, target)
if result:
# Cast successed, set GCD
if settings.GLOBAL_CD > 0:
self.GLOBAL_COOLING_DOWN = True
# Set timer.
TICKER_HANDLER.add(self, settings.GLOBAL_CD, hook_key="global_cooled_down")
return result
示例4: at_object_creation
def at_object_creation(self):
"""
Called when the object is first created.
"""
#Subscribes room to ticker_handler and calls at_hour every tick
TICKER_HANDLER.add(self, 60*60, hook_key="at_hour") #60*60 = seconds
#Room Attributes related to Light Cycles
#whether light cycle phase is active
self.db.light_cycle_active = False
#light phase duration
self.db.light_phase_lengths = {"dawn":2, "day":10, "dusk":2, "night":10}
self.db.light_phase_echoes = {
"dawn":"", "day":"", "dusk":"", "night":""
} #phase change echoes
self.db.light_phase_descs = {
"dawn":"", "day":"", "dusk":"", "night":""
} #phase room descriptions
self.db.light_phase = "dawn" #current phase
self.db.light_phase_time = 2 #time left
self.db.light_phase_hour = 0 #time into cycle, starting at dawn
self.db.lumens = 30 #temporary default lumens value
示例5: global_cooled_down
def global_cooled_down(self):
"""
GCD finished.
"""
self.GLOBAL_COOLING_DOWN = False
# Remove the timer.
TICKER_HANDLER.remove(self, settings.GLOBAL_CD)
示例6: start_auto_combat_skill
def start_auto_combat_skill(self):
"""
Start auto cast skill.
"""
self.can_auto_cast = True
# Cast a skill immediately
self.auto_cast_skill()
# Set timer of auto cast.
TICKER_HANDLER.add(self, settings.AUTO_CAST_SKILL_CD, hook_key="auto_cast_skill")
示例7: reborn
def reborn(self):
"""
Reborn after being killed.
"""
TICKER_HANDLER.remove(self, self.reborn_cd)
# Recover all hp.
self.db.hp = self.max_hp
self.show_status()
# Reborn at its home.
if self.home:
self.move_to(self.home, quiet=True)
self.msg({"msg": LS("You are reborn at {c%s{n.") % self.home.get_name()})
示例8: __init__
def __init__(self, owner):
"""
Initialize handler.
"""
self.owner = owner
self.skills = owner.db.skills
# TICKER_HANDLER need pk.
self.pk = "SKILL"
# always begin with GCD
self.GLOBAL_COOLING_DOWN = True
TICKER_HANDLER.add(self, settings.GLOBAL_CD, hook_key="global_cooled_down")
self.AUTO_CAST_SKILL = False
self.skill_target = None
示例9: reborn
def reborn(self):
"""
Reborn after being killed.
"""
TICKER_HANDLER.remove(self, settings.NPC_REBORN_CD)
# Recover all hp.
self.db.hp = self.max_hp
# Reborn at its home.
if self.home:
self.move_to(self.home, quiet=True)
for content in self.home.contents:
if content.has_player:
content.show_location()
示例10: die
def die(self, killers):
"""
This character is killed. Move it to it's home.
"""
super(MudderyPlayerCharacter, self).die(killers)
self.msg({"msg": LS("You died.")})
if self.reborn_cd <= 0:
# Reborn immediately
self.reborn()
else:
# Set reborn timer.
TICKER_HANDLER.add(self, self.reborn_cd, hook_key="reborn")
self.msg({"msg": LS("You will be reborn at {c%(p)s{n in {c%(s)s{n seconds.") %
{'p': self.home.get_name(), 's': self.reborn_cd}})
示例11: at_object_creation
def at_object_creation(self):
"""
Called when object is first created.
We set up a ticker to update this room regularly.
Note that we could in principle also use a Script to manage
the ticking of the room; the TickerHandler works fine for
simple things like this though.
"""
super(WeatherRoom, self).at_object_creation()
# subscribe ourselves to a ticker to repeatedly call the hook
# "update_weather" on this object. The interval is randomized
# so as to not have all weather rooms update at the same time.
interval = random.randint(50, 70)
TICKER_HANDLER.add(interval=interval, callback=self.update_weather, idstring="tutorial")
# this is parsed by the 'tutorial' command on TutorialRooms.
self.db.tutorial_info = \
"This room has a Script running that has it echo a weather-related message at irregular intervals."
示例12: at_object_receive
def at_object_receive(self, obj, source_location):
if utils.inherits_from(obj, Npc): # An NPC has entered
pass
else:
# Else if a PC has entered
if utils.inherits_from(obj, Character):
# Cause the character to look around
#obj.execute_cmd('look')
for item in self.contents:
# Any NPCs in the room ?
if utils.inherits_from(item, Npc):
# Notify NPCs that a PC entered the room
item.at_char_entered(obj)
tickerhandler.add(item,1)
# if item in room not self
if item.dbref != obj.dbref:
# if item is of class Character
if utils.inherits_from(item, Character):
obj.msg("DATA,char_add," + item.name + item.dbref)
item.msg("DATA,char_add," + obj.name + obj.dbref)
# else if item is of class Mob
elif utils.inherits_from(item, Mob):
obj.msg("DATA,char_add," + item.name + item.dbref)
# else if item is of class Npc
elif utils.inherits_from(item, Npc):
obj.msg("DATA,char_add," + item.name + item.dbref)
# else (an object)
else:
obj.msg("DATA,obj_add," + item.name + item.dbref)
示例13: at_object_leave
def at_object_leave(self, obj, target_location):
if utils.inherits_from(obj, Character):
for item in self.contents:
# if item in room not self
if item.dbref != obj.dbref:
# if item is of class Character
if utils.inherits_from(item, Character):
obj.msg("DATA,char_remove," + item.name + item.dbref)
item.msg("DATA,char_remove," + obj.name + obj.dbref)
# else if item is of class Mob
elif utils.inherits_from(item, Mob):
obj.msg("DATA,char_remove," + item.name + item.dbref)
# else if item is of class Npc
elif utils.inherits_from(item, Npc):
obj.msg("DATA,char_remove," + item.name + item.dbref)
# else (an object)
else:
obj.msg("DATA,obj_remove," + item.name + item.dbref)
if utils.inherits_from(obj, Npc): # An NPC has left
pass
elif utils.inherits_from(obj, Mob): # A Mob has left
pass
else:
# Else if a PC has left the room
if utils.inherits_from(obj, Character):
# Any NPCs in the room ?
for item in self.contents:
if utils.inherits_from(item, Npc):
# Notify NPCs that a PC left the room
tickerhandler.remove(item,1)
示例14: sample_char
def sample_char(char, archetype, race, focus=None):
"""Loads sample traits onto a character.
Args:
char (Character): character to load traits
archetype (str): name of base archetype
race (str): name of race to become
focus Optional(str): focus to apply. if None, default is race's
first item in foci collection
"""
archetypes.apply_archetype(char, archetype, reset=True)
char.traits.STR.base += 1
char.traits.PER.base += 1
char.traits.INT.base += 1
char.traits.DEX.base += 1
char.traits.CHA.base += 1
char.traits.VIT.base += 2
char.traits.MAG.base += 2
focus = focus or races.load_race(race).foci[0]
races.apply_race(char, race, focus)
archetypes.calculate_secondary_traits(char.traits)
archetypes.finalize_traits(char.traits)
tickerhandler.add(char, 6, hook_key='at_turn_start')
skills.apply_skills(char)
skills.finalize_skills(char.skills)
示例15: cast_off
def cast_off(self):
"""
When cast_off, a vessel is subject to movement forces. Current, wind,
and even self power like oars. This means a script will start to run
updating position constantly based on those forces.
"""
self.db.adrift = True
self.msg_contents("The %s is now adrift." % self.key)
tickerhandler.add(3, self.make_way, idstring="adrift")