Exemplo n.º 1
0
    def vote(self, proto):
        if self.vote_timer:
            IOLoop().instance().remove_timeout(self.vote_timer)
        self.dumps()
        self.vote_state = proto.flag
        self.table.logger.info("player {0} vote {1}".format(self.uuid, self.vote_state))

        self.vote_timer = None
        proto_back = game_pb2.PlayerVoteResponse()
        proto_back.player = self.uuid
        proto_back.flag = proto.flag
        for k, v in self.table.player_dict.items():
            send(VOTE, proto_back, v.session)

        if proto.flag:
            for player in self.table.player_dict.values():
                if not player.vote_state:
                    return          # 给除了提出投票的人发
            self.table.dismiss_room()
        else:
            # 只要有一人拒绝则不能解散房间1
            self.table.dismiss_state = False
            self.table.dismiss_sponsor = None
            self.table.dismiss_time = 0
            for player in self.table.player_dict.values():
                player.vote_state = None
                if player.vote_timer:
                    IOLoop.instance().remove_timeout(player.vote_timer)
                    player.vote_timer = None
Exemplo n.º 2
0
    def reconnect(self):
        proto = game_pb2.PokerReconnectResponse()
        proto.room_id = self.table.room_id
        proto.kwargs = self.table.kwargs
        proto.owner = self.table.owner
        proto.room_score = self.table.get_base_core(self)
        proto.room_times = self.table.get_multiple(self)
        proto.room_status = int(table_state_code_map[self.table.state])
        proto.current_round = self.table.cur_round
        proto.active_seat = self.table.active_seat
        proto.spy_card = self.table.spy_card
        proto.spy_seat = -1
        if self.table.spy_chair != -1:
            if self.table.baolu:
                proto.spy_seat = self.table.spy_chair
        # proto.dealer = self.table.dealer_seat
        # active_seat = self.table.active_seat
        # print 'active seat:', active_seat,self.table.seat_dict[active_seat].state
        # 对于前端只有活动玩家处于出牌状态才发送指示灯
        # if active_seat >= 0 and self.table.seat_dict[active_seat].state == "WaitState" :
        #     proto.active_seat = self.table.active_seat
        # else:
        #     proto.active_seat = -1
        # print 'active seat:', proto.active_seat
        # proto.discard_seat = self.table.discard_seat
        # proto.rest_cards = self.table.cards_total if self.table.state == "InitState" else len(self.table.cards_on_desk)
        proto.code = 1
        if self.table.dealer_seat != -1:
            for card in self.table.cards_on_desk:
                cards = proto.rest_cards.add()
                cards.card = card

        log = {
            "description": "reconnect",
            "room_id": self.table.room_id,
            "kwargs": self.table.kwargs,
            "owner": self.table.owner,
            "owner_info": self.table.owner_info,
            "cur_round": self.table.cur_round,
            "room_status": table_state_code_map[self.table.state],
            "dealer": self.table.dealer_seat,
            "active_seat": self.table.active_seat,
            "discard_seat": self.table.discard_seat,
            "rest_cards": len(self.table.cards_on_desk),
            "code": 1,
            "room_score": self.table.get_base_core(self),
            "room_times": self.table.get_multiple(self),
            "current_round": self.table.cur_round,
            "spy_card":self.table.spy_card,
            "spy_seat":proto.spy_seat,
            "players": [],
        }

        for i in self.table.player_dict.values():
            player = proto.player.add()
            player.seat = i.seat
            player.player = i.uuid
            player.info = i.info
            player.status = player_state_code_map[i.state]
            player.is_online = 1 if i.is_online else 0
            player.total_score = i.total
            # 喜的个数
            player.bid_score = i.reward_counts
            # player.is_ting = i.isTing
            # player.is_jia = i.isJia
            # player.last_draw_card = self.draw_card
            # is_yao_fail:
            # is_yao_fail = 1
            # else:
            # is_yao_fail = 0

            for c in i.cards_in_hand:
                cards = player.cards_in_hand.add()
                if i.uuid == self.uuid:
                    cards.card = c
                elif i.show_card == 1:
                    cards.card = c
                else:
                    cards.card = ""
            for c in i.last_cards_discard:
                cards = player.cards_discard.add()
                cards.card = c
            if i.last_cards_discard:
                from algorithm.card_type.main import match_type
                player.cards_type = match_type(i.last_cards_discard, 10)
            if i.table.dealer_seat != -1:
                player.role = 1 if i.seat == i.table.dealer_seat else 0
                if proto.spy_seat != -1 and i.seat == proto.spy_seat:
                    player.role = 2
            else:
                player.role = -1
            # if len(self.table.farmer_double) <= 1:
            #     if self.seat in self.table.farmer_double:
            #         if i.seat == self.seat:
            #             # 自己是第一个农民
            #             player.has_double = i.double
            #         else:
            #             player.has_double = 0
            #     else:
            #         player.has_double = 0
            # else:
            #     player.has_double = i.double
            # 是否选择过明牌,在明牌阶段重连控制不出的显示
            player.has_double = 1 if i.has_chosen_ming else 0

            # 1明牌2不明牌0未选择
            player.has_show = i.show_card

            log["players"].append({
                "seat": i.seat,
                "player": i.uuid,
                "info": i.info,
                "status": player_state_code_map[i.state],
                "is_online": i.is_online,
                "total": i.total,
                "cards_in_hand": i.cards_in_hand,
                "cards_discard": i.cards_discard,
                "bid_score": i.reward_counts,
                "has_double": player.has_double,
                "has_show": i.show_card
            })
        send(POKER_RECONNECT, proto, self.session)
        self.table.logger.info(log)

        if self.table.dismiss_state:
            # 先弹出投票界面
            expire_seconds = int(dismiss_delay + self.table.dismiss_time - time.time())
            if expire_seconds <= 0:
                self.table.dismiss_room()
                return
            proto = game_pb2.SponsorVoteResponse()
            proto.room_id = self.table.room_id
            proto.sponsor = self.table.dismiss_sponsor
            proto.expire_seconds = expire_seconds
            send(SPONSOR_VOTE, proto, self.session)
            # 生成定时器
            if not self.vote_timer and self.uuid != self.table.dismiss_sponsor and not self.vote_state:
                proto_vote = game_pb2.PlayerVoteRequest()
                proto_vote.flag = True
                self.vote_timer = IOLoop().instance().add_timeout(
                    self.table.dismiss_time + dismiss_delay, self.vote, proto_vote)
            # 遍历所有人的投票状态
            for player in self.table.player_dict.values():
                proto_back = game_pb2.PlayerVoteResponse()
                proto_back.player = player.uuid
                if player.vote_state is not None:
                    proto_back.flag = player.vote_state
                    send(VOTE, proto_back, self.session)

        if self.table.active_seat != -1 and  self.table.state != "ShowCardState":
            # 发送出牌提醒
            self.table.clear_prompt()
            self.table.clear_actions()
            proto = game_pb2.PokerDiscardNotifyResponse()
            active_seat = self.table.active_seat

            proto.player = self.table.seat_dict[self.table.active_seat].uuid
            self.table.reset_proto(NOTIFY_DISCARD)
            self.proto.p = copy(proto)
            self.proto.send()
        #
        # elif self.table.machine.cur_state.name == 'DoubleState':
        #     # 加倍信息
        #     if len(self.table.farmer_double) >= self.table.chairs - 1:
        #         # 农民都加倍完成
        #         self.table.reset_proto(POKER_DOUBLE)
        #         proto_double_res = game_pb2.PokerDoubleResponse()
        #         for has_double_player in self.table.farmer_double:
        #             every_player = self.table.seat_dict[has_double_player]
        #             players = proto_double_res.players.add()
        #             players.seat = every_player.seat
        #             players.flag = True if every_player.seat in self.table.double_seat else False
        #         self.proto.p = copy(proto_double_res)
        #         self.proto.send()
        #     elif self.seat in self.table.farmer_double:
        #         # 农民未加倍完成给自己发
        #         self.table.reset_proto(POKER_DOUBLE)
        #         proto_double_res = game_pb2.PokerDoubleResponse()
        #         players = proto_double_res.players.add()
        #         players.seat = self.seat
        #         players.flag = True if self.seat in self.table.double_seat else False
        #         self.proto.p = copy(proto_double_res)
        #         self.proto.send()
        #     # 加倍提醒
        #     if self.seat == self.table.dealer_seat:
        #         # 地主
        #         if len(self.table.farmer_double) == self.table.chairs - 1:
        #             # 两个农民点完了
        #             proto_double_init = game_pb2.PokerDoubleInitResponse(double_list=[self.seat])
        #             send(POKER_DOUBLE_INIT, proto_double_init, self.session)
        #     else:
        #         # 农民
        #         if self.seat not in self.table.farmer_double:
        #             proto_double_init = game_pb2.PokerDoubleInitResponse()
        #             for k, v in self.table.seat_dict.iteritems():
        #                 if k != self.table.dealer_seat:
        #                     proto_double_init.double_list.append(k)
        #             send(POKER_DOUBLE_INIT, proto_double_init, self.session)
        #
        # elif self.table.machine.cur_state.name == "RobState":
        #     # 普通叫地主
        #     if self.table.conf.play_type == 1:
        #         # if self.seat == self.table.rob_seat:
        #         #     if len(self.table.rob_seat) == 0:
        #         #         # 第一个叫地主的人
        #         #         # 全发
        #         #         proto_rob_init = game_pb2.RobLandLordInitResponse()
        #         #         proto.uuid = self.table.seat_dict[self.table.rob_seat].uuid
        #         #         proto.play_type = self.table.conf.play_type
        #         #         send(ROB_DEALER_INIT, proto_rob_init, self.session)
        #         #     else:
        #         #         pass
        #         if len(self.table.rob_players) == 0:
        #             self.table.reset_proto(ROB_DEALER)
        #             proto_rob_res = game_pb2.RobLandLordReponse()
        #             # proto.uuid = player.uuid
        #             proto_rob_res.rob_score = -1
        #             proto_rob_res.win_seat = -1
        #             proto_rob_res.rob_seat = self.table.rob_seat
        #             proto_rob_res.base_score = self.table.get_base_core(self)
        #             self.proto.p = copy(proto_rob_res)
        #             self.proto.send()
        #         else:
        #             self.table.reset_proto(ROB_DEALER)
        #             proto_rob_res = game_pb2.RobLandLordReponse()
        #             rob_p = self.table.seat_dict[self.table.rob_seat]
        #             pre_p = self.table.seat_dict[rob_p.prev_seat]
        #             proto_rob_res.uuid = pre_p.uuid
        #             proto_rob_res.rob_score = pre_p.rob_score
        #             proto_rob_res.win_seat = -1
        #             proto_rob_res.rob_seat = self.table.rob_seat
        #             proto_rob_res.base_score = self.table.get_base_core(self)
        #             self.proto.p = copy(proto_rob_res)
        #             self.proto.send()
        # 明牌状态
        if self.table.state == "ShowCardState":
            proto = game_pb2.PokerShowCardInitResponse()
            proto.seat = self.table.show_card_seat
            proto.flag = self.table.get_show_cards_flag(self.table.show_card_seat)
            send(POKER_SHOW_CARDS_INIT, proto, self.session)
        # 一打四还是叫狗腿,取消计时器之后需要在重连时候弹出按钮
        if self.table.dealer_seat == self.table.spy_chair:
            proto = game_pb2.PokerDealerChooseInitResponse()
            proto.dealer_seat = self.table.dealer_seat
            proto.flag = 1 if self.seat == self.table.dealer_seat else -1
            send(POKER_DEALER_CHOOSE_INIT, proto, self.session)
Exemplo n.º 3
0
    def reconnect(self):
        proto = game_pb2.CockReconnectResponse()
        proto.room_id = self.table.room_id
        proto.kwargs = self.table.kwargs
        proto.owner = self.table.owner
        proto.room_score = self.table.conf.base_score
        proto.room_status = int(table_state_code_map[self.table.state])
        proto.current_round = self.table.cur_round
        proto.code = 1
        log = {
            "description": "reconnect",
            "room_id": self.table.room_id,
            "kwargs": self.table.kwargs,
            "owner": self.table.owner,
            "owner_info": self.table.owner_info,
            "cur_round": self.table.cur_round,
            "room_status": table_state_code_map[self.table.state],
            "code": 1,
            "current_round": self.table.cur_round,
            "players": [],
        }

        for i in self.table.player_dict.values():
            player = proto.player.add()
            player.seat = i.seat
            player.player = i.uuid
            player.info = i.info
            player.status = player_state_code_map[i.state]
            player.is_online = 1 if i.is_online else 0
            player.total_score = i.total
            player.is_abandon = 1 if i.seat in self.table.abandon_list else 0

            log["players"].append({
                "seat": i.seat,
                "player": i.uuid,
                "info": i.info,
                "status": player_state_code_map[i.state],
                "is_online": i.is_online,
                "total": i.total,
                "cards_in_hand": i.cards_in_hand,
            })
            # if i.seat == self.seat:
            for c in i.cards_in_hand:
                cards = player.cards_in_hand.add()
                cards.card = c if i.seat == self.seat else ""
            if i.seat == self.seat:
                for c in i.card_group:
                    cards_list = player.card_group.add()
                    for cc in c:
                        cards_list.cards.append(cc)

        send(POKER_RECONNECT, proto, self.session)
        self.table.logger.info(log)

        if self.table.state == "WaitState" and self.state == "DiscardState":
            # 发送出牌提醒
            proto = game_pb2.CockDiscardNotifyResponse()
            proto.player = self.uuid
            for i in self.table.abandon_list:
                proto.abandon_seat.append(i)
            for i in self.table.discard_list:
                proto.discard_seat.append(i)
            self.table.reset_proto(NOTIFY_DISCARD)
            self.proto.p = copy(proto)
            self.proto.send()

        if self.table.dismiss_state:
            # 先弹出投票界面
            expire_seconds = int(dismiss_delay + self.table.dismiss_time - time.time())
            if expire_seconds <= 0:
                self.table.dismiss_room()
                return
            proto = game_pb2.SponsorVoteResponse()
            proto.room_id = self.table.room_id
            proto.sponsor = self.table.dismiss_sponsor
            proto.expire_seconds = expire_seconds
            send(SPONSOR_VOTE, proto, self.session)
            # 生成定时器
            if not self.vote_timer and self.uuid != self.table.dismiss_sponsor and not self.vote_state:
                proto_vote = game_pb2.PlayerVoteRequest()
                proto_vote.flag = True
                self.vote_timer = IOLoop().instance().add_timeout(
                    self.table.dismiss_time + dismiss_delay, self.vote, proto_vote)
            # 遍历所有人的投票状态
            for player in self.table.player_dict.values():
                proto_back = game_pb2.PlayerVoteResponse()
                proto_back.player = player.uuid
                if player.vote_state is not None:
                    proto_back.flag = player.vote_state
                    send(VOTE, proto_back, self.session)
Exemplo n.º 4
0
    def reconnect(self):
        proto = game_pb2.ReconnectResponse()
        proto.room_id = self.table.room_id
        proto.kwargs = self.table.kwargs
        proto.owner = self.table.owner
        proto.room_status = table_state_code_map[self.table.state]
        proto.current_round = self.table.cur_real_round
        proto.dealer = self.table.dealer_seat
        active_seat = self.table.active_seat
        #print 'active seat:', active_seat,self.table.seat_dict[active_seat].state
        # 对于前端只有活动玩家处于出牌状态才发送指示灯
        if active_seat >= 0 and \
                (self.table.seat_dict[active_seat].state == "DiscardState" or self.table.seat_dict[active_seat].state == "PromptDrawState"
                 or self.table.seat_dict[active_seat].state == "PromptDiscardState"):
            proto.active_seat = self.table.active_seat
        else:
            proto.active_seat = -1
        #print 'active seat:', proto.active_seat, 'self.table.active_seat', self.table.active_seat
        proto.discard_seat = self.table.discard_seat
        proto.rest_cards = self.table.cards_total if self.table.state == "InitState" else len(
            self.table.cards_on_desk)
        proto.code = 1
        last_draw = 0
        if len(self.cards_in_hand
               ) % 3 == 2 and self.draw_card in self.cards_in_hand:
            last_draw = self.draw_card

        proto.extra = json.dumps({'last_draw': last_draw})

        log = {
            "description": "reconnect",
            "room_id": self.table.room_id,
            "kwargs": self.table.kwargs,
            "owner": self.table.owner,
            "owner_info": self.table.owner_info,
            "cur_round": self.table.cur_real_round,
            "room_status": table_state_code_map[self.table.state],
            "dealer": self.table.dealer_seat,
            "active_seat": self.table.active_seat,
            "discard_seat": self.table.discard_seat,
            "rest_cards": len(self.table.cards_on_desk),
            "code": 1,
            "players": [],
            "last_draw": last_draw,
        }

        for i in self.table.player_dict.values():
            player = proto.player.add()
            player.seat = i.seat
            player.player = i.uuid
            player.info = i.info
            player.status = player_state_code_map[i.state]
            player.is_online = i.is_online
            player.total_score = i.total
            player.is_ting = i.isTing
            player.is_jia = i.isJia
            player.last_draw_card = self.draw_card
            if i.is_yao_fail:
                player.is_yao_fail = 1
            else:
                player.is_yao_fail = 0

            for c in i.cards_in_hand:
                cards = player.cards_in_hand.add()
                if i.uuid == self.uuid:
                    cards.card = c
                else:
                    cards.card = 0
            for c in i.cards_discard:
                cards = player.cards_discard.add()
                cards.card = c
            for c in i.cards_kong_exposed:
                cards = player.cards_kong_exposed.add()
                cards.card = c
            for c in i.cards_kong_concealed:
                cards = player.cards_kong_concealed.add()
                cards.card = c
            for c in i.cards_pong:
                cards = player.cards_pong.add()
                cards.card = c
            for c in i.cards_chow:
                cards = player.cards_chow.add()
                cards.card = c

            log["players"].append({
                "seat": i.seat,
                "player": i.uuid,
                "info": i.info,
                "status": player_state_code_map[i.state],
                "is_online": i.is_online,
                "total": i.total,
                "cards_in_hand": i.cards_in_hand,
                "cards_discard": i.cards_discard,
                "cards_Kong_exposed": i.cards_kong_exposed,
                "cards_Kong_concealed": i.cards_kong_concealed,
                "cards_pong": i.cards_pong,
                "cards_chow": i.cards_chow,
            })
        send(RECONNECT, proto, self.session)
        self.table.logger.info(log)
        # 必须屏蔽掉以下代码否则重连之前点过然后重连之后又出现提示
        # 此时再点听则无任何效果客户端显示为卡住
        # from rules.player_rules.ting import TingRule
        # if not self.isTing:
        #     r = TingRule()
        #     r.condition(self)
        # 发送操作提示
        if self.action_dict:
            self.send_prompts()

        #print 'player id:', self.seat, self.uuid, ',isting:', self.isTing, 'ready len:', len(self.cards_ready_hand)
        # 发送听牌提示
        if self.isTing and self.cards_ready_hand:
            proto = game_pb2.ReadyHandResponse()
            proto.ting_tag = 1
            tmp_ready_hand = {}
            for i in self.cards_ready_hand:
                flag = False
                if self.isJia:
                    if "JIAHU" in self.cards_ready_hand[i][1]:
                        flag = True
                        proto.ting_tag = 2
                    elif self.table.conf.bian_hu_jia(
                    ) and "BIANHU" in self.cards_ready_hand[i][1]:
                        flag = True
                        proto.ting_tag = 2
                    else:
                        flag = False
                else:
                    flag = True
                if flag:
                    c = proto.card.add()
                    if type(i) is types.IntType:
                        c.card = i
                    else:
                        c.card = int(i)
                    tmp_ready_hand[int(i)] = self.cards_ready_hand[i]
            self.cards_ready_hand = tmp_ready_hand
            send(READY_HAND, proto, self.session)
            #self.table.broadcast_change_bao()
        if self.table.dismiss_state:
            # 先弹出投票界面
            expire_seconds = int(dismiss_delay + self.table.dismiss_time -
                                 time.time())
            if expire_seconds <= 0:
                self.table.dismiss_room()
                return
            proto = game_pb2.SponsorVoteResponse()
            proto.room_id = self.table.room_id
            proto.sponsor = self.table.dismiss_sponsor
            proto.expire_seconds = expire_seconds
            send(SPONSOR_VOTE, proto, self.session)
            # 生成定时器
            if not self.vote_timer and self.uuid != self.table.dismiss_sponsor and not self.vote_state:
                proto_vote = game_pb2.PlayerVoteRequest()
                proto_vote.flag = True
                self.vote_timer = IOLoop().instance().add_timeout(
                    self.table.dismiss_time + dismiss_delay, self.vote,
                    proto_vote)
            # 遍历所有人的投票状态
            for player in self.table.player_dict.values():
                proto_back = game_pb2.PlayerVoteResponse()
                proto_back.player = player.uuid
                if player.vote_state is not None:
                    proto_back.flag = player.vote_state
                    send(VOTE, proto_back, self.session)
        self.table.send_last_card()