def notify_some_player(self, desk_id, seat_id, act_info={}, interval=1000, max_player_num=4, exclude=[]): """ 推送给桌子上的某些用户, 用于玩家执行动作后的推送 :param desk_id: 桌子ID :param seat_id: 执行动作的玩家位置 :param act_info: 详细动作参数 {act_type:[card_val]} :param interval: 延迟时间 :param exclude: 可以排除推送的作为ID, [seat_id,1] :return: """ logger.debug(u"通知桌子上某些玩家: %s", str([exclude, act_info, interval])) target_seat_id = act_info.get("seat_id") act = act_info.keys()[0] for i in xrange(max_player_num): if not i in exclude: if i != target_seat_id and act == 60: act_info["card_list"] = [] notify_single_user(desk_id, i, PUSH_OTHER_PLAYER_CALL_CARD, act_info)
def bu_hua(self, seat_id, card_list=[]): """检查是否补花""" hua_card = [] tmp_card_list = copy.deepcopy(card_list) for c in tmp_card_list: if CardType.HUA == Card.cal_card_type(c): hua_card.append(c) card_list.remove(c) if not hua_card: return 0 logger.debug(u"发牌补花:%d", len(hua_card)) new_cards = [] temp_hua = copy.deepcopy(hua_card) while temp_hua: cards = self.card_dealer.draw_cards(num=len(temp_hua), is_last=True) temp_hua = [] for c in cards: if CardType.HUA == Card.cal_card_type(c): temp_hua.append(c) hua_card.append(c) else: new_cards.append(c) card_list.extend(new_cards) # 将补花数量添加进手牌中 hua_card_vals 中 self.players[seat_id].hand_card.hua_card_vals.extend(hua_card) for p in self.players: if p.seat_id == seat_id: notify_single_user(self.desk_id, p.seat_id, messageids.PUSH_GAME_DEAL_BU_HUA, data={"seat_id": seat_id, "hua_card": hua_card, "bu_cards": new_cards}) else: notify_single_user(self.desk_id, p.seat_id, messageids.PUSH_GAME_DEAL_BU_HUA, data={"seat_id": seat_id, "hua_card": hua_card, "bu_cards": [BLACK]*len(new_cards)}) return 1
def notify_player(self, desk_id, seat_id, act_info={}, interval=1000, t_type=TimerType.NORMAL, command_id=PUSH_CALL_CARD, code=200): """ :param desk_id: :param seat_id: :param act_info: 玩家可进行的操作信息{act_type:params, ...} :param interval: :return: """ logger.debug(u"通知玩家进行操作: %s", str([seat_id, act_info, interval])) data = {"seat_id": seat_id, "act_info": act_info} notify_single_user(desk_id, seat_id, command_id, data, code) timer_manager_ins.add_timer( desk_id, seat_id, interval, t_type=t_type, call_type=CallbackFuncType.FUNC_AUTO_PLAYER_ACT, call_params={ "seat_id": seat_id, "act_info": act_info })
def cache_act(self, seat_id, act_type, act_params): """ 缓存动作,用于判断动作优先级 :param seat_id: :param act_type: :param act_params: :return: """ if not self.game_data.cur_players_to_act.get(seat_id, []): notify_single_user(self.game_data.desk_id, seat_id, command_id=PUSH_CALL_CARD, data={"desc": "current user can't do anything"}, code=CUR_USER_CANT_SPEAK) return if act_type not in self.game_data.cur_players_to_act[seat_id]: return act_params.update(self.game_data.cur_players_acted[seat_id] [act_type]) # 待执行动作结果中可能存储了部分局部信息 self.game_data.del_player_to_act(seat_id) self.game_data.add_player_acted(seat_id, act_type, act_params) logger.debug( u"cache__act: %s", str([ self.game_data.cur_players_to_act, self.game_data.cur_players_acted ])) return 1
def notify_player_card_change(self, seat_id, code=200): data = { "test_type": TestActionType.HUAN_CARD, "seat_id": seat_id, "hand_card": self.players[seat_id].hand_card.hand_card_vals } notify_single_user(self.desk_id, seat_id, USER_TEST_ACT, data, code)
def notify_player_quick_draw(self, seat_id, code=200): data = { "test_type": TestActionType.QUICK_DRAW, "seat_id": seat_id, "remain_cards": 0 } notify_single_user(self.desk_id, seat_id, USER_TEST_ACT, data, code)
def notify_player(self, seat_id, cards, code=200): data = { "test_type": TestActionType.GET_LAST_CARD, "seat_id": seat_id, "cards": cards } notify_single_user(self.desk_id, seat_id, USER_TEST_ACT, data, code)
def notify_other_player_act_an_gang(self, seat_id, act_info={}, interval=1000, max_player_num=4): """ 通知其他玩家有人进行暗杠操作 :param seat_id: :param act_info: {"seat_id": 座位号, "act_type": Act.CHU, "card_list": [操作的牌]} :param interval: :return: """ for i in xrange(max_player_num): is_ting = self.players[i].hand_card.is_ting if not i == int(seat_id) and not is_ting: tmp_act_info = copy.deepcopy(act_info) tmp_act_info["card_list"] = [0] else: tmp_act_info = act_info notify_single_user(self.desk_id, i, PUSH_OTHER_PLAYER_CALL_CARD, tmp_act_info) timer_manager_ins.add_timer( self.desk_id, i, interval, call_type=CallbackFuncType.FUNC_AUTO_PLAYER_ACT, call_params=act_info) return 1
def notify_other_player(self, **kwargs): # 记录玩家动作 act_info = { "seat_id": self.seat_id, "act_type": Act.ZI_MO, "card_list": [] } for i in xrange(self.game_data.max_player_num): notify_single_user(self.desk_id, self.seat_id, PUSH_OTHER_PLAYER_CALL_CARD, act_info) return 1
def notify_player_next(self, seat_id, code=200): data = { "test_type": TestActionType.SURE_NEXT_CARDS, "seat_id": seat_id, "next_cards": GlobalConfig().test_sure_next_cards[self.desk_id][seat_id] } notify_single_user(self.desk_id, seat_id, USER_TEST_ACT, data, code)
def execute(self): """ 初始发牌 :return: """ logger.debug(u"初始发牌: %s", str([])) card_results = [] for i in xrange(self.max_player_num): drew_card_vals = self.card_dealer.draw_cards(num=13) # 处理测试初始化发牌 if GlobalConfig().test_sure_next_cards.get(self.desk_id): test_cards = GlobalConfig().test_sure_next_cards[self.desk_id][i] if test_cards: min_len = min(len(test_cards),len(drew_card_vals)) for index in xrange(min_len): drew_card_vals[index] = test_cards[index] # 测试初始化发牌结束 card_results.append(drew_card_vals) for x in self.players: result = [] for y in self.players: if x.seat_id == y.seat_id: data = {"seat_id": y.seat_id, "card_list": card_results[y.seat_id]} else: data = {"seat_id": y.seat_id, "card_list": [BLACK]*13} result.append(data) notify_single_user(self.desk_id, x.seat_id, messageids.PUSH_DEAL_CARD, data={"card_list": result}) for x in self.players: if self.game_config.draw_card_bu_hua: self.bu_hua(x.seat_id, card_results[x.seat_id]) # 发牌时候同时将牌添加入手牌 print "card_results[%s] = %s len=%s" % (x.seat_id, card_results[x.seat_id], len(card_results[x.seat_id])) self.players[x.seat_id].hand_card.add_hand_card_by_vals(card_results[x.seat_id]) # 添加玩家动作, Waite_answer # for i in xrange(self.game_data.max_player_num): # self.game_data.add_player_to_act(i, Act.WAITE_ANSWER) # 添加超时回调 self.game_data.next_speaker_callback = {"type": CallbackFuncType.FUNC_NOTIFY_PLAYER_ACT, "call_params": { "seat_id": self.game_data.banker_seat_id, "interval": self.get_act_wait_time(self.game_data.banker_seat_id, Act.WAITE_ANSWER), "act_info": {}}} return 1
def notify_some_player_ting(self, desk_id, seat_id, act_info={}, interval=1000, max_player_num=4): """ 推送给桌子上的某些用户, 用于玩家执行听牌后的推送 :param desk_id: 桌子ID :param seat_id: 执行动作的玩家位置 :param act_info: 详细动作参数 {act_type:[card_val]} :param interval: 延迟时间 :return: """ logger.debug(u"通知桌子上某些玩家: %s", str([desk_id, seat_id, act_info, interval])) act = act_info.keys()[0] for i in xrange(max_player_num): notify_single_user(desk_id, i, PUSH_OTHER_PLAYER_CALL_CARD, act_info)