def show_card_dealer(player, proto): """ 地主二次明牌 """ step = proto.step s1, s2 = divmod(step, 10) if s1 and s1 != 3: return for k, v in player.table.player_dict.iteritems(): if k == player.uuid: continue proto = game_pb2.ShowCardResponse() proto.code = 0 proto.player = k proto.step = step if step != 0: for c in player.cards_in_hand: card = proto.cards.add() card.card = c send(SHOWCARD, proto, v.session) player.show_card = step multiple = player.table.conf.show_card_config['double'].get(step, 1) if multiple > player.table.max_show_multiple: player.table.max_show_multiple = multiple # 刷新面板分 for i in player.table.player_dict.values(): score_proto = game_pb2.PokerScoreResponse() score_proto.multiple = i.table.get_multiple(i) send(POKER_SCORE, score_proto, i.session) player.table.replay["procedure"].append({"show_card": [player.seat]}) from rules.player_rules.manager import PlayerRulesManager PlayerRulesManager().condition(player, PLAYER_RULE_SHOWCARD_DEALER) player.dumps()
def double(player, proto): """ 是否要翻倍 """ double = proto.double if double not in [1, 2]: return # 地主要在农民翻倍后 才可以翻倍 has_dealer = False if player.seat == player.table.dealer_seat: # 防作弊所有农民都翻倍选择后才进行下去 if len(player.table.farmer_double) < player.table.chairs - 1: return has_dealer = True if player.seat not in player.table.farmer_double: player.table.farmer_double.append(player.seat) player.double = double if double == 2: if player.seat not in player.table.double_seat: player.table.double_seat.append(player.seat) if has_dealer: # 刷新倍数 for i in player.table.player_dict.values(): score_proto = game_pb2.PokerScoreResponse() score_proto.multiple = i.table.get_multiple(i) send(POKER_SCORE, score_proto, i.session) if len(player.table.farmer_double) >= player.table.chairs - 1: # 所有人刷新一遍倍数 for i in player.table.player_dict.values(): score_proto = game_pb2.PokerScoreResponse() score_proto.multiple = i.table.get_multiple(i) send(POKER_SCORE, score_proto, i.session) proto = game_pb2.PokerDoubleResponse() player.table.reset_proto(POKER_DOUBLE) if has_dealer: # 地主加倍通知 for every_player in player.table.player_dict.values(): players = proto.players.add() players.seat = every_player.seat players.flag = True if every_player.seat in player.table.double_seat else False for i in player.table.player_dict.values(): i.proto.p = copy(proto) i.proto.send() else: if len(player.table.farmer_double) < player.table.chairs - 1: # 农民1给自己发: # if i.seat == player.seat or i.seat == player.table.dealer_seat: # for i in player.table.player_dict.values(): # if i.seat == player.seat: players = proto.players.add() players.seat = player.seat players.flag = True if player.seat in player.table.double_seat else False player.proto.p = copy(proto) player.proto.send() # 刷新自己的分 score_proto = game_pb2.PokerScoreResponse() score_proto.multiple = player.table.get_multiple(player) send(POKER_SCORE, score_proto, player.session) else: # 农民2发给所有人 for every_player in player.table.player_dict.values(): if every_player.seat == player.table.dealer_seat: continue players = proto.players.add() players.seat = every_player.seat players.flag = True if every_player.seat in player.table.double_seat else False for i in player.table.player_dict.values(): i.proto.p = copy(proto) i.proto.send() # 没人叫地主,跳过地主加倍 if len(player.table.double_seat) == 0: player.table.seat_dict[ player.table.dealer_seat].machine.cur_state.execute( player.table.seat_dict[player.table.dealer_seat], "skip_wait") player.dumps() if not has_dealer and len( player.table.farmer_double) >= player.table.chairs - 1 and len( player.table.double_seat) >= 1: for k, v in player.table.seat_dict.iteritems(): proto = game_pb2.PokerDoubleInitResponse( double_list=[player.table.dealer_seat]) send(POKER_DOUBLE_INIT, proto, v.session) player.table.replay["procedure"].append({"double": [player.seat, double]}) player.machine.cur_state.execute(player, "skip_wait") player.dumps()
def rob_dealer_happy(player, proto): """ 欢乐抢地主 """ rob_score = proto.rob_score win_seat = rob_seat = -1 cancel = 0 if player.table.conf.play_type != 2: return # 当前没有轮到该玩家抢地主 if player.table.rob_seat != player.seat: return # 该玩家已经抢过了 if rob_score == player.rob_score: return # 放弃的不能在抢地主 if not player.rob_score: return # 首次不能抢地主 if player.table.rob_score == 0 and rob_score == 2: return # 地主只能被叫一次 if player.table.rob_score == 1 and rob_score == 1: return # 抢地主后不能在叫 if player.table.rob_score == 2 and rob_score == 1: return player.table.rob_score = rob_score if rob_score else 0 player.table.rob_players_happy.append([player.seat, rob_score]) player.rob_score = rob_score def get_win_seat(player, max_score): lis = player.table.rob_players_happy[::-1] result = None for item in lis: if item[1] == max_score: result = item[0] break return result max_score = max([i[0] for i in player.table.rob_players_happy]) # 只有一个叫地主的 if max_score == 1 and len( player.table.rob_players_happy) == player.table.chairs: win_seat = get_win_seat(player, max_score) else: if len(player.table.rob_players) >= player.table.chairs + 1: win_seat = get_win_seat(player, max_score) else: def set_next(player): next_player = player.table.seat_dict[player.next_seat] if next_player.rob_score == 0: set_next(next_player) return if next_player.table.rob_seat == next_player.seat: return next_player.table.rob_seat = next_player.seat global rob_seat rob_seat = next_player.seat set_next(player) if player.table.rob_seat == player.seat and player.rob_score == 0: # 全都pass 重新发牌 rob_seat = -1 cancel = 1 proto = game_pb2.RobLandLordReponse() proto.seat = player.seat proto.rob_score = rob_score proto.win_seat = win_seat proto.rob_seat = rob_seat if win_seat != -1: for c2 in player.table.cards_on_desk: card = proto.cards_rest.add() card.card = c2 player.table.reset_proto(ROB_DEALER_HAPPY) for i in player.table.player_dict.values(): # player.machine.trigger(RobState()) if i.uuid == player.uuid: continue i.proto.p = copy(proto) i.proto.send() # 刷新面板分 for i in player.table.player_dict.values(): score_proto = game_pb2.PokerScoreResponse() score_proto.multiple = i.table.get_multiple(i) send(POKER_SCORE, score_proto, i.session) player.table.replay["procedure"].append( {"rob_dealer_happy": [player.uuid, rob_score]}) # 确定地主 if win_seat != -1: player.table.dealer_seat = win_seat player.table.seat_dict[player.table.dealer_seat].land_lord_times += 1 for i in player.table.player_dict.values(): i.machine.cur_state.execute(i, "rob_skip") player.table.replay["procedure"].append( {"rob_confirm": [player.seat, rob_score]}) if cancel: player.table.rob_all_cancel() from state.table_state.deal import DealState player.table.machine.trigger(DealState()) player.dumps()