您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字

1064 行
30 KiB

  1. local RoomCmd=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPCmd")
  2. local ZPMessage=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage")
  3. local ZPDef=ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  4. local ZPFuc=ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
  5. local ZPProtocol=ZPFramework.ZPFrameworkClassImprot("zp_base.luaScript.Protocol.ZPProtocol")
  6. local Room = class("xichongRoom" , ZPProtocol)
  7. local tempCardVlue ={
  8. [17] = 20, --11
  9. [18] = 30, --12
  10. [49] = 40, --31
  11. [34] = 41, --22
  12. [20] = 50, --14
  13. [50] = 51, --32
  14. [21] = 60, --15
  15. [36] = 61, --24
  16. [51] = 62, --33
  17. [22] = 70, --16
  18. [82] = 71, --52
  19. [52] = 72, --34
  20. [38] = 80, --26
  21. [53] = 81, --35
  22. [68] = 82, --44
  23. [54] = 90, --36
  24. [84] = 91, --54
  25. [70] = 100, --46
  26. [85] = 101, --55
  27. [86] = 110, --56
  28. [102] = 120, --66
  29. }
  30. function Room:ctor(net)
  31. Room.super.ctor(self , net);
  32. --请求重连消息
  33. self:defMsgFunc{name = ZPDef.ZPEvent.GetTableInfo ,cmd = RoomCmd.GAME_COMMAND_GET_TABLE_INFO};
  34. --广播起手操作
  35. self:defPushMsg{cmd = RoomCmd.GAME_SERVER_BROAD_PIAO, reader = ZPMessage.GamePiao, func = handler(self, self.onBroadCastUserPiao)};
  36. --接收暗操作提示
  37. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_OPERATE_TISHI, reader = ZPMessage.UserOperateNotify, func = handler(self, self.onUserOperateResponse)};
  38. --发送报操作
  39. self:defMsgFunc{name = "sendBaoOperate" , cmd = RoomCmd.GAME_CLIENT_SEND_BAO, sender = ZPMessage.GameBaoSendOperateCode};
  40. --服务器广播报操作
  41. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_BAO_JIAO, reader = ZPMessage.UserBaoResulst, func = handler(self, self.onBroadUserBaoResponse)};
  42. --接收报操作提示
  43. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_BAO_ACTION, reader = ZPMessage.UserCanBaoNotify, func = handler(self, self.onUserCanBaoResponse)};
  44. --广播起手操作
  45. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_TOU_OPERATION, reader = ZPMessage.GameQiShouBroadCastOperate, func = handler(self, self.onBroadCastQiShouOperate)};
  46. --广播通知玩家出牌
  47. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_OUT_PROMPT, reader = ZPMessage.GameUserOutCard, func = handler(self, self.onBroadCastUserOutCard)};
  48. --广播玩家进牌
  49. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_ENTER_CARD, reader = ZPMessage.GameUserGetCard, func = handler(self, self.onBroadCastUserGetCard)};
  50. --玩家进牌后显示的操作
  51. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_TINGCARD_RESPONSE, reader = ZPMessage.GameUserGetCardOperateNotify, func = handler(self, self.onUserGetCardOperteResponse)};
  52. --发送刷新手牌请求
  53. self:defMsgFunc{name = "reflashHandCard",cmd = RoomCmd.GAME_COMMAND_REFLASH_HANDCARDS,sender = ZPMessage.ReflashHandCard};
  54. --刷新手牌
  55. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_REFLASH_HANDCARDS_RESPONSE, reader = ZPMessage.ReflashHandcardsResponse, func = handler(self , self.onReflashHandcardsResponese)};
  56. -- 请求托管
  57. self:defMsgFunc{name = ZPDef.ZPEvent.HostingRequest, cmd = RoomCmd.GAME_COMMAND_USER_HOSTING_REQUEST, sender = ZPMessage.HostingRequest}
  58. -- 收到托管回调
  59. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_HOSTING_RESPONSE, reader = ZPMessage.HostingResponse, func = handler(self,self.onHostingResponse)}
  60. end
  61. --断线重连
  62. function Room:onGameReconnection(status,response)
  63. logD("===============重连成功,清空之前所有存在的队列==================")
  64. app.net:onMsgClear()
  65. app.net:onMsgPause()
  66. logD("Room:onGameReconnection(), response = ", table.tostring(response))
  67. self:initRoomInfo();
  68. -- 获取到的房间信息
  69. self.roomInfo.nShowTableId = response.nShowTableId
  70. self.roomInfo.nMaxPlayCount = response.nMaxPlayCount
  71. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid
  72. self.roomInfo.nTotalGameNum = response.nTotalGameNum
  73. self.roomInfo.nGameStartCount = response.nGameStartCount
  74. self.roomInfo.strGameInfo = response.strGameInfo
  75. self.roomInfo.nStatus = response.nStatus
  76. self.roomInfo.nDismissToTalTime = response.nDismissToTalTime
  77. self.roomInfo.nBankSeatId = response.nBankSeatId
  78. self.roomInfo.nZhongBankCnt = response.nZhongBankCnt
  79. self.roomInfo.bUserDisbandGame = response.bUserDisbandGame
  80. self.roomInfo.nDismissStateTime = response.nDismissStateTime
  81. self.roomInfo.arrayTableInfo = response.arrayTableInfo
  82. self.roomInfo.dipaiList = response.dipaiList
  83. self.roomInfo.showCardSeatId = response.showCardSeatId
  84. self.roomInfo.showCard = response.showCard
  85. self.roomInfo.mainOpCode = response.mainOpCode
  86. self.roomInfo.isSubmitOp = response.isSubmitOp
  87. self.roomInfo.showCardFlag = response.showCardFlag
  88. self.roomInfo.outCardSeatId = response.outCardSeatId
  89. self.roomInfo.lastOperate = response.lastOperate
  90. self.roomInfo.lastOpCard = response.lastOpCard
  91. self.roomInfo.disCardSeatId = response.disCardSeatId
  92. self.roomInfo.disCard = {}
  93. self.roomInfo.leftZhaBirdTime = response.leftZhaBirdTime
  94. self.roomInfo.stopFlag = response.stopFlag
  95. self.roomInfo.winUserId = response.winUserId
  96. self.roomInfo.dianPaoUserId = response.dianPaoUserId
  97. self.roomInfo.huType = response.huType
  98. self.roomInfo.huCard = response.huCard
  99. self.roomInfo.tingCards = response.tingCards
  100. self.roomInfo.hupaiInfo = response.hupaiInfo
  101. self.roomInfo.xiaoSeatId = response.xiaoSeatId;
  102. self.roomInfo.offLineInfo = response.offLineInfo
  103. self.roomInfo.fanpaiSeatId = response.fanpaiSeatId
  104. self.roomInfo.chiPaiList = response.chiCardList or {}
  105. self.roomInfo.totalTuoNum = response.totalTuoNum
  106. self.roomInfo.curOpreateID = response.curOpreateID
  107. self.roomInfo.firstOutCard = {}
  108. self.roomInfo.baoType = response.baoType
  109. self.roomInfo.isSanSiGen = response.isSanSiGen
  110. self.roomInfo.isZiMoHu = response.isZiMoHu
  111. self.roomInfo.isBiHu = response.isBiHu
  112. for k,v in ipairs(response.disCard or {}) do
  113. table.insert(self.roomInfo.disCard,v)
  114. end
  115. for k,v in ipairs(response.nomorlDisCard or {}) do
  116. table.insert(self.roomInfo.disCard,v)
  117. end
  118. for k,v in ipairs(response.firstOutCard or {}) do
  119. table.insert(self.roomInfo.firstOutCard,v)
  120. end
  121. --起手操作
  122. self.roomInfo.startOpList = {}
  123. self.roomInfo.startOpList["ishu"] = response.ishu
  124. self.roomInfo.startOpList["TouoperateCode"] = response.TouoperateCode
  125. self.roomInfo.startOpList["ToucardList"] = response.ToucardList or {}
  126. self.roomInfo.startOpList["BaoperateCode"] = response.BaoperateCode
  127. self.roomInfo.startOpList["BacardList"] = response.BacardList or {}
  128. self.roomInfo.startOpList["totalTuoNum"] = response.totalTuoNum
  129. self:addReconnectionData(response)
  130. if self.roomInfo.offLineInfo and next(self.roomInfo.offLineInfo) ~= nil then
  131. for i,v in pairs(self.roomInfo.offLineInfo) do
  132. if v.extInfo then
  133. local extIf = json.decode(v.extInfo)
  134. if extIf.OffTime and v.nUserId then
  135. self.offLineTime[v.nUserId] = extIf.OffTime
  136. end
  137. end
  138. end
  139. end
  140. for i,v in pairs(self.roomInfo.hupaiInfo) do
  141. self.roomInfo.dianPaoUserId = v.dianPaoUid
  142. self.roomInfo.huCard = v.huCard
  143. end
  144. if app.club_php.clubID and app.club_php.clubID ~= 0 and self.roomInfo.nGameStartCount > 0 then
  145. app.club_php:getClubList();
  146. end
  147. -- 桌子上其他玩家的信息
  148. for k,v in pairs(response.arrayTableInfo) do
  149. if not self.roomInfo.memberList[v.nUserId] then
  150. self.roomInfo.memberList[v.nUserId] = {}
  151. end
  152. self.roomInfo.memberList[v.nUserId].nUserId = v.nUserId
  153. self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId
  154. self.roomInfo.memberList[v.nUserId].nPlayerFlag = v.nPlayerFlag
  155. self.roomInfo.memberList[v.nUserId].userInfo = v.userInfo
  156. self.roomInfo.memberList[v.nUserId].nTotalMoney = v.nTotalMoney
  157. self.roomInfo.memberList[v.nUserId].nOnlineStatus = v.nOnlineStatus
  158. --这里只记录,暂时没用到。可能战绩回放的时候是需要用的
  159. local cardData = self:serverCardToMyCard(v.handCard)
  160. self.roomInfo.memberList[v.nUserId].cardList = {}
  161. self.roomInfo.memberList[v.nUserId].cardList = cardData
  162. if v.nSeatId == self.roomInfo.nBankSeatId then
  163. self.roomInfo.nBankUid = v.nUserId --头家UID
  164. end
  165. end
  166. local myUserId = self:getMyRecordUserId()
  167. for i,v in pairs(self.roomInfo.memberList) do
  168. if self:isLittleFamily() and self.roomInfo.nBankSeatId == v.nSeatId then
  169. self.roomInfo.memberList[myUserId].cardList = v.cardList
  170. end
  171. end
  172. --更新自己的数据
  173. self.cards[myUserId] = self.roomInfo.memberList[myUserId].cardList
  174. print("self.cards[myUserId]:"..table.tostring(self.cards[myUserId]))
  175. --检测GPS
  176. self:updateGpsUserInfo(nil,false)
  177. -- 更新椅子号
  178. self:updateUserSeateShowId()
  179. local jsonInfo = json.decode(self.roomInfo.strGameInfo)
  180. self:resetRound()
  181. --没用到
  182. local extInfo = json.decode(response.extJson or "")
  183. if extInfo and type(extInfo)=='table' and extInfo[tostring(self:getMyUserId())] then
  184. local myinfo = extInfo[tostring(self:getMyUserId())]
  185. self.roomInfo.hosting = myinfo.hosted or 0--托管状态
  186. self.roomInfo.quickStartInfo = extInfo.faststart--提前开局
  187. else
  188. self.roomInfo.hosting = 0
  189. end
  190. -- 发送通知
  191. self:dispatchEvent({name = "onEnterRoomSuccess", gameId = ZPDef.GameID or app.gameId, gameType = jsonInfo.gamerule})
  192. end
  193. --获取手牌结果
  194. function Room:onReflashHandcardsResponese(status, response)
  195. print("Room:onReflashHandcardsResponese()", table.tostring(response))
  196. local cardData = self:serverCardToMyCard(response.handCard)
  197. self.roomInfo.memberList[response.nUserId].cardList = {}
  198. self.roomInfo.memberList[response.nUserId].cardList = cardData
  199. self.cards[response.nUserId] = cardData
  200. self:dispatchEvent({name = "onReflashHandcardsResponese"});
  201. end
  202. -- 广播桌子上所有玩家庄家起手操作
  203. function Room:onBankerOutCard(status, response)
  204. logD("-------------------- 游戏庄家起手操作------------------------")
  205. if not self.roomInfo then
  206. logD("self.roomInfo no exist,容错处理!")
  207. return
  208. end
  209. --self.roomInfo.nBankUid = response.nUserId
  210. logD("Room:onBankerOutCard(), ", table.tostring(response))
  211. -- 发送广播通知,游戏开始了
  212. self:dispatchEvent({name = "onBankerOutCard",response = response});
  213. end
  214. function Room:onUserGetCardOperteResponse(status, response)
  215. logD("------------进牌后通知玩家显示操作--------------")
  216. if not self.roomInfo then
  217. logD("self.roomInfo no exist,容错处理!")
  218. return
  219. end
  220. logD("Room:onUserGetCardOperteResponse(), ", table.tostring(response))
  221. self:dispatchEvent({name = "onUserGetCardOperteResponse",response = response})
  222. end
  223. function Room:onBroadCastUserGetCard(status, response)
  224. logD("------------广播用户进牌操作---------------")
  225. if not self.roomInfo then
  226. logD("self.roomInfo no exist,容错处理!")
  227. return
  228. end
  229. logD("Room:onBroadCastUserGetCard(), ", table.tostring(response))
  230. self:dispatchEvent({name = "onBroadCastUserGetCard",response = response})
  231. end
  232. function Room:onBroadCastUserOutCard(status, response)
  233. logD("------------通知玩家出牌--------------")
  234. if not self.roomInfo then
  235. logD("self.roomInfo no exist,容错处理!")
  236. return
  237. end
  238. logD("Room:onBroadCastUserOutCard(), ", table.tostring(response))
  239. self:dispatchEvent({name = "onBroadCastUserOutCard",response = response})
  240. end
  241. function Room:onBroadUserBaoResponse(status, response)
  242. logD("------------广播用户报操作---------------")
  243. if not self.roomInfo then
  244. logD("self.roomInfo no exist,容错处理!")
  245. return
  246. end
  247. logD("Room:onBroadUserBaoResponse(), ", table.tostring(response))
  248. self:dispatchEvent({name = "onBroadUserBaoResponse",response = response})
  249. end
  250. function Room:onUserCanBaoResponse(status, response)
  251. logD("------------提示用户报操作---------------")
  252. if not self.roomInfo then
  253. logD("self.roomInfo no exist,容错处理!")
  254. return
  255. end
  256. logD("Room:onUserCanBaoResponse(), ", table.tostring(response))
  257. self:dispatchEvent({name = "onUserCanBaoResponse",response = response})
  258. end
  259. function Room:onUserOperateResponse(status, response)
  260. logD("------------提示用户暗操作---------------")
  261. if not self.roomInfo then
  262. logD("self.roomInfo no exist,容错处理!")
  263. return
  264. end
  265. logD("Room:onUserOperateResponse(), ", table.tostring(response))
  266. self:dispatchEvent({name = "onUserOperateResponse",response = response})
  267. end
  268. function Room:onBroadCastQiShouOperate(status, response)
  269. logD("------------广播用户暗操作---------------")
  270. if not self.roomInfo then
  271. logD("self.roomInfo no exist,容错处理!")
  272. return
  273. end
  274. logD("Room:onBroadCastQiShouOperate(), ", table.tostring(response))
  275. self:dispatchEvent({name = "onBroadCastQiShouOperate",response = response})
  276. end
  277. function Room:onBroadCastUserPiao(status, response)
  278. logD("------------广播用户选飘---------------")
  279. if not self.roomInfo then
  280. logD("self.roomInfo no exist,容错处理!")
  281. return
  282. end
  283. logD("Room:onBroadCastUserPiao(), ", table.tostring(response))
  284. self:dispatchEvent({name = "onBroadCastUserPiao",response = response})
  285. end
  286. -- 游戏正式开始
  287. function Room:onGameStartResponse(status, response)
  288. logD("-------------------- 新的一局开始了 ------------------------")
  289. if not self.roomInfo then
  290. logD("self.roomInfo no exist,容错处理!")
  291. return
  292. end
  293. logD("Room:onGameStartResponse(), ", table.tostring(response))
  294. self.roomInfo.nGameStartCount = response.nGameStartCount;
  295. self.roomInfo.nTotalGameNum = response.nTotalGameNum;
  296. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid;
  297. self.roomInfo.nBankSeatId = response.nBankSeatId;
  298. self.roomInfo.xiaoSeatId = response.xiaoSeatId;
  299. self.roomInfo.fanpaiSeatId = response.turnSeatId;
  300. self.roomInfo.fanpaiValue = response.turnCard;
  301. --清空上一局胡牌信息
  302. self.roomInfo.hupaiInfo = nil
  303. -- 清空上一局的手牌信息
  304. self.cards = {}
  305. -- 发送广播通知,游戏开始了
  306. self:dispatchEvent({name = "onGameStartResponse"});
  307. end
  308. -- 获取自己是否是小家(观看的人) 且选了小家可以看牌才返回true 长牌用不到
  309. function Room:isLittleFamily()
  310. return false
  311. end
  312. -- 游戏发牌结果
  313. function Room:onGameSendCardResponse(status, response)
  314. logD("-------------------- 游戏发牌 ------------------------")
  315. if not self.roomInfo then
  316. logD("self.roomInfo no exist,容错处理!")
  317. return
  318. end
  319. logD("Room:onGameSendCardResponse(), ", table.tostring(response))
  320. self.roomInfo.nbankFirstGrabCard = response.nbankFirstGrabCard
  321. --目前server只发自己过来,后续战绩回放考虑到会发所有玩家来,故以userid为key于扩展
  322. local cardData = self:serverCardToMyCard(response.cardList)
  323. logD("Room:onGameSendCardResponse : "..table.tostring(cardData))
  324. self.roomInfo.memberList[response.nUserId].cardList = cardData
  325. self.cards[response.nUserId] = cardData
  326. if self:isLittleFamily() then
  327. self.roomInfo.nBankUid = response.nUserId
  328. self.cards[app.user.loginInfo.uid] = cardData
  329. end
  330. self.roomInfo.totalTuoNum = response.totalTuoNum
  331. -- 发送广播通知,发牌开始了
  332. self:dispatchEvent({name = "onGameSendCardResponse"});
  333. end
  334. -- 获取房间最大玩家人数
  335. function Room:getMaxPlayerCount()
  336. return self.roomInfo.nMaxPlayCount
  337. end
  338. -- 获取房间人数
  339. function Room:getPlayerCount()
  340. local count = 0
  341. for k,v in pairs(self.roomInfo.memberList) do
  342. count = count + 1
  343. end
  344. return count
  345. end
  346. -- 重置上局信息
  347. function Room:resetRound()
  348. self.roomInfo.quickStartInfo = nil
  349. end
  350. function Room:resetFastInfo()
  351. self.roomInfo.quickStartInfo = nil
  352. end
  353. function Room:isMyself(uid)
  354. return uid==self:getMyUserId()
  355. end
  356. -- 更新玩家的相对椅子号
  357. function Room:updateUserSeateShowId(xiaoSeatId)
  358. local myUserId = self:getMyRecordUserId()
  359. local mySeatId = self.roomInfo.memberList[myUserId].nSeatId
  360. self.roomInfo.nUserId = self:getMyRecordUserId()
  361. self.roomInfo.nSeatId = mySeatId
  362. --除了自己的第一次seatid辅助
  363. local anotherSeatID = -1
  364. --[视图椅子号] = userID
  365. --[座位号] = userID
  366. --[userID] = 视图椅子号
  367. self.seatShowList = {}
  368. self.userList = {}
  369. self.seatList = {}
  370. for k,v in pairs(self.roomInfo.memberList) do
  371. if v.nUserId and v.nSeatId then
  372. local maxNum = 3--ZPFuc.getCreateRoomPlayerNum()
  373. local isChange = false
  374. if app.room:getActualPlayerNum() >= 3 then
  375. maxNum = 4
  376. end
  377. local nSeatShowId --= (v.nSeatId - mySeatId + 4) % 4
  378. if mySeatId <= v.nSeatId then
  379. nSeatShowId = v.nSeatId - mySeatId
  380. elseif mySeatId > v.nSeatId then
  381. nSeatShowId = maxNum - mySeatId + v.nSeatId
  382. end
  383. if app.room:getActualPlayerNum() == 2 then--self.roomInfo.playerNum == 2 then
  384. if (v.nSeatId == mySeatId) then
  385. nSeatShowId = 4
  386. else
  387. nSeatShowId = 1--两人玩时,对家坐哪里
  388. end
  389. elseif app.room:getActualPlayerNum() == 3 and v.nUserId ~= 0 then
  390. if (v.nSeatId == mySeatId) then
  391. nSeatShowId = 4
  392. else
  393. --local nSeatShowId = (v.nSeatId - mySeatId + 4) % 4
  394. if nSeatShowId == 2 then
  395. if mySeatId > v.nSeatId then
  396. nSeatShowId = nSeatShowId + 1
  397. isChange = true
  398. else
  399. isChange = true
  400. nSeatShowId = nSeatShowId - 1
  401. end
  402. end
  403. if nSeatShowId == 0 then
  404. if mySeatId > v.nSeatId then
  405. nSeatShowId = nSeatShowId + 1
  406. else
  407. nSeatShowId = 3
  408. end
  409. elseif (nSeatShowId == 1 or nSeatShowId == 3) and anotherSeatID >= 0 then
  410. isChange = true
  411. end
  412. if anotherSeatID < 0 and not isChange then
  413. anotherSeatID = v.nSeatId
  414. end
  415. end
  416. elseif app.room:getActualPlayerNum() == 4 and v.nUserId ~= 0 then
  417. if (v.nSeatId == mySeatId) and (v.nSeatId ~= self.roomInfo.xiaoSeatId) then
  418. nSeatShowId = 4
  419. else
  420. if xiaoSeatId and xiaoSeatId >=0 and nSeatShowId == 2 then
  421. if mySeatId == xiaoSeatId then
  422. if math.abs(mySeatId - v.nSeatId) == 2 then
  423. nSeatShowId = 4
  424. end
  425. elseif mySeatId > v.nSeatId then
  426. isChange = true
  427. nSeatShowId = nSeatShowId + 1
  428. else
  429. isChange = true
  430. nSeatShowId = nSeatShowId - 1
  431. end
  432. else
  433. end
  434. if xiaoSeatId and v.nSeatId == self.roomInfo.xiaoSeatId then
  435. nSeatShowId = 2
  436. end
  437. end
  438. --强制转换小家视角与庄家一致
  439. if mySeatId == xiaoSeatId then
  440. if nSeatShowId == 1 then
  441. nSeatShowId = 3
  442. elseif nSeatShowId == 3 then
  443. nSeatShowId = 1
  444. end
  445. end
  446. end
  447. if nSeatShowId == 0 then
  448. nSeatShowId = 4
  449. end
  450. if v.nUserId == 0 then
  451. nSeatShowId = 2
  452. else
  453. if self.seatShowList[nSeatShowId] and isChange == true then
  454. if nSeatShowId == 1 then
  455. nSeatShowId = 3
  456. elseif nSeatShowId == 3 then
  457. nSeatShowId = 1
  458. end
  459. elseif self.seatShowList[nSeatShowId] and isChange == false then
  460. local olduid = self.seatShowList[nSeatShowId]
  461. local oldshowid = self.userList[olduid]
  462. local newshowid = 0
  463. if nSeatShowId == 1 then
  464. newshowid = 3
  465. elseif nSeatShowId == 3 then
  466. newshowid = 1
  467. end
  468. self.seatShowList[newshowid] = olduid
  469. self.userList[olduid] = newshowid
  470. end
  471. end
  472. self.seatShowList[nSeatShowId] = v.nUserId
  473. self.seatList[v.nSeatId] = v.nUserId
  474. self.userList[v.nUserId] = nSeatShowId
  475. end
  476. end
  477. logD("User:updateUserSeateShowId(), seatShowList", table.tostring(self.seatShowList))
  478. logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList))
  479. logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList))
  480. end
  481. --[[
  482. 思维:
  483. 服务器把牌都排序好了,客户端只要拿到数据负责显示
  484. ]]
  485. function Room:serverCardToMyCard(serverCardList)
  486. --
  487. --根据定义组合牌
  488. local cardData = {}
  489. --单个组合索引
  490. local index = 1
  491. --真实索引
  492. local realIndex = 1
  493. local tempserverCardlist = {}
  494. local singleCardList = {}
  495. for k,v in ipairs(serverCardList) do
  496. local cardlist = {}
  497. for _,val in pairs(v.card or {}) do
  498. table.insert(cardlist,val)
  499. end
  500. table.insert(tempserverCardlist,cardlist)
  501. end
  502. --先对二维数组排序
  503. for k,v in ipairs(tempserverCardlist or {}) do
  504. local cardlist = v
  505. table.sort(cardlist,function(a,b)
  506. local numA = tempCardVlue[a]
  507. local numB = tempCardVlue[b]
  508. if numA ~= nil and numB ~= nil then
  509. return numA < numB
  510. end
  511. end)
  512. end
  513. table.sort(tempserverCardlist,function(a,b)
  514. local index = a[1]
  515. local numA = tempCardVlue[index]
  516. local index1 = b[1]
  517. local numB = tempCardVlue[index1]
  518. if numA ~= nil and numB ~= nil then
  519. return numA < numB
  520. end
  521. end)
  522. logD("Room:sortMycard : "..table.tostring(tempserverCardlist))
  523. for k,v in ipairs(tempserverCardlist) do
  524. local list = v
  525. if #list <= 4 then
  526. --如果是四张以下直接放一列
  527. local cardlist = {}
  528. for k,v in ipairs(list) do
  529. table.insert(cardlist,v)
  530. end
  531. --先按值牌序
  532. table.sort(cardlist,function(a,b)
  533. local numA = tonumber(a)
  534. local numB = tonumber(b)
  535. if numA ~= nil and numB ~= nil then
  536. return numA < numB
  537. end
  538. end)
  539. --按点数排序
  540. table.sort(cardlist,function(a,b)
  541. local numA = tempCardVlue[a]
  542. local numB = tempCardVlue[b]
  543. if (numA ~= nil) and (numB ~= nil) then
  544. return numA > numB
  545. end
  546. return false
  547. end)
  548. cardData[realIndex] = cardlist
  549. realIndex = realIndex + 1
  550. else --大于五张要分开
  551. --首先考虑三张一样的
  552. local cardlist = {}
  553. for k,v in ipairs(list) do
  554. table.insert(cardlist,v)
  555. end
  556. --local tempCardList = self:getSameVlaueList(cardlist)
  557. local tempCardList = self:spiltSameList(cardlist)
  558. local tempResultCardList = {}
  559. for k,v in pairs(tempCardList) do
  560. table.insert(tempResultCardList,v)
  561. end
  562. --按点数排序
  563. table.sort(tempResultCardList,function(a,b)
  564. local index = a[1]
  565. local numA = tempCardVlue[index]
  566. local index1 = b[1]
  567. local numB = tempCardVlue[index1]
  568. if (numA ~= nil) and (numB ~= nil) then
  569. return numA < numB
  570. end
  571. return false
  572. end)
  573. for k,templist in pairs (tempResultCardList) do
  574. table.sort(templist,function(a,b)
  575. local numA = tempCardVlue[tonumber(a)]
  576. local numB = tempCardVlue[tonumber(b)]
  577. if numA ~= nil and numB ~= nil then
  578. return numA > numB
  579. end
  580. return false
  581. end)
  582. local cardlist = templist
  583. cardData[realIndex] = cardlist
  584. realIndex = realIndex + 1
  585. end
  586. --[[ for k,templist in pairs(tempResultCardList) do
  587. if #templist > 4 then
  588. local same,sameValue = self:checkListHaveSame(templist)
  589. local indexValue = {}
  590. if same then
  591. for k,v in ipairs(sameValue) do
  592. local cardlist = {}
  593. for i = 1,#templist do
  594. if templist[i] == tonumber(v) then
  595. table.insert(cardlist,templist[i])
  596. table.insert(indexValue,i) --保存重复的索引值
  597. end
  598. end
  599. cardData[realIndex] = cardlist
  600. realIndex = realIndex + 1
  601. end
  602. local ttlist = {}
  603. for i = 1,#templist do
  604. if not self:isHasInCardlist(i,indexValue) then
  605. table.insert(ttlist,templist[i])
  606. end
  607. end
  608. if #ttlist >= 1 then
  609. local cardlist = {}
  610. for k,v in ipairs(ttlist) do
  611. table.insert(cardlist,v)
  612. end
  613. cardData[realIndex] = cardlist
  614. realIndex = realIndex + 1
  615. end
  616. else
  617. local cardlist = {}
  618. for i = 1,#templist do
  619. table.insert(cardlist,templist[i])
  620. if #cardlist == 4 then
  621. cardData[realIndex] = cardlist
  622. realIndex = realIndex + 1
  623. cardlist = {}
  624. end
  625. end
  626. if #cardlist >= 1 then
  627. cardData[realIndex] = cardlist
  628. realIndex = realIndex + 1
  629. end
  630. end
  631. else
  632. local cardlist = templist
  633. cardData[realIndex] = cardlist
  634. realIndex = realIndex + 1
  635. end
  636. end--]]
  637. end
  638. end
  639. --最后判断单张列表是否还有值
  640. if #singleCardList > 0 then
  641. cardData[realIndex] = singleCardList
  642. realIndex = realIndex + 1
  643. end
  644. logD("Room:resultCardData : "..table.tostring(cardData))
  645. return cardData
  646. end
  647. function Room:getMostBigValue(list)
  648. local smallValue = list[1]
  649. for i = 1,#list do
  650. if list[i] > smallValue then
  651. smallValue = list[i]
  652. end
  653. end
  654. return smallValue
  655. end
  656. --拆分数组中对子和三个以上的值
  657. function Room:spiltSameList(list)
  658. local tt = {}
  659. local templist = list
  660. --按点数从小到大排序
  661. table.sort(templist,function(a,b)
  662. local numA = tempCardVlue[tonumber(a)]
  663. local numB = tempCardVlue[tonumber(b)]
  664. if (numA ~= nil) and (numB ~= nil) then
  665. return numA < numB
  666. end
  667. return false
  668. end)
  669. local ttValue = {}
  670. for i = 1,#list do
  671. local value = list[i]
  672. if ttValue[value] then
  673. ttValue[value] = ttValue[value] + 1
  674. else
  675. ttValue[value] = 1
  676. end
  677. end
  678. local ttResult = {}
  679. for k,v in pairs(ttValue) do
  680. local cardlist = {}
  681. local card = tonumber(k)
  682. cardlist.card = {}
  683. cardlist.value = math.modf(tempCardVlue[tonumber(k)]/10)
  684. cardlist.num = v
  685. for i = 1,v do
  686. table.insert(cardlist.card,tonumber(k))
  687. end
  688. table.insert(ttResult,cardlist)
  689. end
  690. local index = 1
  691. for i = 1, #ttResult do
  692. local resultData = ttResult[i]
  693. if resultData.num then
  694. for j = i+1,#ttResult do
  695. local resultData1 = ttResult[j]
  696. if resultData1.num then
  697. --把加起来为4的列数都先放好
  698. if ((resultData1.num + resultData.num == 4) and (resultData.num == 1 or resultData.num == 3) and resultData.value == resultData1.value)
  699. or ((resultData1.num + resultData.num == 4) and (resultData.num == resultData.num) and resultData.value == resultData1.value) then
  700. local cardlist = {}
  701. for k,v in pairs(resultData1.card) do
  702. table.insert(cardlist,v)
  703. end
  704. for k,v in pairs(resultData.card) do
  705. table.insert(cardlist,v)
  706. end
  707. tt[index] = cardlist
  708. index = index + 1
  709. ttResult[i] = {}
  710. ttResult[j] = {}
  711. break
  712. end
  713. end
  714. end
  715. end
  716. end
  717. local leftNum = 0
  718. for i = 1,#ttResult do
  719. local resultData = ttResult[i]
  720. if resultData.num and resultData.num <= 2 then
  721. leftNum = leftNum + resultData.num
  722. elseif resultData.num and resultData.num >= 3 then --大于三张的要单独放一列
  723. local cardlist = {}
  724. if resultData.num then
  725. for k,v in pairs(resultData.card) do
  726. table.insert(cardlist,v)
  727. end
  728. end
  729. tt[index] = cardlist
  730. index = index + 1
  731. ttResult[i] = {}
  732. end
  733. end
  734. if leftNum > 0 then
  735. local mValue = {}
  736. for i = 1,#ttResult do
  737. local resultData = ttResult[i]
  738. if resultData.num then
  739. if not mValue[resultData.value] then
  740. mValue[resultData.value] = {}
  741. end
  742. for k,v in pairs(resultData.card) do
  743. table.insert(mValue[resultData.value],v)
  744. end
  745. end
  746. end
  747. for k,v in pairs(mValue) do
  748. tt[index] = v
  749. index = index + 1
  750. end
  751. --[[else--]]
  752. --[[ local cardlist = {}
  753. for i = 1,#ttResult do
  754. local resultData = ttResult[i]
  755. if resultData.num then
  756. for k,v in pairs(resultData.card) do
  757. table.insert(cardlist,v)
  758. end
  759. end
  760. end
  761. tt[index] = cardlist
  762. index = index + 1--]]
  763. end
  764. for i = 1,#tt do
  765. local tempResultCardList = tt[i]
  766. table.sort(tempResultCardList,function(a,b)
  767. local numA = tempCardVlue[tonumber(a)]
  768. local numB = tempCardVlue[tonumber(b)]
  769. if numA ~= nil and numB ~= nil then
  770. return numA < numB
  771. end
  772. return false
  773. end)
  774. end
  775. return tt
  776. end
  777. function Room:checkListHaveSame(list)
  778. local tt = {}
  779. local same = false
  780. local sameValue = {}
  781. for i = 1,#list do
  782. local value = list[i]
  783. if tt[value] then
  784. tt[value] = tt[value] + 1
  785. else
  786. tt[value] = 1
  787. end
  788. end
  789. for k,v in pairs(tt) do
  790. if v >= 3 then
  791. same = true
  792. table.insert(sameValue,k)
  793. end
  794. end
  795. return same,sameValue
  796. end
  797. --获取点数相同的列数
  798. function Room:getSameVlaueList(list)
  799. local tt = {}
  800. table.sort(list,function(a,b)
  801. local numA = tempCardVlue[tonumber(a)]
  802. local numB = tempCardVlue[tonumber(b)]
  803. if numA ~= nil and numB ~= nil then
  804. return numA > numB
  805. end
  806. end)
  807. for i = 1,#list do
  808. local value = math.modf(tempCardVlue[tonumber(list[i])]/10)
  809. if tt[value] then
  810. table.insert(tt[value],list[i])
  811. else
  812. tt[value] = {}
  813. table.insert(tt[value],list[i])
  814. end
  815. end
  816. return tt
  817. end
  818. function Room:isHasInCardlist(value,list)
  819. local isHas = false
  820. for k,v in pairs(list) do
  821. if value == v then
  822. isHas = true
  823. end
  824. end
  825. return isHas
  826. end
  827. --回放排序 --根据服务器逻辑进行排序
  828. function Room:rankHandCard(tPureHandCards)
  829. --发牌
  830. local index = 1
  831. local cardData = {}
  832. local list = {}
  833. local cardList = {}
  834. --把手分成点数相同列数
  835. local tempHandCardList = self:getSameVlaueList(tPureHandCards)
  836. logD("Room:rankHandCard : "..table.tostring(tempHandCardList))
  837. --按照点数去寻找牌组 点数只有2-12
  838. for i = 2,12 do
  839. list = {}
  840. cardList = {}
  841. local hCardList = tempHandCardList[i]
  842. if hCardList and table.nums(hCardList) > 0 then
  843. --先把找到的列数放入数组中
  844. for i = 1,#hCardList do
  845. table.insert(cardList, hCardList[i])
  846. end
  847. tempHandCardList[i] = {}
  848. --再找点数加起来为14的列数
  849. local secondDian = 14 - i
  850. local secondList = tempHandCardList[secondDian]
  851. if secondList and table.nums(secondList) > 0 then
  852. --再把找到的加起来为14的列数放入数组中
  853. for i = 1,#secondList do
  854. table.insert(cardList, secondList[i])
  855. end
  856. tempHandCardList[secondDian] = {}
  857. end
  858. end
  859. if table.nums(cardList) > 0 then
  860. table.sort(cardList,function(a,b)
  861. local numA = tempCardVlue[tonumber(a)]
  862. local numB = tempCardVlue[tonumber(b)]
  863. if numA ~= nil and numB ~= nil then
  864. return numA < numB
  865. end
  866. end)
  867. list.card = cardList
  868. cardData[index] = list
  869. index = index + 1
  870. end
  871. end
  872. return cardData
  873. end
  874. ---
  875. -- 托管通知
  876. -- @return
  877. --
  878. function Room:onHostingResponse (status, response)
  879. local userList = response.userList
  880. for k, v in ipairs(userList) do
  881. -- 是否托管
  882. if v.nUserId == self:getMyUserId() then
  883. self.roomInfo.hosting = v.status
  884. end
  885. self:dispatchEvent({name = ZPDef.ZPEvent.HostingRequest, response = {nUserId = v.nUserId, status = v.status}});
  886. end
  887. end
  888. -- 获取我当前是否处于托管状态
  889. function Room:getMeIsInAIStatus()
  890. return self.roomInfo.hosting == 1
  891. end
  892. return Room;