Ejemplo n.º 1
0
    def after_data_loaded(self):
        """
        Load goods data.

        Returns:
            None
        """
        self.available = False

        self.shop_key = getattr(self.system, "shop", "")
        self.goods_key = getattr(self.system, "goods", "")
        self.goods_level = getattr(self.system, "level", 0)

        # set goods information
        self.price = getattr(self.system, "price", 0)
        self.unit_key = getattr(self.system, "unit", "")
        self.number = getattr(self.system, "number", 0)
        self.condition = getattr(self.system, "condition", "")

        # get price unit information
        try:
            # Get record.
            obj_model_name = TYPECLASS("OBJECT").model_name
            unit_record = WorldData.get_table_data(obj_model_name,
                                                   key=self.unit_key)
            unit_record = unit_record[0]
        except Exception as e:
            logger.log_errmsg("Can not find %s's price unit %s." %
                              (self.goods_key, self.unit_key))
            return

        self.unit_name = unit_record.name

        # load goods
        try:
            obj_record = WorldData.get_table_data(obj_model_name,
                                                  key=self.goods_key)
            obj_record = obj_record[0]
            goods_models = TYPECLASS_SET.get_class_modeles(
                obj_record.typeclass)
            goods_data = WorldData.get_tables_data(goods_models,
                                                   key=self.goods_key)
        except Exception as e:
            logger.log_errmsg("Can not find goods %s." % self.goods_key)
            return

        self.name = goods_data["name"]
        self.desc = goods_data["desc"]
        self.icon = goods_data.get("icon", None)

        self.available = True
Ejemplo n.º 2
0
    def calc_combat_rewards(self, winners, losers):
        """
        Called when the character wins the combat.

        Args:
            winners: (List) all combat winners.
            losers: (List) all combat losers.

        Returns:
            (dict) reward dict
        """
        rewards = {}
        for winner in winners:
            winner_char = self.characters[winner]["char"]
            exp = 0
            loots = []
            for loser in losers:
                loser_char = self.characters[loser]["char"]
                exp += loser_char.provide_exp(self)
                obj_list = loser_char.loot_handler.get_obj_list(winner_char)
                if obj_list:
                    loots.extend(obj_list)

            obj_list = []
            if loots:
                obj_model_name = TYPECLASS("OBJECT").model_name

                for obj_info in loots:
                    try:
                        obj_record = WorldData.get_table_data(obj_model_name, key=obj_info["object"])
                        obj_record = obj_record[0]
                        goods_models = TYPECLASS_SET.get_class_modeles(obj_record.typeclass)
                        goods_data = WorldData.get_tables_data(goods_models, key=obj_info["object"])

                        obj_list.append({
                            "object": obj_info["object"],
                            "number": obj_info["number"],
                            "name": goods_data["name"],
                            "icon": goods_data.get("icon", None),
                            "reject": "",
                        })
                    except Exception as e:
                        logger.log_errmsg("Can not loot object %s." % obj_info["object"])
                        pass

            rewards[winner] = {
                "exp": exp,
                "loots": obj_list,
            }

        return rewards