Example #1
0
def receive_rob_task(player, task_id, task_guild_id):
    """
    接受劫运任务
    """
    receive_rob_times = player.finance[const.GUILD_ESCORT_ROB_TIMES]
    escort_open_time_item = game_configs.base_config.get("EscortOpenTime")
    if not is_in_period(escort_open_time_item):
        logger.error("feature not open!")
        return {'result': False, 'result_no': 30000}

    if receive_rob_times <= 0:
        logger.error("receive_rob_times! %s" % receive_rob_times)
        return {'result': False, 'result_no': 190901}

    escort_component = player.escort_component
    task = remote_gate["world"].get_task_by_id_remote(task_guild_id, task_id)
    if task.get('state') != 2:
        logger.error("task state not right! %s" % task.get("state"))
        return {'result': False, 'result_no': 190902}

    #if player.base_info.id in task.get('rob_task_infos') and task.get():
        #logger.debug("this task has been robbed!")
        #return {'result': False, 'result_no': 190902}

    logger.debug("receive_rob_task, start=======")
    res = remote_gate["world"].add_player_remote(task_guild_id, task_id, get_player_info(player), 2, -1, {})
    logger.debug("receive_rob_task, end=======")
    if res.get('result'):
        escort_component.rob_records[task.get("task_id")] = dict(guild_id=task_guild_id, rob_no=res.get('task').get('rob_task_infos')[0].get('rob_no'))
        escort_component.save_data()

    return res
Example #2
0
def invite_1908(data, player):
    """发送/接受邀请"""
    request = escort_pb2.InviteEscortTaskRequest()
    request.ParseFromString(data)
    logger.debug("request %s" % request)
    response = common_pb2.CommonResponse()
    task_id = request.task_id
    send_or_in = request.send_or_in
    protect_or_rob = request.protect_or_rob
    task_guild_id = request.task_guild_id
    rob_no = request.rob_no

    escort_open_time_item = game_configs.base_config.get("EscortOpenTime")
    if not is_in_period(escort_open_time_item):
        logger.error("feature not open!")
        response.result = False
        response.result_no = 30000
        return response.SerializePartialToString()
    res = None
    if send_or_in == 1:
        res = send_invite(player, task_id, protect_or_rob, task_guild_id, rob_no)
    elif send_or_in == 2:
        res = in_invite(player, task_id, protect_or_rob, task_guild_id, rob_no)

    response.result = res.get('result')
    if not res.get('result'):
        response.result_no = res.get('result_no')
        return response.SerializePartialToString()

    tlog_action.log('GuildTaskInvite', player, task_id, task_guild_id, send_or_in, protect_or_rob, rob_no)
    response.result = True
    return response.SerializePartialToString()
Example #3
0
def invite_1908(data, player):
    """发送/接受邀请"""
    request = escort_pb2.InviteEscortTaskRequest()
    request.ParseFromString(data)
    logger.debug("request %s" % request)
    response = common_pb2.CommonResponse()
    task_id = request.task_id
    send_or_in = request.send_or_in
    protect_or_rob = request.protect_or_rob
    task_guild_id = request.task_guild_id
    rob_no = request.rob_no

    escort_open_time_item = game_configs.base_config.get("EscortOpenTime")
    if not is_in_period(escort_open_time_item):
        logger.error("feature not open!")
        response.result = False
        response.result_no = 30000
        return response.SerializePartialToString()
    res = None
    if send_or_in == 1:
        res = send_invite(player, task_id, protect_or_rob, task_guild_id,
                          rob_no)
    elif send_or_in == 2:
        res = in_invite(player, task_id, protect_or_rob, task_guild_id, rob_no)

    response.result = res.get('result')
    if not res.get('result'):
        response.result_no = res.get('result_no')
        return response.SerializePartialToString()

    tlog_action.log('GuildTaskInvite', player, task_id, task_guild_id,
                    send_or_in, protect_or_rob, rob_no)
    response.result = True
    return response.SerializePartialToString()
Example #4
0
def start_protect_escort(player, task_guild_id, task_id):
    """docstring for start_protect_escort"""

    escort_open_time_item = game_configs.base_config.get("EscortOpenTime")
    if not is_in_period(escort_open_time_item):
        logger.error("feature not open!")
        return {'result': False, 'result_no': 30000}

    res = remote_gate["world"].start_protect_task_remote(task_guild_id, task_id)

    # 参与押运次数
    task = res.get("task")
    for no, protecter in enumerate(task.get("protecters")):
        if no == 0: continue
        push_message("remove_escort_in_times_remote", int(protecter.get("id")), 1)
    return {"result": True}
Example #5
0
def start_protect_escort(player, task_guild_id, task_id):
    """docstring for start_protect_escort"""

    escort_open_time_item = game_configs.base_config.get("EscortOpenTime")
    if not is_in_period(escort_open_time_item):
        logger.error("feature not open!")
        return {'result': False, 'result_no': 30000}

    res = remote_gate["world"].start_protect_task_remote(
        task_guild_id, task_id)

    # 参与押运次数
    task = res.get("task")
    for no, protecter in enumerate(task.get("protecters")):
        if no == 0: continue
        push_message("remove_escort_in_times_remote", int(protecter.get("id")),
                     1)
    return {"result": True}
Example #6
0
def receive_protect_task(player, task_id):
    """接受保护任务"""
    escort_component = player.escort_component
    task_info = escort_component.tasks.get(task_id)
    if not task_info:
        logger.error("can't find this task_info!")
        return {'result': False, 'result_no': 190501}

    escort_open_time_item = game_configs.base_config.get("EscortOpenTime")
    if not is_in_period(escort_open_time_item):
        logger.error("feature not open!")
        return {'result': False, 'result_no': 30000}

    res = remote_gate["world"].get_guild_info_remote(player.guild.g_id,
                                                     "build", 0)
    if not res.get("result"):
        logger.error("get guild info error!")
        return res

    build = res.get("build")
    guild_item = game_configs.guild_config.get(4).get(build.get(4))

    escort_component = player.escort_component
    if escort_component.start_protect_times >= guild_item.escortTimeMax:
        logger.error("start_protect_times not enough!")
        return {'result': False, 'result_no': 190502}

    task_info["state"] = 1
    task_info["player_info"] = get_player_info(player)
    escort_component.protect_records[task_id] = dict(
        guild_id=player.guild.g_id)
    escort_component.save_data()
    res = remote_gate["world"].add_task_remote(player.guild.g_id, task_info)
    if not res.get("result"):
        return res

    escort_component.start_protect_times += 1
    escort_component.save_data()
    return {'result': True}
Example #7
0
def receive_protect_task(player, task_id):
    """接受保护任务"""
    escort_component = player.escort_component
    task_info = escort_component.tasks.get(task_id)
    if not task_info:
        logger.error("can't find this task_info!")
        return {'result': False, 'result_no': 190501}

    escort_open_time_item = game_configs.base_config.get("EscortOpenTime")
    if not is_in_period(escort_open_time_item):
        logger.error("feature not open!")
        return {'result': False, 'result_no': 30000}

    res = remote_gate["world"].get_guild_info_remote(player.guild.g_id, "build", 0)
    if not res.get("result"):
        logger.error("get guild info error!")
        return res

    build = res.get("build")
    guild_item = game_configs.guild_config.get(4).get(build.get(4))


    escort_component = player.escort_component
    if escort_component.start_protect_times >= guild_item.escortTimeMax:
        logger.error("start_protect_times not enough!")
        return {'result': False, 'result_no': 190502}

    task_info["state"] = 1
    task_info["player_info"] = get_player_info(player)
    escort_component.protect_records[task_id] = dict(guild_id=player.guild.g_id)
    escort_component.save_data()
    res = remote_gate["world"].add_task_remote(player.guild.g_id, task_info)
    if not res.get("result"):
        return res

    escort_component.start_protect_times += 1
    escort_component.save_data()
    return {'result': True}
Example #8
0
def receive_rob_task(player, task_id, task_guild_id):
    """
    接受劫运任务
    """
    receive_rob_times = player.finance[const.GUILD_ESCORT_ROB_TIMES]
    escort_open_time_item = game_configs.base_config.get("EscortOpenTime")
    if not is_in_period(escort_open_time_item):
        logger.error("feature not open!")
        return {'result': False, 'result_no': 30000}

    if receive_rob_times <= 0:
        logger.error("receive_rob_times! %s" % receive_rob_times)
        return {'result': False, 'result_no': 190901}

    escort_component = player.escort_component
    task = remote_gate["world"].get_task_by_id_remote(task_guild_id, task_id)
    if task.get('state') != 2:
        logger.error("task state not right! %s" % task.get("state"))
        return {'result': False, 'result_no': 190902}

    #if player.base_info.id in task.get('rob_task_infos') and task.get():
    #logger.debug("this task has been robbed!")
    #return {'result': False, 'result_no': 190902}

    logger.debug("receive_rob_task, start=======")
    res = remote_gate["world"].add_player_remote(task_guild_id, task_id,
                                                 get_player_info(player), 2,
                                                 -1, {})
    logger.debug("receive_rob_task, end=======")
    if res.get('result'):
        escort_component.rob_records[task.get("task_id")] = dict(
            guild_id=task_guild_id,
            rob_no=res.get('task').get('rob_task_infos')[0].get('rob_no'))
        escort_component.save_data()

    return res
Example #9
0
def battle_2103(pro_data, player):
    """
    开始战斗
    request:HjqyBattleRequest
    response:HjqyBattleResponse
    """
    request = hjqy_pb2.HjqyBattleRequest()
    request.ParseFromString(pro_data)
    response = hjqy_pb2.HjqyBattleResponse()

    if player.base_info.is_firstday_from_register(const.OPEN_FEATURE_HJQY):
        response.res.result = False
        response.res.result_no = 150901
        return response.SerializeToString()
    boss_id = request.owner_id
    attack_type = request.attack_type  # 全力一击,普通攻击
    logger.debug("request %s" % request)

    hjqyExchangeBUFFTime = game_configs.base_config.get("hjqyExchangeBUFFTime")
    hjqyItemRate = game_configs.base_config.get("hjqyItemRate")

    hjqyExchangeBUFFNumber = game_configs.base_config.get(
        "hjqyExchangeBUFFNumber")
    hjqyExchangeNumber = game_configs.base_config.get("hjqyExchangeNumber")
    need_hjqy_fight_token = hjqyExchangeNumber
    if attack_type == 2:
        need_hjqy_fight_token = hjqyExchangeBUFFNumber
    if is_in_period(hjqyExchangeBUFFTime) and attack_type == 2:
        need_hjqy_fight_token = need_hjqy_fight_token * hjqyItemRate

    if need_hjqy_fight_token > player.finance[const.HJQYFIGHTTOKEN]:
        logger.error("hjqy coin not enough!")
        response.res.result = False
        response.res.result_no = 210301
        return response.SerializePartialToString()

    data = remote_gate['world'].get_boss_info_remote(boss_id)

    if not data or data.get('state') == const.BOSS_DEAD:
        logger.error("hjqy boss dead!")
        response.res.result = False
        response.res.result_no = 210302
        return response.SerializePartialToString()
    if data.get('state') == const.BOSS_RUN_AWAY:
        logger.error("hjqy boss run away!")
        response.res.result = False
        response.res.result_no = 210303
        return response.SerializePartialToString()

    stage_id = data.get("stage_id")
    player.fight_cache_component.stage_id = stage_id
    red_units = player.fight_cache_component.get_red_units()

    blue_units = cPickle.loads(remote_gate['world'].blue_units_remote(boss_id))

    seed1, seed2 = get_seeds()
    player_info = dict(player_id=player.base_info.id,
                       nickname=player.base_info.base_name,
                       user_icon=player.base_info.heads.now_head,
                       level=player.base_info.level)

    str_red_units = cPickle.dumps(red_units)
    red_unpar_data = player.line_up_component.get_red_unpar_data()
    fight_result, boss_state, current_damage_hp, is_kill = remote_gate[
        'world'].hjqy_battle_remote(player_info, boss_id, str_red_units,
                                    red_unpar_data, attack_type, seed1, seed2)

    logger.debug("============battle over")

    # 消耗讨伐令
    player.finance.consume(const.HJQYFIGHTTOKEN, need_hjqy_fight_token,
                           const.HJQY_BATTLE)

    # 功勋奖励
    hjqyMeritoriousServiceOpenTime = game_configs.base_config.get(
        "hjqyMeritoriousServiceOpenTime")
    hjqyMeritoriousServiceRate = game_configs.base_config.get(
        "hjqyMeritoriousServiceRate")
    meritorious_service = player.fight_cache_component._get_stage_config(
    ).meritorious_service
    logger.debug("========= %s %s ========" %
                 (is_in_period(hjqyMeritoriousServiceOpenTime),
                  hjqyMeritoriousServiceOpenTime))
    if is_in_period(hjqyMeritoriousServiceOpenTime):  # 增加功勋的活动
        meritorious_service = meritorious_service * hjqyMeritoriousServiceRate
    player.finance.add(const.HJQYCOIN,
                       meritorious_service,
                       reason=const.HJQY_BATTLE)
    player.finance.save_data()

    response.fight_result = fight_result
    pvp_assemble_units(red_units, blue_units, response)
    response.seed1 = seed1
    response.seed2 = seed2
    response.attack_type = attack_type
    response.hjqy_coin = meritorious_service
    response.stage_id = stage_id
    response.res.result = True

    hook_task(player, CONDITIONId.HJQY, 1)

    tlog_action.log('BattleHJQY', player, boss_id, is_kill)

    # start target
    all_current_damage_hp = remote_gate['world'].\
        hjqy_damage_hp_remote(player.base_info.id)
    player.act.condition_update(38, current_damage_hp)
    player.act.condition_update(39, all_current_damage_hp)
    # 更新 七日奖励
    target_update(player, [38, 39])

    return response.SerializePartialToString()
Example #10
0
def trigger_boss_2402(pro_data, player):
    """召唤圣兽
    """
    guild_boss_open_time_item = game_configs.base_config.get("AnimalOpenTime")
    response = guild_pb2.TriggerGuildBossResponse()
    response.res.result = False
    if not is_in_period(guild_boss_open_time_item):
        logger.debug("feature not open!")
        response.res.result_no = 30000
        return response.SerializeToString()

    request = guild_pb2.TriggerGuildBossRequest()
    request.ParseFromString(pro_data)
    logger.debug("request %s" % request)
    boss_type = request.boss_type
    trigger_stone_num = player.finance[const.GUILD_BOSS_TRIGGER_STONE]

    data = remote_gate['world'].guild_boss_init_remote(player.guild.g_id)
    build = data.get("build")
    guild_boss_trigger_times = data.get("guild_boss_trigger_times")
    guild_boss_item = game_configs.guild_config.get(4).get(build.get(4))
    logger.debug("guild_boss_item %s" % guild_boss_item)
    boss_open_item = guild_boss_item.animalOpen.get(boss_type)
    stage_id = boss_open_item[0]
    consume_num = boss_open_item[2]

    # 召唤石是否足够
    if trigger_stone_num < boss_open_item[2]:
        logger.debug("trigger stone is not enough!")
        response.res.result_no = 240201
        return response.SerializeToString()
    # 召唤次数是否达到上限
    if guild_boss_trigger_times >= guild_boss_item.animalOpenTime:
        logger.debug("trigger times reach the max!")
        response.res.result_no = 240202
        return response.SerializeToString()

    # 军团等级是否满足此类型boss
    if not boss_open_item[1]:
        logger.debug("guild level is not enough!")
        response.res.result_no = 240204
        return response.SerializeToString()

    res = remote_gate['world'].guild_boss_add_remote(player.guild.g_id, stage_id, boss_type, player.base_info.id, player.base_info.base_name)
    response.res.result = res.get("result")
    if not res.get("result"):
        response.res.result_no = res.get("result_no")
        return response.SerializeToString()

    player.finance.consume(const.GUILD_BOSS_TRIGGER_STONE, consume_num, 0)

    return_data = [[const.RESOURCE, consume_num, 15]]
    logger.debug(return_data)
    get_return(player, return_data, response.consume)
    player.guild.guild_boss_last_attack_time["boss_id"] = res.get("guild_boss").get("boss_id")
    player.guild.guild_boss_last_attack_time["time"] = 0
    logger.debug("guild_boss_last_attack_time %s " % (player.guild.guild_boss_last_attack_time))
    construct_boss_pb(res.get("guild_boss"), response.guild_boss)
    logger.debug("response %s" % response)

    remote_gate.push_object_character_remote(24021, construct_init_data(player), player.guild.get_guild_member_ids(res.get("p_list", {})))
    # add guild activity times
    player.guild_activity.add_guild_boss_times(res.get("guild_boss").get("boss_type"))
    player.act.add_guild_boss_times(res.get("guild_boss").get("boss_type"))
    hook_task(player, CONDITIONId.GUILD_BOSS, 1)
    tlog_action.log('TriggerBoss', player, player.guild.g_id, boss_type)

    return response.SerializeToString()
Example #11
0
def battle_2103(pro_data, player):
    """
    开始战斗
    request:HjqyBattleRequest
    response:HjqyBattleResponse
    """
    request = hjqy_pb2.HjqyBattleRequest()
    request.ParseFromString(pro_data)
    response = hjqy_pb2.HjqyBattleResponse()

    if player.base_info.is_firstday_from_register(const.OPEN_FEATURE_HJQY):
        response.res.result = False
        response.res.result_no = 150901
        return response.SerializeToString()
    boss_id = request.owner_id
    attack_type = request.attack_type # 全力一击,普通攻击
    logger.debug("request %s" % request)

    hjqyExchangeBUFFTime = game_configs.base_config.get("hjqyExchangeBUFFTime")
    hjqyItemRate = game_configs.base_config.get("hjqyItemRate")

    hjqyExchangeBUFFNumber = game_configs.base_config.get("hjqyExchangeBUFFNumber")
    hjqyExchangeNumber = game_configs.base_config.get("hjqyExchangeNumber")
    need_hjqy_fight_token = hjqyExchangeNumber
    if attack_type == 2:
        need_hjqy_fight_token = hjqyExchangeBUFFNumber
    if is_in_period(hjqyExchangeBUFFTime) and attack_type == 2:
        need_hjqy_fight_token = need_hjqy_fight_token * hjqyItemRate

    if need_hjqy_fight_token > player.finance[const.HJQYFIGHTTOKEN]:
        logger.error("hjqy coin not enough!")
        response.res.result = False
        response.res.result_no = 210301
        return response.SerializePartialToString()

    data = remote_gate['world'].get_boss_info_remote(boss_id)

    if not data or data.get('state') == const.BOSS_DEAD:
        logger.error("hjqy boss dead!")
        response.res.result = False
        response.res.result_no = 210302
        return response.SerializePartialToString()
    if data.get('state') == const.BOSS_RUN_AWAY:
        logger.error("hjqy boss run away!")
        response.res.result = False
        response.res.result_no = 210303
        return response.SerializePartialToString()


    stage_id = data.get("stage_id")
    player.fight_cache_component.stage_id = stage_id
    red_units = player.fight_cache_component.get_red_units()

    blue_units = cPickle.loads(remote_gate['world'].blue_units_remote(boss_id))

    seed1, seed2 = get_seeds()
    player_info = dict(player_id=player.base_info.id,
            nickname=player.base_info.base_name,
            user_icon=player.base_info.heads.now_head,
            level=player.base_info.level)

    str_red_units = cPickle.dumps(red_units)
    red_unpar_data = player.line_up_component.get_red_unpar_data()
    fight_result, boss_state, current_damage_hp, is_kill = remote_gate['world'].hjqy_battle_remote(player_info, boss_id, str_red_units, red_unpar_data, attack_type, seed1, seed2)

    logger.debug("============battle over")

    # 消耗讨伐令
    player.finance.consume(const.HJQYFIGHTTOKEN, need_hjqy_fight_token, const.HJQY_BATTLE)

    # 功勋奖励
    hjqyMeritoriousServiceOpenTime = game_configs.base_config.get("hjqyMeritoriousServiceOpenTime")
    hjqyMeritoriousServiceRate = game_configs.base_config.get("hjqyMeritoriousServiceRate")
    meritorious_service = player.fight_cache_component._get_stage_config().meritorious_service
    logger.debug("========= %s %s ========"%(is_in_period(hjqyMeritoriousServiceOpenTime), hjqyMeritoriousServiceOpenTime ))
    if is_in_period(hjqyMeritoriousServiceOpenTime):  # 增加功勋的活动
        meritorious_service = meritorious_service * hjqyMeritoriousServiceRate
    player.finance.add(const.HJQYCOIN, meritorious_service, reason=const.HJQY_BATTLE)
    player.finance.save_data()

    response.fight_result = fight_result
    pvp_assemble_units(red_units, blue_units, response)
    response.seed1 = seed1
    response.seed2 = seed2
    response.attack_type = attack_type
    response.hjqy_coin = meritorious_service
    response.stage_id = stage_id
    response.res.result = True

    hook_task(player, CONDITIONId.HJQY, 1)

    tlog_action.log('BattleHJQY', player, boss_id, is_kill)

    # start target
    all_current_damage_hp = remote_gate['world'].\
        hjqy_damage_hp_remote(player.base_info.id)
    player.act.condition_update(38, current_damage_hp)
    player.act.condition_update(39, all_current_damage_hp)
    # 更新 七日奖励
    target_update(player, [38, 39])

    return response.SerializePartialToString()
Example #12
0
def trigger_boss_2402(pro_data, player):
    """召唤圣兽
    """
    guild_boss_open_time_item = game_configs.base_config.get("AnimalOpenTime")
    response = guild_pb2.TriggerGuildBossResponse()
    response.res.result = False
    if not is_in_period(guild_boss_open_time_item):
        logger.debug("feature not open!")
        response.res.result_no = 30000
        return response.SerializeToString()

    request = guild_pb2.TriggerGuildBossRequest()
    request.ParseFromString(pro_data)
    logger.debug("request %s" % request)
    boss_type = request.boss_type
    trigger_stone_num = player.finance[const.GUILD_BOSS_TRIGGER_STONE]

    data = remote_gate['world'].guild_boss_init_remote(player.guild.g_id)
    build = data.get("build")
    guild_boss_trigger_times = data.get("guild_boss_trigger_times")
    guild_boss_item = game_configs.guild_config.get(4).get(build.get(4))
    logger.debug("guild_boss_item %s" % guild_boss_item)
    boss_open_item = guild_boss_item.animalOpen.get(boss_type)
    stage_id = boss_open_item[0]
    consume_num = boss_open_item[2]

    # 召唤石是否足够
    if trigger_stone_num < boss_open_item[2]:
        logger.debug("trigger stone is not enough!")
        response.res.result_no = 240201
        return response.SerializeToString()
    # 召唤次数是否达到上限
    if guild_boss_trigger_times >= guild_boss_item.animalOpenTime:
        logger.debug("trigger times reach the max!")
        response.res.result_no = 240202
        return response.SerializeToString()

    # 军团等级是否满足此类型boss
    if not boss_open_item[1]:
        logger.debug("guild level is not enough!")
        response.res.result_no = 240204
        return response.SerializeToString()

    res = remote_gate['world'].guild_boss_add_remote(
        player.guild.g_id, stage_id, boss_type, player.base_info.id,
        player.base_info.base_name)
    response.res.result = res.get("result")
    if not res.get("result"):
        response.res.result_no = res.get("result_no")
        return response.SerializeToString()

    player.finance.consume(const.GUILD_BOSS_TRIGGER_STONE, consume_num, 0)

    return_data = [[const.RESOURCE, consume_num, 15]]
    logger.debug(return_data)
    get_return(player, return_data, response.consume)
    player.guild.guild_boss_last_attack_time["boss_id"] = res.get(
        "guild_boss").get("boss_id")
    player.guild.guild_boss_last_attack_time["time"] = 0
    logger.debug("guild_boss_last_attack_time %s " %
                 (player.guild.guild_boss_last_attack_time))
    construct_boss_pb(res.get("guild_boss"), response.guild_boss)
    logger.debug("response %s" % response)

    remote_gate.push_object_character_remote(
        24021, construct_init_data(player),
        player.guild.get_guild_member_ids(res.get("p_list", {})))
    # add guild activity times
    player.guild_activity.add_guild_boss_times(
        res.get("guild_boss").get("boss_type"))
    player.act.add_guild_boss_times(res.get("guild_boss").get("boss_type"))
    hook_task(player, CONDITIONId.GUILD_BOSS, 1)
    tlog_action.log('TriggerBoss', player, player.guild.g_id, boss_type)

    return response.SerializeToString()