def pvp_fight_revenge_1507(data, player): request = pvp_rank_pb2.PvpFightRevenge() response = pvp_rank_pb2.PvpFightResponse() request.ParseFromString(data) line_up = request.lineup skill = request.skill target_id = request.black_id if not player.friends.can_revenge(target_id): logger.error('black id is not in blacklist:%s', target_id) response.res.result = False response.res.result_no = 1516 return response.SerializePartialToString() fight_result = pvp_fight(player, target_id, line_up, skill, response) logger.debug("fight revenge result:%s" % fight_result) if fight_result: player.friends.del_blacklist(target_id) player.friends.save_data() revenge_reward = game_configs.base_config['arenaRevengeRewards'] return_data = gain(player, revenge_reward, const.FRIEND_REVENGE) get_return(player, return_data, response.gain) response.res.result = True logger.debug("red_units: %s" % response.red) return response.SerializeToString()
def pvp_rob_treasure_864(data, player): request = pvp_rank_pb2.PvpRobTreasureRequest() response = pvp_rank_pb2.PvpFightResponse() request.ParseFromString(data) uid = request.uid chip_id = request.chip_id chip_conf = check_can_rob(player, uid, chip_id, 1, response) check_res, res_no, chip_conf = check_can_rob(player, uid, chip_id, 1, response) if not check_res: response.res.result = False response.res.result_no = res_no return response.SerializePartialToString() fight_result = deal_pvp_rob_fight(player, uid, chip_id, response, chip_conf) player.rob_treasure.truce = [0, 1] if fight_result: indiana_conf = get_indiana_conf(player, uid, chip_conf) player.rob_treasure.can_receive = indiana_conf.id player.rob_treasure.save_data() player.pvp.reset_rob_treasure() player.pvp.save_data() response.res.result = True logger.debug("response ==================== : %s" % response) return response.SerializeToString()
def fight_1508(self, message): response = pvp_rank_pb2.PvpFightResponse() response.ParseFromString(message) print response # gevent.sleep(1) # self.command_fight() self.on_command_finish()
def pvp_fight_assemble_data(red_units, blue_units, red_skill, red_skill_level, blue_skill, blue_skill_level): """docstring for pvp_fight_assemble_data""" # assemble pvp response response = pvp_rank_pb2.PvpFightResponse() response.res.result = True for slot_no, red_unit in red_units.items(): if not red_unit: continue red_add = response.red.add() assemble(red_add, red_unit) for slot_no, blue_unit in blue_units.items(): if not blue_unit: continue blue_add = response.blue.add() assemble(blue_add, blue_unit) response.red_skill = red_skill response.red_skill_level = red_skill_level response.blue_skill = blue_skill response.blue_skill_level = blue_skill_level return response.SerializeToString()
def pvp_fight_overcome_1508(data, player): request = pvp_rank_pb2.PvpFightOvercome() response = pvp_rank_pb2.PvpFightResponse() request.ParseFromString(data) line_up = request.lineup skill = request.skill if player.pvp.pvp_overcome_failed: logger.error('overcome is already failed') response.res.result = False response.res.result_no = 150805 return response.SerializeToString() if player.base_info.is_firstday_from_register(const.OPEN_FEATURE_GGZJ): logger.error('overcome is not open ') response.res.result = False response.res.result_no = 150801 return response.SerializeToString() ggzj_item = game_configs.ggzj_config.get(request.index) if not ggzj_item: logger.error('ggzj config id err:%s', request.index) response.res.result = False response.res.result_no = 150804 return response.SerializePartialToString() if ggzj_item.get('section') != player.pvp.pvp_overcome_current: logger.error('overcome index is error:%s-%s', ggzj_item.get('section'), player.pvp.pvp_overcome_current) response.res.result = False response.res.result_no = 150801 return response.SerializePartialToString() target_id = player.pvp.get_overcome_id(ggzj_item.get('index')) if not target_id: logger.error('overcome index is not exist:%s', request.index) response.res.result = False response.res.result_no = 150802 return response.SerializePartialToString() fight_result = pvp_fight(player, target_id, line_up, skill, response, is_copy_unit=True) logger.debug("fight revenge result:%s" % fight_result) if fight_result: player.pvp.pvp_overcome_current += 1 player.pvp.pvp_overcome_stars += ggzj_item.get('star') player.pvp.save_data() return_data = gain(player, ggzj_item.get('reward1'), const.PVP_OVERCOME) get_return(player, return_data, response.gain) return_data = gain(player, ggzj_item.get('reward2'), const.PVP_OVERCOME) get_return(player, return_data, response.gain) else: player.pvp.pvp_overcome_failed = True player.pvp.save_data() response.res.result = True logger.debug("red_units: %s" % response.red) return response.SerializeToString()
def pvp_fight_request_1505(data, player): """ pvp战斗开始 """ request = pvp_rank_pb2.PvpFightRequest() response = pvp_rank_pb2.PvpFightResponse() request.ParseFromString(data) # player.pvp.check_time() if is_not_open(player, FO_PVP_RANK): response.res.result = False response.res.result_no = 837 return response.SerializePartialToString() arena_consume = game_configs.base_config.get('arenaConsume') result = is_afford(player, arena_consume) # 校验 if not result.get('result'): logger.error('not enough consume:%s', arena_consume) response.res.result = False response.res.result_no = 150501 return response.SerializePartialToString() # if player.pvp.pvp_times <= 0: # logger.error('not enough pvp times:%s-%s', player.pvp.pvp_times, # game_configs.base_config.get('arena_free_times')) # response.res.result = False # response.res.result_no = 836 # return response.SerializeToString() challenge_rank = request.challenge_rank if challenge_rank < 0 and player.pvp.pvp_upstage_challenge_rank != 0: challenge_rank = player.pvp.pvp_upstage_challenge_rank if challenge_rank < 0: logger.error('pvp challenge rank error!!%s-%s', challenge_rank, player.pvp.pvp_upstage_challenge_rank) response.res.result = False response.res.result_no = 839 return response.SerializeToString() line_up = request.lineup skill = request.skill target_id = int( tb_pvp_rank.zrangebyscore(challenge_rank, challenge_rank)[0]) if target_id != request.challenge_id: logger.error('pvp challenge id changed!!%s-%s', target_id, request.challenge_id) response.res.result = False response.res.result_no = 150508 return response.SerializeToString() before_player_rank = tb_pvp_rank.zscore(player.base_info.id) if not before_player_rank: before_player_rank = int(tb_pvp_rank.getObj('incr').incr()) tb_pvp_rank.zadd(before_player_rank, player.base_info.id) player.pvp.pvp_high_rank = before_player_rank elif before_player_rank != request.self_rank: logger.error('pvp self rank changed!!%s-%s', before_player_rank, request.self_rank) response.res.result = False response.res.result_no = 150509 return response.SerializeToString() before_player_rank = int(before_player_rank) if before_player_rank == challenge_rank: logger.error('cant not fight self') response.res.result = False response.res.result_no = 1505 return response.SerializeToString() return_data = consume(player, arena_consume, const.PVP) get_return(player, return_data, response.consume) fight_result = pvp_fight(player, target_id, line_up, skill, response) rank_incr = 0 response.top_rank = player.pvp.pvp_high_rank response.before_rank = before_player_rank if fight_result: logger.debug("fight result:True:%s:%s", before_player_rank, challenge_rank) _arena_win_points = game_configs.base_config.get('arena_win_points') if _arena_win_points: return_data = gain(player, _arena_win_points, const.ARENA_WIN) get_return(player, return_data, response.gain) else: logger.debug('arena win points is not find') push_config = game_configs.push_config[1003] rank_count = push_config.conditions[0] if challenge_rank - before_player_rank >= rank_count: txt = game_configs.push_config[1003].text message = game_configs.language_config.get(str(txt)).get('cn') remote_gate['push'].add_push_message_remote( player.base_info.id, 3, message, int(time.time())) push_message('add_blacklist_request_remote', target_id, player.base_info.id) if challenge_rank < before_player_rank: tb_pvp_rank.zadd(challenge_rank, player.base_info.id, before_player_rank, target_id) send_mail(conf_id=123, receive_id=target_id, pvp_rank=before_player_rank, nickname=player.base_info.base_name) if challenge_rank < player.pvp.pvp_high_rank: rank_incr = player.pvp.pvp_high_rank - challenge_rank if player.pvp.pvp_high_rank > challenge_rank: hook_task(player, CONDITIONId.PVP_RANK, challenge_rank) formula = game_configs.formula_config.get( "arenaRankUpRewardsValue").get("formula") gain_num = eval( formula, dict(upRank=challenge_rank, highestRank=player.pvp.pvp_high_rank)) # stage award stage_info_before = get_player_pvp_stage(player.pvp.pvp_high_rank) stage_info_current = get_player_pvp_stage(challenge_rank) before_gradient = stage_info_before.get('Gradient') current_gradient = stage_info_current.get('Gradient') if stage_info_current and stage_info_current \ and before_gradient > current_gradient: arena_stage_reward = stage_info_current.get('Reward') stage_reward_data = gain(player, arena_stage_reward, const.ARENA_WIN) get_return(player, stage_reward_data, response.award2) logger.debug('stage award %s %s', stage_info_current, stage_info_before) player.pvp.pvp_high_rank = min(player.pvp.pvp_high_rank, challenge_rank) logger.debug("history_high_rank %s current %s" % (player.pvp.pvp_high_rank, before_player_rank)) # 首次达到某名次的奖励 arena_rank_rewards = game_configs.base_config.get('arenaRankUpRewards') if arena_rank_rewards: return_data = gain(player, arena_rank_rewards, const.ARENA_WIN, multiple=int(gain_num)) get_return(player, return_data, response.award) else: logger.debug('arena rank up points is not find') else: logger.debug("fight result:False") send_mail(conf_id=124, receive_id=target_id, nickname=player.base_info.base_name) hook_task(player, CONDITIONId.PVP_RANk_TIMES, 1) player.pvp.pvp_times -= 1 player.pvp.pvp_refresh_time = time.time() player.pvp.save_data() response.res.result = True # response.top_rank = player.pvp.pvp_high_rank response.rank_incr = rank_incr logger.debug(response) return response.SerializeToString()
def pvp_fight_request_1505(data, player): request = pvp_rank_pb2.PvpFightRequest() request.ParseFromString(data) __skill = request.skill __best_skill = player.line_up_component.get_skill_id_by_unpar(__skill) __skill_level = 0 if __skill in player.line_up_component.unpars: __skill_level = player.line_up_component.unpars[request.skill] else: logger.error('error skill level:%s,%s', request.skill, player.line_up_component.unpars.keys()) line_up = {} # {hero_id:pos} for line in request.lineup: if not line.hero_id: continue line_up[line.hero_id] = line.pos player.line_up_component.line_up_order = line_up player.line_up_component.save_data() prere = dict(character_id=player.base_info.id) record = util.GetOneRecordInfo(PVP_TABLE_NAME, prere, ['id']) before_player_rank = 0 if record: before_player_rank = record.get('id') refresh_rank_data(player, before_player_rank, __skill, __skill_level) if before_player_rank == request.challenge_rank: logger.error('cant not fight self') return False prere = dict(id=request.challenge_rank) record = util.GetOneRecordInfo(PVP_TABLE_NAME, prere, ['character_id', 'nickname', 'level', 'ap', 'best_skill', 'unpar_skill', 'unpar_skill_level', 'units', 'slots', 'hero_ids']) blue_units = record.get('units') # print "blue_units:", blue_units blue_units = cPickle.loads(blue_units) # print "blue_units:", blue_units red_units = player.fight_cache_component.red_unit player.fight_cache_component.awake_hero_units(blue_units) player.fight_cache_component.awake_hero_units(red_units) process = BattlePVPProcess(red_units, __best_skill, player.level.level, blue_units, record.get('best_skill', 0), record.get('level', 1)) fight_result = process.process() logger.debug("fight result:%s" % fight_result) if fight_result: logger.debug("fight result:True:%s:%s", before_player_rank, request.challenge_rank) if before_player_rank != 0: if request.challenge_rank < before_player_rank: prere = dict(id=before_player_rank) result = util.UpdateWithDict(PVP_TABLE_NAME, record, prere) logger.info('update result:%s', result) refresh_rank_data(player, request.challenge_rank, __skill, __skill_level) else: refresh_rank_data(player, request.challenge_rank, __skill, __skill_level) else: logger.debug("fight result:False") response = pvp_rank_pb2.PvpFightResponse() response.res.result = True for slot_no, red_unit in red_units.items(): if not red_unit: continue red_add = response.red.add() assemble(red_add, red_unit) for slot_no, blue_unit in blue_units.items(): if not blue_unit: continue blue_add = response.blue.add() assemble(blue_add, blue_unit) response.red_skill = __skill response.red_skill_level = __skill_level response.blue_skill = record.get('unpar_skill') response.blue_skill_level = record.get('unpar_skill_level') lively_event = CountEvent.create_event(EventType.SPORTS, 1, ifadd=True) tstatus = player.tasks.check_inter(lively_event) if tstatus: task_data = task_status(player) remote_gate.push_object_remote(1234, task_data, [player.dynamic_id]) return response.SerializeToString()