Example #1
0
    def pay(self, avt_mb):
        card_cost, diamond_cost = self.base_info['cost']

        def callback(uid, content):
            avt = x42.GW.avatars.get(uid)
            if content[0] != '{':
                DEBUG_MSG(content)
                if avt:
                    avt.showTip("摩卡不足")
                return
            if avt and avt.isDestroyed == False:
                avt.gameLeft = const.WEEK_SPORT_GAME_NUM
                self.joinSuccess(avt)
            else:
                sql = "UPDATE tbl_Avatar set sm_left_games = {} where sm_userId = {}".format(
                    const.WEEK_SPORT_GAME_NUM, uid)

                def update_cb(result, num, insert_id, error):
                    if error:
                        ERROR_MSG(
                            "update gameLeft for player-{} failed!".format(
                                uid))

                KBEngine.executeRawDatabaseCommand(sql, update_cb)

        utility.update_card_diamond(avt_mb.accountName, -card_cost,
                                    -diamond_cost,
                                    Functor.Functor(callback, avt_mb.userId),
                                    "PaoDeKuai sport:{}".format(self.sportId))
Example #2
0
	def createRoomCallback(self, room, err = None):
		DEBUG_MSG("createRoomCallback")
		if room:
			room.roomID = utility.gen_room_id(room.id)
			if room.is_agent == 1:
				def callback(content):
					try:
						content = content.decode()
						if content[0] != '{':
							DEBUG_MSG(content)
							return
						room.reqEnterRoom(self, True)
						self.room = room
						KBEngine.globalData["GameWorld"].addRoom(room)
						info = room.get_init_client_dict()
						if getattr(self, 'client', None):
							self.client.createRoomSucceed(info)
					except:
						DEBUG_MSG("agent consume callback error:{}".format(content))
				card_cost, diamond_cost = switch.calc_cost(room.game_round, room.player_num, room.pay_mode)
				if switch.DEBUG_BASE:
					callback('{"card":99, "diamond":999}'.encode())
				else:
					utility.update_card_diamond(self.accountName, -card_cost, -diamond_cost ,callback, "NingBoMJ RoomID:{}".format(self.roomID)) # reason 必须为英文
			else:
				room.reqEnterRoom(self, True)
				self.room = room
				KBEngine.globalData["GameWorld"].addRoom(room)
				info = room.get_init_client_dict()
				if getattr(self, 'client', None):
					self.client.createRoomSucceed(info)
		else:
			if getattr(self, 'client', None):
				self.client.createRoomFailed(const.CREATE_FAILED_OTHER)
Example #3
0
	def dropRoom(self):
		self.dismiss_timer = None
		for i,p in enumerate(self.players_list):
			if p and p.mb:
				try:
					p.mb.quitRoomSucceed()
				except:
					pass

		if self.room_type == const.AGENT_ROOM and self.agent:
			# 将房间从代理房间中删除
			if not self.agent.isDestroyed:
				self.agent.agentRoomDropped(self.roomID)

			try:
				# 如果是代开房, 没打完一局返还房卡
				if switch.DEBUG_BASE == 0 and self.current_round < 1 and self.agent and self.pay_mode == const.AGENT_PAY_MODE:
					card_cost, diamond_cost = switch.calc_cost(self.game_round, self.getCalCostNeed())

					def callback(room_id, user_id, content):
						try:
							content = content.decode()
							if content[0] != '{':
								DEBUG_MSG(content)
								return
						except:
							DEBUG_MSG("dropRoom{} AgentRoom return Failed, userID = {}. return {} back".format(room_id, user_id, (card_cost, diamond_cost)))

					utility.update_card_diamond(self.agent.accountName, card_cost, diamond_cost,
												Functor(callback, self.roomID, self.agent.userId), "KouDianDian drop AgentRoomID:{}".format(self.roomID))  # reason 必须为英文
			except:
				pass

		self._reset()
Example #4
0
	def run(self, entityCall, user_id):
		if entityCall.isDestroyed:
			DEBUG_MSG("Award card: entityCall isDestroyed, user id {}, task id {}, card {}".format(user_id, self.task_id, self.card))
		else:
			if switch.DEBUG_BASE > 0:
				entityCall.task_action_complete(self.task_id, self.card)
			else:
				utility.update_card_diamond(entityCall.accountName, self.card, 0, Functor(self.callback, user_id), "task {} award {}".format(self.task_id, self.card))
Example #5
0
	def getReward(self, op):
		# 默认操作为领取 0 领取 1转房卡
		DEBUG_MSG("getReward:: {} op is {}".format(self.userId, op))
		# 检查领奖物品是否过期
		if not self.checkRewardTime():
			# 清空记录
			self.reward_list = []
			if self.hasClient:
				self.client.gotReward(const.LOTTERY_OVER_TIME, '您的奖品已经超过领取时间!')
				return

		reward = copy.copy(self.reward_list[0])
		# reward 不可能为空
		if op == const.LOTTERY_OPERATION_1:
			num = reward['change']
			reward_type = 'card'
		else:
			num = reward['num']
			reward_type = reward['type']

		def db_cb(state, error):
			DEBUG_MSG("update offline reward : {} {}".format(state, error))

		dbid = self.databaseID

		# 房卡增加的回调函数
		def callback(user_id, msg, dbid, reward, content):
			DEBUG_MSG("{} lottery add card {}".format(user_id, content))
			avatar = x42.GW.avatars.get(user_id)
			if avatar is None or avatar.isDestroyed:
				dbi.deleteFromAvatarReward(dbid, reward, db_cb)
				DEBUG_MSG("Lottery card: entityCall isDestroyed, user id {}, type {}, num {}".format(user_id, reward_type, num))
			else:
				self.reward_list = []
				if avatar.hasClient:
					avatar.client.gotReward(const.LOTTERY_SUCCESS, msg)

		def add_card_cb(accountName, user_id, msg, content):
			if content is None:
				WARNING_MSG("add card error")
			DEBUG_MSG("add_card_cb:: card {}".format(content))
			utility.post_award_msg(accountName, Functor(callback, user_id, msg, dbid, reward), "lottery type {} award {} is_change_card {}".format(reward_type, num, op))

		# 如果
		if reward_type == 'card':
			msg = '领取奖励成功!增加了' + str(num) + '张房卡'
			if switch.DEBUG_BASE > 0:
				callback(self.userId, msg, dbid, reward, 'test')
			else:
				utility.update_card_diamond(self.accountName, num, 0, Functor(add_card_cb, self.accountName, self.userId, msg), "lottery type {} award {} is_change_card {}".format(reward_type, num, op))
		if reward_type == 'call':
			msg = '领取话费奖励成功!话费将在1~3个工作日内为您充值!'
			if switch.DEBUG_BASE > 0:
				callback(self.userId, msg, dbid, reward, 'test')
			else:
				# 通知php服 有人抽到了话费
				# callback(self.userId,'领取话费奖励成功!话费将在1~3个工作日内为您充值!')
				utility.post_award_msg(self.accountName, Functor(callback, self.userId, msg, dbid, reward), "lottery type {} award {} is_change_card {}".format(reward_type, num, op))
Example #6
0
	def chargeEffect(self):
		card_cost	= 1
		diamond_cost = 9999
		def pay_callback(content):
			INFO_MSG("player charge effect userId:{} account:{} content:{}".format(self.userId, self.accountName, content))
			if content is not None and content[0] == '{':
				if self.client:
					self.client.client_update_card_diamond()
		utility.update_card_diamond(self.accountName, -card_cost, -diamond_cost, pay_callback, "player {} pay effect".format(self.userId))
Example #7
0
	def pay2StartGame(self):
		""" 开始游戏 """
		DEBUG_MSG("room:{},curround:{},game_mode:{},king_mode:{},game_round:{},hand_prepare:{} pay2StartGame state:{}".format(self.roomID, self.current_round,
		self.game_mode, self.king_mode, self.game_round, self.hand_prepare,
		self.state))

		if self.timeout_timer:
			self.cancel_timer(self.timeout_timer)
			self.timeout_timer = None

		self.state = const.ROOM_TRANSITION

		# 在第2局开始扣房卡
		if self.current_round == 1:
			if switch.DEBUG_BASE:
				self.paySuccessCbk()
				return

			card_cost, diamond_cost = switch.calc_cost(self.game_round, self.getCalCostNeed())
			if self.pay_mode == const.NORMAL_PAY_MODE:
				pay_account = self.origin_players_list[0].mb.accountName
				reason = "KouDianDian RoomID:{}".format(self.roomID)

				def pay_callback(content):
					if self._check_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond(pay_account, -card_cost, -diamond_cost, pay_callback, reason)
			elif self.pay_mode == const.AGENT_PAY_MODE:
				# 开房的时候已经扣了房卡
				self.paySuccessCbk()
			elif self.pay_mode == const.CLUB_PAY_MODE:
				pay_account = self.club.owner['accountName']
				reason = "KouDianDian Club:{} RoomID:{}".format(self.club.clubId, self.roomID)

				def pay_callback(content):
					if self._check_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond(pay_account, -card_cost, -diamond_cost, pay_callback, reason)
			elif self.pay_mode == const.AA_PAY_MODE:
				pay_accounts = [p.mb.accountName for p in self.players_list]
				if self.club:
					reason = "KouDianDian Club:{} AA RoomID:{}".format(self.club.clubId, self.roomID)
				else:
					reason = "KouDianDian AA RoomID:{}".format(self.roomID)

				def pay_callback(content):
					if self._check_aa_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond_aa(pay_accounts, -card_cost, -diamond_cost, pay_callback, reason)
			else:
				ERROR_MSG("pay2StartGame Error: No this PayMode:{}".format(self.pay_mode))
				return
		else:
			self.paySuccessCbk()
Example #8
0
    def pay(self, avt_mb):
        card_cost, diamond_cost = self.base_info['cost']

        def callback(content):
            DEBUG_MSG("pay callback {0},{1}".format(card_cost, diamond_cost))
            if content[0] != '{':
                DEBUG_MSG(content)
                return
            self.joinSuccess(avt_mb)

        DEBUG_MSG("pay {0},{1}".format(card_cost, diamond_cost))
        utility.update_card_diamond(avt_mb.accountName, -card_cost,
                                    -diamond_cost, callback,
                                    "PaoDeKuai sport:{}".format(self.sportId))
Example #9
0
	def handleCardBack(self, req_d):
		if switch.DEBUG_BASE != 0 or len(req_d) == 0:
			# 1.测试服不用管 2.长度为空也直接结束
			self.destroyProcessFinish()
			return
		INFO_MSG("handleCardBack, all Request = {}".format(req_d))
		self.executor.set('c', 0)
		self.executor.set('c_ok', 0)
		self.executor.add_condition(lambda: self.executor.get('c_ok') >= 1, [self.destroyProcessFinish, []])
		self.executor.add_condition(lambda: self.executor.get('c') >= len(req_d), [self.executor.inc1, ['c_ok']])

		for k, v in req_d.items():
			utility.update_card_diamond(k, v[0], v[1], Functor(self.updateCb, k, v),
										"KouDianDian safe kill server, pay back agent:{}".format(k))  # reason 必须为英文
Example #10
0
    def createRoomCallback(self, room, err=None):
        DEBUG_MSG("createRoomCallback")
        if room:
            if room.room_type == const.AGENT_ROOM:
                if room.pay_mode == const.AGENT_PAY_MODE:

                    def callback(content):
                        self.req_entering_room = False
                        try:
                            if content is None or content[0] != '{':
                                DEBUG_MSG(
                                    "agent consume callback error: content is None or error, room id {} ,content: {}"
                                    .format(room.roomId, content))
                                # 此处应当执行退款逻辑
                                room.destroySelf()
                                return
                            room.agent = self
                            x42.GW.addRoom(room)
                            self.playingRoomList.append(room.roomId)
                            self.getPlayingRoomInfo(True)
                        except:
                            DEBUG_MSG("agent consume callback error:{}".format(
                                content))
                            # 此处应当执行退款逻辑
                            room.destroySelf()
                            return

                    card_cost, diamond_cost = switch.calc_cost(
                        room.game_round, room.pay_mode)
                    if switch.DEBUG_BASE:
                        callback('{"card":99, "diamond":9999}')
                    else:
                        utility.update_card_diamond(
                            self.accountName, -card_cost, -diamond_cost,
                            callback, "GuiXi RoomID:{}".format(
                                room.roomId))  # reason 必须为英文
                elif room.pay_mode == const.AA_PAY_MODE:
                    self.req_entering_room = False
                    room.agent = self
                    x42.GW.addRoom(room)
                    self.playingRoomList.append(room.roomId)
                    self.getPlayingRoomInfo(True)
                else:
                    self.createRoomFailed(const.CREATE_FAILED_OTHER)
            else:
                room.reqEnterRoom(self, True)
        else:
            self.createRoomFailed(const.CREATE_FAILED_OTHER)
Example #11
0
    def createRoomCallback(self, room, err=None):
        if room:
            if room.is_agent == 1:
                def callback(content):
                    if content[0] != '{':
                        DEBUG_MSG(content)
                        return
                    self.createRoomSucceed(room)

                card_cost, diamond_cost = switch.calc_cost(room.game_round)
                if switch.DEBUG_BASE:
                    callback('{"card":99, "diamond":999}')
                else:
                    utility.update_card_diamond(self.accountName, -card_cost, -diamond_cost, callback,
                                                "PaoDeKuai RoomID:{}".format(self.roomID))  # reason 必须为英文
            else:
                self.createRoomSucceed(room)
        else:
            self.createRoomFailed(const.CREATE_FAILED_OTHER)
Example #12
0
	def pay2StartGame(self):
		""" 开始游戏 """
		DEBUG_MSG("{} game_mode:{},game_max_lose:{},game_round:{},hand_prepare:{} pay2StartGame state:{}"
				  .format(self.prefixLogStr, self.game_mode, self.game_max_lose, self.game_round, self.hand_prepare, self.state))

		if self.timeout_timer:
			self.cancel_timer(self.timeout_timer)
			self.timeout_timer = None

		self.state = const.ROOM_TRANSITION

		# 仅仅在第1局扣房卡, 不然每局都会扣房卡
		if self.current_round == 0:
			self.origin_players_list = self.players_list[:]
			if switch.DEBUG_BASE != 0:
				self.paySuccessCbk()
				return

			card_cost, diamond_cost = switch.calc_cost(self.game_round, self.getCalCostNeed())
			if self.pay_mode == const.NORMAL_PAY_MODE:
				def pay_callback(content):
					if self._check_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond(self.origin_players_list[0].mb.accountName, -card_cost, -diamond_cost, pay_callback, "{} RoomID:{}".format(const.GAME_NAME, self.roomID))
			elif self.pay_mode == const.AGENT_PAY_MODE:
				# 开房的时候已经扣了房卡 续房的时候需要再扣一次,这个时候房卡不足怎么办?
				if self._continue_room_flag:
					def pay_callback(content):
						if self._check_pay_callback(content):
							self.paySuccessCbk()

					utility.update_card_diamond(self.agent.accountName, -card_cost, -diamond_cost, pay_callback, "{} RoomID:{}".format(const.GAME_NAME, self.roomID))  # reason 必须为英文
			elif self.pay_mode == const.CLUB_PAY_MODE:
				pay_account = self.club.owner['accountName']
				reason = "{} Club:{} RoomID:{}".format(const.GAME_NAME, self.club.clubId, self.roomID)

				def pay_callback(content):
					if self._check_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond(pay_account, -card_cost, -diamond_cost, pay_callback, reason)
			elif self.pay_mode == const.AA_PAY_MODE:
				pay_accounts = [p.mb.accountName for p in self.players_list if p is not None]
				if self.club:
					reason = "{} Club:{} AA RoomID:{}".format(const.GAME_NAME, self.club.clubId, self.roomID)
				else:
					reason = "{} AA RoomID:{}".format(const.GAME_NAME, self.roomID)

				def pay_callback(content):
					if self._check_aa_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond_aa(pay_accounts, -card_cost, -diamond_cost, pay_callback, reason)
			else:
				ERROR_MSG("pay2StartGame Error: No this PayMode:{}".format(self.pay_mode))
				return
		else:
			self.paySuccessCbk()
Example #13
0
	def startGame(self):
		""" 开始游戏 """
		DEBUG_MSG("startGame")
		self.op_record = []
		self.state = 1
		self.current_round += 1

		diceList = self.throwTheDice([self.dealer_idx])
		idx, num = self.getMaxDiceIdx(diceList)

		# 仅仅在第1局扣房卡, 不然每局都会扣房卡
		def callback(content):
			content = content.decode()
			try:
				if content[0] != '{':
					DEBUG_MSG(content)
					self.dropRoom()
					return
				# 第一局时房间默认房主庄家, 之后谁上盘赢了谁是, 如果臭庄, 最后摸牌的人是庄
				for p in self.players_list:
					p.reset()
				self.current_idx = self.dealer_idx

				self.initTiles()
				self.deal(self.king_num)
				dragon_greens_list = [p.dragon_greens for i,p in enumerate(self.players_list)]
				for p in self.players_list:
					if p and p.mb:
						DEBUG_MSG("start game,dealer_idx:{0},tiles:{1}, kingTiles:{2}, diceList:{3},leftTileNum:{4}".format(self.dealer_idx, p.tiles, self.kingTiles, diceList, len(self.tiles)))
						p.mb.startGame(self.dealer_idx, p.tiles, dragon_greens_list, self.kingTiles, diceList)
				
				self.beginRound()
			except:
				DEBUG_MSG("consume failed!")

		if self.current_round == 1 and self.is_agent == 0:
			card_cost, diamond_cost = switch.calc_cost(self.game_round, self.player_num)
			if switch.DEBUG_BASE:
				callback('{"card":99, "diamond":999}'.encode())
			else:
				signal = 0
				def payCallback(content):
					nonlocal signal
					try:
						signal += 1
						if signal == len(self.players_list):
							callback(content)
					except:
						DEBUG_MSG("AA payCallback Failed")
				if self.player_num == 3:
					utility.update_card_diamond(self.players_list[0].mb.accountName, -card_cost, -diamond_cost, payCallback, "WuNingMJ RoomID:{}".format(self.roomID))
					utility.update_card_diamond(self.players_list[1].mb.accountName, -card_cost, -diamond_cost, payCallback, "WuNingMJ RoomID:{}".format(self.roomID))
					utility.update_card_diamond(self.players_list[2].mb.accountName, -card_cost, -diamond_cost, payCallback, "WuNingMJ RoomID:{}".format(self.roomID))
				else:
					utility.update_card_diamond(self.players_list[0].mb.accountName, -card_cost, -diamond_cost, payCallback, "WuNingMJ RoomID:{}".format(self.roomID))
					utility.update_card_diamond(self.players_list[1].mb.accountName, -card_cost, -diamond_cost, payCallback, "WuNingMJ RoomID:{}".format(self.roomID))
					utility.update_card_diamond(self.players_list[2].mb.accountName, -card_cost, -diamond_cost, payCallback, "WuNingMJ RoomID:{}".format(self.roomID))
					utility.update_card_diamond(self.players_list[3].mb.accountName, -card_cost, -diamond_cost, payCallback, "WuNingMJ RoomID:{}".format(self.roomID))
			return

		DEBUG_MSG("start Game: Room{0} - Round{1}".format(self.roomID, str(self.current_round)+'/'+str(self.game_round)))

		callback('{"card":99, "diamond":999}'.encode())
Example #14
0
    def startGame(self):
        """ 开始游戏 """
        self.op_record = []
        self.controller_discard_list = []
        self.deskPokerList = [[] for i in range(const.ROOM_PLAYER_NUMBER)]
        self.state = 1
        self.current_round += 1
        self.key_card = 0

        #扣费后开始游戏的回调
        def callback(content):
            content = content.decode()
            # try:
            if content[0] != '{':
                DEBUG_MSG(content)
                self.dropRoom()
                return
            for p in self.players_list:
                p.reset()
            self.initCards()
            self.deal()
            if self.changeSeat:
                if True or self.current_round == 1 or len(
                        self.show_empty_list) == 2:
                    # 根据需求每次重新换座位
                    self.random_key_card()
                    first_key_idx, second_key_idx = self.getKeyCardSeat()
                    self.swap_list = self.swapSeat(first_key_idx,
                                                   second_key_idx)
                    self.controller_idx = self.swap_list.index(first_key_idx)
                    self.wait_idx = self.controller_idx
                else:
                    self.key_card = 0
                    self.controller_idx = self.show_empty_list[0]
                    self.wait_idx = self.controller_idx
            else:
                if len(self.show_empty_list) > 0:
                    self.controller_idx = self.show_empty_list[0]
                    self.wait_idx = self.controller_idx
                else:
                    self.controller_idx = 0
                    self.wait_idx = self.controller_idx
            self.show_empty_list = []

            #DEBUG_MSG
            for i, p in enumerate(self.players_list):
                DEBUG_MSG("player [{0}] cards: {1}".format(p.idx, p.cards))
            for p in self.players_list:
                if p and p.mb:
                    p.start()
                    p.mb.startGame(self.controller_idx, self.key_card, p.cards,
                                   self.swap_list)
            # except:
            # 	DEBUG_MSG("consume failed!")

        if self.current_round == 1 and self.is_agent == 0:
            # 仅仅在第1局扣房卡, 不然每局都会扣房卡
            card_cost, diamond_cost = switch.calc_cost(self.game_round,
                                                       self.room_mode)
            if switch.DEBUG_BASE:
                callback('{"card":99, "diamond":999}'.encode())
            else:
                utility.update_card_diamond(
                    self.players_list[0].mb.accountName, -card_cost,
                    -diamond_cost, callback,
                    "BaiBianShuangKou RoomID:{}".format(self.roomID))
            return

        DEBUG_MSG("start Game: Room{0} - Round{1}".format(
            self.roomID,
            str(self.current_round) + '/' + str(self.game_round)))

        callback('{"card":99, "diamond":999}'.encode())
Example #15
0
    def charge(self, accountList):
        accountList = list(accountList)
        self.state = const.ROOM_TRANSITION
        if switch.DEBUG_BASE:
            self.chargeCallback(True)
            return
        card_cost, diamond_cost = utility.calc_cost(self.gameType,
                                                    self.roomParams)
        if self.pay_mode == const.NORMAL_PAY_MODE:
            pay_account = accountList[0]
            reason = "{} RoomID:{} type:{}".format(const.GAME_NAME,
                                                   self.roomID, self.className)

            def pay_callback(content):
                # ret = self._check_pay_callback(content)
                # self.chargeCallback(ret)
                INFO_MSG(
                    "player {} charge NORMAL_PAY_MODE pay_callback content:{}".
                    format(pay_account, content))
                # 不论是否扣卡成功, 都让玩家继续游戏
                self.chargeCallback(True)

            utility.update_card_diamond(pay_account, -card_cost, -diamond_cost,
                                        pay_callback, reason)
        elif self.pay_mode == const.CLUB_PAY_MODE:
            pay_account = self.club.owner['accountName']
            reason = "{} Club:{} RoomID:{} type:{}".format(
                const.GAME_NAME, self.club.clubId, self.roomID, self.className)

            def pay_callback(content):
                # ret = self._check_pay_callback(content)
                # self.chargeCallback(ret)
                INFO_MSG(
                    "player {} charge CLUB_PAY_MODE pay_callback  content:{}".
                    format(pay_account, content))
                # 不论是否扣卡成功, 都让玩家继续游戏
                self.chargeCallback(True)

            utility.update_card_diamond(pay_account, -card_cost, -diamond_cost,
                                        pay_callback, reason)
        elif self.pay_mode == const.AA_PAY_MODE:
            if self.club:
                reason = "{} Club:{} AA RoomID:{} type:{}".format(
                    const.GAME_NAME, self.club.clubId, self.roomID,
                    self.className)
            else:
                reason = "{} AA RoomID:{} type:{}".format(
                    const.GAME_NAME, self.roomID, self.className)

            def pay_callback(content):
                # ret = self._check_aa_pay_callback(content)
                # self.chargeCallback(ret)
                INFO_MSG(
                    "player {} charge AA_PAY_MODE pay_callback  content:{}".
                    format(str(accountList), content))
                # 不论是否扣卡成功, 都让玩家继续游戏
                self.chargeCallback(True)

            utility.update_card_diamond_aa(accountList, -card_cost,
                                           -diamond_cost, pay_callback, reason)
        else:
            ERROR_MSG("pay2StartGame Error: No this PayMode:{}".format(
                self.pay_mode))
            self.chargeCallback(False)
Example #16
0
    def startGame(self):
        """ 开始游戏 """
        DEBUG_MSG("startGame")
        self.op_record = []
        self.state = 1
        self.current_round += 1
        self.wait_give_up_list = []
        self.give_up_list = []
        self.polling_give_up_op = -1
        for i, p in enumerate(self.players_list):
            if p is not None:
                p.wreaths = []

        diceList = self.throwTheDice([self.dealer_idx])
        idx, num = self.getMaxDiceIdx(diceList)

        # 仅仅在第1局扣房卡, 不然每局都会扣房卡
        def callback(content):
            content = content.decode()
            try:
                if content[0] != '{':
                    DEBUG_MSG(content)
                    self.dropRoom()
                    return
                # 第一局时房间默认房主庄家, 之后谁上盘赢了谁是, 如果臭庄, 最后摸牌的人是庄
                for p in self.players_list:
                    p.reset()
                self.current_idx = self.dealer_idx
                #圈风
                if sum([1 for state in self.player_dealer_state
                        if state == 1]) == self.player_num:
                    windIdx = (self.prevailing_wind + 1 -
                               const.WIND_EAST) % len(const.WINDS)
                    self.prevailing_wind = const.WINDS[windIdx]
                    self.player_dealer_state = [0, 0, 0, 0]
                self.player_dealer_state[self.dealer_idx] = 1
                #自风
                for i, p in enumerate(self.players_list):
                    if p is not None:
                        p.wind = (self.player_num + i - self.dealer_idx
                                  ) % self.player_num + const.WIND_EAST
                self.initTiles()
                self.deal(self.king_num)
                wreathsList = [
                    p.wreaths for i, p in enumerate(self.players_list)
                ]
                playerWindList = [
                    p.wind for i, p in enumerate(self.players_list)
                ]

                for p in self.players_list:
                    if p and p.mb:
                        DEBUG_MSG(
                            "start game,dealer_idx:{0},tiles:{1}, wreathsList:{2}, kingTiles:{3}, diceList:{4},leftTileNum:{5}"
                            .format(self.dealer_idx, p.tiles, wreathsList,
                                    self.kingTiles, diceList, len(self.tiles)))
                        p.mb.startGame(self.dealer_idx, p.tiles, wreathsList,
                                       self.kingTiles, self.prevailing_wind,
                                       playerWindList, diceList)

                self.beginRound()
            except:
                DEBUG_MSG("consume failed!")

        if self.current_round == 1 and self.is_agent == 0:
            card_cost, diamond_cost = switch.calc_cost(self.game_round,
                                                       self.player_num,
                                                       self.pay_mode)
            if switch.DEBUG_BASE:
                callback('{"card":99, "diamond":999}'.encode())
            elif self.pay_mode == 1:
                utility.update_card_diamond(
                    self.players_list[0].mb.accountName, -card_cost,
                    -diamond_cost, callback,
                    "FengHua RoomID:{}".format(self.roomID))
            else:
                signal = 0

                def payCallback(content):
                    nonlocal signal
                    try:
                        signal += 1
                        if signal == len(self.players_list):
                            callback(content)
                    except:
                        DEBUG_MSG("AA payCallback Failed")

                if self.player_num == 3:
                    utility.update_card_diamond(
                        self.players_list[0].mb.accountName, -card_cost,
                        -diamond_cost, payCallback,
                        "NingBoMJ RoomID:{}".format(self.roomID))
                    utility.update_card_diamond(
                        self.players_list[1].mb.accountName, -card_cost,
                        -diamond_cost, payCallback,
                        "NingBoMJ RoomID:{}".format(self.roomID))
                    utility.update_card_diamond(
                        self.players_list[2].mb.accountName, -card_cost,
                        -diamond_cost, payCallback,
                        "NingBoMJ RoomID:{}".format(self.roomID))
                else:
                    utility.update_card_diamond(
                        self.players_list[0].mb.accountName, -card_cost,
                        -diamond_cost, payCallback,
                        "NingBoMJ RoomID:{}".format(self.roomID))
                    utility.update_card_diamond(
                        self.players_list[1].mb.accountName, -card_cost,
                        -diamond_cost, payCallback,
                        "NingBoMJ RoomID:{}".format(self.roomID))
                    utility.update_card_diamond(
                        self.players_list[2].mb.accountName, -card_cost,
                        -diamond_cost, payCallback,
                        "NingBoMJ RoomID:{}".format(self.roomID))
                    utility.update_card_diamond(
                        self.players_list[3].mb.accountName, -card_cost,
                        -diamond_cost, payCallback,
                        "NingBoMJ RoomID:{}".format(self.roomID))
            return

        DEBUG_MSG("start Game: Room{0} - Round{1}".format(
            self.roomID,
            str(self.current_round) + '/' + str(self.game_round)))

        callback('{"card":99, "diamond":999}'.encode())
Example #17
0
    def startGame(self):
        """ 开始游戏 """
        self.op_record = []
        self.state = 1
        self.current_round += 1
        self.discardKingTileIdx = -2

        diceList = [[0, 0], [0, 0], [0, 0], [0, 0]]

        addDealNum = 0
        if self.current_round <= 1:  #首次选庄
            diceList = self.throwTheDice([0, 1, 2, 3])
            idx, num = self.getMaxDiceIdx(diceList)
            self.dealer_idx = idx
            if self.diceAddNum > 0 and num >= self.diceAddNum:
                addDealNum += 1
            elif self.isSameAdd > 0 and diceList[idx][0] == diceList[idx][1]:
                addDealNum += 1
        else:
            diceList = self.throwTheDice([self.dealer_idx])
            idx, num = self.getMaxDiceIdx(diceList)
            if self.dealer_idx != self.last_dealer_idx:
                if self.diceAddNum > 0 and num >= self.diceAddNum:
                    addDealNum += 1
                elif self.isSameAdd > 0 and diceList[idx][0] == diceList[idx][
                        1]:
                    addDealNum += 1

        #老庄
        self.setCurOldDealNum(addDealNum)
        DEBUG_MSG(
            "start game,curOldDealNum{0},dealer_idx{1},diceList{2}".format(
                self.curOldDealNum, self.dealer_idx, str(diceList)))

        # 仅仅在第1局扣房卡, 不然每局都会扣房卡
        def callback(content):
            content = content.decode()
            try:
                if content[0] != '{':
                    DEBUG_MSG(content)
                    self.dropRoom()
                    return
                for p in self.players_list:
                    p.reset()
                self.initTiles()
                self.deal()
                self.current_idx = self.dealer_idx

                for p in self.players_list:
                    if p and p.mb:
                        p.mb.startGame(self.dealer_idx, p.tiles, self.kingTile,
                                       diceList, self.curOldDealNum,
                                       self.game_round, self.roomMode)
                self.beginRound()
            except:
                DEBUG_MSG("consume failed!")

        if self.current_round == 1 and self.is_agent == 0:
            card_cost, diamond_cost = switch.calc_cost(self.roomMode,
                                                       self.game_round)
            if switch.DEBUG_BASE:
                callback('{"card":99, "diamond":999}'.encode())
            else:
                utility.update_card_diamond(
                    self.players_list[0].mb.accountName, -card_cost,
                    -diamond_cost, callback,
                    "XiaoShanMJ RoomID:{}".format(self.roomID))
            return

        DEBUG_MSG("start Game: Room{0} - Round{1}".format(
            self.roomID,
            str(self.current_round) + '/' + str(self.game_round)))

        callback('{"card":99, "diamond":999}'.encode())
Example #18
0
	def pay2StartGame(self):
		""" 开始游戏 """
		DEBUG_MSG("room:{},curround:{},game_mode:{},base_score:{},king_mode:{},begin_dealer_mul:{},win_mode:{},three_job:{},pong_useful:{},bao_tou:{},round_max_lose:{},game_max_lose:{},game_round:{},hand_prepare:{} pay2StartGame state:{}".format(self.roomID, self.current_round,
		self.game_mode, self.base_score, self.king_mode, self.begin_dealer_mul, self.win_mode, self.three_job,
		self.pong_useful, self.bao_tou, self.round_max_lose, self.game_max_lose, self.game_round, self.hand_prepare,
		self.state))

		if self.timeout_timer:
			self.cancel_timer(self.timeout_timer)
			self.timeout_timer = None

		self.state = const.ROOM_TRANSITION

		if self.current_round == 0:
			# 第一局备份原始座位
			self.origin_players_list = self.players_list[:]
			self.dealer_idx = 0

		# 仅仅在第1局扣房卡, 不然每局都会扣房卡
		if self.current_round == 0:
			if switch.DEBUG_BASE:
				self.paySuccessCbk()
				return

			card_cost, diamond_cost = switch.calc_cost(self.game_round, self.getCalCostNeed())
			if self.pay_mode == const.NORMAL_PAY_MODE:
				pay_account = self.origin_players_list[0].mb.accountName
				reason = "FourDeckCards RoomID:{}".format(self.roomID)

				def pay_callback(content):
					if self._check_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond(pay_account, -card_cost, -diamond_cost, pay_callback, reason)
			elif self.pay_mode == const.CLUB_PAY_MODE:
				pay_account = self.club.owner['accountName']
				reason = "FourDeckCards Club:{} RoomID:{}".format(self.club.clubId, self.roomID)

				def pay_callback(content):
					if self._check_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond(pay_account, -card_cost, -diamond_cost, pay_callback, reason)
			elif self.pay_mode == const.AGENT_PAY_MODE:
				# 开房的时候已经扣了房卡
				self.paySuccessCbk()
			elif self.pay_mode == const.AA_PAY_MODE:
				pay_accounts = [p.mb.accountName for p in self.players_list]
				if self.club:
					reason = "FourDeckCards Club:{} AA RoomID:{}".format(self.club.clubId, self.roomID)
				else:
					reason = "FourDeckCards AA RoomID:{}".format(self.roomID)

				def pay_callback(content):
					if self._check_aa_pay_callback(content):
						self.paySuccessCbk()

				utility.update_card_diamond_aa(pay_accounts, -card_cost, -diamond_cost, pay_callback, reason)
			else:
				ERROR_MSG("pay2StartGame Error: No this PayMode:{}".format(self.pay_mode))
				return
		else:
			self.paySuccessCbk()