You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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