Пример #1
0
    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)
Пример #2
0
    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
0
    def auto_cast_skill(self):
        """
        Cast a new skill automatically.
        """
        if not self.can_auto_cast:
            return

        if not self.owner:
            return

        if not self.owner.is_alive():
            return

        if not self.owner.ndb.combat_handler:
            # combat is finished, stop ticker
            TICKER_HANDLER.remove(self.auto_cast_skill_cd,
                                  self.owner.auto_cast_skill)
            return

        # Choose a skill and the skill's target.
        result = ChooseSkill.choose(self.owner)
        if result:
            skill, target = result
            self.owner.ndb.combat_handler.prepare_skill(
                skill, self.owner, target)
Пример #4
0
 def stop_auto_combat_skill(self):
     """
     Stop auto cast skill.
     """
     self.can_auto_cast = False
     TICKER_HANDLER.remove(self.auto_cast_skill_cd,
                           self.owner.auto_cast_skill)
Пример #5
0
    def at_post_unpuppet(self, player, session=None):
        """
        We stove away the character when the player goes ooc/logs off,
        otherwise the character object will remain in the room also
        after the player logged off ("headless", so to say).

        Args:
            player (Player): The player object that just disconnected
                from this object.
            session (Session): Session controlling the connection that
                just disconnected.
        """
        if not self.sessions.count():
            tickerhandler.remove(7, self.player_character_ticks)

            # only remove this char from grid if no sessions control it anymore.
            if self.location:

                def message(obj, from_obj):
                    obj.msg(
                        "The form of %s shimmers briefly, then fades away into the ether."
                        % self.get_display_name(obj),
                        from_obj=from_obj)

                self.location.for_contents(message,
                                           exclude=[self],
                                           from_obj=self)
                self.db.prelogout_location = self.location
                self.location = None
Пример #6
0
    def npc_active_ticks(self, *args, **kwargs):
        "Ticks after the NPC has been attacked."

        targets = False  # Any targets in the room?

        # This should probably go below.
        if self.db.tries_left > 0:
            for i in self.location.contents:
                if i in self.db.offended_by:
                    targets = True
                    npc_rules.attack(self, i)
                    self.db.tries_left = 3
                    return

        if not targets:
            for k, v in self.location.db.trails.iteritems():
                target_name = str(self.db.offended_by[0])
                if k == target_name:
                    destination = self.search(v)
                    self.move_to(destination)
                    for i in self.location.contents:
                        if i in self.db.offended_by:
                            targets = True
                            npc_rules.attack(self, i)
                            self.db.tries_left = 3
                            break
                    break

        self.db.tries_left = self.db.tries_left - 1

        if self.db.tries_left < 0:
            self.db.offended_by = []
            self.db.tries_left = self.db.tries
            tickerhandler.remove(self.db.ticker_speed, self.npc_active_ticks)
            return
Пример #7
0
    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)
Пример #8
0
    def global_cooled_down(self):
        """
        GCD finished.
        """
        self.GLOBAL_COOLING_DOWN = False

        # Remove the timer.
        TICKER_HANDLER.remove(self, settings.GLOBAL_CD)
Пример #9
0
    def at_stop(self):
        "Called just before the script is stopped/destroyed."
        if self.timeout:
            TICKER_HANDLER.remove(self.timeout, self.at_timeout)

        for character in self.characters.values():
            # note: the list() call above disconnects list from database
            self._cleanup_character(character)
Пример #10
0
 def global_cooled_down(self):
     """
     GCD finished.
     """
     self.GLOBAL_COOLING_DOWN = False
     
     # Remove the timer.
     TICKER_HANDLER.remove(self, settings.GLOBAL_CD)
Пример #11
0
def check_defeat(character, id):
    "Checks if a character is 'defeated'."
    if character.db.hp['Current'] <= 0:
        character.msg("You fall down, defeated!")
        character.db.hp['Current'] = character.db.hp['Max']
        character.db.fighting = None
        tickerhandler.remove(5, skill_combat, persistent=False, idstring=id)
        update_prompt(character)
        return
Пример #12
0
    def doit(self):
        caller = self.db.caller
        substance_name = self.db.substance
        if substance_name in caller.db.effects:
            del caller.db.effects[substance_name]
            caller.msg(u"Тебя попустило с %s" % substance_name)

        tickerhandler.remove(self, self.db.affect_time)
        self.delete()
Пример #13
0
def stand(self):
    if self.db.position is not 0:
        self.msg("You stand up.")
        for Character in self.location.contents:
            if Character is not self:
                Character.msg("{} stands up.".format(self.db._sdesc))
        cooldown = (10 - (self.db.endurance * .1))
        tickerhandler.remove(cooldown, self.rest_tick)
        self.db.position = 0
    else:
        self.msg("You are already standing.")
Пример #14
0
    def update_show(self, *args, **kwargs):
        """
        Called by the tickerhandler at regular intervals.
        """

        if self.show_counter >= len(PUPPET_STRINGS):
            self.show_counter = 0
            TICKER_HANDLER.remove(2,
                                  self.update_show,
                                  idstring="puppet_start_show_ticker")
        else:
            phrase = PUPPET_STRINGS[self.show_counter]
            self.msg_contents("%s" % phrase)
            self.show_counter += 1
Пример #15
0
    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()})
Пример #16
0
 def _init_character(self, character):
     """
     This initializes handler back-reference
     and combat cmdset on a character. It also
     stops the tickerhandler that normally calls
     at_turn_start every 6s
     """
     if not character.nattributes.has('combat_handler'):
         tickerhandler.remove(6, character.at_turn_start)
         character.ndb.combat_handler = self
         character.cmdset.add("commands.combat.CombatBaseCmdSet")
         character.cmdset.add("commands.combat.CombatCmdSet")
         prompt = _COMBAT_PROMPT.format(tr=character.traits)
         character.msg(prompt=prompt)
Пример #17
0
 def death(self, room, held_by):
     tickerhandler.remove(30, self.on_burn_tick, persistent=True)
     if inherits_from(held_by, "characters.characters.Character"):
         held_by.msg(
             f"Your {self.name} torch dies out and it collapses into a tiny pile of ash."
         )
         room.msg_contents(
             f"{held_by.name}'s {self.name} dies out and it collapses into a tiny pile of ash.",
             exclude=held_by)
     else:
         room.msg_contents(
             f"{self.name} dies out and it collapses into a tiny pile of ash."
         )
     self.delete()
Пример #18
0
 def at_tick(self):
     if self.db.attacking != None:
         print self.attacking.location
         # if character in same roome as self and aggressive
         if self.location == self.db.attacking.location and self.db.count < 10:
             # attack with probability and after cooldown
             if (time() - self.db.last_attack) > randint(1, 3):
                 self.execute_cmd("say Graaah, die %s!" % self.db.attacking)
                 rules.roll_challenge(self, self.db.attacking, "combat")
                 self.db.last_attack = time()
                 self.db.count += 1
         else:
             tickerhandler.remove(self, 1)
     else:
         tickerhandler.remove(self, 1)
Пример #19
0
    def npc_revive_ticks(self, *args, **kwargs):
        "ticked when "

        self.db.alive = True

        self.name = self.db.live_name
        self.db.health = self.db.max_health

        self.db.looted_yet = False
        self.db.skinned_yet = False

        destination = self.search(self.db.home_location, global_search=True)
        self.move_to(destination)

        tickerhandler.remove(self.db.respawn_speed, self.npc_revive_ticks)
        return
Пример #20
0
    def reborn(self):
        """
        Reborn after being killed.
        """
        TICKER_HANDLER.remove(self.reborn_cd, self.reborn)

        # 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()
Пример #21
0
    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()
Пример #22
0
 def at_object_leave(self, moved_obj, target_location, **kwargs):
     """
     Called just before an object leaves from inside this object
     Args:
         moved_obj (Object): The object leaving
         target_location (Object): Where `moved_obj` is going.
         **kwargs (dict): Arbitrary, optional arguments for users
             overriding the call (unused by default).
     """
     if self.db.connected_to_ticker:
         # If we no longer have players in the room. Turn off ticker.
         if not [obj.has_account for obj in self.contents_get()]:
             tickerhandler.remove(self.db.ambient_interval,
                                  self.display_ambient_msg())
             self.db.connected_to_ticker = False
         pass
Пример #23
0
    def npc_active_ticks(self, *args, **kwargs):
        "ticked when "

        # This should probably go below.
        if self.db.tries_left > 0:
            for i in self.location.contents:
                if i in self.db.offended_by:
                    npc_rules.attack(self, i)
                    return

        self.db.tries_left = self.db.tries_left - 1

        if self.db.tries_left < 0:
            self.db.offended_by = []
            self.db.tries_left = self.db.tries
            tickerhandler.remove(self.db.ticker_speed, self.npc_active_ticks)
            return
Пример #24
0
    def set_state(self, interval, hook_key, stop=False):
        idstring = self.key + "-" + str(self.id)
        last_interval = self.db.last_ticker_interval
        last_hook_key = self.db.last_hook_key

        if last_interval and last_hook_key:
             # we have a previous subscription, kill this first.
            tickerhandler.remove(interval=last_interval,
                                  callback=getattr(self, last_hook_key), idstring=idstring)

        self.db.last_ticker_interval = interval
        self.db.last_hook_key = hook_key

        if not stop:
            # set the new ticker
            tickerhandler.add(interval=interval,
                               callback=getattr(self, hook_key), idstring=idstring)
Пример #25
0
    def at_tick(self):

        tickerhandler.remove(self, self.db.last_ticker_deley_value)
        self.db.last_ticker_deley_value = random.randint(15, 120) 
        tickerhandler.add(self, self.db.last_ticker_deley_value)

        if not self.goods:
            return

        goods_to_create = self.goods.values()

        for good in goods_to_create:
            good_in_inv = self.search(good["name"], location=self, nofound_string="")
            if not good_in_inv:
                new_good = create_object(good["typeclass"], good["name"], self, home=self)
                if not new_good.db.desc:
                    if good["desc"]:
                        new_good.db.desc = good["desc"]
                new_good.db.coast = good["coast"]
Пример #26
0
    def at_tick(self):

        tickerhandler.remove(self, self.db.last_ticker_deley_value)
        self.db.last_ticker_deley_value = random.randint(15, 120) 
        tickerhandler.add(self, self.db.last_ticker_deley_value)

        if not self.goods:
            return

        goods_to_create = self.goods.values()

        for good in goods_to_create:
            good_in_inv = self.search(good["name"], location=self, nofound_string="")
            if not good_in_inv:
                new_good = create_object(good["typeclass"], good["name"], self, home=self)
                if not new_good.db.desc:
                    if good["desc"]:
                        new_good.db.desc = good["desc"]
                new_good.db.coast = good["coast"]
Пример #27
0
    def auto_cast_skill(self):
        """
        Cast a new skill automatically.
        """
        if not self.can_auto_cast:
            return

        if not self.owner:
            return

        if not self.owner.is_alive():
            return

        if not self.owner.ndb.combat_handler:
            # combat is finished, stop ticker
            TICKER_HANDLER.remove(self.auto_cast_skill_cd,
                                  self.owner.auto_cast_skill)
            return

        # Get target.
        choose_new_target = True
        if self.skill_target:
            if self.skill_target.is_alive():
                choose_new_target = False

        if choose_new_target:
            self.skill_target = self.choose_skill_target()

        if not self.skill_target:
            # No target.
            return

        # Get available skills.
        available_skills = self.get_available_skills()
        if not available_skills:
            # No available skill.
            return

        # Random chooses a skill.
        skill = random.choice(available_skills)
        if skill:
            self.owner.ndb.combat_handler.prepare_skill(
                skill, self.owner, self.skill_target)
Пример #28
0
    def auto_cast_skill(self):
        """
        Cast a new skill automatically.
        """
        if not self.can_auto_cast:
            return

        if not self.owner:
            return

        if not self.owner.ndb.combat_handler:
            # combat is finished, stop ticker
            TICKER_HANDLER.remove(self, settings.AUTO_CAST_SKILL_CD)
            return

        # Get target.
        choose_new_target = True
        if self.skill_target:
            if self.skill_target.is_alive():
                choose_new_target = False

        if choose_new_target:
            self.skill_target = self.choose_skill_target()

        if not self.skill_target:
            # No target.
            return

        # Get available skills.
        available_skills = self.get_available_skills()
        if not available_skills:
            # No available skill.
            return

        # Random chooses a skill.
        skill = random.choice(available_skills)
        if skill:
            self.cast_skill(skill, self.skill_target)
Пример #29
0
    def auto_cast_skill(self):
        """
        Cast a new skill automatically.
        """
        if not self.AUTO_CAST_SKILL:
            return

        if not self.owner:
            return

        if not self.owner.ndb.combat_handler:
            # combat is finished, stop ticker
            TICKER_HANDLER.remove(self, settings.AUTO_CAST_SKILL_CD)
            return

        # Get target.
        choose_new_target = True
        if self.skill_target:
            if self.skill_target.is_alive():
                choose_new_target = False

        if choose_new_target:
            self.skill_target = self.choose_skill_target()

        if not self.skill_target:
            # No target.
            return

        # Get available skills.
        available_skills = self.get_available_skills()
        if not available_skills:
            # No available skill.
            return

        # Random chooses a skill.
        skill = random.choice(available_skills)
        self.cast_combat_skill(skill, self.skill_target.dbref)
Пример #30
0
 def remove_health_ticker(self):
     try:
         TICKER_HANDLER.remove(HEALTH_TICK_SECONDS, self.tick_health)
     except KeyError:
         pass
Пример #31
0
 def __del__(self):
     """
     Remove tickers.
     """
     if self.can_auto_cast:
         TICKER_HANDLER.remove(callback=self.owner.auto_cast_skill)
Пример #32
0
# -*- coding: utf-8 -*-

#HEADER
from evennia import TICKER_HANDLER as tickerhandler
from evennia.objects.models import ObjectDB

#CODE

#for each in ObjectDB.objects.all():
#    if each.is_typeclass('typeclasses.objects.Object'):
#        each.db.invis = 0

for each in ObjectDB.objects.all():
    if each.is_typeclass('typeclasses.characters.Character'):
        tickerhandler.add(60, each.heal, persistent=True)
        tickerhandler.add(120, each.heal_lethal, persistent=True)
        tickerhandler.add(180, each.spells, persistent=True)
        tickerhandler.remove(5, each.heal, persistent=True)
Пример #33
0
 def anchor(self):
     tickerhandler.remove(3, self.make_way, idstring="adrift")
     self.db.power = 0
     self.db.underway = False
     self.db.adrift = False
Пример #34
0
 def __del__(self):
     """
     Remove tickers.
     """
     if self.GLOBAL_COOLING_DOWN or self.AUTO_CAST_SKILL:
         TICKER_HANDLER.remove(self)
Пример #35
0
 def __del__(self):
     """
     Remove tickers.
     """
     if self.GLOBAL_COOLING_DOWN or self.AUTO_CAST_SKILL:
         TICKER_HANDLER.remove(self)
Пример #36
0
 def stop_auto_combat_skill(self):
     """
     Stop auto cast skill.
     """
     self.AUTO_CAST_SKILL = False
     TICKER_HANDLER.remove(self, settings.AUTO_CAST_SKILL_CD)
Пример #37
0
 def remove_trapdoor_ticker(self):
     try:
         TICKER_HANDLER.remove(TRAPDOOR_TICK_SECONDS, self.tick_trapdoor)
     except KeyError:
         pass
Пример #38
0
 def remove_mana_ticker(self):
     try:
         TICKER_HANDLER.remove(MANA_TICK_SECONDS, self.tick_mana)
     except KeyError:
         pass
Пример #39
0
 def remove_mob_generator_ticker(self):
     try:
         TICKER_HANDLER.remove(MOB_GENERATOR_TICK_SECONDS,
                               self.tick_mob_generator)
     except KeyError:
         pass
Пример #40
0
 def stop_auto_combat_skill(self):
     """
     Stop auto cast skill.
     """
     self.can_auto_cast = False
     TICKER_HANDLER.remove(self, settings.AUTO_CAST_SKILL_CD)
Пример #41
0
 def __del__(self):
     """
     Remove tickers.
     """
     if self.can_auto_cast:
         TICKER_HANDLER.remove(self)
Пример #42
0
    def target_type_check(
        self, target
    ):  # This stuff could go into a pre_command thing, shrinking the code.
        caller = self.caller

        can_attack = False
        if utils.inherits_from(
                target,
                "typeclasses.characters.Character") or utils.inherits_from(
                    target,
                    "typeclasses.npcs.Combat_Mob") or utils.inherits_from(
                        target, "typeclasses.npcs.Combat_Merchant_Mob"):
            can_attack = True

        if not can_attack:
            caller.msg("You can't attack that.")
            return True

        # npc
        if utils.inherits_from(
                target, "typeclasses.npcs.Combat_Mob") or utils.inherits_from(
                    target, "typeclasses.npcs.Combat_Merchant_Mob"):
            if not target.db.alive:
                caller.msg("It's dead, %s. It has to be dead." % caller.name)
                return True
            npc_rules.npc_attacked(target)
            if self.caller in target.db.offended_by:
                target.db.offended_by.remove(self.caller)
            target.db.offended_by.insert(0, self.caller)
            caller.db.last_mob_target = target

            mob_damage = caller.db.level + caller.db.current_strength
            mob_damage = float(
                mob_damage) * caller.db.wielding[0].db.damage_multiplier
            target.db.health = target.db.health - int(mob_damage)

            string_c, string_t, string_r = rules.weapon_attack_messages(
                caller, target, caller.db.wielding[0])
            caller.msg(string_c)
            target.msg(string_t)
            caller.location.msg_contents(string_r, exclude=[caller, target])

            if target.db.health <= 0:
                target.db.health = 0
                caller.msg("You have slain %s." % target.name)
                string_r = "%s falls." % target.name
                caller.location.msg_contents(string_r,
                                             exclude=[caller, target])
                rules.exp_gain(caller, target)

                target.name = target.db.defeated_name
                target.db.offended_by = []
                target.db.tries_left = target.db.tries
                tickerhandler.remove(target.db.ticker_speed,
                                     target.npc_active_ticks)
                target.db.alive = False
                tickerhandler.add(
                    target.db.respawn_speed, target.npc_revive_ticks
                )  # this would actually go into MeleeCommand's function for when an npc is hit.

            MeleeCommand.endurance_loss(caller, 2)
            caller.db.balance_time = time.time(
            ) + 3.5 + caller.db.wielding[0].db.balance_duration_change

            return True