示例#1
0
	def _get_debug_prefab(self, callback):
		def _callback(data):
			DEBUG_MSG("{} data:{}".format(self.prefixLogStr, data))
			if data is None:
				callable(callback) and callback(None)
			else:
				hand_tiles = [[] for i in range(self.player_num)]
				for k, v in enumerate(data["handTiles"]):
					k < self.player_num and hand_tiles[k].extend(v)
				callable(callback) and callback(hand_tiles)

		utility.getDebugPrefab(self.origin_players_list[0].accountName, _callback, DEBUG_JSON_NAME)
示例#2
0
	def _get_debug_prefab(self, callback):
		def _callback(content):
			DEBUG_MSG("{} debugmode,content:{}".format(self.prefixLogStr, content))
			if content is None or content == "10000" or content[0:2] != "ok":  # 10000代表找不到该文件
				callable(callback) and callback()
			else:
				try:
					data = json.loads(content[2:])
					DEBUG_MSG("{} data:{}".format(self.prefixLogStr, data))
					hand_tiles = [[] for i in range(self.player_num)]
					for k, v in enumerate(data["handTiles"]):
						k < self.player_num and hand_tiles[k].extend(v)
					callable(callback) and callback(hand_tiles)
				except:
					err, msg, stack = sys.exc_info()
					DEBUG_MSG("{} try begin error; exc_info: {}, {}, {}".format(self.prefixLogStr, err, msg, traceback.extract_tb(stack)))

		utility.getDebugPrefab(self.origin_players_list[0].mb.accountName, _callback)
示例#3
0
	def paySuccessCbk(self):
		DEBUG_MSG("room:{},curround:{} paySuccessCbk state:{}".format(self.roomID, self.current_round, self.state))
		try:
			# 第一局时房间默认房主庄家, 之后谁上盘赢了谁是, 如果臭庄, 上一把玩家继续坐庄
			swap_list = [p.idx for p in self.players_list]
			if self.current_round == 0:
				self.origin_players_list = self.players_list[:]
				self.dealer_idx = self.confirm_next_idx[0]
				# self.swapSeat(swap_list)

			self.op_record = []
			# self.op_special_record = []
			self.state = const.ROOM_PLAYING
			self.current_round += 1
			self.all_discard_tiles = []

			for p in self.players_list:
				p.reset()

			self.current_idx = self.dealer_idx
			self.discard_king_idx = -1

			def begin(prefabKingTiles=None, prefabHandTiles=None, prefabTopList=None):
				self.setPrevailingWind()  					# 圈风
				self.setPlayerWind()  						# 位风
				self.initTiles()  							# 牌堆
				self.deal(prefabHandTiles, prefabTopList)  	# 发牌
				self.kongWreath()  							# 杠花
				self.addWreath()  							# 补花
				self.rollKingTile(prefabKingTiles)  		# 财神
				beginTilesList = [copy.deepcopy(p.tiles) for i, p in enumerate(self.players_list)]
				self.tidy()  								# 整理
				self.count_king_tile()						# 统计初始牌财神数量
				self.beginRound(True)  						# 第一张牌优先抓,后开始游戏
				beginTilesList[self.current_idx].append(self.players_list[self.current_idx].last_draw)
				self.startGame(beginTilesList, swap_list)

			if switch.DEBUG_BASE == 0:
				begin([], [[] for i in range(self.player_num)], [])
			elif switch.DEBUG_BASE == 1: # 开发模式 除去不必要的通信时间 更接近 真实环境
				prefabKingTiles = []
				prefabHandTiles = [
					[],
					[],
					[],
					[]
				]
				prefabTopList	= []
				begin(prefabKingTiles, prefabHandTiles, prefabTopList)
			else:
				def callback(content):
					DEBUG_MSG("room:{},curround:{} debugmode,content:{}".format(self.roomID, self.current_round,content))
					if content is None or content == "10000" or content[0:2] != "ok": # 10000代表找不到该文件
						begin()
					else:
						try:
							content = content[2:]
							data = json.loads(content)
							DEBUG_MSG("room:{},curround:{} data:{}".format(self.roomID, self.current_round, data))
							kingTiles = []
							handTiles = [[] for i in range(self.player_num)]
							topList = []
							# 检查数据
							for t in data["kingTiles"]:
								if t not in kingTiles and utility.validTile(t):
									kingTiles.append(t)

							for k,v in enumerate(data["handTiles"]):
								if k < self.player_num:
									for t in v:
										if utility.validTile(t):
											handTiles[k].append(t)

							for t in data["topList"]:
								if utility.validTile(t):
									topList.append(t)
							begin(kingTiles, handTiles, topList)
						except:
							err, msg, stack = sys.exc_info()
							DEBUG_MSG("room:{},curround:{} try begin error; exc_info: {} ,{}".format(self.roomID, self.current_round, err, msg))

				utility.getDebugPrefab(self.origin_players_list[0].mb.accountName, callback)
		except:
			err, msg, stack = sys.exc_info()
			DEBUG_MSG("room:{},curround:{} paySuccessCbk error; exc_info: {} ,{}".format(self.roomID, self.current_round, err, msg))
			DEBUG_MSG("room:{},curround:{} consume failed! users: {}".format(self.roomID, self.current_round, [p.userId for p in self.origin_players_list if p]))
示例#4
0
	def start(self, restart=False):
		DEBUG_MSG("{} start restart:{}".format(self.prefixLogStr, restart))
		if self.quit_times >= const_ll7.QUIT_TIMES:
			self.base.destroyByServer("无人叫主次数达到上限:{},解散房间.".format(self.quit_times))
			return
		self.quit_times += 1
		if not restart:
			self.current_round += 1
			self.base.onRoomRoundChange(self.current_round)
		# 重置数据
		self.op_record = []
		self.wait_aid_list = []
		self.lord_idx = -1
		self.partner_idx = -1
		self.bonus_idx = -1
		self.lord_pokers = []
		self.lord_state = [0] * self.player_num
		self.player_cover_pokers = []
		self.round_pokers = [None, None, None, None, None, None, [None] * self.player_num]

		for p in self.players_list:
			p.reset()

		def begin(prefab_pokers = [[] for i in range(self.player_num)], cover_pokers = []):
			self.state = const.ROOM_PLAYING
			self.init_pokers()  # 牌堆
			self.shuffle_pokers()  # 打乱
			self.prefabPokers(prefab_pokers, cover_pokers)
			# self.deal(prefab_pokers, cover_pokers)  # 发牌
			self.firstDeal()  # 发牌
			self.tidy()  # 整理
			self.beginGame(restart)

		if switch.DEBUG_BASE == 0:
			begin()
		elif switch.DEBUG_BASE == 1:  # 开发模式 除去不必要的通信时间 更接近 真实环境
			prefab_pokers = [[31],
							 [30,30],
							 [29,29],
							 [28],
							 [28]]
			cover_pokers = [31]
			begin(prefab_pokers, cover_pokers)
		else:
			def callback(data):
				DEBUG_MSG("{} data:{}".format(self.prefixLogStr, data))
				if data is None:
					begin()
					return
				prefab_pokers = [[] for i in range(self.player_num)]
				cover_pokers = []
				# 检查数据
				for k, v in enumerate(data["pokers"]):
					if k < self.player_num:
						for t in v:
							if utility_ll7.validPoker(t):
								prefab_pokers[k].append(t)

				for t in data["cover_poker"]:
					if utility_ll7.validPoker(t):
						cover_pokers.append(t)
				begin(prefab_pokers, cover_pokers)
			utility.getDebugPrefab(self.players_list[0].accountName, callback, const_ll7.DEBUG_JSON_NAME)