def start_rob_escort(player, task_id, response, task_guild_id, rob_no): """ 手动开始劫运 """ res = remote_gate["world"].start_rob_escort_remote(task_guild_id, task_id, rob_no, player.base_info.id) if res.get("result"): player.finance.consume(const.GUILD_ESCORT_ROB_TIMES, 1, const.ESCORT_ROB) player.finance.save_data() update_rob_task_info_pb(res.get("protecters", []), res.get("rob_task_info", {}), response.rob_task_info, protect_or_rob=2) # push info to head players push_response = escort_pb2.InviteEscortTaskPushResponse() task = res.get("task") update_task_pb(task, push_response.task) push_response.protect_or_rob = 2 logger.debug("19101 push_response %s" % push_response) for player_info in res.get("rob_task_info", {}).get("robbers"): remote_gate.push_object_character_remote(19101, push_response.SerializePartialToString(), [player_info.get("id")]) remote_gate.push_object_character_remote(19102, push_response.SerializePartialToString(), [task.get("protecters")[0].get("id")]) # 参与劫运次数 task = res.get("task") for no, robber in enumerate(res.get("rob_task_info", {}).get("robbers", [])): if res.get("rob_task_info").get("rob_result", False): push_message("add_guild_activity_times_remote", int(robber.get("id")), task.get("task_no"), 2) if no == 0: continue push_message("remove_escort_in_times_remote", int(robber.get("id")), 2) return res
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}
def given_stamina(self, target_id, if_present=True): if target_id not in self._friends.keys(): return False given_time_list = self._friends[target_id] given_times = len(given_time_list) if given_times >= 1: return False given_time_list.append(datetime.datetime.now()) if not if_present: return True stamina_mail = mail_config.get(1) if stamina_mail: mail = dict(sender_id=self.owner.base_info.id, sender_name=self.owner.base_info.base_name, sender_icon=self.owner.line_up_component.lead_hero_no, receive_id=target_id, title=stamina_mail.get('title'), content=stamina_mail.get('content'), mail_type=stamina_mail.get('type'), send_time=int(time.time()), prize=stamina_mail.get('rewards')) # command:id 为收邮件的命令ID if netforwarding.push_message('receive_mail_remote', target_id, mail): return True else: logger.error('stamina mail push message fail') else: logger.error('can not find stamina mail!!!') return False
def add_friend_request_1100(data, player): """ request to invite target as friend """ response = CommonResponse() response.result = True response.result_no = 0 request = friend_pb2.FriendCommon() request.ParseFromString(data) if len(request.target_ids) < 1: response.result = False response.result_no = 11005 # fail return response.SerializePartialToString() # fail max_num_friend = game_configs.base_config.get('max_of_UserFriend') if len(player.friends.friends) >= max_num_friend: response.result = False response.result_no = 11003 # fail return response.SerializePartialToString() # fail target_id = request.target_ids[0] if target_id == player.base_info.id: response.result = False # cant invite oneself as friend response.result_no = 11004 # fail return response.SerializePartialToString() # fail if not push_message('add_friend_request_remote', target_id, player.base_info.id): response.result = False response.result_no = 11002 return response.SerializePartialToString() # fail return response.SerializePartialToString()
def add_friend_respond_accept_1101(data, player): """ respond to inviter """ response = CommonResponse() response.result = True response.result_no = 0 request = friend_pb2.FriendCommon() request.ParseFromString(data) for target_id in request.target_ids: if not player.friends.add_friend(target_id): response.result = False continue # save data player.friends.save_data() if not push_message('become_friends_remote', target_id, player.base_info.id): response.result = False send_mail(conf_id=301, nickname=player.base_info.base_name, receive_id=target_id) return response.SerializePartialToString()
def add_friend_request_1100(data, player): """ request to invite target as friend """ response = CommonResponse() response.result = True response.result_no = 0 request = friend_pb2.FriendCommon() request.ParseFromString(data) if len(request.target_ids) < 1: response.result = False response.result_no = 5 # fail return response.SerializePartialToString() # fail target_id = request.target_ids[0] if target_id == player.base_info.id: response.result = False # cant invite oneself as friend response.result_no = 4 # fail return response.SerializePartialToString() # fail if not push_message('add_friend_request_remote', target_id, player.base_info.id): response.result = False response.result_no = 2 return response.SerializePartialToString() # fail return response.SerializePartialToString()
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}
def start_rob_escort(player, task_id, response, task_guild_id, rob_no): """ 手动开始劫运 """ res = remote_gate["world"].start_rob_escort_remote(task_guild_id, task_id, rob_no, player.base_info.id) if res.get("result"): player.finance.consume(const.GUILD_ESCORT_ROB_TIMES, 1, const.ESCORT_ROB) player.finance.save_data() update_rob_task_info_pb(res.get("protecters", []), res.get("rob_task_info", {}), response.rob_task_info, protect_or_rob=2) # push info to head players push_response = escort_pb2.InviteEscortTaskPushResponse() task = res.get("task") update_task_pb(task, push_response.task) push_response.protect_or_rob = 2 logger.debug("19101 push_response %s" % push_response) for player_info in res.get("rob_task_info", {}).get("robbers"): remote_gate.push_object_character_remote( 19101, push_response.SerializePartialToString(), [player_info.get("id")]) remote_gate.push_object_character_remote( 19102, push_response.SerializePartialToString(), [task.get("protecters")[0].get("id")]) # 参与劫运次数 task = res.get("task") for no, robber in enumerate( res.get("rob_task_info", {}).get("robbers", [])): if res.get("rob_task_info").get("rob_result", False): push_message("add_guild_activity_times_remote", int(robber.get("id")), task.get("task_no"), 2) if no == 0: continue push_message("remove_escort_in_times_remote", int(robber.get("id")), 2) return res
def friend_private_chat_1060(data, player): """ 发送好友单聊邮件 @author: jiang """ response = CommonResponse() request = friend_pb2.FriendPrivateChatRequest() request.ParseFromString(data) target_id = request.target_uid content = request.content title_display_len = 10 if len(content) <= title_display_len: title = content else: title = content[:title_display_len] + "..." mail = { 'sender_id': player.base_info.id, 'sender_name': player.base_info.base_name, 'sender_icon': player.line_up_component.lead_hero_no, 'receive_id': target_id, 'receive_name': '0', 'title': title, 'content': content, 'mail_type': MailComponent.TYPE_MESSAGE, 'prize': 0 } if not mail: response.result = False return response.SerializePartialToString() mail['send_time'] = int(time.time()) receive_id = mail['receive_id'] # command:id 为收邮件的命令ID netforwarding.push_message('receive_mail_remote', receive_id, mail) response.result = True return response.SerializePartialToString()
def del_friend_request_1103(data, player): """ delete friend from friend list """ response = CommonResponse() response.result = True response.result_no = 0 request = friend_pb2.FriendCommon() request.ParseFromString(data) for target_id in request.target_ids: if not player.friends.del_friend(target_id): response.result = False # save data player.friends.save_data() response.result = push_message('delete_friend_remote', target_id, player.base_info.id) response.result_no += 1 return response.SerializePartialToString()
def send_mail_1304(proto_data, player): """发送邮件""" request = SendMailRequest() request.ParseFromString(proto_data) mail = request.mail mail = {'sender_id': mail.sender_id, 'sender_name': mail.sender_name, 'receive_id': mail.receive_id, 'receive_name': mail.receive_name, 'title': mail.title, 'content': mail.content, 'mail_type': mail.mail_type, 'send_time': mail.send_time, 'prize': mail.prize} response = CommonResponse() """发送邮件, mail为json类型""" mail['send_time'] = int(time.time()) receive_id = mail['receive_id'] # command:id 为收邮件的命令ID response.result = netforwarding.push_message('receive_mail_remote', receive_id, mail) logger.debug('send_mail_1304 %s', response.result) return response.SerializePartialToString()
def send_mail(**args): mail_data, receive_id = deal_mail(**args) if not netforwarding.push_message('receive_mail_remote', receive_id, mail_data): logger.error('mail push message fail') traceback.print_stack()
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 settle(player, fight_result): rank_incr = 0 response.top_rank = player.pvp.pvp_high_rank if fight_result: logger.debug("fight result:True:%s:%s", before_player_rank, request.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 request.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 request.challenge_rank < before_player_rank: tb_pvp_rank.zadd(request.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 request.challenge_rank < player.pvp.pvp_high_rank: rank_incr = player.pvp.pvp_high_rank - request.challenge_rank if player.pvp.pvp_high_rank > request.challenge_rank: hook_task(player, CONDITIONId.PVP_RANK, request.challenge_rank) player.pvp.pvp_high_rank = min(player.pvp.pvp_high_rank, request.challenge_rank) logger.debug(" history_high_rank %s current %s" % (player.pvp.pvp_high_rank, before_player_rank)) # 首次达到某名次的奖励 arena_rank_up_rewards = game_configs.base_config.get('arenaRankUpRewards') if arena_rank_up_rewards: return_data = gain(player, arena_rank_up_rewards, const.ARENA_WIN, multiple=rank_incr) 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 send_mail(**args): mail_data, receive_id = deal_mail(**args) if not netforwarding.push_message('receive_mail_remote', receive_id, mail_data): logger.error('mail push message fail') traceback.print_stack()