Пример #1
0
    def _query_basic_activity_succeed(self, basic_data, activities,
                                      with_detail, req, timer):
        """
        """
        res = activity_pb2.QueryBasicActivityRes()
        res.status = 0
        for activity in activities:
            msg = res.activities.add()
            pack.pack_basic_activity_info(activity, msg, timer.now)

            if with_detail:
                #steps
                steps_id = activity.get_steps()
                for step_id in steps_id:
                    step = basic_data.activity_step_list.get(step_id)
                    if step is None:
                        logger.warning("not exist activity step[id=%d]" %
                                       step_id)
                        continue
                    pack.pack_basic_activity_step_info(step,
                                                       msg.steps_info.add(),
                                                       timer.now)

                #rewards
                if activity.hero_basic_id != 0:
                    rewards_id = BasicActivityHeroRewardInfo.generate_all_ids(
                        activity.hero_basic_id)
                    for reward_id in rewards_id:
                        reward = basic_data.activity_hero_reward_list.get(
                            reward_id)
                        if reward is None:
                            logger.warning(
                                "not exist activity hero reward[id=%d]" %
                                reward_id)
                            continue
                        pack.pack_basic_hero_reward_info(
                            reward, msg.hero_rewards_info.add(), timer.now)
                #treasure
                if activity.type_id == 29:
                    rewards_id = BasicActivityHeroRewardInfo.generate_all_ids(
                        activity.id)
                    for reward_id in rewards_id:
                        reward = basic_data.activity_hero_reward_list.get(
                            reward_id)
                        if reward is None:
                            logger.warning(
                                "not exist activity treasure reward[id=%d]" %
                                reward_id)
                            continue
                        pack.pack_basic_reward_info(reward, msg.rewards_info,
                                                    timer.now)
        response = res.SerializeToString()
        logger.notice("Query basic activity succeed"
                      "[user_id=%d][req=%s][res=%s][consume=%d]" %
                      (timer.id, req, res, timer.count_ms()))
        return response
Пример #2
0
def pack_activity_info(activity, basic_activity, basic_steps, message, now, basic_data, data, cat_list ):
    message.id = activity.basic_id
    message.type_id = basic_activity.type_id
    
    if len(basic_activity.description) > 0:
        message.description = base64.b64decode(basic_activity.description)#.encode('utf-8')
    if len(basic_activity.icon_name) > 0:
        message.icon_name = base64.b64decode(basic_activity.icon_name)#.encode('utf-8')
    if len(basic_activity.name) > 0:
        message.title = base64.b64decode(basic_activity.name)#.encode('utf-8')
    for value in activity.get_step_progress():
        message.step_progress.append(value)
    for status in activity.get_reward_status():
        message.reward_status.append(status)
    for target in activity.get_step_target():
        message.step_target.append(target)

    if activity.has_time_limit():
        message.duration = activity.end_time - now

    if activity.start_time != 0:
        ltime = time.localtime(activity.start_time)
        message.begin_date = time.strftime("%Y-%m-%d", ltime)#.encode('utf-8')
        if activity.end_time != 0:
            #结束时间是0点,需要减1s,否则日期错误
            ltime = time.localtime(activity.end_time - 1)
            message.end_date = time.strftime("%Y-%m-%d", ltime)#.encode('utf-8') 

    step_status = activity.get_reward_status()
    for step_index in range(0, len(step_status)):
        step_id = basic_activity.get_steps()[step_index]
        step_info_proto = message.step_infos.add()
        step_info_proto.id = step_id

        for basic_step in basic_steps:
            if step_id == basic_step.id:
                stepInfo = basic_step
                break;

        for hero_basic_id in stepInfo.get_heroes_basic_id():
            step_info_proto.reward_hero_basic_ids.append(hero_basic_id)

        items = stepInfo.get_items()
        items_id = []
        items_num = []
        for item in items:
            items_id.append(item[0])
            items_num.append(item[1])

        for i in range(0, len(items_id)):
            item = step_info_proto.reward_items.add()
            item.basic_id = items_id[i]
            item.num = items_num[i]

        if stepInfo.gold > 0:
            step_info_proto.reward_gold = stepInfo.gold

        if stepInfo.value1 > 0:
            step_info_proto.value1 = stepInfo.value1

        if stepInfo.value2 > 0:
            step_info_proto.value2 = stepInfo.value2
        if len(stepInfo.description) > 0:
            step_info_proto.description = base64.b64decode(stepInfo.description)#.encode('utf-8')

    resource = data.resource.get()
    if (basic_activity.type_id == 
            int(float(data_loader.OtherBasicInfo_dict["activity_hero_type_id"].value))):
        message.hero_basic_id = basic_activity.hero_basic_id
    elif basic_activity.type_id == 30 :
        message.hero_basic_id = resource.total_gain_cat
        for cat in cat_list:
            msg_cat = message.cats.add()
            msg_cat.name = cat.name
            msg_cat.gold = cat.gold

    if basic_activity.type_id == 29 :
        rewards_id = BasicActivityHeroRewardInfo.generate_all_ids(basic_activity.id)
        for reward_id in rewards_id:
            reward_info_proto = message.rewards_info.add()
            
            reward = basic_data.activity_hero_reward_list.get(reward_id)
            if reward is None:
                logger.warning("not exist activity treasure reward[id=%d]" % reward_id)
                continue
            reward_info_proto.id = reward_id
            reward_info_proto.level = reward.level
            item = reward.get_items()
            reward_info_proto.reward_item.basic_id = item[0][0]
            reward_info_proto.reward_item.num = item[0][1]
               

    message.weight = basic_activity.weight