当前位置: 首页>>代码示例>>Python>>正文


Python Inventory.ref_in方法代码示例

本文整理汇总了Python中inventory.Inventory.ref_in方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.ref_in方法的具体用法?Python Inventory.ref_in怎么用?Python Inventory.ref_in使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inventory.Inventory的用法示例。


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

示例1: Character

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import ref_in [as 别名]
class Character(object):
    """
    Define a character and its abilities
    """

    def __init__(self, reference=None, **custom):
        if reference:
            try:
                data = get_character_data(reference)
            except ValueError:
                raise UnexistingCharacterException(
                    "The reference \"{}\" doesn't exist".format(reference))
            else:
                for key in LIST_CARAC:
                    if not key in data:
                        data[key] = get_character_data("unknown")[key]
        else:
            data = get_character_data("unknown")
        self._health = 0
        self._inventory = inventory.Inventory()
        self.name = self.operations(custom.get("name", data["name"]))
        self.maxhealth = self.operations(custom.get(
            "maxhealth", data["maxhealth"]))
        self.health = custom.get("health", self.maxhealth)
        self.range_attack = self.operations(custom.get(
            "range_attack", data["range_attack"]))
        self.attack = self.operations(custom.get(
            "attack", data["attack"]))
        self.defense = self.operations(custom.get(
            "defense", data["defense"]))
        self.initiative = self.operations(custom.get(
            "initiative", data["initiative"]))
        self.inventory = Inventory(custom.get("inventory", data.get("inventory", None)))
        self.abilities = self.operations(custom.get(
            "abilities", data["abilities"]))  # Not used in this version
        self.ref = reference
        self.weapon = self.inventory.weapons[0]  # Take the first
                                                 # weapon found

    @property
    def inventory(self):
        return self._inventory

    @inventory.setter
    def inventory(self, value):
        self._inventory = value
        if not self.inventory.ref_in(inventory.create_item("bare_hands")):
            self.inventory.add(inventory.create_item("bare_hands"))

    @property
    def is_alive(self):
        return self.health > 0

    @property
    def is_dead(self):
        return not self.is_alive

    @property
    def health(self):
        return max(0, min(self._health, self.maxhealth))

    @health.setter
    def health(self, value):
        self._health = max(0, min(value, self.maxhealth))

    def operations(self, caract):
        """Calcule les valeurs aléatoire d'un Character"""
        if isinstance(caract, dict) and "_random_" in caract:
            if caract["_random_"] == "gauss":
                result = -1
                while not(caract.get("min", 0) <= result
                          and result <= caract.get("max", 10 ** 5)):
                    result = int(gauss(caract["mean"],
                                       caract["deviation"]) / 10) * 10
            elif caract["random"] == "choice":
                if caract["max_items"] < 1:
                    result = caract["items"][randint(0, len(caract["items"]))]
                else:
                    item = None
                    result = None
                    for i in caract["max_items"]:
                        while not item or item in result:
                            item = caract["items"][randint(
                                0, len(caract["items"]))]
                        result.append(item)
            elif caract["random"] == "equiproba":
                caract = int(randint(caract["min"], caract["max"]) / 10) * 10
            return result
        else:
            return caract

    def __str__(self):
        return str(self.__dict__)
开发者ID:PaulEcoffet,项目名称:stonewallsgate,代码行数:95,代码来源:character.py


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