Exemplo n.º 1
0
    def _calc_upgrade(self, data, req, timer):
        """进行升级
        """
        #涉及到跨天的数据统计,所以此处要更新所有跨天数据
        if not account_business.update_across_day_info(data, timer.now):
            raise Exception("Update across day info failed")

        node_basic_id = req.node.basic_id
        node_id = NodeInfo.generate_id(data.id, node_basic_id)
        node = data.node_list.get(node_id)
        gold = 0
        if req.HasField("gold"):
            gold = req.gold

        if not exploitation_business.finish_upgrade_event(
                data, node, timer.now, gold):
            raise Exception("Finish upgrade event failed")

        resource = data.resource.get(True)
        res = self._pack_upgrade_response(data, resource, node, timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._upgrade_succeed, req, res, timer)
        return defer
Exemplo n.º 2
0
    def _pack_rematch_node_response(self, matcher, data, node, req, timer):
        res = map_pb2.RematchNodeRes()
        res.status = 0
        pack.pack_node_info(data, node, res.node, timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._rematch_node_succeed, req, res, timer)
        return defer
Exemplo n.º 3
0
    def _update_all_info(self, proxy, basic_data, data, req, timer):
        """用户登录游戏服时,载入数据,更新所有离线的信息
        """
        #更新离线数据
        if not self._update_offline_info(basic_data, data, timer.now):
            raise Exception("Update offline info failed")

        map_business.check_map_data(data)

        #更新数据
        defer = DataBase().commit(data)
        return defer
Exemplo n.º 4
0
    def _pack_abandon_node_response(self, matcher, data, change_nodes, req,
                                    timer):
        res = event_pb2.AbandonNodeRes()
        res.status = 0
        for node in change_nodes:
            pack.pack_node_info(data, node, res.nodes.add(), timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._abandon_node_succeed, req, res, timer)
        return defer
Exemplo n.º 5
0
    def _pack_finish_appoint_response(self, matcher, data, node_list, items,
                                      heroes, mails, req, timer):
        """构造返回
        args:
            items : list((num, basic_id)元组)
            heroes: list((basic_id, level, exp, battle_node_basic_id )元组)
        Returns:
            res[protobuf]: 向客户端的返回的响应
        """
        resource = data.resource.get(True)
        user = data.user.get(True)

        conscript_list = data.conscript_list.get_all(True)

        res = appoint_pb2.FinishAppointRes()
        res.status = 0
        res.ret = appoint_pb2.FinishAppointRes.OK

        pack.pack_resource_info(resource, res.resource)
        pack.pack_monarch_info(user, res.monarch)
        for conscript in conscript_list:
            pack.pack_conscript_info(conscript, res.conscripts.add(),
                                     timer.now)
        for node in node_list:
            pack.pack_node_info(data, node, res.nodes.add(), timer.now)

        for item in items:
            pack.pack_item_info(item, res.items.add())

        for hero in heroes:
            hero_message = res.heros.add()
            hero_message.basic_id = hero[0]
            hero_message.level = hero[1]
            hero_message.exp = hero[2]
            hero_message.battle_node_id = hero[3]

        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)

        if 'is_battle_cost_energy' in account_business.get_flags():
            energy = data.energy.get()
            energy.update_current_energy(timer.now)
            pack.pack_energy_info(energy, res.energy, timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._finish_appoint_succeed, req, res, timer)
        return defer
Exemplo n.º 6
0
    def _pack_event_response(self, matcher, data, items, mails, nodes, type,
                             req, timer):
        """打包返回 response
        """
        resource = data.resource.get(True)
        map = data.map.get(True)

        #更新邮件中的敌人信息
        for mail in mails:
            if mail.related_node_id in matcher.players:
                rival_id = mail.related_node_id
                rival = data.rival_list.get(rival_id)
                mail.attach_enemy_info(rival)
            else:
                node = data.node_list.get(mail.related_node_id)
                if node.is_key_node():
                    mail.attach_enemy_detail(
                        NameGenerator().gen(), 0,
                        NodeInfo.ENEMY_TYPE_PVE_RESOURCE)  #TODO 随机

        #打包响应
        res = map_pb2.TriggerEventRes()
        res.status = 0

        #res.map.next_war_gap = map.next_war_time - timer.now
        res.map.next_luck_gap = map.next_luck_time - timer.now
        for node in nodes:
            pack.pack_node_info(data, node, res.map.nodes.add(), timer.now)
        pack.pack_resource_info(resource, res.resource)
        for item in items:
            item_message = res.items.add()
            item_message.basic_id = item[1]
            item_message.num = item[0]
        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)
        energy = data.energy.get(True)
        pack.pack_energy_info(energy, res.energy_info, timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._trigger_event_succeed, req, res, timer)
        return defer
Exemplo n.º 7
0
    def _pack_clear_lucky_event_response(self, matcher, data, change_nodes,
                                         items, mails, req, timer):
        """打包
        """
        resource = data.resource.get()
        map = data.map.get()

        #更新邮件中的敌人信息
        for mail in mails:
            if mail.related_node_id in matcher.players:
                rival_id = mail.related_node_id
                rival = data.rival_list.get(rival_id)
                mail.attach_enemy_info(rival)
            else:
                node = data.node_list.get(mail.related_node_id)
                if node.is_key_node():
                    mail.attach_enemy_detail(
                        NameGenerator().gen(), 0,
                        NodeInfo.ENEMY_TYPE_PVE_RESOURCE)  #TODO 随机

        #打包响应
        res = map_pb2.ClearLuckyEventRes()
        res.status = 0
        res.ret = map_pb2.ClearLuckyEventRes.OK

        for node in change_nodes:
            pack.pack_node_info(data, node, res.nodes.add(), timer.now)
        pack.pack_resource_info(resource, res.resource)
        for item in items:
            item_message = res.items.add()
            item_message.basic_id = item[1]
            item_message.num = item[0]
        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._clear_lucky_event_succeed, req, res, timer)
        return defer