• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python localized_strings_handler._函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中muddery.utils.localized_strings_handler._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: func

    def func(self):
        "Continue a dialogue."
        caller = self.caller

        if not self.args:
            caller.msg({"alert":_("You should talk to someone.")})
            return

        npc = None
        if "npc" in self.args:
            if self.args["npc"]:
                # get NPC
                npc = caller.search(self.args["npc"], location=caller.location)
                if not npc:
                    caller.msg({"msg":_("Can not find it.")})
                    return

        # Get the current sentence.
        dialogue = ""
        sentence = 0

        have_current_dlg = False
        try:
            dialogue = self.args["dialogue"]
            sentence = int(self.args["sentence"])
            have_current_dlg = True
        except Exception, e:
            pass
开发者ID:kickreg,项目名称:muddery,代码行数:28,代码来源:general.py


示例2: take_off_position

    def take_off_position(self, position):
        """
        Take off an object from position.
        """
        if not position in self.db.equipments:
            raise MudderyError(_("Can not find this equipment."))

        if not self.db.equipments[position]:
            raise MudderyError(_("Can not find this equipment."))

        # Set object's attribute 'equipped' to False
        dbref = self.db.equipments[position]

        for obj in self.contents:
            if obj.dbref == dbref:
                obj.equipped = False
                find = True

        self.db.equipments[position] = None

        # reset character's attributes
        self.refresh_data()

        message = {"status": self.return_status(),
                   "equipments": self.return_equipments(),
                   "inventory": self.return_inventory()}
        self.msg(message)
开发者ID:kickreg,项目名称:muddery,代码行数:27,代码来源:player_characters.py


示例3: use_object

    def use_object(self, obj, number=1):
        """
        Use an object.

        Args:
            obj: (object) object to use
            number: (int) number to use

        Returns:
            result: (string) the description of the result
        """
        if not obj:
            return _("Can not find this object.")

        if obj.db.number < number:
            return _("Not enough number.")

        # take effect
        try:
            result, used = obj.take_effect(self, number)
            if used > 0:
                # remove used object
                self.remove_object(obj.get_data_key(), used)
            return result
        except Exception, e:
            ostring = "Can not use %s: %s" % (obj.get_data_key(), e)
            logger.log_tracemsg(ostring)
开发者ID:kickreg,项目名称:muddery,代码行数:27,代码来源:player_characters.py


示例4: func

    def func(self):
        """
        Implement the function.
        """
        combat_handler = self.caller.ndb.combat_handler
        if not combat_handler:
            # caller is not in combat.
            return

        self.obj = self.caller

        odd = 0.0
        if self.args:
            odd = self.args[0]

        rand = random.random()
        if rand >= odd:
            # escape failed
            return _("Failed.")

        # send skill's result to the combat handler manually
        # before the handler is removed from the character
        combat_handler.msg_all({"skill_cast": {"caller": self.caller.get_name(),
                                               "target": self.obj.get_name(),
                                               "skill": self.key,
                                               "cast": _("{c%s{n tried to escape.") % self.caller.get_name(),
                                               "result": _("Succeeded!")}})

        combat_handler.skill_escape(self.caller)
开发者ID:muddery,项目名称:muddery,代码行数:29,代码来源:skill.py


示例5: sell_to

    def sell_to(self, caller):
        """
        Buy this goods.

        Args:
            caller: the buyer

        Returns:

        """
        # check price
        unit_number = caller.get_object_number(self.unit_key)
        if unit_number < self.price:
            caller.msg({"alert": _("Sorry, %s is not enough.") % self.unit_name})
            return

        # check if can get these objects
        if not caller.can_get_object(self.db.goods.get_data_key(), self.number):
            caller.msg({"alert": _("Sorry, you can not take more %s.") % self.db.goods.get_name()})
            return

        # Reduce price units.
        if not caller.remove_object(self.unit_key, self.price):
            caller.msg({"alert": _("Sorry, %s is not enough.") % self.unit_name})
            return

        # Give goods.
        obj_list = [{"object": self.db.goods.get_data_key(),
                     "number": self.number}]
        caller.receive_objects(obj_list)
开发者ID:kickreg,项目名称:muddery,代码行数:30,代码来源:shop_goods.py


示例6: cast_skill

    def cast_skill(self, skill_key, target):
        """
        Cast a skill.

        Args:
            skill_key: (string) skill's key.
            target: (object) skill's target.
        """
        time_now = time.time()
        if time_now < self.gcd_finish_time:
            # In GCD.
            self.msg({"skill_cast": {"cast": _("Global cooling down!")}})
            return

        if skill_key not in self.db.skills:
            self.msg({"skill_cast": {"cast": _("You do not have this skill.")}})
            return

        skill = self.db.skills[skill_key]
        if not skill.cast_skill(target, passive=False):
            return

        if self.skill_gcd > 0:
            # set GCD
            self.gcd_finish_time = time_now + self.skill_gcd

        # send CD to the player
        cd = {"skill": skill_key,               # skill's key
              "cd": skill.cd,                   # skill's cd
              "gcd": self.skill_gcd}

        self.msg({"skill_cd": cd})
        return
开发者ID:muddery,项目名称:muddery,代码行数:33,代码来源:character.py


示例7: func

    def func(self):
        "Handle command"

        caller = self.caller
        if not caller:
            return
            
        if caller.db.level < settings.MIN_HONOUR_LEVEL:
            caller.msg({"alert":_("You need to reach level %s." % settings.MIN_HONOUR_LEVEL)})
            return
        
        try:
            # getcandidates
            ids = HONOURS_MAPPER.get_characters(caller, settings.HONOUR_OPPONENTS_NUMBER)
            characters = [caller.search_dbref("#%s" % id) for id in ids]
            candidates = [char for char in characters if char and not char.is_in_combat()]
            if candidates:
                match = random.choice(candidates)
                # create a new combat handler
                chandler = create_script(settings.HONOUR_COMBAT_HANDLER)
                # set combat team and desc
                chandler.set_combat({1:[match], 2:[caller]}, _("Fight of Honour"), settings.AUTO_COMBAT_TIMEOUT)
            else:
                caller.msg({"alert":_("Can not make match.")})
        except Exception, e:
            logger.log_err("Find match error: %s" % e)
            caller.msg({"alert":_("Can not make match.")})
开发者ID:muddery,项目名称:muddery,代码行数:27,代码来源:general.py


示例8: func

    def func(self):
        """
        Main puppet method
        """
        session = self.session
        player = self.account
        args = self.args

        # Find the character to puppet.
        new_character = None
        if args:
            # search for a matching character
            new_character = [char for char in search.object_search(args) if char.access(player, "puppet")]
            if not new_character:
                session.msg({"alert":_("That is not a valid character choice.")})
                return
            new_character = new_character[0]
        else: 
            # Puppet last character.
            new_character = player.db._last_puppet
            if not new_character:
                session.msg({"alert":_("You should puppet a character.")})
                return

        try:
            player.puppet_object(session, new_character)
            player.db._last_puppet = new_character
        except RuntimeError as exc:
            session.msg({"alert":_("{rYou cannot become {C%s{n: %s") % (new_character.name, exc)})
开发者ID:muddery,项目名称:muddery,代码行数:29,代码来源:player.py


示例9: announce_move_to

    def announce_move_to(self, source_location, msg=None, mapping=None, **kwargs):
        """
        Called after the move if the move was not quiet. At this point
        we are standing in the new location.

        Args:
            source_location (Object): The place we came from
            msg (str, optional): the replacement message if location.
            mapping (dict, optional): additional mapping objects.
            **kwargs (dict): Arbitrary, optional arguments for users
                overriding the call (unused by default).

        Notes:
            You can override this method and call its parent with a
            message to simply change the default message.  In the string,
            you can use the following as mappings (between braces):
                object: the object which is moving.
                exit: the exit from which the object is moving (if found).
                origin: the location of the object before the move.
                destination: the location of the object after moving.

        """

        if not source_location and self.location.has_account:
            # This was created from nowhere and added to an account's
            # inventory; it's probably the result of a create command.
            string = "You now have %s in your possession." % self.get_display_name(self.location)
            self.location.msg(string)
            return

        if source_location:
            if msg:
                string = msg
            else:
                string = _("{object} arrives to {destination} from {origin}.")
        else:
            string = _("{object} arrives to {destination}.")

        origin = source_location
        destination = self.location
        exits = []
        if origin:
            exits = [o for o in destination.contents if o.location is destination and o.destination is origin]

        if not mapping:
            mapping = {}

        mapping.update({
            "object": self.get_name(),
            "exit": exits[0].get_name() if exits else "",
            "origin": origin.get_name() if origin else "",
            "destination": destination.get_name() if destination else "",
        })

        destination.msg_contents(string.format(**mapping), exclude=(self, ))
开发者ID:muddery,项目名称:muddery,代码行数:55,代码来源:object.py


示例10: get_available_commands

 def get_available_commands(self, caller):
     """
     This returns a list of available commands.
     "args" must be a string without ' and ", usually it is self.dbref.
     """
     commands = []
     if self.db.number > 0:
         commands.append({"name": _("Use"), "cmd": "use", "args": self.dbref})
         if self.location and self.can_discard:
             commands.append({"name": _("Discard"), "cmd": "discard", "args": self.dbref})
     return commands
开发者ID:kickreg,项目名称:muddery,代码行数:11,代码来源:common_objects.py


示例11: create_normal_player

def create_normal_player(session, playername, password):
    """
    Create a new player.
    """
    # sanity checks
    if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 32):
        # this echoes the restrictions made by django's auth
        # module (except not allowing spaces, for convenience of
        # logging in).
        string = "\n\r Playername can max be 32 characters or fewer. Letters, spaces, digits and @/./+/-/_ only."
        session.msg({"alert":string})
        return
    # strip excessive spaces in playername
    playername = re.sub(r"\s+", " ", playername).strip()
    if AccountDB.objects.filter(username__iexact=playername):
        # player already exists (we also ignore capitalization here)
        session.msg({"alert":_("Sorry, there is already a player with the name '%s'.") % playername})
        return
    # Reserve playernames found in GUEST_LIST
    if settings.GUEST_LIST and playername.lower() in (guest.lower() for guest in settings.GUEST_LIST):
        string = "\n\r That name is reserved. Please choose another Playername."
        session.msg({"alert":string})
        return

    if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)):
        string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." \
                 "\nFor best security, make it longer than 8 characters. You can also use a phrase of" \
                 "\nmany words if you enclose the password in quotes."
        session.msg({"alert":string})
        return

    # Check IP and/or name bans
    bans = ServerConfig.objects.conf("server_bans")
    if bans and (any(tup[0]==playername.lower() for tup in bans)
                 or
                 any(tup[2].match(session.address) for tup in bans if tup[2])):
        # this is a banned IP or name!
        string = "{rYou have been banned and cannot continue from here." \
                 "\nIf you feel this ban is in error, please email an admin.{x"
        session.msg({"alert":string})
        session.execute_cmd('{"cmd":"quit","args":""}')
        return

    # everything's ok. Create the new player account.
    new_player = None
    try:
        new_player = create_player(playername, password)
    except Exception, e:
        # We are in the middle between logged in and -not, so we have
        # to handle tracebacks ourselves at this point. If we don't,
        # we won't see any errors at all.
        session.msg({"alert":_("There was an error creating the Player: %s" % e)})
        logger.log_tracemsg()
开发者ID:muddery,项目名称:muddery,代码行数:53,代码来源:unloggedin.py


示例12: func

    def func(self):
        """
        Uses the Django admin api. Note that unlogged-in commands
        have a unique position in that their func() receives
        a session object instead of a source_object like all
        other types of logged-in commands (this is because
        there is no object yet before the player has logged in)
        """
        session = self.caller
        args = self.args

        try:
            playername = args["playername"]
            password = args["password"]
        except Exception:
            string = 'Can not log in.'
            logger.log_errmsg(string)
            session.msg({"alert":string})
            return

        # check for too many login errors too quick.
        if _throttle(session, maxlim=5, timeout=5*60, storage=_LATEST_FAILED_LOGINS):
            # timeout is 5 minutes.
            session.msg({"alert":_("{RYou made too many connection attempts. Try again in a few minutes.{n")})
            return

        # Guest login
        if playername.lower() == "guest":
            enabled, new_player = create_guest_player(session)
            if new_player:
                session.msg({"login":{"name": playername, "dbref": new_player.dbref}})
                session.sessionhandler.login(session, new_player)
            if enabled:
                return

        if not password:
            session.msg({"alert":_("Please input password.")})
            return

        player = connect_normal_player(session, playername, password)
        if player:
            # actually do the login. This will call all other hooks:
            #   session.at_login()
            #   player.at_init()  # always called when object is loaded from disk
            #   player.at_first_login()  # only once, for player-centric setup
            #   player.at_pre_login()
            #   player.at_post_login(session=session)
            session.msg({"login":{"name": playername, "dbref": player.dbref}})
            session.sessionhandler.login(session, player)
开发者ID:muddery,项目名称:muddery,代码行数:49,代码来源:unloggedin.py


示例13: check_available

    def check_available(self):
        """
        Check this skill.

        Returns:
            message: (string) If the skill is not available, returns a string of reason.
                     If the skill is available, return "".
        """
        if self.passive:
            return _("This is a passive skill!")

        if self.is_cooling_down():
            return _("This skill is not ready yet!")

        return ""
开发者ID:kickreg,项目名称:muddery,代码行数:15,代码来源:character_skills.py


示例14: die

    def die(self, killers):
        """
        This character is killed. Move it to it's home.
        """

        # player's character can always reborn
        if self.reborn_time < 1:
            self.reborn_time = 1

        super(MudderyPlayerCharacter, self).die(killers)
        
        self.msg({"msg": _("You died.")})

        if self.reborn_time > 0:
            self.msg({"msg": _("You will be reborn at {c%(p)s{n in {c%(s)s{n seconds.") %
                             {'p': self.home.get_name(), 's': self.reborn_time}})
开发者ID:kickreg,项目名称:muddery,代码行数:16,代码来源:player_characters.py


示例15: at_after_move

    def at_after_move(self, source_location):
        """
        We make sure to look around after a move.

        """
        self.msg({"msg": _("Moving to %s ...") % self.location.name})
        self.show_location()
开发者ID:kickreg,项目名称:muddery,代码行数:7,代码来源:player_characters.py


示例16: turn_in

    def turn_in(self, quest_key):
        """
        Turn in a quest.

        Args:
            quest_key: (string) quest's key

        Returns:
            None
        """
        if quest_key not in self.current_quests:
            return

        if not self.current_quests[quest_key].is_accomplished:
            return

        # Get quest's name.
        name = self.current_quests[quest_key].get_name()

        # Call turn in function in the quest.
        self.current_quests[quest_key].turn_in()

        # Delete the quest.
        self.current_quests[quest_key].delete()
        del (self.current_quests[quest_key])

        self.finished_quests.add(quest_key)

        self.owner.msg({"msg": _("Turned in quest {c%s{n.") % name})
        self.show_quests()
        self.owner.show_location()
开发者ID:muddery,项目名称:muddery,代码行数:31,代码来源:quest_handler.py


示例17: get_appearance

    def get_appearance(self, caller):
        """
        This is a convenient hook for a 'look'
        command to call.
        """
        # Get name and description.
        if caller.is_exit_unlocked(self.get_data_key()):
            # If is unlocked, use common appearance.
            return super(MudderyLockedExit, self).get_appearance(caller)

        can_unlock = self.can_unlock(caller)

        if self.auto_unlock and can_unlock:
            # Automatically unlock the exit when a character looking at it.
            caller.unlock_exit(self)
            
            # If is unlocked, use common appearance.
            return super(MudderyLockedExit, self).get_appearance(caller)

        cmds = []
        if can_unlock:
            # show unlock command
            verb = self.unlock_verb
            if not verb:
                verb = _("Unlock")
            cmds = [{"name": verb, "cmd": "unlock_exit", "args": self.dbref}]
        
        info = {"dbref": self.dbref,
                "name": self.name,
                "desc": self.locked_desc,
                "cmds": cmds}
                
        return info
开发者ID:muddery,项目名称:muddery,代码行数:33,代码来源:locked_exit.py


示例18: cast_skill

    def cast_skill(self, target):
        """
        Cast this skill.

        Args:
            target: (object) skill's target

        Returns:
            (result, cd):
                result: (dict) skill's result
                cd: (dice) skill's cd
        """
        owner = self.db.owner
        time_now = time.time()

        if not self.passive:
            if time_now < self.db.cd_finish_time:
                # skill in CD
                if owner:
                    owner.msg({"msg": _("This skill is not ready yet!")})
                return

        # call skill function
        STATEMENT_HANDLER.do_skill(self.function, owner, target,
                                   key=self.get_data_key(), name=self.get_name(),
                                   message=self.message)

        if not self.passive:
            # set cd
            time_now = time.time()
            if self.cd > 0:
                self.db.cd_finish_time = time_now + self.cd

        return
开发者ID:kickreg,项目名称:muddery,代码行数:34,代码来源:character_skills.py


示例19: get_available_commands

 def get_available_commands(self, caller):
     """
     This returns a list of available commands.
     """
     commands = []
     if GAME_SETTINGS.get("can_give_up_quests"):
         commands.append({"name": _("Give Up"), "cmd": "giveup_quest", "args": self.get_data_key()})
     return commands
开发者ID:kickreg,项目名称:muddery,代码行数:8,代码来源:character_quests.py


示例20: get_available_commands

 def get_available_commands(self, caller):
     """
     This returns a list of available commands.
     """
     commands = []
     if self.is_alive():
         commands.append({"name": _("Attack"), "cmd": "attack", "args": self.dbref})
     return commands
开发者ID:kickreg,项目名称:muddery,代码行数:8,代码来源:monsters.py



注:本文中的muddery.utils.localized_strings_handler._函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python localiztion_handler.localize_form_fields函数代码示例发布时间:2022-05-27
下一篇:
Python python3.PythonMode类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap