Exemple #1
0
    def onRoomCreateCustomTable(self, gameId, msg):
        '''在GR处理自建桌逻辑
        '''
        if ftlog.is_debug():
            ftlog.debug("<< |msg", msg, caller=self)

        userId = msg.getParam("userId")
        selectedRoomOptions = msg.getParam("selectedRoomOptions")
        if not selectedRoomOptions:
            return
        customConfVer = msg.getParam("customConfVer")
        if customConfVer != difangConf.getCustomRoomConf(gameId, 'ver'):
            ftlog.warn("onRoomCreateCustomTable confVer error! |msg:", msg, caller=self)
            return
        gameRoundN = selectedRoomOptions.get("gameRoundN")
        if not gameRoundN:
            return
        roomId = msg.getParam("roomId")
        room = gdata.rooms()[roomId]
        clientId = msg.getParam("clientId")

        needRoomCardN = difangConf.getCustomRoomConf(gameId, 'roomCardNCost').get(str(gameRoundN), -1)
        if needRoomCardN == -1:
            tips = difangConf.getCustomRoomConf(difangConf.GAME_ID, 'err_tips')
            tip = tips[self.CREATE_CUSTOM_TABLE_ERR_NO_NOT_ALLOW]
            TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskShowInfo(tip, True))
            ftlog.warn("onRoomCreateCustomTable get needRoomCardN error! |msg:", msg, caller=self)
            self.sendGameCreateCustomTableRes(0, userId)
            return

        if ftlog.is_debug():
            ftlog.debug("|userId, gameId, customConfVer, gameRoundN, needRoomCardN:",
                        userId, gameId, customConfVer, gameRoundN, needRoomCardN, caller=self)

        if needRoomCardN > 0 and not self.isCardEnough(gameId, userId, needRoomCardN, clientId):
            tips = difangConf.getCustomRoomConf(difangConf.GAME_ID, 'err_tips')
            tip = tips[self.CREATE_CUSTOM_TABLE_ERR_NO_NOT_ENOUGH]
            TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskShowInfo(tip, True))
            self.sendGameCreateCustomTableRes(0, userId)
            return

        tableId = room.getIdleTableId()
        if not tableId:
            ftlog.error("there are no idle tables!", "|userId, roomId:", userId, room.roomId)
            return

        ftId = self.assignFriendTableId(gameId, tableId)

        ftlog.info("onRoomCreateCustomTable |userId, tableId, ftId:", userId, tableId, ftId, caller=self)
        self.sendGameCreateCustomTableRes(ftId, userId)
        gamedata.setGameAttr(userId, gameId, "selectedRoomOptions", json.dumps(selectedRoomOptions))
        gamedata.setGameAttr(userId, gameId, "customConfVer", customConfVer)

        shadowRoomId = tableId / 10000
        room.querySitReq(userId, shadowRoomId, tableId, clientId,
                         extParams={"selectedRoomOptions": selectedRoomOptions, "ftId": ftId})
Exemple #2
0
    def _getSelectedRoomOptions(self, userId, gameId):

        if ftlog.is_debug():
            ftlog.debug("|userId, gameId:", userId, gameId, caller=self)

        if not self._checkUserLastSelectedCustomRoomConfVer(userId, gameId):
            return difangConf.getCustomRoomConf(gameId, 'defaultSelectedOptions')

        selectedRoomOptions = gamedata.getGameAttrJson(userId, gameId, "selectedRoomOptions")
        if not selectedRoomOptions:  # 新加玩法类型
            return difangConf.getCustomRoomConf(gameId, 'defaultSelectedOptions')

        if ftlog.is_debug():
            ftlog.debug("|userId, gameId:", userId, gameId, "|selectedRoomOptions:", selectedRoomOptions, caller=self)

        return selectedRoomOptions
Exemple #3
0
    def _checkUserLastSelectedCustomRoomConfVer(self, userId, gameId):
        confVer = difangConf.getCustomRoomConf(gameId, 'ver')
        userLastSelectedCustomRoomConfVer = gamedata.getGameAttr(userId, gameId, "customConfVer")
        if ftlog.is_debug():
            ftlog.debug("|userId, gameId, confVer, userLastSelectedCustomRoomConfVer:",
                        userId, gameId, confVer, userLastSelectedCustomRoomConfVer, caller=self)
        if userLastSelectedCustomRoomConfVer and confVer != userLastSelectedCustomRoomConfVer:
            return False

        return True
Exemple #4
0
    def onGameGetCustomOptions(self, gameId, msg):
        # def onRoomGetCustomOptions(self, gameId, msg):
        '''在GR处理获取自建桌配置逻辑
        '''
        if ftlog.is_debug():
            ftlog.debug("<< |msg", msg, caller=self)

        msg = runcmd.getMsgPack()
        userId = msg.getParam("userId")

        selectedRoomOptions = self._getSelectedRoomOptions(userId, gameId)

        msgRes = MsgPack()
        msgRes.setCmd("game")
        msgRes.setResult("action", "get_custom_options")
        msgRes.setResult("userId", userId)
        msgRes.setResult("gameId", gameId)
        msgRes.setResult("selectedRoomOptions", selectedRoomOptions)
        msgRes.setResult("customRoomOptions", difangConf.getCustomRoomConf(gameId, 'options'))
        msgRes.setResult("customConfVer", difangConf.getCustomRoomConf(gameId, 'ver'))
        router.sendToUser(msgRes, userId)
Exemple #5
0
    def consumeRooCardsFirstWay(self, table, needRoomCardN):
        gameId = table.gameId

        oneRoomCardGameRoundN = difangConf.getCustomRoomConf(gameId, "oneRoomCardGameRoundN")
        if not oneRoomCardGameRoundN:
            return

        if table.gamePlay.gameSeq % oneRoomCardGameRoundN != 1:
            return

        userId = table.firstPlayerId
        clientId = sessiondata.getClientId(userId)
        self.consumeRoomCard(gameId, userId, 1, clientId)
        table.consumedRoomCardN += 1
Exemple #6
0
    def onSendTableInfo(self, gameId, msg):
        if ftlog.is_debug():
            ftlog.debug("<< |msg", msg, caller=self)

        userId = msg.getParam("userId")
        table = msg.getParam("table")
        mpTableInfoRes = msg.getParam("mpTableInfoRes")

        winxinDesc = u"房间号:" + table.ftId
        selectedOptionNames = []
        options = difangConf.getCustomRoomConf(gameId, "options")

        for option in options:
            key = option["key"]
            for i, value in enumerate(option["values"]):
                if value == table.selectedRoomOptions[key]:
                    name = unicode(option["names"][i])
                    winxinDesc += " ," + name
                    selectedOptionNames.append(name)

        # maxSeatN = table.selectedRoomOptions["maxSeatN"]
        # gameRoundN = table.selectedRoomOptions["gameRoundN"]

        # for option in options:
        #     if option["key"] == "bankerRule":
        #         for i, value in enumerate(option["values"]):
        #             if value == table.selectedRoomOptions["bankerRule"]:
        #                 bankerRuleName = option["names"][i]
        #         if option["key"] == "bombMultipleType":
        #             for i, value in enumerate(option["values"]):
        #                 if value == table.selectedRoomOptions["bombMultipleType"]:
        #                     bombMultipleTypeName = option["names"][i]
        #         if option["key"] == "bombMultipleMax":
        #             for i, value in enumerate(option["values"]):
        #                 if value == table.selectedRoomOptions["bombMultipleMax"]:
        #                     bombMultipleMaxName = option["title"] + option["names"][i]

        # 微信配置
        weixinShare = difangConf.getPublicConf(gameId, "weixinShare")
        weixinurl, weixintitle = difangConf.getShareInfo(userId, gameId, "gdy_invite_play_share")
        if weixinurl:
            weixinShare["weixinurl"] = weixinurl
            weixinShare["weixintitle"] = weixintitle
        weixinShare["weixindesc"] = winxinDesc
        mpTableInfoRes.setResult('weixinShare', weixinShare)
        mpTableInfoRes.setResult('selectedOptionNames', selectedOptionNames)
Exemple #7
0
    def onTableGameStart(self, gameId, msg):
        '''在GT处理牌局开始时扣房卡
        '''
        if ftlog.is_debug():
            ftlog.debug("<< |msg", msg, caller=self)

        table = msg.getParam("table")

        gameRoundN = table.selectedRoomOptions["gameRoundN"]
        needRoomCardN = difangConf.getCustomRoomConf(gameId, 'roomCardNCost').get(str(gameRoundN), -1)
        if needRoomCardN <= 0 or needRoomCardN == table.consumedRoomCardN:
            return

        way = msg.getParam("way", 2)
        if way == 2:
            self.consumeRooCardsSecondWay(table, needRoomCardN)

        ftlog.info("onTableGameStart >> |userId, tableId, ftId, consumedRoomCardN:",
                   table.firstPlayerId, table.tableId, table.ftId, table.consumedRoomCardN, caller=self)