Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

1294 righe
36 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("ErWuRoom" , 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:defMsgFunc{name = "reflashHandCard",cmd = RoomCmd.GAME_COMMAND_REFLASH_HANDCARDS,sender = ZPMessage.ReflashHandCard};
  36. --发送起手操作码
  37. self:defMsgFunc{name = "sendQiShouOperate" , cmd = RoomCmd.GAME_COMMAND_QI_SHOU_SEND_OPCODE, sender = ZPMessage.GameSendOpCodeResponse};
  38. --接收起手操作提示
  39. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_OPERATE_TISHI, reader = ZPMessage.UserOperateNotify, func = handler(self, self.onUserOperateResponse)};
  40. --广播起手操作
  41. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_QI_SHOU_BROADCARST, reader = ZPMessage.GameQiShouBroadCastOperate, func = handler(self, self.onBroadCastQiShouOperate)};
  42. --广播玩家进牌
  43. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_GETCARD, reader = ZPMessage.GameUserGetCard, func = handler(self, self.onBroadCastUserGetCard)};
  44. --广播头家出牌
  45. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BANKER_OUT_CARD, reader = ZPMessage.GameBankerOutCard, func = handler(self, self.onBroadCastBankerOutCard)};
  46. --通知玩家包赔
  47. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_CHECK_USER_BAOPEI, reader = ZPMessage.BaoPei, func = handler(self, self.onOutCardIsBaoPeiResponse)};
  48. --玩家进牌后显示的操作
  49. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_TINGCARD_RESPONSE, reader = ZPMessage.GameUserGetCardOperateNotify, func = handler(self, self.onUserGetCardOperteResponse)};
  50. --刷新手牌
  51. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_REFLASH_HANDCARDS_RESPONSE, reader = ZPMessage.ReflashHandcardsResponse, func = handler(self , self.onReflashHandcardsResponese)};
  52. --抢巴胡
  53. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_QIANG_BA_HU, reader = ZPMessage.QiangBaResponse, func = handler(self , self.onQiangBaResponese)};
  54. --过巴变灰
  55. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_GUOBA_LOAK_CARD, reader = ZPMessage.GuoBaResponse, func = handler(self, self.onGuoBaResponse)};
  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:getMaxPlayerCount()
  63. return self.roomInfo.nMaxPlayCount
  64. end
  65. -- 获取房间人数
  66. function Room:getPlayerCount()
  67. local count = 0
  68. for k,v in pairs(self.roomInfo.memberList) do
  69. count = count + 1
  70. end
  71. return count
  72. end
  73. -- 重置上局信息
  74. function Room:resetRound()
  75. self.roomInfo.quickStartInfo = nil
  76. end
  77. function Room:resetFastInfo()
  78. self.roomInfo.quickStartInfo = nil
  79. end
  80. function Room:isMyself(uid)
  81. return uid==self:getMyUserId()
  82. end
  83. -- 更新玩家的相对椅子号
  84. function Room:updateUserSeateShowId(xiaoSeatId)
  85. local myUserId = self:getMyRecordUserId()
  86. local mySeatId = self.roomInfo.memberList[myUserId].nSeatId
  87. self.roomInfo.nUserId = self:getMyRecordUserId()
  88. self.roomInfo.nSeatId = mySeatId
  89. --除了自己的第一次seatid辅助
  90. local anotherSeatID = -1
  91. --[视图椅子号] = userID
  92. --[座位号] = userID
  93. --[userID] = 视图椅子号
  94. self.seatShowList = {}
  95. self.userList = {}
  96. self.seatList = {}
  97. for k,v in pairs(self.roomInfo.memberList) do
  98. if v.nUserId and v.nSeatId then
  99. local maxNum = 3--ZPFuc.getCreateRoomPlayerNum()
  100. local isChange = false
  101. if app.room:getActualPlayerNum() >= 3 then
  102. maxNum = 4
  103. end
  104. local nSeatShowId --= (v.nSeatId - mySeatId + 4) % 4
  105. if mySeatId <= v.nSeatId then
  106. nSeatShowId = v.nSeatId - mySeatId
  107. elseif mySeatId > v.nSeatId then
  108. nSeatShowId = maxNum - mySeatId + v.nSeatId
  109. end
  110. if app.room:getActualPlayerNum() == 2 then--self.roomInfo.playerNum == 2 then
  111. if (v.nSeatId == mySeatId) then
  112. nSeatShowId = 4
  113. else
  114. nSeatShowId = 2--两人玩时,对家坐哪里
  115. end
  116. elseif app.room:getActualPlayerNum() == 3 and v.nUserId ~= 0 then
  117. if (v.nSeatId == mySeatId) then
  118. nSeatShowId = 4
  119. else
  120. --local nSeatShowId = (v.nSeatId - mySeatId + 4) % 4
  121. if nSeatShowId == 2 then
  122. if mySeatId > v.nSeatId then
  123. nSeatShowId = nSeatShowId + 1
  124. isChange = true
  125. else
  126. isChange = true
  127. nSeatShowId = nSeatShowId - 1
  128. end
  129. end
  130. if nSeatShowId == 0 then
  131. if mySeatId > v.nSeatId then
  132. nSeatShowId = nSeatShowId + 1
  133. else
  134. nSeatShowId = 3
  135. end
  136. elseif (nSeatShowId == 1 or nSeatShowId == 3) and anotherSeatID >= 0 then
  137. isChange = true
  138. end
  139. if anotherSeatID < 0 and not isChange then
  140. anotherSeatID = v.nSeatId
  141. end
  142. end
  143. elseif app.room:getActualPlayerNum() == 4 and v.nUserId ~= 0 then
  144. if (v.nSeatId == mySeatId) and (v.nSeatId ~= self.roomInfo.xiaoSeatId) then
  145. nSeatShowId = 4
  146. else
  147. if xiaoSeatId and xiaoSeatId >=0 and nSeatShowId == 2 then
  148. if mySeatId == xiaoSeatId then
  149. if math.abs(mySeatId - v.nSeatId) == 2 then
  150. nSeatShowId = 4
  151. end
  152. elseif mySeatId > v.nSeatId then
  153. isChange = true
  154. nSeatShowId = nSeatShowId + 1
  155. else
  156. isChange = true
  157. nSeatShowId = nSeatShowId - 1
  158. end
  159. else
  160. end
  161. if xiaoSeatId and v.nSeatId == self.roomInfo.xiaoSeatId then
  162. nSeatShowId = 2
  163. end
  164. end
  165. --强制转换小家视角与庄家一致
  166. if mySeatId == xiaoSeatId then
  167. if nSeatShowId == 1 then
  168. nSeatShowId = 3
  169. elseif nSeatShowId == 3 then
  170. nSeatShowId = 1
  171. end
  172. end
  173. end
  174. if nSeatShowId == 0 then
  175. nSeatShowId = 4
  176. end
  177. if v.nUserId == 0 then
  178. nSeatShowId = 2
  179. if app.room:getActualPlayerNum() == 2 then
  180. nSeatShowId = 1
  181. end
  182. else
  183. if self.seatShowList[nSeatShowId] and isChange == true then
  184. if nSeatShowId == 1 then
  185. nSeatShowId = 3
  186. elseif nSeatShowId == 3 then
  187. nSeatShowId = 1
  188. end
  189. elseif self.seatShowList[nSeatShowId] and isChange == false then
  190. local olduid = self.seatShowList[nSeatShowId]
  191. local oldshowid = self.userList[olduid]
  192. local newshowid = 0
  193. if nSeatShowId == 1 then
  194. newshowid = 3
  195. elseif nSeatShowId == 3 then
  196. newshowid = 1
  197. end
  198. self.seatShowList[newshowid] = olduid
  199. self.userList[olduid] = newshowid
  200. end
  201. end
  202. self.seatShowList[nSeatShowId] = v.nUserId
  203. self.seatList[v.nSeatId] = v.nUserId
  204. self.userList[v.nUserId] = nSeatShowId
  205. end
  206. end
  207. logD("User:updateUserSeateShowId(), seatShowList", table.tostring(self.seatShowList))
  208. logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList))
  209. logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList))
  210. end
  211. --[[-- 玩家进入桌子成功
  212. function Room:onSitDownSuccessResponse(status, response)
  213. logD("--------------------玩家进入桌子成功--------------------")
  214. logD("Room:onSitDownSuccessResponse(), ", table.tostring(response))
  215. app.net:onMsgClear()
  216. app.net:onMsgPause()
  217. -- 记录当前桌子号
  218. self:initRoomInfo()
  219. -- 获取到的房间信息
  220. self.roomInfo.nShowTableId = response.nShowTableId
  221. self.roomInfo.nMaxPlayCount = response.nMaxPlayCount
  222. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid
  223. self.roomInfo.nTotalGameNum = response.nTotalGameNum
  224. self.roomInfo.strGameInfo = response.strGameInfo
  225. -- 桌子上其他玩家的信息
  226. for k,v in pairs(response.memberList) do
  227. self.roomInfo.memberList[v.nUserId] = v
  228. end
  229. -- 更新椅子号
  230. self:updateUserSeateShowId()
  231. logD("Room:onSitDownSuccessResponse() roomInfo = ", table.tostring(self.roomInfo))
  232. -- 发送通知
  233. self:dispatchEvent({name = "onEnterRoomSuccess", gameId = GAME_IDS.luzhouDaEr, gameType = self.roomInfo.strGameInfo.gamerule})
  234. end--]]
  235. -- 游戏正式开始
  236. function Room:onGameStartResponse(status, response)
  237. logD("-------------------- 新的一局开始了 ------------------------")
  238. if not self.roomInfo then
  239. logD("self.roomInfo no exist,容错处理!")
  240. return
  241. end
  242. logD("Room:onGameStartResponse(), ", table.tostring(response))
  243. self.roomInfo.nGameStartCount = response.nGameStartCount;
  244. self.roomInfo.nTotalGameNum = response.nTotalGameNum;
  245. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid;
  246. self.roomInfo.nBankSeatId = response.nBankSeatId;
  247. self.roomInfo.xiaoSeatId = response.xiaoSeatId;
  248. self.roomInfo.fanpaiSeatId = response.turnSeatId;
  249. self.roomInfo.fanpaiValue = response.turnCard;
  250. --清空上一局胡牌信息
  251. self.roomInfo.hupaiInfo = nil
  252. -- 清空上一局的手牌信息
  253. self.cards = {}
  254. -- 发送广播通知,游戏开始了
  255. self:dispatchEvent({name = "onGameStartResponse"});
  256. end
  257. -- 游戏发牌结果
  258. function Room:onGameSendCardResponse(status, response)
  259. logD("-------------------- 游戏发牌 ------------------------")
  260. if not self.roomInfo then
  261. logD("self.roomInfo no exist,容错处理!")
  262. return
  263. end
  264. logD("Room:onGameSendCardResponse(), ", table.tostring(response))
  265. self.roomInfo.nbankFirstGrabCard = response.nbankFirstGrabCard
  266. --[[
  267. --test
  268. response.cardList = {}
  269. response.cardList = {
  270. {
  271. type = 1,
  272. card = {0x11,0x22,0x14,0x15}
  273. },
  274. {
  275. type = 2,
  276. card = {0x11,0x22,0x14,0x15}
  277. },
  278. {
  279. type = 3,
  280. card = {0x11,0x22,0x14,0x15}
  281. },
  282. {
  283. type = 4,
  284. card = {0x11,0x22,0x14,0x15}
  285. }
  286. }
  287. ]]
  288. --目前server只发自己过来,后续战绩回放考虑到会发所有玩家来,故以userid为key于扩展
  289. local cardData = self:serverCardToMyCard(response.cardList)
  290. logD("Room:onGameSendCardResponse : "..table.tostring(cardData))
  291. self.roomInfo.memberList[response.nUserId].cardList = cardData
  292. self.cards[response.nUserId] = cardData
  293. if self:isLittleFamily() then
  294. self.roomInfo.nBankUid = response.nUserId
  295. self.cards[app.user.loginInfo.uid] = cardData
  296. end
  297. self.roomInfo.totalTuoNum = response.totalTuoNum
  298. -- 发送广播通知,发牌开始了
  299. self:dispatchEvent({name = "onGameSendCardResponse"});
  300. end
  301. function Room:onUserOperateResponse(status, response)
  302. logD("------------提示用户偷巴操作---------------")
  303. if not self.roomInfo then
  304. logD("self.roomInfo no exist,容错处理!")
  305. return
  306. end
  307. logD("Room:onUserOperateResponse(), ", table.tostring(response))
  308. --self.roomInfo.TouoperateCard = response.ToucardList
  309. --self.roomInfo.BaoperateCard = response.BacardList
  310. if self:isMyself(response.nUserId) then
  311. self.roomInfo.totoalTuoNum = response.totalTuoNum
  312. end
  313. self:dispatchEvent({name = "onUserOperateResponse",response = response})
  314. end
  315. function Room:onBroadCastQiShouOperate(status, response)
  316. logD("------------广播用户偷巴操作---------------")
  317. if not self.roomInfo then
  318. logD("self.roomInfo no exist,容错处理!")
  319. return
  320. end
  321. logD("Room:onBroadCastQiShouOperate(), ", table.tostring(response))
  322. if self:isMyself(response.nUserId) then
  323. self.roomInfo.totoalTuoNum = response.totalTuoNum
  324. end
  325. self:dispatchEvent({name = "onBroadCastQiShouOperate",response = response})
  326. end
  327. function Room:onBroadCastUserGetCard(status, response)
  328. logD("------------广播用户进牌操作---------------")
  329. if not self.roomInfo then
  330. logD("self.roomInfo no exist,容错处理!")
  331. return
  332. end
  333. logD("Room:onBroadCastUserGetCard(), ", table.tostring(response))
  334. self:dispatchEvent({name = "onBroadCastUserGetCard",response = response})
  335. end
  336. function Room:onGuoBaResponse(status, response)
  337. logD("------------广播用户过巴操作---------------")
  338. if not self.roomInfo then
  339. logD("self.roomInfo no exist,容错处理!")
  340. return
  341. end
  342. logD("Room:onGuoBaResponse(), ", table.tostring(response))
  343. self:dispatchEvent({name = "onGuoBaResponse",response = response})
  344. end
  345. function Room:onBroadCastBankerOutCard(status, response)
  346. logD("------------通知头家出牌--------------")
  347. if not self.roomInfo then
  348. logD("self.roomInfo no exist,容错处理!")
  349. return
  350. end
  351. logD("Room:onBroadCastBankerOutCard(), ", table.tostring(response))
  352. self:dispatchEvent({name = "onBroadCastBankerOutCard",response = response})
  353. end
  354. function Room:onOutCardIsBaoPeiResponse(status, response)
  355. logD("------------通知打出的牌可能包赔--------------")
  356. if not self.roomInfo then
  357. logD("self.roomInfo no exist,容错处理!")
  358. return
  359. end
  360. logD("Room:onOutCardIsBaoPeiResponse(), ", table.tostring(response))
  361. self:dispatchEvent({name = "onOutCardIsBaoPeiResponse",response = response})
  362. end
  363. function Room:onUserGetCardOperteResponse(status, response)
  364. logD("------------进牌后通知玩家显示操作--------------")
  365. if not self.roomInfo then
  366. logD("self.roomInfo no exist,容错处理!")
  367. return
  368. end
  369. logD("Room:onUserGetCardOperteResponse(), ", table.tostring(response))
  370. self:dispatchEvent({name = "onUserGetCardOperteResponse",response = response})
  371. end
  372. function Room:onQiangBaResponese(status, response)
  373. logD("------------通知玩家抢巴操作--------------")
  374. if not self.roomInfo then
  375. logD("self.roomInfo no exist,容错处理!")
  376. return
  377. end
  378. logD("Room:onQiangBaResponese(), ", table.tostring(response))
  379. self:dispatchEvent({name = "onQiangBaResponese",response = response})
  380. end
  381. -- 获取自己是否是小家(观看的人) 且选了小家可以看牌才返回true 长牌用不到
  382. function Room:isLittleFamily()
  383. return false
  384. end
  385. --小局结算
  386. function Room:onGameXiaoJuResponse(status, response)
  387. logD("--------------------小局结算 ------------------------")
  388. if not self.roomInfo then
  389. logD("self.roomInfo no exist,容错处理!")
  390. return
  391. end
  392. if self:getActualPlayerNum() == 2 then
  393. local handcards = self:rankHandCard(response.thirdHandcards);
  394. -- handcards = self:serverCardToMyCard(handcards);
  395. local userId = 0;
  396. local player = {
  397. nUserId = userId,
  398. nTurnScore = 0,
  399. nTotalMoney = 0,
  400. nBaoPaiStatus = 0,
  401. totalTuoNum = 0,
  402. tableWeaveCard = {},
  403. handCard = handcards,
  404. desertedArea = 0,
  405. };
  406. response.playList.Datas[userId] = player;
  407. end
  408. logD("Room:onGameXiaoJuResponse() :", table.tostring(response))
  409. self:dispatchEvent({name = "onGameXiaoJuResponse",response = response});
  410. end
  411. --断线重连
  412. function Room:onGameReconnection(status,response)
  413. logD("===============重连成功,清空之前所有存在的队列==================")
  414. app.net:onMsgClear()
  415. app.net:onMsgPause()
  416. logD("Room:onGameReconnection(), response = ", table.tostring(response))
  417. self:initRoomInfo();
  418. -- 获取到的房间信息
  419. self.roomInfo.nShowTableId = response.nShowTableId
  420. self.roomInfo.nMaxPlayCount = response.nMaxPlayCount
  421. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid
  422. self.roomInfo.nTotalGameNum = response.nTotalGameNum
  423. self.roomInfo.nGameStartCount = response.nGameStartCount
  424. self.roomInfo.strGameInfo = response.strGameInfo
  425. self.roomInfo.nStatus = response.nStatus
  426. self.roomInfo.nDismissToTalTime = response.nDismissToTalTime
  427. self.roomInfo.nBankSeatId = response.nBankSeatId
  428. self.roomInfo.nZhongBankCnt = response.nZhongBankCnt
  429. self.roomInfo.bUserDisbandGame = response.bUserDisbandGame
  430. self.roomInfo.nDismissStateTime = response.nDismissStateTime
  431. self.roomInfo.arrayTableInfo = response.arrayTableInfo or {}
  432. self.roomInfo.dipaiList = response.dipaiList
  433. self.roomInfo.showCardSeatId = response.showCardSeatId
  434. self.roomInfo.showCard = response.showCard
  435. self.roomInfo.mainOpCode = response.mainOpCode
  436. self.roomInfo.isSubmitOp = response.isSubmitOp
  437. self.roomInfo.showCardFlag = response.showCardFlag
  438. self.roomInfo.outCardSeatId = response.outCardSeatId
  439. self.roomInfo.lastOperate = response.lastOperate
  440. self.roomInfo.lastOpCard = response.lastOpCard
  441. self.roomInfo.disCardSeatId = response.disCardSeatId
  442. self.roomInfo.disCard = {}
  443. self.roomInfo.leftZhaBirdTime = response.leftZhaBirdTime
  444. self.roomInfo.stopFlag = response.stopFlag
  445. self.roomInfo.winUserId = response.winUserId
  446. self.roomInfo.dianPaoUserId = response.dianPaoUserId
  447. self.roomInfo.huType = response.huType
  448. self.roomInfo.huCard = response.huCard
  449. self.roomInfo.tingCards = response.tingCards
  450. self.roomInfo.hupaiInfo = response.hupaiInfo or {}
  451. self.roomInfo.xiaoSeatId = response.xiaoSeatId;
  452. self.roomInfo.offLineInfo = response.offLineInfo
  453. self.roomInfo.fanpaiSeatId = response.fanpaiSeatId
  454. self.roomInfo.chiPaiList = response.chiCardList or {}
  455. self.roomInfo.isBaopeiCard = response.isBaopeiCard
  456. self.roomInfo.totalTuoNum = response.totalTuoNum
  457. self.roomInfo.curOpreateID = response.curOpreateID
  458. self.roomInfo.isBaopeiGuo = response.isBaopeiGuo
  459. self.roomInfo.houzhuaCard = response.houzhuaCard or {}
  460. self.roomInfo.curEnterCard = response.curEnterCard
  461. self.roomInfo.isZiMoHu = response.isZiMoHu
  462. self.roomInfo.isQiangBaHu = response.isQiangBaHu
  463. for k,v in ipairs(response.disCard or {}) do
  464. table.insert(self.roomInfo.disCard,v)
  465. end
  466. for k,v in ipairs(response.afterbadisCard or {}) do
  467. table.insert(self.roomInfo.disCard,v)
  468. end
  469. --起手操作
  470. self.roomInfo.startOpList = {}
  471. self.roomInfo.startOpList["ishu"] = response.ishu
  472. self.roomInfo.startOpList["TouoperateCode"] = response.TouoperateCode
  473. self.roomInfo.startOpList["ToucardList"] = response.ToucardList or {}
  474. self.roomInfo.startOpList["BaoperateCode"] = response.BaoperateCode
  475. self.roomInfo.startOpList["BacardList"] = response.BacardList or {}
  476. self.roomInfo.startOpList["totalTuoNum"] = response.totalTuoNum
  477. self.roomInfo.startOpList["PengList"] = response.pengList
  478. self:addReconnectionData(response)
  479. if self.roomInfo.offLineInfo and next(self.roomInfo.offLineInfo) ~= nil then
  480. for i,v in pairs(self.roomInfo.offLineInfo) do
  481. if v.extInfo then
  482. local extIf = json.decode(v.extInfo)
  483. if extIf.OffTime and v.nUserId then
  484. self.offLineTime[v.nUserId] = extIf.OffTime
  485. end
  486. end
  487. end
  488. end
  489. for i,v in pairs(self.roomInfo.hupaiInfo) do
  490. self.roomInfo.dianPaoUserId = v.dianPaoUid
  491. self.roomInfo.huCard = v.huCard
  492. end
  493. if app.club_php.clubID and app.club_php.clubID ~= 0 and self.roomInfo.nGameStartCount > 0 then
  494. app.club_php:getClubList();
  495. end
  496. -- 桌子上其他玩家的信息
  497. for k,v in pairs(response.arrayTableInfo) do
  498. if not self.roomInfo.memberList[v.nUserId] then
  499. self.roomInfo.memberList[v.nUserId] = {}
  500. end
  501. self.roomInfo.memberList[v.nUserId].nUserId = v.nUserId
  502. self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId
  503. self.roomInfo.memberList[v.nUserId].nPlayerFlag = v.nPlayerFlag
  504. self.roomInfo.memberList[v.nUserId].userInfo = v.userInfo
  505. self.roomInfo.memberList[v.nUserId].nTotalMoney = v.nTotalMoney
  506. self.roomInfo.memberList[v.nUserId].nOnlineStatus = v.nOnlineStatus
  507. --这里只记录,暂时没用到。可能战绩回放的时候是需要用的
  508. local cardData = self:serverCardToMyCard(v.handCard)
  509. self.roomInfo.memberList[v.nUserId].cardList = {}
  510. self.roomInfo.memberList[v.nUserId].cardList = cardData
  511. if v.nSeatId == self.roomInfo.nBankSeatId then
  512. self.roomInfo.nBankUid = v.nUserId --头家UID
  513. end
  514. end
  515. if self:getActualPlayerNum() == 2 and table.nums(response.thirdHandcards) > 0 then
  516. local userId = 0
  517. local thirdHandcards = self:rankHandCard(response.thirdHandcards)
  518. thirdHandcards = self:serverCardToMyCard(thirdHandcards)
  519. if not self.roomInfo.memberList[userId] then
  520. self.roomInfo.memberList[userId] = {}
  521. end
  522. self.roomInfo.memberList[userId].cardList = thirdHandcards
  523. if self.roomInfo.arrayTableInfo[userId] then
  524. self.roomInfo.arrayTableInfo[userId].Datas.handCard.Datas = self:rankHandCard(response.thirdHandcards)
  525. end
  526. end
  527. local myUserId = self:getMyRecordUserId()
  528. for i,v in pairs(self.roomInfo.memberList) do
  529. if self:isLittleFamily() and self.roomInfo.nBankSeatId == v.nSeatId then
  530. self.roomInfo.memberList[myUserId].cardList = v.cardList
  531. end
  532. end
  533. --更新自己的数据
  534. self.cards[myUserId] = self.roomInfo.memberList[myUserId].cardList
  535. print("self.cards[myUserId]:"..table.tostring(self.cards[myUserId]))
  536. --检测GPS
  537. self:updateGpsUserInfo(nil,false)
  538. -- 更新椅子号
  539. self:updateUserSeateShowId()
  540. local jsonInfo = json.decode(self.roomInfo.strGameInfo)
  541. self:resetRound()
  542. --没用到
  543. local extInfo = json.decode(response.extJson or "")
  544. if extInfo and type(extInfo)=='table' and extInfo[tostring(self:getMyUserId())] then
  545. local myinfo = extInfo[tostring(self:getMyUserId())]
  546. self.roomInfo.hosting = myinfo.hosted or 0--托管状态
  547. self.roomInfo.quickStartInfo = extInfo.faststart--提前开局
  548. else
  549. self.roomInfo.hosting = 0
  550. end
  551. -- 发送通知
  552. self:dispatchEvent({name = "onEnterRoomSuccess", gameId = ZPDef.GameID or app.gameId, gameType = jsonInfo.gamerule})
  553. end
  554. --获取手牌结果
  555. function Room:onGetHandcardsResponese(status, response)
  556. end
  557. --获取手牌结果
  558. function Room:onReflashHandcardsResponese(status, response)
  559. print("Room:onReflashHandcardsResponese()", table.tostring(response))
  560. local cardData = self:serverCardToMyCard(response.handCard)
  561. self.roomInfo.memberList[response.nUserId].cardList = {}
  562. self.roomInfo.memberList[response.nUserId].cardList = cardData
  563. self.cards[response.nUserId] = cardData
  564. self:dispatchEvent({name = "onReflashHandcardsResponese"});
  565. end
  566. -- 系统发牌后发来的自动提操作
  567. function Room:onSystemOperationStart(status, response)
  568. logD("-------------------- 等待玩家报叫------------------------")
  569. if not self.roomInfo then
  570. logD("self.roomInfo no exist,容错处理!")
  571. return
  572. end
  573. logD("Room:onSystemOperationStart(), ", table.tostring(response))
  574. end
  575. function Room:onOutCardError(status,response)
  576. logD("-------------------- 出牌错误 ------------------------")
  577. if not self.roomInfo then
  578. print("容错处理")
  579. return
  580. end
  581. logD("Room:onOutCardError(), response = ", table.tostring(response))
  582. --[[错误码说明:
  583. OUT_CARD_SUCCESS = 0, //正常
  584. OUT_CARD_ON_NEED = 1, //不需要出牌
  585. OUT_CARD_INVALID = 2, //出牌非法
  586. OUT_CARD_BAOPEI = 3, //不出包赔牌--]]
  587. local errorCode = response.result
  588. if errorCode == ZPDef.OutCardErrorTip.OUT_CARD_SUCCESS then
  589. showTooltip("出牌无效")
  590. elseif errorCode == ZPDef.OutCardErrorTip.OUT_CARD_SUCCESS then
  591. showTooltip("不需要出牌")
  592. elseif errorCode == ZPDef.OutCardErrorTip.OUT_CARD_BAOPEI then
  593. showTooltip("请重新选择!")
  594. else
  595. showTooltip("出牌未知")
  596. end
  597. self:dispatchEvent({name = "onOutCardError"});
  598. end
  599. --[[
  600. 思维:
  601. 服务器把牌都排序好了,客户端只要拿到数据负责显示
  602. ]]
  603. function Room:serverCardToMyCard(serverCardList)
  604. --
  605. --根据定义组合牌
  606. local cardData = {}
  607. --单个组合索引
  608. local index = 1
  609. --真实索引
  610. local realIndex = 1
  611. local tempserverCardlist = {}
  612. local singleCardList = {}
  613. for k,v in ipairs(serverCardList) do
  614. table.insert(tempserverCardlist,v.card)
  615. end
  616. table.sort(tempserverCardlist,function(a,b)
  617. local index = a[1]
  618. local numA = tempCardVlue[index]
  619. local index1 = b[1]
  620. local numB = tempCardVlue[index1]
  621. if numA ~= nil and numB ~= nil then
  622. return numA < numB
  623. end
  624. end)
  625. logD("Room:sortMycard : "..table.tostring(tempserverCardlist))
  626. for k,v in ipairs(tempserverCardlist) do
  627. local list = v
  628. if #list <= 5 then
  629. --如果是四张以下直接放一列
  630. local cardlist = {}
  631. for k,v in ipairs(list) do
  632. table.insert(cardlist,v)
  633. end
  634. --先按值牌序
  635. table.sort(cardlist,function(a,b)
  636. local numA = tonumber(a)
  637. local numB = tonumber(b)
  638. if numA ~= nil and numB ~= nil then
  639. return numA < numB
  640. end
  641. end)
  642. --按点数排序
  643. table.sort(cardlist,function(a,b)
  644. local numA = tempCardVlue[a]
  645. local numB = tempCardVlue[b]
  646. if (numA ~= nil) and (numB ~= nil) then
  647. return numA < numB
  648. end
  649. return false
  650. end)
  651. cardData[realIndex] = cardlist
  652. realIndex = realIndex + 1
  653. else --大于五张要分开
  654. --首先考虑三张一样的
  655. local cardlist = {}
  656. for k,v in ipairs(list) do
  657. table.insert(cardlist,v)
  658. end
  659. --local tempCardList = self:getSameVlaueList(cardlist)
  660. local tempCardList = self:spiltSameList(cardlist)
  661. local tempResultCardList = {}
  662. for k,v in pairs(tempCardList) do
  663. table.insert(tempResultCardList,v)
  664. end
  665. --按点数排序
  666. table.sort(tempResultCardList,function(a,b)
  667. local index = a[1]
  668. local numA = tempCardVlue[index]
  669. local index1 = b[1]
  670. local numB = tempCardVlue[index1]
  671. if (numA ~= nil) and (numB ~= nil) then
  672. return numA < numB
  673. end
  674. return false
  675. end)
  676. for k,templist in pairs (tempResultCardList) do
  677. local cardlist = templist
  678. cardData[realIndex] = cardlist
  679. realIndex = realIndex + 1
  680. end
  681. --[[ for k,templist in pairs(tempResultCardList) do
  682. if #templist > 5 then
  683. local same,sameValue = self:checkListHaveSame(templist)
  684. local indexValue = {}
  685. if same then
  686. for k,v in ipairs(sameValue) do
  687. local cardlist = {}
  688. for i = 1,#templist do
  689. if templist[i] == tonumber(v) then
  690. table.insert(cardlist,templist[i])
  691. table.insert(indexValue,i) --保存重复的索引值
  692. end
  693. end
  694. cardData[realIndex] = cardlist
  695. realIndex = realIndex + 1
  696. end
  697. local ttlist = {}
  698. for i = 1,#templist do
  699. if not self:isHasInCardlist(i,indexValue) then
  700. table.insert(ttlist,templist[i])
  701. end
  702. end
  703. if #ttlist >= 1 then
  704. local cardlist = {}
  705. for k,v in ipairs(ttlist) do
  706. table.insert(cardlist,v)
  707. end
  708. cardData[realIndex] = cardlist
  709. realIndex = realIndex + 1
  710. end
  711. else
  712. local cardlist = {}
  713. for i = 1,#templist do
  714. table.insert(cardlist,templist[i])
  715. if #cardlist == 5 then
  716. cardData[realIndex] = cardlist
  717. realIndex = realIndex + 1
  718. cardlist = {}
  719. end
  720. end
  721. if #cardlist >= 1 then
  722. cardData[realIndex] = cardlist
  723. realIndex = realIndex + 1
  724. end
  725. end
  726. else
  727. local cardlist = templist
  728. cardData[realIndex] = cardlist
  729. realIndex = realIndex + 1
  730. end
  731. end--]]
  732. end
  733. end
  734. --最后判断单张列表是否还有值
  735. if #singleCardList > 0 then
  736. cardData[realIndex] = singleCardList
  737. realIndex = realIndex + 1
  738. end
  739. logD("Room:resultCardData : "..table.tostring(cardData))
  740. return cardData
  741. end
  742. function Room:checkListHaveSame(list)
  743. local tt = {}
  744. local same = false
  745. local sameValue = {}
  746. for i = 1,#list do
  747. local value = list[i]
  748. if tt[value] then
  749. tt[value] = tt[value] + 1
  750. else
  751. tt[value] = 1
  752. end
  753. end
  754. for k,v in pairs(tt) do
  755. if v >= 3 then
  756. same = true
  757. table.insert(sameValue,k)
  758. end
  759. end
  760. return same,sameValue
  761. end
  762. --获取点数相同的列数
  763. function Room:getSameVlaueList(list)
  764. local tt = {}
  765. table.sort(list,function(a,b)
  766. local numA = tempCardVlue[tonumber(a)]
  767. local numB = tempCardVlue[tonumber(b)]
  768. if numA ~= nil and numB ~= nil then
  769. return numA < numB
  770. end
  771. end)
  772. for i = 1,#list do
  773. local value = math.modf(tempCardVlue[tonumber(list[i])]/10)
  774. if tt[value] then
  775. table.insert(tt[value],list[i])
  776. else
  777. tt[value] = {}
  778. table.insert(tt[value],list[i])
  779. end
  780. end
  781. return tt
  782. end
  783. --拆分数组中对子和三个以上的值
  784. function Room:spiltSameList(list)
  785. local tt = {}
  786. local templist = list
  787. --按点数从小到大排序
  788. table.sort(templist,function(a,b)
  789. local numA = tempCardVlue[tonumber(a)]
  790. local numB = tempCardVlue[tonumber(b)]
  791. if (numA ~= nil) and (numB ~= nil) then
  792. return numA < numB
  793. end
  794. return false
  795. end)
  796. local ttValue = {}
  797. for i = 1,#list do
  798. local value = list[i]
  799. if ttValue[value] then
  800. ttValue[value] = ttValue[value] + 1
  801. else
  802. ttValue[value] = 1
  803. end
  804. end
  805. local ttResult = {}
  806. for k,v in pairs(ttValue) do
  807. local cardlist = {}
  808. local card = tonumber(k)
  809. cardlist.card = {}
  810. cardlist.value = math.modf(tempCardVlue[tonumber(k)]/10)
  811. cardlist.num = v
  812. for i = 1,v do
  813. table.insert(cardlist.card,tonumber(k))
  814. end
  815. table.insert(ttResult,cardlist)
  816. end
  817. --先把加起来等于5的分开出来
  818. local index = 1
  819. for i = 1, #ttResult do
  820. local resultData = ttResult[i]
  821. if resultData.num then
  822. for j = i+1,#ttResult do
  823. local resultData1 = ttResult[j]
  824. if resultData1.num then
  825. --把加起来为4的列数都先放好
  826. if ((resultData1.num + resultData.num == 5) and (resultData.num == 1 or resultData.num == 4) and resultData.value == resultData1.value)
  827. or ((resultData1.num + resultData.num == 5) and (resultData.num == 3 or resultData.num == 2) and resultData.value == resultData1.value) then
  828. local cardlist = {}
  829. for k,v in pairs(resultData1.card) do
  830. table.insert(cardlist,v)
  831. end
  832. for k,v in pairs(resultData.card) do
  833. table.insert(cardlist,v)
  834. end
  835. tt[index] = cardlist
  836. index = index + 1
  837. ttResult[i] = {}
  838. ttResult[j] = {}
  839. break
  840. end
  841. end
  842. end
  843. end
  844. end
  845. --再把对子放一起去 最多放两对
  846. for i = 1, #ttResult do
  847. local resultData = ttResult[i]
  848. if resultData.num then
  849. for j = i+1,#ttResult do
  850. local resultData1 = ttResult[j]
  851. if resultData1.num then
  852. --把加起来为4的列数都先放好
  853. if ((resultData1.num + resultData.num == 4) and (resultData.num == resultData.num) and resultData.value == resultData1.value) then
  854. local cardlist = {}
  855. for k,v in pairs(resultData1.card) do
  856. table.insert(cardlist,v)
  857. end
  858. for k,v in pairs(resultData.card) do
  859. table.insert(cardlist,v)
  860. end
  861. tt[index] = cardlist
  862. index = index + 1
  863. ttResult[i] = {}
  864. ttResult[j] = {}
  865. break
  866. end
  867. end
  868. end
  869. end
  870. end
  871. local leftNum = 0
  872. for i = 1,#ttResult do
  873. local resultData = ttResult[i]
  874. if resultData.num and resultData.num <= 2 then
  875. leftNum = leftNum + resultData.num
  876. elseif resultData.num and resultData.num >= 3 then --大于三张的要单独放一列
  877. local cardlist = {}
  878. if resultData.num then
  879. for k,v in pairs(resultData.card) do
  880. table.insert(cardlist,v)
  881. end
  882. end
  883. tt[index] = cardlist
  884. index = index + 1
  885. ttResult[i] = {}
  886. end
  887. end
  888. for i = 1,#tt do
  889. table.sort(tt,function(a,b)
  890. local index = a[1]
  891. local numA = tempCardVlue[index]
  892. local index1 = b[1]
  893. local numB = tempCardVlue[index1]
  894. if numA ~= nil and numB ~= nil then
  895. return numA < numB
  896. end
  897. return false
  898. end)
  899. end
  900. if leftNum <= 2 then
  901. local hasFind = false
  902. local lens = table.nums(tt)
  903. if lens > 0 then
  904. --优先去找对子
  905. for i=lens,1,-1 do
  906. local cardlist = tt[i]
  907. if table.nums(cardlist) == 4 and leftNum == 1 then
  908. for i = 1,#ttResult do
  909. local resultData = ttResult[i]
  910. if resultData.num then
  911. for k,v in pairs(resultData.card) do
  912. table.insert(cardlist,v)
  913. end
  914. end
  915. end
  916. hasFind = true
  917. end
  918. if hasFind then
  919. break
  920. end
  921. end
  922. --如果没有对子则找三个的
  923. if not hasFind then
  924. for i=lens,1,-1 do
  925. local cardlist = tt[i]
  926. if table.nums(cardlist) == 3 then
  927. for i = 1,#ttResult do
  928. local resultData = ttResult[i]
  929. if resultData.num then
  930. for k,v in pairs(resultData.card) do
  931. table.insert(cardlist,v)
  932. end
  933. end
  934. end
  935. hasFind = true
  936. end
  937. if hasFind then
  938. break
  939. end
  940. end
  941. end
  942. end
  943. --如果三个的都没有则单独放一列
  944. if not hasFind then
  945. local cardlist = {}
  946. for i = 1,#ttResult do
  947. local resultData = ttResult[i]
  948. if resultData.num then
  949. for k,v in pairs(resultData.card) do
  950. table.insert(cardlist,v)
  951. end
  952. end
  953. end
  954. tt[index] = cardlist
  955. index = index + 1
  956. end
  957. elseif leftNum > 2 and leftNum <= 5 then
  958. local cardlist = {}
  959. for i = 1,#ttResult do
  960. local resultData = ttResult[i]
  961. if resultData.num then
  962. for k,v in pairs(resultData.card) do
  963. table.insert(cardlist,v)
  964. end
  965. end
  966. end
  967. tt[index] = cardlist
  968. index = index + 1
  969. else
  970. local mValue = {}
  971. for i = 1,#ttResult do
  972. local resultData = ttResult[i]
  973. if resultData.num then
  974. if not mValue[resultData.value] then
  975. mValue[resultData.value] = {}
  976. end
  977. for k,v in pairs(resultData.card) do
  978. table.insert(mValue[resultData.value],v)
  979. end
  980. end
  981. end
  982. for k,v in pairs(mValue) do
  983. tt[index] = v
  984. index = index + 1
  985. end
  986. end
  987. for i = 1,#tt do
  988. local tempResultCardList = tt[i]
  989. table.sort(tempResultCardList,function(a,b)
  990. local numA = tempCardVlue[tonumber(a)]
  991. local numB = tempCardVlue[tonumber(b)]
  992. if numA ~= nil and numB ~= nil then
  993. return numA < numB
  994. end
  995. return false
  996. end)
  997. end
  998. return tt
  999. end
  1000. function Room:isHasInCardlist(value,list)
  1001. local isHas = false
  1002. for k,v in pairs(list) do
  1003. if value == v then
  1004. isHas = true
  1005. end
  1006. end
  1007. return isHas
  1008. end
  1009. --回放排序 --先做最简单的排序
  1010. function Room:rankHandCard(tPureHandCards)
  1011. --发牌
  1012. local index = 1
  1013. local cardData = {}
  1014. local list = {}
  1015. local cardList = {}
  1016. --把手分成点数相同列数
  1017. local tempHandCardList = self:getSameVlaueList(tPureHandCards)
  1018. logD("Room:rankHandCard : "..table.tostring(tempHandCardList))
  1019. --按照点数去寻找牌组 点数只有2-12
  1020. for i = 2,12 do
  1021. list = {}
  1022. cardList = {}
  1023. local hCardList = tempHandCardList[i]
  1024. if hCardList and table.nums(hCardList) > 0 then
  1025. --先把找到的列数放入数组中
  1026. for i = 1,#hCardList do
  1027. table.insert(cardList, hCardList[i])
  1028. end
  1029. tempHandCardList[i] = {}
  1030. --再找点数加起来为14的列数
  1031. local secondDian = 14 - i
  1032. local secondList = tempHandCardList[secondDian]
  1033. if secondList and table.nums(secondList) > 0 then
  1034. --再把找到的加起来为14的列数放入数组中
  1035. for i = 1,#secondList do
  1036. table.insert(cardList, secondList[i])
  1037. end
  1038. tempHandCardList[secondDian] = {}
  1039. end
  1040. end
  1041. if table.nums(cardList) > 0 then
  1042. table.sort(cardList,function(a,b)
  1043. local numA = tempCardVlue[tonumber(a)]
  1044. local numB = tempCardVlue[tonumber(b)]
  1045. if numA ~= nil and numB ~= nil then
  1046. return numA < numB
  1047. end
  1048. end)
  1049. list.card = cardList
  1050. cardData[index] = list
  1051. index = index + 1
  1052. end
  1053. end
  1054. return cardData
  1055. end
  1056. ---
  1057. -- 托管通知
  1058. -- @return
  1059. --
  1060. function Room:onHostingResponse (status, response)
  1061. local userList = response.userList
  1062. for k, v in ipairs(userList) do
  1063. -- 是否托管
  1064. if v.nUserId == self:getMyUserId() then
  1065. self.roomInfo.hosting = v.status
  1066. end
  1067. self:dispatchEvent({name = ZPDef.ZPEvent.HostingRequest, response = {nUserId = v.nUserId, status = v.status}});
  1068. end
  1069. end
  1070. --获取自己的ID,API仅限回放使用
  1071. --[[
  1072. 如果自己在里面玩,那么就返回我自己的ID,为第一视角
  1073. 如果是管理员或者其他目的进来查看回放,则以这局玩家最小的ID为第一视角
  1074. ]]
  1075. function Room:getMyRecordUserId()
  1076. local myUserId = app.user.loginInfo.uid
  1077. local minID = 0
  1078. local isFind = false
  1079. for k,v in pairsByKeys(self.roomInfo.memberList) do
  1080. if myUserId == v.nUserId then
  1081. return myUserId
  1082. end
  1083. if not isFind and v.nUserId ~= 0 then
  1084. minID = v.nUserId
  1085. isFind = true
  1086. end
  1087. end
  1088. return minID
  1089. end
  1090. return Room;