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.

4840 lines
147 KiB

  1. local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  2. local ZPMessage = ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage")
  3. local ZPRoomView = ZPFramework.ZPFrameworkClassImprot("zp_base.luaScript.Views.Room.ZPRoomView")
  4. local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
  5. local ChangPaiRoomCard=ZPFramework.ZPImport("zp_changpai.luaScript.Views.Room.changpaiRoomCard")
  6. local changpaiRoomSettingView=ZPFramework.ZPImport("zp_changpai.luaScript.Views.Room.changpaiRoomSettingView")
  7. local ZPRoomPlayerView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomPlayerView")
  8. local ZPRoomToolView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomToolView")
  9. local ZPRoomXiaoJuChaPaiView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomXiaoJuChaPaiView")
  10. local changpaiRoomXiaoJuView=ZPFramework.ZPImport("zp_changpai.luaScript.Views.Room.changpaiRoomXiaoJuView")
  11. local ChangpaiRoomOperationView=ZPFramework.ZPImport("zp_changpai.luaScript.Views.Room.changpaiRoomOperationView")
  12. local ChangpaiCard = ZPFramework.ZPImport("zp_changpai.luaScript.Views.Room.changpaiCard")
  13. local ZPRoomQuickStartView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomQuickStartView")
  14. local ZPWanFa=ZPFramework.ImportWanFa("luaScript.SubGameDefine.ZiPai.ZPWanFa")
  15. local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound")
  16. local ZPRoomCountAllView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomCountAllView")
  17. --每张牌的点数 用于排序
  18. local tempCardVlue ={
  19. [17] = 2, --11
  20. [18] = 3, --12
  21. [49] = 4, --31
  22. [34] = 4, --22
  23. [20] = 5, --14
  24. [50] = 5, --32
  25. [21] = 6, --15
  26. [36] = 6, --24
  27. [51] = 6, --33
  28. [22] = 7, --16
  29. [82] = 7, --52
  30. [52] = 7, --34
  31. [38] = 8, --26
  32. [53] = 8, --35
  33. [68] = 8, --44
  34. [54] = 9, --36
  35. [84] = 9, --54
  36. [70] = 10, --46
  37. [85] = 10, --55
  38. [86] = 11, --56
  39. [102] = 12, --66
  40. }
  41. local changpaiRoomView = class("changpaiRoomView", ZPRoomView)
  42. function changpaiRoomView:ctor()
  43. changpaiRoomView.super.ctor(self)
  44. --是否是起手操作的标志
  45. self.isQiShou = true
  46. --扇形最大列数
  47. self.lieShuMax = 8
  48. --最大行数
  49. self.hangShuMax = 5
  50. --操作牌数组
  51. self.opOutCard = {}
  52. --摸牌
  53. self.moValue = 0
  54. --要吃的那张牌
  55. self.chiCard = 0
  56. --是否包赔
  57. self.isBaopei = 0
  58. --是否是必吃的牌
  59. self.isBiChi = 0 --是否必吃
  60. --点击过后是否需要提示包赔
  61. self.isTishi = false
  62. --弃牌的缩放大小
  63. self.littleCardScale = 0.9
  64. --报叫的状态
  65. self.baoJiaoStatus = 0
  66. self.isTouchOpOutCard = false
  67. self.lieshulist[1] = {5}
  68. self.lieshulist[2] = {4,5}
  69. self.lieshulist[3] = {4,5,6}
  70. self.lieshulist[4] = {3,4,5,6}
  71. self.lieshulist[5] = {3,4,5,6,7}
  72. self.lieshulist[6] = {2,3,4,5,6,7}
  73. self.lieshulist[7] = {2,3,4,5,6,7,8}
  74. self.lieshulist[8] = {1,2,3,4,5,6,7,8}
  75. self.lieshulist[9] = {1,2,3,4,5,6,7,8,9}
  76. self.lieshuBlanklist[1] = {1,2,3,4,6,7,8,9}
  77. self.lieshuBlanklist[2] = {1,2,3,6,7,8,9}
  78. self.lieshuBlanklist[3] = {1,2,3,7,8,9}
  79. self.lieshuBlanklist[4] = {1,2,7,8,9}
  80. self.lieshuBlanklist[5] = {1,2,8,9}
  81. self.lieshuBlanklist[6] = {1,8,9}
  82. self.lieshuBlanklist[7] = {1,9}
  83. self.lieshuBlanklist[8] = {9}
  84. self.lieshuBlanklist[9] = {}
  85. --初始化牌颜色
  86. local cacheColor = "cardColor"..(ZPDef.GameID or app.gameId)
  87. self.colorType = tonumber(loadUserInfo(cacheColor)) or ZPDef.ColorType.White
  88. local cacheGameViewType = "gameViewType"..(ZPDef.GameID or app.gameId)
  89. self.desktopType = loadUserInfo(cacheGameViewType) or ZPDef.DesktopType.ThreeD
  90. if not self.desktopType or self.desktopType == "" then
  91. self.desktopType=ZPDef.DesktopType.ThreeD
  92. end
  93. self.outCardScale = 0.88
  94. self.moLieshu = 0
  95. self.myHandCardNums = 0
  96. end
  97. function changpaiRoomView:loadRoomUI()
  98. local ui = loadUI("zp_changpai/res/ui/ui_fangjian/changpai_ui_fangjian.ui");
  99. self.ui = ui;
  100. self:addChild(ui);
  101. end
  102. function changpaiRoomView:onEnter()
  103. changpaiRoomView.super.onEnter(self)
  104. self.ui.Items.ImageView_mytuoshu:setVisible(false)
  105. self.ui.Items.Layout_Touch:registerClick(handler(self,self.touchOutCard))
  106. end
  107. function changpaiRoomView:touchOutCard()
  108. local cardNum = table.nums(self.handCardItem)
  109. if self.isRecordStart then
  110. return
  111. end
  112. if cardNum <= 0 then
  113. return
  114. else
  115. self:setColorWhite()
  116. end
  117. end
  118. function changpaiRoomView:initBaseNode()
  119. --自己的出生坐标,视图是4
  120. self:initMySelfCardPos()
  121. self.scorePosList = {}
  122. --坐标记录
  123. self.srcOutCardPosList = {}
  124. for k = 1,ZPDef.GameMaxPlayer do
  125. local name = string.format("Layout_outCardPoint_%d",k)
  126. local imgName = string.format("ImageView_outCardImg_%d",k)
  127. self.ui.Items[name]:setScale(self.outCardScale)
  128. self.srcOutCardPosList[k] = self.ui.Items[imgName]:getPosition()
  129. --操作分数坐标
  130. --name = string.format("TextBMFont_Score_%d",k)
  131. --self.scorePosList[k] = self.ui.Items[name]:getPosition()
  132. end
  133. --初始化扎鸟
  134. self.PlayerView:initPlayerPiaoFenByRule()
  135. local timestr = os.date("%y-%m-%d %H:%M:%S")
  136. self.ui.Items.Text_systemTime:setText(timestr)
  137. --定时器
  138. if not self.Time then
  139. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  140. local timestr = os.date("%y-%m-%d %H:%M:%S")
  141. self.ui.Items.Text_systemTime:setText(timestr)--(getTimeString())
  142. end,1.0,false)
  143. end
  144. self.ui.Items.ImageView_tou_tip:setVisible(false)
  145. end
  146. --[[function changpaiRoomView:changeOutCardScale()
  147. --坐标记录
  148. self.srcOutCardPosList = {}
  149. for k = 1,ZPDef.GameMaxPlayer do
  150. local name = string.format("Layout_outCardPoint_%d",k)
  151. local imgName = string.format("ImageView_outCardImg_%d",k)
  152. self.ui.Items[name]:setScale(self.outCardScale)
  153. self.srcOutCardPosList[k] = self.ui.Items[imgName]:getPosition()
  154. --操作分数坐标
  155. --name = string.format("TextBMFont_Score_%d",k)
  156. --self.scorePosList[k] = self.ui.Items[name]:getPosition()
  157. end
  158. end--]]
  159. function changpaiRoomView:initMySelfCardPos()
  160. self.boxPosList4 = {}
  161. local weaveCardPos4 = self.ui.Items.Layout_StartPos:getPosition()
  162. --最后一列要固定所以加了一列 8+1 形式
  163. local tempLieshu = self.lieShuMax + 1
  164. for i = 1, tempLieshu do
  165. --矩形3
  166. self.boxPosList4[i] = cc.p(weaveCardPos4.x + 98 * (i - 1) - 100, weaveCardPos4.y)--手牌间隙改这里
  167. end
  168. end
  169. -- 设置房间信息
  170. function changpaiRoomView:setRoomInfo()
  171. self.ui.Items.ListView:removeAllChildren()
  172. self.ui.Items.ListView:getInnerContainer():setAutoSize(true)
  173. local rules = ZPWanFa.getClubRuleInfo(app.room.roomInfo.strGameInfo)
  174. for k,v in pairs(rules) do
  175. local text = self.ui.Items.Text_Rule:getCopied()
  176. text:setVisible(true)
  177. if v.name == "封顶" then
  178. if tostring(v.value[1]) == "不封顶" then
  179. text:setString(tostring(v.value[1]))
  180. else
  181. text:setString(tostring(v.value[1]..v.name))
  182. end
  183. elseif v.name == "超番加底" then
  184. text:setString(tostring(v.value[1]))
  185. else
  186. text:setString(tostring(v.value[1]))
  187. end
  188. self.ui.Items.ListView:addChild(text)
  189. end
  190. self.ui.Items.ListView:jumpToTopOnSizeChanged();
  191. end
  192. function changpaiRoomView:loadTextureCache()
  193. changpaiRoomView.super.loadTextureCache(self)
  194. ZPFuc.loadSpriteFromFile("zp_changpai/res/ui/zy_fangjian/cards/changpai_group_out_type1.plist")
  195. ZPFuc.loadSpriteFromFile("zp_changpai/res/ui/zy_fangjian/cards/changpai_group_out_type2.plist")
  196. ZPFuc.loadSpriteFromFile("zp_changpai/res/ui/zy_fangjian/cards/changpai_handCard_type1.plist")
  197. ZPFuc.loadSpriteFromFile("zp_changpai/res/ui/zy_fangjian/cards/changpai_handCard_type2.plist")
  198. ZPFuc.loadSpriteFromFile("zp_changpai/res/ui/zy_fangjian/cards/changpai_quitCard_type1.plist")
  199. ZPFuc.loadSpriteFromFile("zp_changpai/res/ui/zy_fangjian/cards/changpai_quitCard_type2.plist")
  200. ZPFuc.loadSpriteFromFile("zp_changpai/res/ui/zy_fangjian/cards/changpai_smallCard_type1.plist")
  201. ZPFuc.loadSpriteFromFile("zp_changpai/res/ui/zy_fangjian/cards/changpai_smallCard_type2.plist")
  202. end
  203. function changpaiRoomView:initGameButton()
  204. --出牌按钮
  205. self.ui.Items.Button_OutCard:registerClick(function()
  206. local k = self.ui.Items.ImageView_handTempCard.cIdx
  207. local value = self.ui.Items.ImageView_handTempCard.value
  208. --send sender
  209. self.isGodHand = true;
  210. self.handCardItem[k]:setOpacity(0)
  211. self:setColorWhite()
  212. self:sendOutCard(value)
  213. self.bOutCard = false
  214. end)
  215. self.canClick = true
  216. --提牌按钮
  217. self.ui.Items.Button_tipai:registerClick(function()
  218. if not self.canClick then
  219. return
  220. end
  221. self.canClick = false
  222. runDelay(3,function()
  223. self.canClick = true
  224. end)
  225. self:requestFlashHandCard()
  226. end)
  227. --暂时屏蔽提牌功能
  228. self:showTiPaiBtn(true)
  229. --点击空白
  230. self.ui.Items.Layout_Touch:registerClick(nil,function()
  231. --隐藏工具界面 详情
  232. if self.toolView.ui.Items.ImageView_Rule_bg then
  233. self.toolView.ui.Items.ImageView_Rule_bg:setVisible(false)
  234. end
  235. self.ui.Items.Layout_Rule:setVisible(false)
  236. self.ui.Items.Button_wanfa:setVisible(true)
  237. end)
  238. -- 玩法
  239. self.ui.Items.Button_wanfa:registerClick(function ()
  240. playBtnEffect()
  241. self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  242. self.ui.Items.Button_wanfa:setVisible(false)
  243. end)
  244. if app.room.roomInfo.nGameStartCount and app.room.roomInfo.nGameStartCount > 0 then
  245. self.ui.Items.Layout_Rule:setVisible(false)
  246. else
  247. self.ui.Items.Layout_Rule:setVisible(true)
  248. self.ui.Items.Button_wanfa:setVisible(false)
  249. self.ui.Items.Layout_Rule:runAction(cc.Sequence:create(
  250. cc.DelayTime:create(2),
  251. cc.CallFunc:create(function()
  252. self.ui.Items.Layout_Rule:setVisible(false)
  253. self.ui.Items.Button_wanfa:setVisible(true)
  254. end)))
  255. end
  256. self.ui.Items.Text_Rule:setVisible(false)
  257. local bar = self.ui.Items.ListView:getVBar()
  258. bar:setVisible(false)
  259. end
  260. function changpaiRoomView:setTableImg(idx)
  261. --如果界面是3D 但是桌布为2d时 则需要同步回来
  262. if self.desktopType == ZPDef.DesktopType.ThreeD then
  263. if idx >= 4 then
  264. idx = idx - 3
  265. end
  266. else
  267. if idx <= 3 then
  268. idx = idx + 3
  269. end
  270. end
  271. local name = string.format("zp_changpai/res/ui/zy_fangjian/bg/fangjian_di_%d.jpg",idx)
  272. --桌布
  273. self.ui.Items.ImageView_bg:loadTexture(name)
  274. local cacheGameBgPic = "gameBgPicture"..(ZPDef.GameID or app.gameId)
  275. saveUserInfo(cacheGameBgPic,idx)
  276. end
  277. --改变外发光颜色
  278. function changpaiRoomView:changeOutCardLight(isMoPai)
  279. local colorType = ZPDef.ColorType.YELLOW
  280. for i = 1 ,ZPDef.GameMaxPlayer do
  281. local outCardLightName = string.format("ImageView_outCardLight_%d",i)
  282. local light = self.ui.Items[outCardLightName]
  283. local fileName
  284. if isMoPai then
  285. fileName = string.format(ZPDef.LightType.BLUE, colorType)
  286. else
  287. fileName = string.format(ZPDef.LightType.YELLOW, colorType)
  288. end
  289. light:loadTexture(fileName)
  290. end
  291. end
  292. function changpaiRoomView:setFaPaiQiPanelView(bVisible,viewId,leftNum)
  293. if viewId and leftNum then
  294. self.ui.Items.TextBMFont_leftCardNum:setText(tostring(self.leftNum))
  295. end
  296. end
  297. --更新房间基础数据
  298. function changpaiRoomView:updateRoomBaseData()
  299. --初始化背景
  300. local ZiPaigameBgPicture = "gameBgPicture"..(ZPDef.GameID or app.gameId)
  301. local idx2 = tonumber(loadUserInfo(ZiPaigameBgPicture)) or 2
  302. self:setTableImg(idx2)
  303. --初始化牌颜色
  304. local cacheColor = "cardColor"..(ZPDef.GameID or app.gameId)
  305. self.colorType = tonumber(loadUserInfo(cacheColor)) or ZPDef.ColorType.White
  306. local roomInfo = app.room.roomInfo;
  307. -- 房间号
  308. self.ui.Items.Text_roomNum:setText(tostring(roomInfo.nShowTableId));
  309. --局数
  310. self:updateGameNums()
  311. --房间玩法
  312. --local ruleAll = ZPFuc.getRuleInfo();
  313. --self.toolView.ui.Items.Text_Rule:setText(ruleAll)
  314. self:setRoomInfo()
  315. self:onUserReadyResponse()
  316. for i = 1,ZPDef.GameMaxPlayer do
  317. self.PlayerView:updatePlayerInfo(i)
  318. end
  319. -- 是否显示邀请好友
  320. self:setWetChatVisible(app.room:getActualPlayerNum() < ZPFuc.getCreateRoomPlayerNum())
  321. self.toolView:showFastStart(true)
  322. if isReviewVersion() then
  323. self:setWetChatVisible(false);
  324. end
  325. -- 更新玩家手牌列表时,按需显示
  326. if app.room.roomInfo.nGameStartCount > 0 then
  327. self:setWetChatVisible(false)
  328. end
  329. if app.room.roomInfo.nGameStartCount == 0 then
  330. self.ui.Items.Button_tipai:setVisible(false)
  331. end
  332. --显示弃牌界面
  333. for i = 1,ZPDef.GameMaxPlayer do
  334. local name = string.format("Layout_tuopai_%d",i)
  335. self.ui.Items[name]:setVisible(false)
  336. local imgGiveUp = self.ui.Items["ImageView_giveUp_" .. i]
  337. local layoutGiveUp = self.ui.Items["Layout_giveUp_" .. i]
  338. local onTouchBegan = function ()
  339. layoutGiveUp:setScale(1.7)
  340. end
  341. local onTouchMove = function ()
  342. end
  343. local onTouchEnd = function ()
  344. layoutGiveUp:setScale(1.0)
  345. end
  346. local onTouchCancel = function ()
  347. layoutGiveUp:setScale(1.0)
  348. end
  349. imgGiveUp:setTouchEnabled(true)
  350. imgGiveUp:registerTouchEvent(onTouchBegan,onTouchMove,onTouchEnd,onTouchCancel)
  351. end
  352. end
  353. function changpaiRoomView:initToolLayer()
  354. --人物头像层
  355. self.PlayerView = ZPRoomPlayerView:new()
  356. self.ui.Items.Layout_Player:addChild(self.PlayerView)
  357. --操作界面(吃碰杠胡)
  358. self.operationView = ChangpaiRoomOperationView:new()
  359. --self.operationView:setVisible(false)
  360. self.ui.Items.Layout_Tool:addChild(self.operationView)
  361. local headInfos = {}
  362. for k,v in pairs(self.PlayerView.allNodes) do
  363. if k == 2 then
  364. local pos = cc.pAdd(v.player:getPosition(),cc.p(150,30))
  365. table.insert(headInfos,{headPos=pos})
  366. elseif k == 4 then
  367. local pos = cc.pAdd(v.player:getPosition(),cc.p(40,40))
  368. table.insert(headInfos,{headPos=pos})
  369. elseif k == 3 then
  370. local pos = cc.pAdd(v.player:getPosition(),cc.p(40,40))
  371. table.insert(headInfos,{headPos=pos})
  372. elseif k == 1 then
  373. local pos = cc.pAdd(v.player:getPosition(),cc.p(0,40))
  374. table.insert(headInfos,{headPos=pos})
  375. end
  376. end
  377. self.playerPos = headInfos
  378. --加载工具层
  379. self.toolView = ZPRoomToolView:new()
  380. self.ui.Items.Layout_Tool:addChild(self.toolView)
  381. -- 小局查牌界面
  382. self.xiaojuChaPaiView = ZPRoomXiaoJuChaPaiView:new(self.colorType)
  383. self.xiaojuChaPaiView:setVisible(false)
  384. --亮牌界面确定
  385. local function cb()
  386. --显示小局结算
  387. if self.xiaojuView then
  388. self.xiaojuView:setVisible(true)
  389. end
  390. end
  391. self.xiaojuChaPaiView:setQueDingCallBack(cb)
  392. self.xiaojuChaPaiView:showHuCardCallBack(handler(self , self.onShowHuCard))
  393. self:addChild(self.xiaojuChaPaiView)
  394. end
  395. --更新头家家
  396. function changpaiRoomView:updateBanker()
  397. --隐藏所有的庄家头家标志
  398. self.PlayerView:setBankerVisible()
  399. self.PlayerView:hideTouJia()
  400. --只显示当前的庄家座位号
  401. local nBankerSeatId = app.room.roomInfo.nBankSeatId
  402. local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
  403. if self.PlayerView:setPlayerTouJiaVisible(viewId,true) then
  404. else
  405. showTooltip("头家椅子号"..nBankerSeatId.."不匹配")
  406. end
  407. end
  408. --显示房主
  409. function changpaiRoomView:showOwner()
  410. self.PlayerView:setOwnerVisible()
  411. --只显示当前的庄家座位号 不显示房主
  412. local nBankerSeatId = app.room.roomInfo.nRoomOwnedUid
  413. local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
  414. --self.PlayerView:setPlayerBankerVisible(viewId,true)
  415. end
  416. --显示小家
  417. function changpaiRoomView:showXiaojia()
  418. self.PlayerView:hideXiaoJia()
  419. --只显示当前的庄家座位号
  420. local nBankerSeatId = app.room.roomInfo.xiaoSeatId
  421. local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
  422. self.PlayerView:setPlayerXiaoJiaVisible(viewId,true)
  423. end
  424. --断线重连
  425. function changpaiRoomView:recontactDoOperation(operationType,viewId,list,optype,isMoPaiOrId)
  426. local mType = ZPDef.CardType.CARD_TYPE_GROUP_OUT
  427. --[[
  428. if viewId == 1 then
  429. mType = ZPDef.CardType.CARD_TYPE_OPCARD_1
  430. elseif viewId == 2 then
  431. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  432. elseif viewId == 3 then
  433. mType = ZPDef.CardType.CARD_TYPE_OPCARD_3
  434. elseif viewId == 4 then
  435. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  436. end
  437. ]]
  438. if optype == ZPDef.SendCardType.TOU_THREE_SAME or optype == ZPDef.SendCardType.CHI_PAI_PENG then
  439. for k,v in ipairs(list) do
  440. self:createOpOutcard(viewId,mType,v,3)
  441. end
  442. elseif optype == ZPDef.SendCardType.BA_FOUR_SAME then
  443. for k,v in ipairs(list) do
  444. self:createOpOutcard(viewId,mType,v,4)
  445. end
  446. elseif optype == ZPDef.SendCardType.TWO_SUM_CHI then
  447. for k,v in ipairs(list) do
  448. self:createOpOutcard(viewId,mType,v,1)
  449. end
  450. end
  451. end
  452. function changpaiRoomView:onGameReconnection()
  453. --logE("ZiPai当前版本号:"..ZPFuc.getZPCurVersion())
  454. --更新房间基础数据
  455. self:updateRoomBaseData()
  456. local roomInfo = app.room.roomInfo;
  457. --self:updateAllGpsInfo()
  458. --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0)
  459. --self:checkMyGpsNeedUpdate();
  460. --断线重连
  461. if roomInfo.nGameStartCount > 0 then
  462. local function runOnGameReconnection(onEnd)
  463. self.isQiShou = false
  464. local roomInfo = app.room.roomInfo;
  465. --显示庄家
  466. self:updateBanker()
  467. self:showOwner()
  468. self:showXiaojia()
  469. local myUserID = app.room:getMyRecordUserId()
  470. --解散状态
  471. local isDismiss = false
  472. local uid = 0
  473. for k,v in pairs(roomInfo.arrayTableInfo) do
  474. local viewId = app.room:getViewIdByUserId(k)
  475. local nOffLineState = v.nOnlineStatus
  476. --显示离线
  477. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  478. local viewId = app.room:getViewIdByUserId(k)
  479. --记录玩家解散状态 0:初始状态, 1:发起解散 2: 同意解散 3:不同意解散
  480. app.room.dismissInfo[k] = v.nDisbandStatus;
  481. app.room.roomInfo.memberList[k].nDisbandStatus = v.nDisbandStatus;
  482. --有人发起解散时才显示解散界面
  483. if v.nDisbandStatus == 1 then
  484. isDismiss = true
  485. uid = k
  486. end
  487. end
  488. --self.PlayerView:setXiaoJiaFlagVis(true)
  489. local actualNum = app.room:getActualPlayerNum()
  490. --显示弃牌界面
  491. for i = 1,ZPDef.GameMaxPlayer do
  492. if i == 2 and actualNum == 3 then
  493. elseif (i == 1 or i == 3) and actualNum == 2 then
  494. else
  495. local name = string.format("Layout_tuopai_%d",i)
  496. self.ui.Items[name]:setVisible(true)
  497. end
  498. end
  499. --有人发起解散时才显示解散界面
  500. if isDismiss then
  501. app.room.roomInfo.nDismissStateTime = roomInfo.nDismissStateTime;
  502. app.room.roomInfo.nDismissToTalTime = roomInfo.nDismissToTalTime;
  503. local view = require("luaScript.Views.Room.RoomDismissView"):new(uid,app.room.roomInfo.memberList,roomInfo.nDismissStateTime)
  504. view:setAnchorPoint(cc.p(0.5, 0.5));
  505. app:showWaitDialog(view);
  506. end
  507. --如果一局结束,玩家点了准备,不再显示牌信息
  508. if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == 1
  509. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == 1
  510. then --游戏为停止或开始状态
  511. self:onUserReadyResponse()
  512. self.ui.Items.Button_tipai:setVisible(false)
  513. if onEnd then
  514. onEnd()
  515. end
  516. return
  517. end
  518. --胡牌类型
  519. local huType = ZPDef.ReconnectHuType.NO_HU
  520. --状态显示
  521. if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
  522. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then --游戏为停止或开始状态
  523. for hi,hv in pairs(app.room.roomInfo.hupaiInfo) do
  524. if hv.huPaiUid > -1 then
  525. app.room.roomInfo.baopeiUserid =app.room:getUserIdBySeatId(hv.BaoPeiUid)
  526. app.room.roomInfo.fourNormolNum = hv.fourNormolNum
  527. app.room.roomInfo.fourHongNum = hv.fourHongNum
  528. app.room.roomInfo.threeHongNum = hv.threeHongNum
  529. end
  530. end
  531. self.ui.Items.Button_tipai:setVisible(false)
  532. --显示小局结算亮牌画布
  533. self:setLiangPaiVisible(true)
  534. --显示底牌
  535. self.xiaojuChaPaiView:showDiPai()
  536. --亮手牌
  537. huType = self.xiaojuChaPaiView:liangShouPai(true)
  538. local function nextCallBackFun()
  539. self:resetGameData()
  540. end
  541. self.xiaojuView = changpaiRoomXiaoJuView:new(nextCallBackFun,true,self.colorType)
  542. self:addChild(self.xiaojuView)
  543. --播放黄庄动画
  544. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
  545. local userInfo=app.room:getUserInfo(app.user.loginInfo.uid)
  546. if userInfo then
  547. ZPSound.PlayHuangZhuang(userInfo.sex)
  548. end
  549. self.xiaojuChaPaiView:PlayHuangZhuangAni(false)
  550. end
  551. self.xiaojuView:setVisible(false)
  552. self:setBtnSitDownVisible(false)
  553. end
  554. local diPaiMax = table.nums(roomInfo.dipaiList)
  555. for k,v in pairs(roomInfo.arrayTableInfo) do
  556. local viewId = app.room:getViewIdByUserId(k)
  557. local nScore = v.nTotalMoney or 0
  558. --玩家分数
  559. self.PlayerView:setPlayerScore(viewId,nScore)
  560. --扎鸟
  561. --self.PlayerView:setPlayerPiaoFen(viewId,v.nZhaBirdScore)
  562. --恢复手牌
  563. if k == myUserID then
  564. self:createCard(false,myUserID,nil)
  565. end
  566. --恢复爆牌动画
  567. if v.nBaoPaiStatus == 2 and not (ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
  568. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus) and viewId == self:getMeViewId() then
  569. --self.PlayerView:playBaoAnim(viewId)
  570. self.baoJiaoStatus = 1 --已经报叫
  571. local nBankerSeatId = app.room.roomInfo.nBankSeatId
  572. local toujiaViewId = app.room:getViewIdBySeatId(nBankerSeatId)
  573. local nSeatId = roomInfo.showCardSeatId
  574. local curOpViewId = app.room:getViewIdBySeatId(nSeatId)
  575. if ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_BAO == roomInfo.nStatus
  576. or ZPDef.ReconnectState.GAME_STATUS_WAIT_BANKER_OUTCARD == roomInfo.nStatus
  577. and viewId == toujiaViewId then --当前是庄家出牌并且自己的ID是头家 这时候放开出牌,其他时候手牌全锁
  578. elseif (ZPDef.ReconnectState.GAME_STATUS_WAIT_OUT_CARDS == roomInfo.nStatus or ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TOU == roomInfo.nStatus)
  579. and curOpViewId == viewId then --如果报叫后进了牌,则只能打进的牌
  580. app.room.roomInfo.tingCards = {}
  581. table.insert(app.room.roomInfo.tingCards, app.room.roomInfo.curEnterCard)
  582. else
  583. app.room.roomInfo.tingCards = {}
  584. end
  585. self:lockMyHandCards()
  586. end
  587. if v.nBaoPaiStatus == 2 then
  588. self.PlayerView:setPlayerBaoJiaoVisible(viewId,true)
  589. end
  590. local hushu = 0
  591. --恢复组合牌
  592. for key,value in pairs(v.tableWeaveCard) do
  593. local list,operationType = ZPFuc.getZPCardList(value.card,value.type)
  594. local isShow = true
  595. local card = value.opcard
  596. local optype = value.type
  597. hushu = hushu + value.hushu
  598. list = value.card
  599. --上面吃或不吃不要用if else因为还可能都不成立
  600. local isMoPaiOrId = value.seatId
  601. --创建桌面操作牌
  602. self:recontactDoOperation(operationType,viewId,list,optype,isMoPaiOrId)
  603. end
  604. self.tableHuXiList[viewId] = hushu
  605. --self.PlayerView:setPlayerHuXi(viewId,hushu)
  606. --self.PlayerView:setPlayerHuXi("油:"..tostring(hushu))
  607. if viewId ~= self:getMeViewId() then
  608. self.PlayerView:setLeftCardNum(viewId,true,tonumber(v.leftCardNum))
  609. else
  610. self.myHandCardNums = tonumber(v.leftCardNum)
  611. end
  612. end
  613. --self:getLocalHuShu()
  614. for i = 1, 4 do
  615. local tt = self.qiPaiList[i]
  616. end
  617. --恢复弃牌
  618. for k,v in pairs(roomInfo.arrayTableInfo) do
  619. local viewId = app.room:getViewIdByUserId(v.nUserId)
  620. local qiList = self.qiPaiList[viewId] or {}
  621. for key,value in pairs(v.desertedArea) do
  622. local card = value.card
  623. local maxQi = table.nums(qiList)
  624. if maxQi > 0 then
  625. --染色弃牌
  626. local isInQiList = false
  627. for qiK,qiCard in pairs(qiList) do
  628. if qiCard == value.card then
  629. --染色弃牌
  630. self:playQiPaiAni(false,value.card,viewId,nil,true)
  631. isInQiList = true
  632. qiList[qiK] = nil
  633. break
  634. end
  635. end
  636. if not isInQiList then
  637. self:playQiPaiAni(false,value.card,viewId,nil,false)
  638. end
  639. else
  640. --普通弃牌
  641. self:playQiPaiAni(false,value.card,viewId,nil,false)
  642. end
  643. end
  644. end
  645. --听牌显示
  646. local max = table.nums(app.room.roomInfo.tingCards)
  647. if max > 0 then
  648. --self:setTingCardViewVisible(true,app.room.roomInfo.tingCards)
  649. end
  650. --显示玩家剩余手牌
  651. if app.room.roomInfo.offLineInfo and next(app.room.roomInfo.offLineInfo) ~= nil then
  652. for i,v in pairs(app.room.roomInfo.offLineInfo) do
  653. if v.extInfo then
  654. local extIf = json.decode(v.extInfo)
  655. if extIf.HuShu and v.nUserId then
  656. local viewId = app.room:getViewIdByUserId(v.nUserId)
  657. self.PlayerView:setPlayerTuoShu(viewId,extIf.HuShu)
  658. end
  659. end
  660. end
  661. end
  662. --吃后巴后油牌
  663. if app.room.roomInfo.disCard then
  664. self:lockYouPai(app.room.roomInfo.disCard)
  665. end
  666. --self:setTotalTuoNum(app.room.roomInfo.totalTuoNum)
  667. local myViewId = self:getMeViewId()
  668. self.PlayerView:setPlayerTuoShu(myViewId,app.room.roomInfo.totalTuoNum)
  669. --状态显示
  670. if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
  671. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then --游戏为停止或开始状态
  672. self.PlayerView:hideLeftCard()
  673. --所有的暗偎默认亮起一张
  674. --self:showLastAnWeiPai()
  675. --点炮显示
  676. --self:showPaoImage()
  677. for hi,hv in pairs(app.room.roomInfo.hupaiInfo) do
  678. if hv.huPaiUid > -1 then
  679. local winerViewId = app.room:getViewIdByUserId(hv.huPaiUid)
  680. app.room.roomInfo.huType = hv.huTypes
  681. app.room.roomInfo.baopeiUserid =app.room:getUserIdBySeatId(hv.BaoPeiUid)
  682. self:playHuEffect(winerViewId,nil,true)
  683. --self:setLayoutScoreTipVisible(true,playerList,false,nil,true)
  684. end
  685. end
  686. --显示坨数
  687. for k,v in pairs(roomInfo.arrayTableInfo) do
  688. local viewId = app.room:getViewIdByUserId(v.nUserId)
  689. local tuoNum = v.totalTuoNum
  690. self.PlayerView:setPlayerTuoShu(viewId,tuoNum)
  691. end
  692. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TIAN_HU == roomInfo.nStatus
  693. or ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_TURN_OVER == roomInfo.nStatus
  694. or ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TOU == roomInfo.nStatus
  695. or ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_OUTCARD == roomInfo.nStatus
  696. or ZPDef.ReconnectState.GAME_STATUS_WAIT_QIANGBA == roomInfo.nStatus then -- 天胡,翻牌后等待玩家操作中,出牌后等待玩家操作中
  697. local nSeatId = roomInfo.showCardSeatId
  698. local nCard = roomInfo.showCard
  699. local operateCode = roomInfo.mainOpCode
  700. local viewId = app.room:getViewIdBySeatId(nSeatId)
  701. local nUserId = app.room:getUserIdBySeatId(nSeatId)
  702. local opCardList = {}
  703. local curOpeateid = roomInfo.curOpreateID --当前操作ID
  704. local curOpView = app.room:getViewIdBySeatId(curOpeateid)
  705. --记录真实数据
  706. self.outCard = nCard
  707. self.EatOperationCode = operateCode
  708. self.moPaiViewId = viewId
  709. if ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TIAN_HU == roomInfo.nStatus then --等待天胡
  710. local hasGuo = true
  711. self.isQiShou = true
  712. local curOpView = app.room:getViewIdBySeatId(curOpeateid)
  713. local operationCardlist = {}
  714. local opeateCode = 0
  715. if #roomInfo.startOpList.BacardList > 0 then
  716. operationCardlist[roomInfo.startOpList.BaoperateCode] = {}
  717. for k,v in ipairs(roomInfo.startOpList.BacardList) do
  718. table.insert(operationCardlist[roomInfo.startOpList.BaoperateCode],v)
  719. end
  720. opeateCode = getNumOr(opeateCode,roomInfo.startOpList.BaoperateCode)
  721. end
  722. --操作码
  723. if #roomInfo.startOpList.ToucardList > 0 then
  724. operationCardlist[roomInfo.startOpList.TouoperateCode] = {}
  725. for k,v in ipairs(roomInfo.startOpList.ToucardList) do
  726. table.insert(operationCardlist[roomInfo.startOpList.TouoperateCode],v)
  727. end
  728. opeateCode = getNumOr(opeateCode,roomInfo.startOpList.TouoperateCode)
  729. end
  730. --标记天胡
  731. -- if roomInfo.startOpList.ishu == 1 then
  732. --opeateCode = ZPDef.OpCode.OP_HU
  733. --end
  734. local retHu = bit32.band(roomInfo.mainOpCode,ZPDef.OpCode.OP_HU)
  735. local retHu1 = bit32.band(roomInfo.mainOpCode,ZPDef.OpCode.OP_TIAN_HU)
  736. if retHu > 0 then
  737. opeateCode = getNumOr(opeateCode,ZPDef.OpCode.OP_HU)
  738. elseif retHu1 > 0 then
  739. opeateCode = ZPDef.OpCode.OP_TIAN_HU
  740. hasGuo = false
  741. self.isTianHu = true
  742. end
  743. if curOpView == self:getMeViewId() then
  744. if opeateCode > 0 then
  745. self:showOperation(opeateCode,operationCardlist,self.isQiShou,hasGuo) --天胡没有过
  746. end
  747. end
  748. self.ui.Items.ImageView_tou_tip:setVisible(true)
  749. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TOU == roomInfo.nStatus then --玩家进牌状态
  750. self.isQiShou = false
  751. local operationCardlist = {}
  752. local opeateCode = 0
  753. if #roomInfo.startOpList.BacardList > 0 then
  754. operationCardlist[roomInfo.startOpList.BaoperateCode] = {}
  755. for k,v in ipairs(roomInfo.startOpList.BacardList) do
  756. table.insert(operationCardlist[roomInfo.startOpList.BaoperateCode],v)
  757. end
  758. opeateCode = getNumOr(opeateCode,roomInfo.startOpList.BaoperateCode)
  759. end
  760. --操作码
  761. if #roomInfo.startOpList.ToucardList > 0 then
  762. operationCardlist[roomInfo.startOpList.TouoperateCode] = {}
  763. for k,v in ipairs(roomInfo.startOpList.ToucardList) do
  764. table.insert(operationCardlist[roomInfo.startOpList.TouoperateCode],v)
  765. end
  766. opeateCode = getNumOr(opeateCode,roomInfo.startOpList.TouoperateCode)
  767. end
  768. if roomInfo.startOpList.ishu == 1 then
  769. opeateCode = getNumOr(opeateCode,ZPDef.OpCode.OP_HU)
  770. operationCardlist[ZPDef.OpCode.OP_HU] = {}
  771. table.insert(operationCardlist[ZPDef.OpCode.OP_HU],0) --自摸的时候发0
  772. end
  773. if opeateCode > 0 then
  774. self:showOperation(opeateCode,operationCardlist,self.isQiShou,true) --天胡没有过
  775. end
  776. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_OUTCARD == roomInfo.nStatus then
  777. --是否已经操作过 0表示没有,非0表示已经提交了操作
  778. self.isQiShou = false
  779. if roomInfo.isBaopeiCard == 1 then
  780. self.isBiChi = 2
  781. end
  782. if operateCode ~= 0 and roomInfo.isSubmitOp == 0 then
  783. opCardList[ZPDef.OpCode.OP_HU] = {}
  784. table.insert(opCardList[ZPDef.OpCode.OP_HU],nCard)
  785. opCardList[ZPDef.OpCode.OP_PENG] = {}
  786. table.insert(opCardList[ZPDef.OpCode.OP_PENG],nCard)
  787. opCardList[ZPDef.OpCode.OP_CHI] = {}
  788. for k,v in ipairs(roomInfo.chiPaiList) do
  789. table.insert(opCardList[ZPDef.OpCode.OP_CHI],v)
  790. end
  791. self:showOperation(operateCode,opCardList,self.isQiShou,true)
  792. self:setOutCardVisible(true,viewId,nCard,false,nil,true)
  793. elseif roomInfo.isSubmitOp == 1 or roomInfo.isSubmitOp == 0 or roomInfo.isSubmitOp == 2 then
  794. self:setOutCardVisible(true,viewId,nCard,false,nil,true)
  795. --playVoiceCardValue(nCard,nUserId)
  796. --elseif roomInfo.isSubmitOp == 2 then --比牌不显示出牌或者摸牌
  797. --self.operationView:touchEatOneCardCallBack(true)
  798. end
  799. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_TURN_OVER == roomInfo.nStatus then
  800. if roomInfo.isSubmitOp == 1 then
  801. operateCode = 0
  802. self:playMoPaiAni(diPaiMax,nCard,viewId,operateCode,roomInfo.showCardFlag,nil,true)
  803. elseif roomInfo.isSubmitOp == 0 then --自己摸牌翻牌
  804. opCardList[ZPDef.OpCode.OP_HU] = {}
  805. table.insert(opCardList[ZPDef.OpCode.OP_HU],nCard)
  806. opCardList[ZPDef.OpCode.OP_BA_FAN] = {}
  807. table.insert(opCardList[ZPDef.OpCode.OP_BA_FAN],nCard)
  808. opCardList[ZPDef.OpCode.OP_PENG] = {}
  809. table.insert(opCardList[ZPDef.OpCode.OP_PENG],nCard)
  810. opCardList[ZPDef.OpCode.OP_CHI] = {}
  811. for k,v in ipairs(roomInfo.chiPaiList) do
  812. table.insert(opCardList[ZPDef.OpCode.OP_CHI],v)
  813. end
  814. local isBaoPeiCard = false
  815. if roomInfo.isBaopeiCard == 1 then
  816. self.isBiChi = 2
  817. end
  818. if roomInfo.isBaopeiGuo == 1 then
  819. self.isTishi = true
  820. end
  821. self:playMoPaiAni(diPaiMax,nCard,viewId,operateCode,roomInfo.showCardFlag,nil,true,isBaoPeiCard,roomInfo.chiPaiList)
  822. elseif roomInfo.isSubmitOp == 2 then --比牌不显示出牌或者摸牌
  823. operateCode = 0
  824. self:playMoPaiAni(diPaiMax,nCard,viewId,operateCode,roomInfo.showCardFlag,nil,true)
  825. self.operationView:touchEatOneCardCallBack(true)
  826. end
  827. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_QIANGBA == roomInfo.nStatus then
  828. if operateCode ~= 0 and roomInfo.isSubmitOp == 0 then
  829. opCardList[ZPDef.OpCode.OP_HU] = {}
  830. table.insert(opCardList[ZPDef.OpCode.OP_HU],nCard)
  831. self:showOperation(operateCode,opCardList,self.isQiShou,true)
  832. end
  833. end
  834. --显示剩余牌
  835. --如果有出的牌,则闹钟显示在该玩家,如果没有则显示在等待操作的玩家
  836. if nCard > 0 then
  837. self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
  838. else
  839. self:setCircleCardLeftPanelView(true,curOpView,diPaiMax)
  840. end
  841. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OUT_CARDS == roomInfo.nStatus or ZPDef.ReconnectState.GAME_STATUS_WAIT_BANKER_OUTCARD == roomInfo.nStatus then --等待玩家出牌中
  842. --显示底牌
  843. self.isQiShou = false
  844. local viewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
  845. --显示剩余牌
  846. self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
  847. if viewId == self:getMeViewId() then
  848. self:setGuideView(true)
  849. self.bOutCard = true
  850. end
  851. elseif ZPDef.ReconnectState.GAME_STATUS_AUTO_DISCSRD == roomInfo.nStatus then --玩家自动弃牌中
  852. self.isQiShou = false
  853. local nSeatId = roomInfo.showCardSeatId
  854. local nCard = roomInfo.disCard
  855. local viewId = app.room:getViewIdBySeatId(nSeatId)
  856. --显示剩余牌
  857. self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
  858. --弃牌
  859. self:playQiPaiAni(true,nCard,viewId,nil)
  860. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_BAO == roomInfo.nStatus then --等待玩家爆牌中
  861. --爆牌中
  862. local viewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
  863. self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
  864. for k,v in pairs(roomInfo.arrayTableInfo) do
  865. local viewId = app.room:getViewIdByUserId(k)
  866. local nBankerSeatId = app.room.roomInfo.nBankSeatId
  867. local toujiaviewId = app.room:getViewIdBySeatId(nBankerSeatId)
  868. if viewId == self:getMeViewId() and viewId ~= toujiaviewId then
  869. app.room.roomInfo.tingCards = {}
  870. end
  871. --等待爆牌状态
  872. if v.nBaoPaiStatus == 1 and k == app.user.loginInfo.uid then
  873. self.operationView:showBaoPaiOpView(true)
  874. end
  875. end
  876. self.ui.Items.ImageView_tou_tip:setVisible(true)
  877. end
  878. if onEnd then
  879. onEnd()
  880. end
  881. end
  882. log("2000000000-ZPRoomView - self:addCallBack(runOnGameReconnection)" )
  883. self:addCallBack(runOnGameReconnection)
  884. else
  885. --未开局正常坐下这里会进来
  886. for k,v in pairs(roomInfo.memberList or {}) do
  887. local viewId = app.room:getViewIdByUserId(k)
  888. local nOffLineState = v.nOnlineStatus or 1
  889. --显示离线
  890. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  891. end
  892. --未开局重连坐下
  893. for k,v in pairs(roomInfo.arrayTableInfo or {}) do
  894. local viewId = app.room:getViewIdByUserId(k)
  895. local nOffLineState = v.nOnlineStatus
  896. --显示离线
  897. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  898. end
  899. end
  900. end
  901. --提示报叫
  902. function changpaiRoomView:onTingCardResult(data)
  903. local function runTingCardResult(onEnd)
  904. log("2000000000-changpaiRoomView - (runTingCardResult)")
  905. local response = data.response
  906. local tingCards = response.tingCards
  907. local nBankerSeatId = app.room.roomInfo.nBankSeatId
  908. local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
  909. if viewId == self:getMeViewId() then
  910. app.room.roomInfo.tingCards = response.tingCards or {}
  911. else
  912. app.room.roomInfo.tingCards = {}
  913. end
  914. if onEnd then
  915. onEnd()
  916. end
  917. local isCanBao = response.canBaoPai
  918. if isCanBao == 1 then
  919. self.operationView:showBaoPaiOpView(true)
  920. end
  921. end
  922. log("2000000000-changpaiRoomView - addCallBack(runTingCardResult)")
  923. self:addCallBack(runTingCardResult)
  924. end
  925. --爆牌结果
  926. function changpaiRoomView:onBaoPaiResponese(data)
  927. local function runBaoPai(onEnd)
  928. log("2000000000-ZPRoomView - (runBaoPai)")
  929. local response = data.response
  930. local uid = response.nUserId
  931. local viewId = app.room:getViewIdByUserId(uid)
  932. --玩家选择了爆牌 播放爆牌动画
  933. if response.optType == 1 then
  934. self:showOperatorTip(viewId,-55)
  935. --self.PlayerView:playBaoAnim(viewId)
  936. self.PlayerView:setPlayerBaoJiaoVisible(viewId,true)
  937. if uid == app.room:getMyUserId() then
  938. self.baoJiaoStatus = 1
  939. self:lockMyHandCards()
  940. end
  941. end
  942. if uid == app.room:getMyUserId() then
  943. self:hideOperation()
  944. end
  945. self:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
  946. if onEnd then
  947. onEnd()
  948. end
  949. end)))
  950. end
  951. self:addCallBack(runBaoPai)
  952. end
  953. function changpaiRoomView:lockMyHandCards()
  954. --先把手牌全部锁了
  955. for col = self.lieShuMax,1,-1 do --列数
  956. for row = self.hangShuMax,1,-1 do --行数
  957. self.handCardRoot[col].imgList[row].isKan = true
  958. self.handCardRoot[col].imgList[row]:setTouchEnabled(false)
  959. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(125,125,125))
  960. end
  961. end
  962. --根据服务器发来的牌解锁
  963. for k,v in pairs(app.room.roomInfo.tingCards) do
  964. for col = self.lieShuMax,1,-1 do --列数
  965. for row = self.hangShuMax,1,-1 do --行数
  966. local cardValue = self.handCardRoot[col].imgList[row].value
  967. if v == cardValue then
  968. self.handCardRoot[col].imgList[row].isKan = false
  969. self.handCardRoot[col].imgList[row]:setTouchEnabled(true)
  970. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  971. end
  972. end
  973. end
  974. end
  975. end
  976. -- 立即开始
  977. function changpaiRoomView:onQuickStartResponse(event)
  978. log("2000000000-ZPRoomView - runnQuickStartResponse()" )
  979. if not event or not event.response then
  980. return
  981. end
  982. logE("onQuickStartResponse() response = ", event.response)
  983. local response = event.response
  984. --app.room.roomInfo.nShowDismiss = true
  985. local isStart = true
  986. local selectNums = table.nums(app.room.quickStartInfo)
  987. for i,v in pairs(app.room.quickStartInfo) do
  988. if v > 1 then
  989. --有人投过票
  990. isStart = false
  991. end
  992. end
  993. if tolua.isnull(self.quickStartView) then
  994. for i,v in pairs(app.room.quickStartInfo) do
  995. if v == 1 then
  996. self.quickStartView = ZPRoomQuickStartView:new(i);
  997. self.quickStartView:setAnchorPoint(cc.p(0.5, 0.5));
  998. app:showWaitDialog(self.quickStartView);
  999. log("onQuickStartResponse() v = 1 "..i )
  1000. return
  1001. else
  1002. local startuid = 0
  1003. for i,v in pairs(app.room.quickStartInfo) do
  1004. if v == 1 then
  1005. startuid = i
  1006. end
  1007. end
  1008. self.quickStartView = ZPRoomQuickStartView:new(startuid);
  1009. self.quickStartView:setAnchorPoint(cc.p(0.5, 0.5));
  1010. app:showWaitDialog(self.quickStartView);
  1011. log("onQuickStartResponse() v ~= 1 "..i )
  1012. return
  1013. end
  1014. end
  1015. end
  1016. end
  1017. -- 游戏开始
  1018. function changpaiRoomView:onGameStartResponse()
  1019. local function runGameStartResponse(onEnd)
  1020. log("2000000000-ZPRoomView - runGameStartResponse()" )
  1021. local actualNum = app.room:getActualPlayerNum()
  1022. --显示弃牌界面
  1023. for i = 1,ZPDef.GameMaxPlayer do
  1024. if i == 2 and actualNum == 3 then
  1025. elseif (i == 1 or i == 3) and actualNum == 2 then
  1026. else
  1027. local name = string.format("Layout_tuopai_%d",i)
  1028. self.ui.Items[name]:setVisible(true)
  1029. end
  1030. end
  1031. --重置玩家数据
  1032. self:resetGameData()
  1033. app.room.roomInfo.tingCards = {}
  1034. app.room.roomInfo.disCard = {}
  1035. if not tolua.isnull(self.quickStartView) then
  1036. self.quickStartView:removeView()
  1037. self.quickStartView = nil
  1038. end
  1039. --写入数据
  1040. for k,v in pairs(app.room.roomInfo.memberList) do
  1041. v.nPlayerFlag = 2
  1042. end
  1043. --更新玩家状态状态
  1044. self:onUserReadyResponse()
  1045. -- 隐藏邀请好友
  1046. self:setWetChatVisible(false)
  1047. self.toolView:showFastStart(false)
  1048. -- 更新局数
  1049. self:updateGameNums()
  1050. --更新位置
  1051. app.room:updateUserSeateShowId()
  1052. --[[ if app.room.roomInfo.xiaoSeatId and app.room.roomInfo.xiaoSeatId >= 0 and app.room:getActualPlayerNum()==4 then
  1053. app.room:updateUserSeateShowId()
  1054. --self.PlayerView:setXiaoJiaFlagVis(true)
  1055. elseif app.room:getActualPlayerNum()==3 then
  1056. app.room:updateUserSeateShowId()
  1057. end
  1058. ]]
  1059. for k,v in pairs(app.room.roomInfo.memberList) do
  1060. local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
  1061. self.PlayerView:updatePlayerInfo(nSeatShowId)
  1062. end
  1063. --更新庄家
  1064. self:updateBanker()
  1065. self:showXiaojia()
  1066. --翻牌
  1067. local fanpaiSeatid = app.room.roomInfo.fanpaiSeatId
  1068. local fanCard = app.room.roomInfo.fanpaiValue
  1069. local fanViewId = app.room:getViewIdBySeatId(fanpaiSeatid)
  1070. local function callback()
  1071. self:setOutCardVisible(true,fanViewId,fanCard,false,nil,false)
  1072. end
  1073. local function call_func()
  1074. self:setOutCardVisible(false)
  1075. local toujiaId = app.room.roomInfo.nBankSeatId
  1076. local toujiaViewId = app.room:getViewIdBySeatId(toujiaId)
  1077. self.PlayerView:setPlayerTouJiaVisible(toujiaViewId,true)
  1078. end
  1079. local seq = cc.Sequence:create(cc.CallFunc:create(callback),cc.DelayTime:create(1),cc.CallFunc:create(call_func))
  1080. self.ui:runAction(seq)
  1081. if onEnd then
  1082. onEnd()
  1083. end
  1084. end
  1085. log("2000000000-ZPRoomView - addCallBack(runGameStartResponse)" )
  1086. self:addCallBack(runGameStartResponse);
  1087. end
  1088. --@parm:手牌列表
  1089. function changpaiRoomView:getLocalHuShu(list)
  1090. return 0
  1091. end
  1092. function changpaiRoomView:onGameSendCardResponse()
  1093. local function runGameSendCardResponse(onEnd)
  1094. self.PlayerView:stopAndHideBaoAnim()
  1095. log("2000000000-ZPRoomView - runGameSendCardResponse()" )
  1096. if self.taiPaiTimer then
  1097. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.taiPaiTimer)
  1098. end
  1099. --显示指示器
  1100. local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
  1101. local leftCardNum = 38
  1102. if app.room:getActualPlayerNum() == 4 then--and GameFunctions.getCurFangShu() == 0
  1103. leftCardNum = 33
  1104. end
  1105. self:setCircleCardLeftPanelView(true,bankerViewId,leftCardNum)
  1106. --发牌
  1107. self:createCard(true,app.user.loginInfo.uid,onEnd)
  1108. print("ding piao:"..table.tostring(app.room.roomInfo.memberList))
  1109. self.ui.Items.Button_tipai:setVisible(true)
  1110. local xiaojiaViewId = app.room:getViewIdBySeatId(app.room.roomInfo.xiaoSeatId)
  1111. local toujiaViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
  1112. self.myHandCardNums = 15
  1113. for i = 1,ZPDef.GameMaxPlayer do
  1114. if app.room:getActualPlayerNum() == 4 then
  1115. if i == xiaojiaViewId and i ~= self:getMeViewId() then
  1116. self.PlayerView:setLeftCardNum(i,true,5)
  1117. elseif i == toujiaViewId and i ~= self:getMeViewId() then
  1118. self.PlayerView:setLeftCardNum(i,true,16)
  1119. else
  1120. self.PlayerView:setLeftCardNum(i,true,15)
  1121. end
  1122. else
  1123. if i == toujiaViewId and i ~= self:getMeViewId() then
  1124. self.PlayerView:setLeftCardNum(i,true,16)
  1125. elseif i ~= 2 then
  1126. self.PlayerView:setLeftCardNum(i,true,15)
  1127. end
  1128. end
  1129. end
  1130. --保存自己手牌张数
  1131. for i = 1,ZPDef.GameMaxPlayer do
  1132. if app.room:getActualPlayerNum() == 4 then
  1133. if i == xiaojiaViewId and i == self:getMeViewId() then
  1134. self.myHandCardNums = 5
  1135. elseif i == toujiaViewId and i == self:getMeViewId() then
  1136. self.myHandCardNums = 16
  1137. end
  1138. else
  1139. if i == toujiaViewId and i == self:getMeViewId() then
  1140. self.myHandCardNums = 16
  1141. end
  1142. end
  1143. end
  1144. --self:setTotalTuoNum(app.room.roomInfo.totalTuoNum)
  1145. local myViewId = self:getMeViewId()
  1146. self.PlayerView:setPlayerTuoShu(myViewId,app.room.roomInfo.totalTuoNum)
  1147. self.toolView:showTuoGuan(app.room.roomInfo.hosting==1)
  1148. end
  1149. log("2000000000-ZPRoomView - addCallBack(runGameSendCardResponse)" )
  1150. self:addCallBack(runGameSendCardResponse);
  1151. end
  1152. function changpaiRoomView:createCard(bShowAnimation,nUserID,onEnd)
  1153. logE("====================RoomView:createCard()===================");
  1154. local cardList = app.room.cards[nUserID]
  1155. if not cardList or table.nums(cardList) <= 0 then
  1156. --重连当自己没有手牌且有7方门子
  1157. if onEnd then
  1158. onEnd()
  1159. end
  1160. return
  1161. end
  1162. local lieshuMax = table.nums(cardList)
  1163. local RankCardList = {}
  1164. local colList = self.lieshulist[lieshuMax]
  1165. local blankList = self.lieshuBlanklist[lieshuMax]
  1166. local wuIndex = 0
  1167. local youIndex = 0
  1168. --最后一列要固定所以加了一列 8+1 形式
  1169. local tempLieshu = self.lieShuMax + 1
  1170. --重新调整
  1171. for k = 1,tempLieshu do
  1172. if not cardList[k] then
  1173. cardList[k] = {}
  1174. end
  1175. if table.nums(cardList[k]) <= 0 then
  1176. wuIndex = wuIndex + 1
  1177. local blankIndex = blankList[wuIndex] -- 1,10
  1178. if blankIndex then
  1179. RankCardList[blankIndex] = {}
  1180. end
  1181. else
  1182. youIndex = youIndex + 1
  1183. local index = colList[youIndex] -- 2,3,4,5,6,7,8,9
  1184. RankCardList[index] = cardList[k]
  1185. end
  1186. end
  1187. cardList = {}
  1188. cardList = RankCardList
  1189. logE("createCard Rank ok :"..table.tostring(cardList))
  1190. local index = 1
  1191. --不管有无数据,默认创建10列数据
  1192. for i = 1,tempLieshu do
  1193. local value = cardList[i] or {}
  1194. local isKan = self:getCurrentColIsKan(value)
  1195. local card = ChangPaiRoomCard:new(value,ZPDef.CardType.CARD_TYPE_HAND,i,isKan,false,self.colorType)
  1196. local pos = self.boxPosList4[i]
  1197. card.ui:setPosition(pos)
  1198. self.ui.Items.LayoutMain_4:addChild(card.ui,1)
  1199. --数据记录
  1200. self.handCardRoot[i] = card
  1201. self.handCardValueLocal[i] = value
  1202. self.handCardValueBak[i] = clone(value)
  1203. if i == 9 then
  1204. self.handCardItem[index] = card.imgList[1] --最后第九列只能是摸牌 要注册点击事件
  1205. break
  1206. end
  1207. --存储所有的单牌节点Image
  1208. for k = 1 ,self.hangShuMax do
  1209. self.handCardItem[index] = card.imgList[k]
  1210. index = index + 1
  1211. end
  1212. end
  1213. logE("create card finish self.handCardValueLocal : "..table.tostring(self.handCardValueLocal))
  1214. if bShowAnimation then
  1215. --发牌动画(10*0.1+ 0.15 = 1.15miao)
  1216. for k,v in ipairs(self.handCardRoot) do
  1217. if v.ui:isVisible() then
  1218. v.ui:setVisible(false)
  1219. local spawnTime = 0.3
  1220. local mSpawn = cc.Spawn:create(cc.FadeIn:create(spawnTime),cc.CallFunc:create(function ()
  1221. v.ui:setVisible(true)
  1222. --播放发牌声音
  1223. if k < table.nums(self.handCardRoot) - 4 then
  1224. playVoiceGiveCard()
  1225. end
  1226. end))
  1227. v.ui:runAction(cc.Sequence:create(cc.DelayTime:create(k * 0.05),mSpawn,cc.DelayTime:create(k * 0.05),cc.CallFunc:create(function()
  1228. if k == self:getVisibleCardLayoutNum() then
  1229. --排序
  1230. self:RankCard()
  1231. --注册点击
  1232. self:registerCardTouch()
  1233. if onEnd then
  1234. onEnd()
  1235. end
  1236. end
  1237. end)))
  1238. end
  1239. end
  1240. else
  1241. --注册点击
  1242. self:registerCardTouch()
  1243. --排序
  1244. self:RankCard()
  1245. if onEnd then
  1246. onEnd()
  1247. end
  1248. end
  1249. if app.room.roomInfo.disCard then
  1250. local num = table.nums(app.room.roomInfo.disCard)
  1251. if num > 0 then
  1252. self:lockYouPai(app.room.roomInfo.disCard)
  1253. end
  1254. end
  1255. if self.baoJiaoStatus == 1 then
  1256. --[[ app.room.roomInfo.tingCards = {}
  1257. table.insert(app.room.roomInfo.tingCards,self.moValue)--]]
  1258. self:lockMyHandCards()
  1259. end
  1260. end
  1261. -- 广播桌子上所有玩家庄家起手操作
  1262. function changpaiRoomView:onBankerOutCard(data)
  1263. local function runOnBankerOutCard(onEnd)
  1264. log("2000000000-ZPRoomView - (runOnBankerOutCard)")
  1265. logE("onBankerOutCard :"..table.tostring(data.response))
  1266. if data.response.nUserId == app.room:getMyUserId() then
  1267. if data.response.IsShouldOutCard > 0 then
  1268. self:setGuideView(true)
  1269. self.bOutCard = true
  1270. end
  1271. if data.response.mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
  1272. --操作码
  1273. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1274. self.operationLocalCode = data.response.mainOpCode
  1275. self:showOperation(data.response.mainOpCode,viewId)
  1276. self:setGuideView(false)
  1277. self.bOutCard = false
  1278. self.isTianHu = true
  1279. end
  1280. end
  1281. local operations = {}
  1282. --操作码
  1283. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1284. operations[viewId] = {}
  1285. operations[viewId].nUserId = data.response.nUserId
  1286. operations[viewId].isCanOpereate = 1
  1287. self:showDelayTimeTip(operations)
  1288. if onEnd then
  1289. onEnd()
  1290. end
  1291. end
  1292. log("2000000000-changpaiRoomView - addCallBack(runOnBankerOutCard)")
  1293. self:addCallBack(runOnBankerOutCard);
  1294. end
  1295. --发牌后偷牌巴牌的操作
  1296. function changpaiRoomView:onUserOperateResponse(data)
  1297. local function runUserOperate(onEnd)
  1298. log("2000000000-changpaiRoomView - (runUserOperate)")
  1299. logE("runUserOperate :"..table.tostring(data.response))
  1300. self.isQiShou = true
  1301. if data.response.nUserId == app.room:getMyUserId() then
  1302. if data.response.TouoperateCode ~= ZPDef.OpCode.OP_ERROR or data.response.BaoperateCode ~= ZPDef.OpCode.OP_ERROR then
  1303. local ishu = data.response.ishu
  1304. local hasGuo = true
  1305. local operationCardlist = {}
  1306. local opeateCode = 0
  1307. self.outCard = 0
  1308. if #data.response.BacardList > 0 then
  1309. operationCardlist[data.response.BaoperateCode] = data.response.BacardList
  1310. opeateCode = getNumOr(opeateCode,data.response.BaoperateCode)
  1311. end
  1312. --操作码
  1313. if #data.response.ToucardList > 0 then
  1314. operationCardlist[data.response.TouoperateCode] = data.response.ToucardList
  1315. opeateCode = getNumOr(opeateCode,data.response.TouoperateCode)
  1316. end
  1317. local mainOpCode = data.response.mainOpCode
  1318. local retHu = bit32.band(mainOpCode,ZPDef.OpCode.OP_HU)
  1319. local retHu1 = bit32.band(mainOpCode,ZPDef.OpCode.OP_TIAN_HU)
  1320. if ishu == 1 then
  1321. if retHu > 0 then
  1322. opeateCode = getNumOr(opeateCode,ZPDef.OpCode.OP_HU)
  1323. else
  1324. opeateCode = ZPDef.OpCode.OP_TIAN_HU
  1325. end
  1326. end
  1327. if ishu == 1 and self.isQiShou and opeateCode == ZPDef.OpCode.OP_TIAN_HU then
  1328. hasGuo = false
  1329. end
  1330. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1331. self.operationLocalCode = opeateCode
  1332. if self.operationLocalCode > 0 then
  1333. self:showOperation(opeateCode,operationCardlist,self.isQiShou,hasGuo)
  1334. end
  1335. --self:setTotalTuoNum(data.response.totalTuoNum)
  1336. local myViewId = self:getMeViewId()
  1337. self.PlayerView:setPlayerTuoShu(myViewId,data.response.totalTuoNum)
  1338. self:setGuideView(false)
  1339. self.bOutCard = false
  1340. end
  1341. end
  1342. self.ui.Items.ImageView_tou_tip:setVisible(true)
  1343. local operations = {}
  1344. --操作码
  1345. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1346. operations[viewId] = {}
  1347. operations[viewId].nUserId = data.response.nUserId
  1348. operations[viewId].isCanOpereate = 1
  1349. self:showDelayTimeTip(operations)
  1350. if onEnd then
  1351. onEnd()
  1352. end
  1353. end
  1354. log("2000000000-changpaiRoomView - addCallBack(runUserOperate)")
  1355. self:addCallBack(runUserOperate);
  1356. end
  1357. --起手偷巴操作
  1358. function changpaiRoomView:onUserOperateSuccess(data)
  1359. local function runUserOperateSuccess(onEnd)
  1360. log("2000000000-changpaiRoomView - (runUserOperateSuccess)")
  1361. logE("runUserOperateSuccess :"..table.tostring(data.response))
  1362. local response = data.response
  1363. local nUserId = response.nUserId
  1364. local opType = response.operateCodes
  1365. local opCard = response.opCard
  1366. local totoalTuoNum = response.totalTuoNum
  1367. local leftCardNum = tonumber(response.leftCardNum)
  1368. self.operationSuccessCode = opType
  1369. local viewId = app.room:getViewIdByUserId(nUserId)
  1370. local mType = 4
  1371. if viewId == 1 then
  1372. mType = ZPDef.CardType.CARD_TYPE_OPCARD_1
  1373. elseif viewId == 2 then
  1374. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  1375. elseif viewId == 3 then
  1376. mType = ZPDef.CardType.CARD_TYPE_OPCARD_3
  1377. elseif viewId == 4 then
  1378. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  1379. end
  1380. if opType == ZPDef.OpCode.OP_TOU_QI_SHOU or opType == ZPDef.OpCode.OP_TOU_ZHUA then --偷
  1381. self:doOperation(ZPDef.OpType.OP_TYPE_TOU,viewId,opCard,nil)
  1382. elseif opType == ZPDef.OpCode.OP_BA_QI_SHOU or opType == ZPDef.OpCode.OP_BA_ZHUA or opType == ZPDef.OpCode.OP_BA_FAN then
  1383. self:doOperation(ZPDef.OpType.OP_TYPE_BA,viewId,opCard,nil)
  1384. end
  1385. if viewId == self:getMeViewId() then
  1386. --self:setTotalTuoNum(totoalTuoNum)
  1387. --self:reflashHandCards()
  1388. self.PlayerView:setPlayerTuoShu(viewId,totoalTuoNum)
  1389. self:hideOperation()
  1390. else
  1391. self.PlayerView:setPlayerTuoShu(viewId,response.otherTuoNum)
  1392. end
  1393. if viewId ~= 4 then
  1394. self.PlayerView:setLeftCardNum(viewId,true,leftCardNum)
  1395. else
  1396. self.myHandCardNums = leftCardNum
  1397. end
  1398. if onEnd then
  1399. onEnd()
  1400. end
  1401. end
  1402. log("2000000000-changpaiRoomView - addCallBack(runUserOperateSuccess)")
  1403. self:addCallBack(runUserOperateSuccess);
  1404. end
  1405. function changpaiRoomView:removeHandByNums(card,nums)
  1406. local nums = nums
  1407. local tempLieshu = self.lieShuMax + 1
  1408. for col = tempLieshu,1,-1 do --列数
  1409. for row = self.hangShuMax,1,-1 do --行数
  1410. local tempCard = self.handCardRoot[col].imgList[row].value
  1411. if tempCard and card == tempCard and nums > 0 then
  1412. table.remove(self.handCardValueLocal[col],row)
  1413. self:rankDeletOneBakCard(card)
  1414. --单张图片的值归nil
  1415. self.handCardRoot[col].imgList[row].value = nil
  1416. self.handCardRoot[col].imgList[row].isKan = false
  1417. --单个图片隐藏
  1418. self.handCardRoot[col].imgList[row]:setVisible(false)
  1419. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  1420. nums = nums - 1
  1421. end
  1422. end
  1423. end
  1424. end
  1425. function changpaiRoomView:cleanOpOutCard(viewId,card)
  1426. if viewId then
  1427. if self.opOutCard[viewId] then
  1428. local index = 0
  1429. local isfind = false
  1430. local tempCardValue = {}
  1431. for k,v in pairs(self.opOutCard[viewId]) do
  1432. v:removeFromParent()
  1433. if v.value == card and not isfind then
  1434. index = tonumber(k)
  1435. isfind = true
  1436. end
  1437. table.insert(tempCardValue,v.value)
  1438. end
  1439. self.opOutCard[viewId] = {}
  1440. local mType = ZPDef.CardType.CARD_TYPE_GROUP_OUT
  1441. --[[
  1442. if viewId == 1 then
  1443. mType = ZPDef.CardType.CARD_TYPE_OPCARD_1
  1444. elseif viewId == 2 then
  1445. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  1446. elseif viewId == 3 then
  1447. mType = ZPDef.CardType.CARD_TYPE_OPCARD_3
  1448. elseif viewId == 4 then
  1449. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  1450. end
  1451. ]]
  1452. table.insert(tempCardValue,index,card)
  1453. for k,v in pairs(tempCardValue) do
  1454. self:createOpOutcard(viewId,mType,v,1)
  1455. end
  1456. end
  1457. else
  1458. for i = 1,ZPDef.GameMaxPlayer do
  1459. if self.opOutCard[i] then
  1460. for k,v in pairs(self.opOutCard[i]) do
  1461. v:removeFromParent()
  1462. end
  1463. self.opOutCard[i] = {}
  1464. else
  1465. self.opOutCard[i] = {}
  1466. end
  1467. end
  1468. end
  1469. end
  1470. function changpaiRoomView:createOpOutcard(viewId,mType,value,nums)
  1471. local opLayout = string.format("Layout_groupCard_%d",viewId)
  1472. local position = self.ui.Items[opLayout]:getPosition()
  1473. local function onTouchBegan(touch)
  1474. log("---changpaiRoomView onTouchBegan ---")
  1475. if self.isTouchOpOutCard then
  1476. return
  1477. end
  1478. self.isTouchOpOutCard = true
  1479. local touchPos = touch:getLocation();
  1480. local viewId = -1
  1481. for i = 1, 4 do
  1482. for k, v in ipairs(self.opOutCard[i] or {}) do
  1483. local mSprite = v
  1484. --local posNode = mSprite:convertToNodeSpace(touchPos);
  1485. local width = mSprite:getContentSize().width
  1486. local height = mSprite:getContentSize().height
  1487. --不可以用getWorldPosition(),因为会出现旋转后,可点区域会停留在原来的地方。
  1488. local x = mSprite:getPosition().x -width/2
  1489. local y = mSprite:getPosition().y -height/2
  1490. local tempWidth = width+50
  1491. local tempHight = height+50
  1492. local mRect = cc.Rectangle:new(x,y,tempWidth,tempHight)
  1493. if mRect:contains(touchPos.x,touchPos.y) then
  1494. viewId = v.viewId
  1495. log("要放大的视图为:", viewId)
  1496. end
  1497. end
  1498. end
  1499. if viewId and viewId > -1 then
  1500. local index = 1
  1501. local colNum = ZPDef.OpOutCardNum[viewId]
  1502. local colMax = math.modf(index/colNum)
  1503. for k,v in ipairs(self.opOutCard[viewId]) do
  1504. v:setScale(0.7)
  1505. local pos = v:getPosition()
  1506. if index > colNum then
  1507. colMax = colMax + 1
  1508. end
  1509. index = index % colNum
  1510. if index == 0 then
  1511. index = colNum
  1512. end
  1513. --local opCardSize = cc.size(81,106)
  1514. local endpos = cc.p(0,0)
  1515. if self.desktopType == ZPDef.DesktopType.ThreeD then
  1516. if viewId == 1 then
  1517. endpos.x = pos.x + 7*index
  1518. endpos.y = pos.y - index*20
  1519. if colMax > 0 then
  1520. endpos.x = endpos.x - colMax*20
  1521. end
  1522. elseif viewId == 2 then
  1523. endpos.x = pos.x + index*15
  1524. endpos.y = pos.y
  1525. if colMax > 0 then
  1526. endpos.y = endpos.y + colMax*25
  1527. end
  1528. elseif viewId == 3 then
  1529. endpos.x = pos.x - 7*index
  1530. endpos.y = pos.y - index*20
  1531. if colMax > 0 then
  1532. endpos.x = endpos.x + colMax*20
  1533. end
  1534. elseif viewId == 4 then
  1535. endpos.x = pos.x + index*15
  1536. endpos.y = pos.y
  1537. if colMax > 0 then
  1538. endpos.y = endpos.y - colMax*25
  1539. end
  1540. end
  1541. else
  1542. if viewId == 1 then
  1543. endpos.x = pos.x
  1544. endpos.y = pos.y - index*20
  1545. if colMax > 0 then
  1546. endpos.x = endpos.x - colMax*25
  1547. end
  1548. elseif viewId == 2 then
  1549. endpos.x = pos.x + index*15
  1550. endpos.y = pos.y
  1551. if colMax > 0 then
  1552. endpos.y = endpos.y + colMax*25
  1553. end
  1554. elseif viewId == 3 then
  1555. endpos.x = pos.x
  1556. endpos.y = pos.y - index*20
  1557. if colMax > 0 then
  1558. endpos.x = endpos.x + colMax*25
  1559. end
  1560. elseif viewId == 4 then
  1561. endpos.x = pos.x + index*15
  1562. endpos.y = pos.y
  1563. if colMax > 0 then
  1564. endpos.y = endpos.y - colMax*25
  1565. end
  1566. end
  1567. end
  1568. v:setPosition(endpos)
  1569. index = index + 1
  1570. end
  1571. end
  1572. return true
  1573. end
  1574. local function onTouchMove()
  1575. log("---changpaiRoomView onTouchMove ---")
  1576. return true
  1577. end
  1578. local function onTouchEnd()
  1579. log("---changpaiRoomView onTouchEnd ---")
  1580. self:restoreOpOutCard()
  1581. return true
  1582. end
  1583. local function onTouchCancel()
  1584. log("---changpaiRoomView onTouchCancel ---")
  1585. self:restoreOpOutCard()
  1586. end
  1587. for i = 1,nums do
  1588. local changpai = ChangpaiCard:new(value,mType,viewId,self.colorType,self.desktopType)
  1589. if self.opOutCard[viewId] and table.nums(self.opOutCard[viewId]) > 0 then
  1590. local colNum = ZPDef.OpOutCardNum[viewId]
  1591. local opcardNum = #self.opOutCard[viewId]
  1592. local colMax = math.modf(opcardNum/colNum)
  1593. local orderX = position.x
  1594. local orderY = position.y
  1595. local offsetX = ZPDef.OpOutCardOffset[self.desktopType][viewId].x
  1596. local offsetY = ZPDef.OpOutCardOffset[self.desktopType][viewId].y
  1597. local offsetSpace = ZPDef.opOutCardSpace[self.desktopType][viewId]
  1598. if viewId == 1 then
  1599. if colMax > 0 then
  1600. orderX = orderX - offsetSpace*colMax
  1601. end
  1602. orderX = orderX + offsetX*opcardNum
  1603. orderY = orderY - (opcardNum%colNum)*offsetY
  1604. elseif viewId == 2 then
  1605. if colMax > 0 then
  1606. orderY = orderY + offsetY*colMax
  1607. end
  1608. orderX = orderX + (opcardNum%colNum)*offsetX
  1609. elseif viewId == 3 then
  1610. if colMax > 0 then
  1611. orderX = orderX + offsetSpace*colMax
  1612. end
  1613. orderX = orderX - offsetX*opcardNum
  1614. orderY = orderY - (opcardNum%colNum)*offsetY
  1615. elseif viewId == 4 then
  1616. if colMax > 0 then
  1617. orderY = orderY - offsetY*colMax
  1618. end
  1619. orderX = orderX + (opcardNum%colNum)*offsetX
  1620. end
  1621. changpai:setPosition(cc.p(orderX,orderY))
  1622. else
  1623. self.opOutCard[viewId] = {}
  1624. changpai:setPosition(position)
  1625. end
  1626. table.insert(self.opOutCard[viewId],changpai)
  1627. changpai:setTouchEnabled(true)
  1628. changpai:registerTouchEvent(onTouchBegan,onTouchMove,onTouchEnd,onTouchCancel)
  1629. local Zoreder = 100
  1630. if viewId == 3 then
  1631. Zoreder = 99
  1632. else
  1633. Zoreder = viewId * 100
  1634. end
  1635. self.ui.Items.Layout_HandCard:addChild(changpai,Zoreder)
  1636. end
  1637. end
  1638. function changpaiRoomView:restoreOpOutCard()
  1639. for viewId = 1, 4 do
  1640. if self.opOutCard[viewId] then
  1641. local index = 0
  1642. local isfind = false
  1643. local tempCardValue = {}
  1644. for k,v in pairs(self.opOutCard[viewId]) do
  1645. v:removeFromParent()
  1646. table.insert(tempCardValue,v.value)
  1647. end
  1648. self.opOutCard[viewId] = {}
  1649. local mType = ZPDef.CardType.CARD_TYPE_GROUP_OUT
  1650. for k,v in pairs(tempCardValue) do
  1651. self:createOpOutcard(viewId,mType,v,1)
  1652. end
  1653. end
  1654. end
  1655. self.isTouchOpOutCard = false
  1656. end
  1657. function changpaiRoomView:onGetHandcardsResponese(event)
  1658. end
  1659. --刷新手牌
  1660. function changpaiRoomView:onReflashHandcardsResponese(event)
  1661. local function runUserReflashHandcard(onEnd)
  1662. log("2000000000-changpaiRoomView - onReflashHandcardsResponese()" )
  1663. logD("onReflashHandcardsResponese self.handCardValueBak---",table.tostring(self.handCardValueBak));
  1664. logD("onReflashHandcardsResponese self.handCardValueLocal---",table.tostring(self.handCardValueLocal));
  1665. --uploadLogs("reflashhandcard2")
  1666. self.ui.Items.LayoutMain_4:removeAllChildren()
  1667. self.handCardRoot = {}
  1668. self.handCardItem = {}
  1669. self.handCardValueLocal = {}
  1670. self.handCardValueBak = {}
  1671. local myUserID = app.room:getMyUserId()
  1672. self:createCard(false,myUserID,onEnd)
  1673. end
  1674. log("2000000000-changpaiRoomView - addCallBack(runUserReflashHandcard)")
  1675. self:addCallBack(runUserReflashHandcard);
  1676. end
  1677. --解锁
  1678. function changpaiRoomView:unLockYouPai()
  1679. --根据服务器发来的牌解锁
  1680. local tempLieshu = self.lieShuMax + 1
  1681. for col = 1, tempLieshu do
  1682. for row = 1,self.hangShuMax do
  1683. self.handCardRoot[col].imgList[row].isKan = false
  1684. self.handCardRoot[col].imgList[row]:setTouchEnabled(true)
  1685. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  1686. end
  1687. end
  1688. end
  1689. function changpaiRoomView:onBroadCastUserGetCard(data)
  1690. local function runUserGetCard(onEnd)
  1691. log("2000000000-changpaiRoomView - (runUserGetCard)")
  1692. logE("runUserGetCard :"..table.tostring(data.response))
  1693. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1694. local leftcardNum = data.response.leftCardNum
  1695. local isHouZhua = data.response.isHouZhuaCard
  1696. local mocard = data.response.moCard
  1697. local function callback()
  1698. if data.response.nUserId == app.room:getMyUserId() then
  1699. --进牌后解锁油牌
  1700. --如果报叫了则不能解锁
  1701. --先刷新一遍手牌,存在上一轮摸了牌无操作也没出牌的情况
  1702. self:neatenCard()
  1703. self:unLockYouPai()
  1704. app.room.roomInfo.disCard = {}
  1705. local moValue = data.response.moCard
  1706. self.outCard = 0 --进牌的时候点过可以发0
  1707. self.moValue = moValue
  1708. local moSepAction = cc.Sequence:create(cc.CallFunc:create(function()
  1709. self:setMoCardVisible(true,moValue)
  1710. self.isGodHand = true --播放动画的时候不能点击手牌
  1711. end),
  1712. cc.DelayTime:create(0.5),
  1713. cc.CallFunc:create(function()
  1714. self:setMoCardsPos()
  1715. self.isGodHand = false
  1716. if onEnd then
  1717. onEnd()
  1718. end
  1719. end))
  1720. self:runAction(moSepAction)
  1721. local myViewId = self:getMeViewId()
  1722. self.PlayerView:setPlayerTuoShu(myViewId,data.response.totoltuoNum)
  1723. else
  1724. if onEnd then
  1725. onEnd()
  1726. end
  1727. end
  1728. end
  1729. local HOUZHUA_TAG = 100
  1730. if isHouZhua == 1 then
  1731. local function call_func()
  1732. self:playMoPaiAni(leftCardNum,mocard,viewId,0,1,nil,false)
  1733. local name = string.format("ImageView_outCardLight_%d",viewId)
  1734. local img = self.ui.Items[name]
  1735. local size = img:getContentSize()
  1736. --后抓精灵
  1737. local mSprite = cc.ImageView:createNode()
  1738. mSprite:loadTexture("zp_changpai/res/ui/zy_fangjian/btn_effect/effect/houzhua.png")
  1739. img:addChild(mSprite)
  1740. mSprite:setTag(HOUZHUA_TAG)
  1741. if viewId == 2 then
  1742. mSprite:setEulerRotation(cc.vec3(0,0,-90))
  1743. end
  1744. mSprite:setPosition(cc.p(size.width/2,size.height/2))
  1745. mSprite:setScale(0.4)
  1746. end
  1747. local seq = cc.Sequence:create(cc.CallFunc:create(call_func),cc.DelayTime:create(1.5),cc.CallFunc:create(function()
  1748. self:setOutCardVisible(false)
  1749. local name = string.format("ImageView_outCardLight_%d",viewId)
  1750. local img = self.ui.Items[name]
  1751. for i,child in pairs(img:getChildren()) do
  1752. local tag = child:getTag()
  1753. if tag == HOUZHUA_TAG then
  1754. child:removeFromParent()
  1755. end
  1756. end
  1757. callback()
  1758. end))
  1759. self.ui:runAction(seq)
  1760. else
  1761. callback()
  1762. end
  1763. local leftCard = data.response.tableCardNum
  1764. self:setCircleCardLeftPanelView(true,viewId,leftCard)
  1765. self.PlayerView:setLeftCardNum(viewId,true,leftcardNum)
  1766. if viewId == self:getMeViewId() then
  1767. self.myHandCardNums = leftcardNum
  1768. end
  1769. end
  1770. log("2000000000-changpaiRoomView - addCallBack(runUserGetCard)")
  1771. self:addCallBack(runUserGetCard);
  1772. end
  1773. --[[
  1774. function changpaiRoomView:reflashHandCards()
  1775. local card = self.moValue
  1776. local isfind = false
  1777. if card and card > 0 then
  1778. for col = 1,self.lieShuMax do --列数
  1779. for row = self.hangShuMax,1,-1 do --行数
  1780. local temp = self.handCardRoot[col]
  1781. local tempCard = self.handCardRoot[col].imgList[row].value
  1782. if tempCard == card and not isfind then --牌堆未填满的状态
  1783. --单张图片的值
  1784. self.handCardRoot[col].imgList[row].value = nil
  1785. self.handCardRoot[col].imgList[row].isKan = false
  1786. --单个图片先隐藏
  1787. self.handCardRoot[col].imgList[row]:setVisible(false)
  1788. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  1789. --先把该张牌从前面牌堆删除
  1790. table.remove(self.handCardValueLocal[col],row)
  1791. --数据备份
  1792. table.remove(self.handCardValueBak[col],row)
  1793. self:rankDeletOneBakCard(card)
  1794. isfind = true
  1795. end
  1796. end
  1797. end
  1798. if isfind then
  1799. self:neatenCard(true)
  1800. self:setMoCardVisible(true,card)
  1801. end
  1802. end
  1803. end
  1804. ]]
  1805. function changpaiRoomView:setMoCardsPos()
  1806. if self:checkMopaiVis() then
  1807. log("changpaiRoomView setMoCardsPos",self.moValue)
  1808. local moMaxIndex =self.moLieshu
  1809. local card = self.moValue
  1810. table.remove(self.handCardValueLocal[moMaxIndex],1)
  1811. self:rankDeletOneBakCard(card)
  1812. --单张图片的值归nil
  1813. self.handCardRoot[moMaxIndex].imgList[1].value = nil
  1814. self.handCardRoot[moMaxIndex].imgList[1].isKan = false
  1815. --单个图片隐藏
  1816. self.handCardRoot[moMaxIndex].imgList[1]:setVisible(false)
  1817. self.handCardRoot[moMaxIndex].imgList[1]:setColor(cc.c3b(255,255,255))
  1818. --找到牌的位置
  1819. local firstCol,firstRow = self:findCardPos(card)
  1820. log("--changpaiRoomView tobe--",firstCol,firstRow)
  1821. local node = self.handCardRoot[firstCol].imgList[firstRow]
  1822. node:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_HAND,self.colorType))
  1823. node.value = card
  1824. node.isKan = false
  1825. self:restoreCardUiPos()
  1826. self.handCardValueLocal[firstCol][firstRow] = card
  1827. table.insert(self.handCardValueBak[firstCol],card)
  1828. node:setVisible(true)
  1829. end
  1830. --保证牌已经摸进来了再锁牌
  1831. if self.baoJiaoStatus == 1 then
  1832. app.room.roomInfo.tingCards = {}
  1833. table.insert(app.room.roomInfo.tingCards,self.moValue)
  1834. self:lockMyHandCards()
  1835. end
  1836. end
  1837. --还原每列的位置
  1838. function changpaiRoomView:restoreCardUiPos()
  1839. local tempLieshu = self.lieShuMax + 1
  1840. for i = 1,tempLieshu do
  1841. local card = self.handCardRoot[i]
  1842. local pos = self.boxPosList4[i]
  1843. card.ui:setPosition(pos)
  1844. end
  1845. end
  1846. function changpaiRoomView:checkMopaiVis()
  1847. --local moMaxIndex = self:getMoCardLieMax()
  1848. --[[ if self.moLieshu > 0 then
  1849. logD("changpaiRoomView checkMopaiVis",self.moLieshu)
  1850. local node = self.handCardRoot[self.moLieshu].imgList[1]
  1851. if node and node:isVisible() and self.moValue > 0 and node.value == self.moValue then
  1852. return true
  1853. end
  1854. end--]]
  1855. return true
  1856. end
  1857. function changpaiRoomView:setMoCardVisible(bisVsible,card)
  1858. --local moPos = self:getMoCardPos()
  1859. local moMaxIndex =self:getMoCardLieMax()
  1860. self.moLieshu = moMaxIndex
  1861. if bisVsible and self.moValue and self.moValue > 0 then
  1862. local colUI = self.handCardRoot[moMaxIndex]
  1863. local posUI = cc.p(0,0)
  1864. posUI.x = colUI.ui:getPosition().x + 10
  1865. colUI.ui:setPositionX(posUI.x)
  1866. colUI.imgList[1].value = card
  1867. local fileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  1868. colUI.imgList[1]:loadTextureFromPlist(fileName)
  1869. colUI.imgList[1]:setVisible(true)
  1870. table.insert(self.handCardValueLocal[moMaxIndex],card)
  1871. --数据备份
  1872. table.insert(self.handCardValueBak[moMaxIndex],card)
  1873. end
  1874. end
  1875. --锁住吃后不能出的牌
  1876. function changpaiRoomView:lockYouPai(youlist)
  1877. --根据服务器发来的牌解锁
  1878. for k,v in pairs(youlist) do
  1879. local tempLieshu = self.lieShuMax + 1
  1880. for col = tempLieshu,1,-1 do --列数
  1881. for row = self.hangShuMax,1,-1 do --行数
  1882. local cardValue = self.handCardRoot[col].imgList[row].value
  1883. if v == cardValue and not self.handCardRoot[col].imgList[row].isKan then --防止锁两次
  1884. self.handCardRoot[col].imgList[row].isKan = true
  1885. self.handCardRoot[col].imgList[row]:setTouchEnabled(false)
  1886. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(125,125,125))
  1887. end
  1888. end
  1889. end
  1890. end
  1891. end
  1892. --通知玩家家出牌
  1893. function changpaiRoomView:onBroadCastBankerOutCard(data)
  1894. local function runBankerOutCardd(onEnd)
  1895. log("2000000000-changpaiRoomView - (runBankerOutCardd)")
  1896. logE("runBankerOutCardd :"..table.tostring(data.response))
  1897. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1898. --吃后不能出的牌
  1899. self.isQiShou = false
  1900. if data.response.nUserId == app.room:getMyUserId() then
  1901. app.room.roomInfo.disCard = {}
  1902. for k,v in ipairs(data.response.disCard or {}) do
  1903. table.insert(app.room.roomInfo.disCard,v)
  1904. end
  1905. for k,v in ipairs(data.response.afterbadisCard or {}) do
  1906. table.insert(app.room.roomInfo.disCard,v)
  1907. end
  1908. self:lockYouPai(app.room.roomInfo.disCard)
  1909. self:setGuideView(true)
  1910. self.bOutCard = true
  1911. end
  1912. self.ui.Items.ImageView_tou_tip:setVisible(false)
  1913. self:setCircleCardLeftPanelView(true,viewId,self.leftNum)
  1914. if onEnd then
  1915. onEnd()
  1916. end
  1917. end
  1918. log("2000000000-changpaiRoomView - addCallBack(runBankerOutCardd)")
  1919. self:addCallBack(runBankerOutCardd);
  1920. end
  1921. --过巴锁牌
  1922. function changpaiRoomView:onGuoBaResponse(data)
  1923. log("2000000000-changpaiRoomView - addCallBack(onGuoBaResponse)")
  1924. local function runGuoBa(onEnd)
  1925. logE("runBankerOutCardd :"..table.tostring(data.response))
  1926. if data.response.nUserId == app.room:getMyUserId() then
  1927. app.room.roomInfo.disCard = {}
  1928. for k,v in ipairs(data.response.disCard or {}) do
  1929. table.insert(app.room.roomInfo.disCard,v)
  1930. end
  1931. self:lockYouPai(app.room.roomInfo.disCard)
  1932. end
  1933. --结束
  1934. if onEnd then
  1935. onEnd()
  1936. end
  1937. end
  1938. log("2000000000-changpaiRoomView - addCallBack(runGuoBa)")
  1939. self:addCallBack(runGuoBa)
  1940. end
  1941. --包赔提示
  1942. function changpaiRoomView:onOutCardIsBaoPeiResponse(data)
  1943. local baoPeiCard = data.response.bCard
  1944. local view = import("zp_changpai.luaScript.Views.Room.changpaiRoomBaoPei"):new(baoPeiCard,0)
  1945. view:setAnchorPoint(cc.p(0.5, 0.5))
  1946. app:showWaitDialog(view)
  1947. end
  1948. --出牌成功
  1949. function changpaiRoomView:onOutCardSuccess(data)
  1950. logE("changpaiRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  1951. local function runOnOutCardSuccess(onEnd)
  1952. log("2000000000-changpaiRoomView - runOnOutCardSuccess")
  1953. --设置出牌动画隐藏
  1954. self:setGuideView(false)
  1955. --只要出了牌就不是起手操作了
  1956. self.isQiShou = false
  1957. local response = data.response
  1958. local nUserId = response.nOutCardUserId
  1959. local card = response.byOutCard
  1960. local operateCode = response.mainOpCode
  1961. local leftHandCardNum = response.leftHandCardNum
  1962. local isBaoPei = response.isBaopei
  1963. local opCardList = response.opCardList
  1964. if isBaoPei == 1 then
  1965. self.isBiChi = 2
  1966. else
  1967. self.isBiChi = 0
  1968. end
  1969. local viewId = app.room:getViewIdByUserId(nUserId)
  1970. self.moPaiViewId = viewId
  1971. --隐藏出牌
  1972. self.bOutCard = false
  1973. --记录真实牌值
  1974. self.outCard = card
  1975. --记录操作码
  1976. self.EatOperationCode = operateCode
  1977. self:showDelayTimeTip()
  1978. self.PlayerView:setLeftCardNum(viewId,true,leftHandCardNum)
  1979. if viewId == self:getMeViewId() then
  1980. self.myHandCardNums = leftHandCardNum
  1981. end
  1982. --self.PlayerView:setNoOpTime(false,viewId)
  1983. logE("my userid :"..app.room:getMyUserId())
  1984. logE("out card response nUserId:"..nUserId)
  1985. local userInfo=app.room:getUserInfo(nUserId)
  1986. if userInfo then
  1987. ZPSound.PlayZPSound(userInfo.sex,card)
  1988. else
  1989. ZPSound.PlayZPSound(1,card)
  1990. end
  1991. local operationCardlist = {}
  1992. if operateCode ~= ZPDef.OpCode.OP_CANCEL and operateCode ~= ZPDef.OpCode.OP_ERROR then
  1993. operationCardlist[ZPDef.OpCode.OP_PENG] = {}
  1994. table.insert(operationCardlist[ZPDef.OpCode.OP_PENG],card)
  1995. operationCardlist[ZPDef.OpCode.OP_HU] = {}
  1996. table.insert(operationCardlist[ZPDef.OpCode.OP_HU],card)
  1997. operationCardlist[ZPDef.OpCode.OP_CHI] = {}
  1998. for k,v in ipairs(opCardList) do
  1999. table.insert(operationCardlist[ZPDef.OpCode.OP_CHI],v)
  2000. end
  2001. end
  2002. if nUserId ~= app.room:getMyUserId() then
  2003. if operateCode ~= ZPDef.OpCode.OP_CANCEL and operateCode ~= ZPDef.OpCode.OP_ERROR then
  2004. self:showOperation(operateCode,operationCardlist,self.isQiShou,true)
  2005. end
  2006. --其他玩家显示
  2007. self:setOutCardVisible(true,viewId,card,false,onEnd)
  2008. else
  2009. self.isGodHand = true
  2010. local function rankDeletOneCard(card)
  2011. local isEnd = false
  2012. --倒叙遍历1-10列
  2013. local tempLieshu = self.lieShuMax + 1
  2014. for col = tempLieshu,1,-1 do --列数
  2015. for row = self.hangShuMax,1,-1 do --行数
  2016. if card == self.handCardRoot[col].imgList[row].value then --判断值是否相等
  2017. logE("delete card1 ============= :"..card)
  2018. table.remove(self.handCardValueLocal[col],row)
  2019. --单张图片的值归nil
  2020. self.handCardRoot[col].imgList[row].value = nil
  2021. self.handCardRoot[col].imgList[row].isKan = false
  2022. --单个图片隐藏
  2023. self.handCardRoot[col].imgList[row]:setOpacity(255)
  2024. self.handCardRoot[col].imgList[row]:setVisible(false)
  2025. isEnd = true
  2026. break
  2027. end
  2028. end
  2029. if isEnd then
  2030. break
  2031. end
  2032. end
  2033. end
  2034. local index = self.ui.Items.ImageView_handTempCard.index
  2035. local lieshu = self.ui.Items.ImageView_handTempCard.lieshu
  2036. local row = self.ui.Items.ImageView_handTempCard.hangshu --self:getRowByIndex(index)
  2037. --说明:数据校验:弱网棋牌的通病(麻将出牌等一切可以允许玩家自己插牌的游戏,需要注意弱网情况,出牌会出现删错牌)
  2038. --判断该列是否有牌
  2039. if self.handCardValueLocal[lieshu] ~= nil and table.nums(self.handCardValueLocal[lieshu]) > 0 then
  2040. --二次校验牌数据是否是出牌数据
  2041. local recordValue = self.handCardRoot[lieshu].imgList[row].value
  2042. if recordValue == card then
  2043. logE("delete card2 ============= :"..card)
  2044. table.remove(self.handCardValueLocal[lieshu],row)
  2045. --数据干掉
  2046. self.handCardRoot[lieshu].imgList[row].value = nil
  2047. self.handCardRoot[lieshu].imgList[row].isKan = false
  2048. --视图处理
  2049. self.handCardRoot[lieshu].imgList[row]:setOpacity(255)
  2050. self.handCardRoot[lieshu].imgList[row]:setVisible(false)
  2051. else
  2052. --随机删掉手里那张牌
  2053. rankDeletOneCard(card)
  2054. end
  2055. else
  2056. --随机删掉手里那张牌
  2057. rankDeletOneCard(card)
  2058. end
  2059. if app.room.roomInfo.hosting == 1 then
  2060. self.ui.Items.ImageView_handTempCard:setVisible(false) --托管出牌的时候要把自己点击在桌面上的牌清理掉
  2061. self:setOutCardVisible(true,viewId,card,false, function () end)
  2062. end
  2063. self:rankDeletOneBakCard(card)
  2064. --self:reflashHandCards()
  2065. self:neatenCard(true)
  2066. if onEnd then
  2067. onEnd()
  2068. end
  2069. --检查是否少牌
  2070. self:checkCardAndRecover()
  2071. --设置坨数
  2072. --self:setTotalTuoNum(data.response.totoltuoNum)
  2073. local myViewId = self:getMeViewId()
  2074. self.PlayerView:setPlayerTuoShu(myViewId,data.response.totoltuoNum)
  2075. if viewId == self:getMeViewId() then
  2076. self:reflashHandCards()
  2077. end
  2078. if self.baoJiaoStatus == 1 then
  2079. app.room.roomInfo.tingCards = {}
  2080. self:lockMyHandCards()
  2081. end
  2082. end
  2083. end
  2084. log("2000000000-changpaiRoomView - addCallBack(runOnOutCardSuccess)")
  2085. self:addCallBack(runOnOutCardSuccess)
  2086. end
  2087. -- 操作成功
  2088. function changpaiRoomView:onOperationCodeSuccess(data)
  2089. local function runOnOperationSuccess(onEnd)
  2090. log("2000000000-changpaiRoomView - (runOnOperationSuccess)")
  2091. self:hideOperation()
  2092. logE("changpaiRoomView:onOperationCodeSuccess :"..table.tostring(data.response))
  2093. local response = data.response
  2094. local nUserID = response.nUserId
  2095. local card = response.card
  2096. local tablecard = response.tableCard
  2097. local bIsOutCard = response.isShouldOutCard > 0
  2098. local operateCodes = response.operateCodes
  2099. local weaveCardList = response.weaveCardList
  2100. local playerList = response.playerList
  2101. local maxWeave = table.nums(weaveCardList)
  2102. local totalHuShu = response.totalHuShu
  2103. local leftHandCardNum = response.leftHandCardNum
  2104. local isChilaiBao = response.isChilaiBao
  2105. self.isBaopei = isChilaiBao
  2106. --local isMoPaiOrId = -1
  2107. --app.room.roomInfo.huType = response.huType
  2108. --点炮胡时,表示为点炮用户
  2109. app.room.roomInfo.dianPaoSeatId = response.dianPaoSeatId
  2110. --碰胡规则
  2111. if maxWeave > 0 then
  2112. --isMoPaiOrId = weaveCardList[maxWeave].seatId
  2113. end
  2114. --记录操作成功
  2115. self.operationSuccessCode = operateCodes
  2116. self.outCard = card
  2117. self.chiCard = tablecard
  2118. --视图ID
  2119. local viewId = app.room:getViewIdByUserId(nUserID)
  2120. if nUserID == app.room:getMyUserId() then
  2121. --self:setTotalTuoNum(totalHuShu)
  2122. self.PlayerView:setPlayerTuoShu(viewId,totalHuShu)
  2123. else
  2124. self.PlayerView:setPlayerTuoShu(viewId,response.otherTuoNum)
  2125. end
  2126. self.tableHuXiList[viewId] = totalHuShu
  2127. self.PlayerView:setPlayerHuXi(viewId,totalHuShu)
  2128. self.PlayerView:setLeftCardNum(viewId,true,leftHandCardNum)
  2129. if viewId == self:getMeViewId() then
  2130. self.myHandCardNums = leftHandCardNum
  2131. end
  2132. --self.PlayerView:setNoOpTime(false,viewId)
  2133. if bIsOutCard then
  2134. for k,v in pairs(app.room.roomInfo.memberList) do
  2135. local operations = {}
  2136. operations[viewId] = {}
  2137. operations[viewId].nUserId = v.nUserId
  2138. operations[viewId].isCanOpereate = 0
  2139. self:showDelayTimeTip(operations)
  2140. end
  2141. end
  2142. local operations = {}
  2143. operations[viewId] = {}
  2144. operations[viewId].nUserId = nUserID
  2145. operations[viewId].isCanOpereate = bIsOutCard and 1 or 0
  2146. self:showDelayTimeTip(operations)
  2147. --隐藏handTemp
  2148. if viewId == self:getMeViewId() then
  2149. self.isGodHand = true
  2150. --出牌动画 setGuideView延迟了0.5
  2151. self:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
  2152. self:setColorWhite()
  2153. if operateCodes == 0 then--点击过的时候设置可以点牌
  2154. self.isGodHand = false
  2155. end
  2156. end)))
  2157. self.ui.Items.ImageView_handTempCard:setVisible(false)
  2158. end
  2159. --显示指示器
  2160. if bIsOutCard and operateCodes ~= 0 then
  2161. self:setCircleCardLeftPanelView(true,viewId,self.leftNum)
  2162. end
  2163. --隐藏操作层
  2164. self:setOperatorPanelView(false,nil)
  2165. --判断自己是否需要出牌
  2166. if bIsOutCard and viewId == self:getMeViewId()
  2167. and operateCodes ~= 0
  2168. and operateCodes ~= ZPDef.OpCode.OP_HU then
  2169. self:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
  2170. self:setGuideView(true)
  2171. end)))
  2172. self.bOutCard = true
  2173. end
  2174. if self.isTianHu and viewId == self:getMeViewId() then
  2175. self.isTianHu = false
  2176. self:setGuideView(true)
  2177. self.bOutCard = true
  2178. end
  2179. --隐藏吃牌层
  2180. self.operationView:setEatCardView(false)
  2181. --执行操作
  2182. local code = operateCodes
  2183. logE("changpaiRoomView:onOperationCodeSuccess nOperationCode:"..code)
  2184. local operations = ZPFuc.getZPOperationType(code,false,false)
  2185. local operationType = operations[1]
  2186. --体验:等待0.5秒结束
  2187. if operationType ~= ZPDef.OpType.OP_TYPE_HU and operationType ~= ZPDef.OpType.OP_TYPE_CANCEL and operationType ~= nil then
  2188. --吃碰操作
  2189. --隐藏出牌层
  2190. self:setOutCardVisible(false)
  2191. self:doOperation(operationType,viewId,card,onEnd,isChilaiBao)
  2192. elseif operationType == ZPDef.OpType.OP_TYPE_HU then
  2193. --胡牌操作
  2194. --1.隐藏引导出牌动画2.显示胡了哪张牌,3.播放胡牌特效
  2195. self:setGuideView(false)
  2196. local imgName = string.format("ImageView_outCardImg_%d",self.moPaiViewId)
  2197. local mSprite = self.ui.Items[imgName]
  2198. if self.outCard ~= 0 then
  2199. local fileName = ZPFuc.getZPCardImgByValue(self.outCard,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  2200. mSprite:loadTextureFromPlist(fileName)
  2201. end
  2202. if coperateCodes ~= 0 then
  2203. self:runAction(cc.Sequence:create(cc.DelayTime:create(0),cc.CallFunc:create(function ()
  2204. self:setLayoutScoreTipVisible(true,playerList,false,onEnd,true)
  2205. app.room.roomInfo.winUserId = nUserID
  2206. --self:playHuEffect(viewId,onEnd)
  2207. if self.leftNum and not self.isTianHu and card ~= 0 and app.room.roomInfo.dianPaoSeatId == -1 and viewId == self.moPaiViewId then
  2208. self:playMoPaiAni(self.leftNum,card,viewId,0,1,nil,true)
  2209. end
  2210. if onEnd then
  2211. onEnd()
  2212. end
  2213. end)))
  2214. end
  2215. else
  2216. --self:showOperatorTip(viewId,ZPDef.OpType.OP_TYPE_CANCEL)
  2217. --过
  2218. self:doOperation(ZPDef.OpType.OP_TYPE_CANCEL,viewId,card,nil)
  2219. if onEnd then
  2220. onEnd()
  2221. end
  2222. end
  2223. end
  2224. log("2000000000-changpaiRoomView - addCallBack(runOnOperationSuccess)")
  2225. self:addCallBack(runOnOperationSuccess)
  2226. end
  2227. --多维数组转 一维数组
  2228. function changpaiRoomView:ChangeDataToVector(data)
  2229. local tt = {}
  2230. local tempLieshu = self.lieShuMax + 1
  2231. for i = 1, tempLieshu do
  2232. for j = 1, #data[i] do ---因为理了牌之后本地牌值的数组和保存的数组可能会不一致,保存的数组的一列长度可能会大于行数,所以要判断数组的长度
  2233. if data[i][j] then
  2234. table.insert(tt,data[i][j])
  2235. end
  2236. end
  2237. end
  2238. return tt
  2239. end
  2240. function changpaiRoomView:reflashHandCards()
  2241. local handCard = self:ChangeDataToVector(self.handCardValueBak)
  2242. local sendCardResult = app.room:rankHandCard(handCard)
  2243. local newCardList
  2244. newCardList = app.room:serverCardToMyCard(sendCardResult)
  2245. self.ui.Items.LayoutMain_4:removeAllChildren()
  2246. self.handCardRoot = {}
  2247. self.handCardItem = {}
  2248. self.handCardValueLocal = {}
  2249. self.handCardValueBak = {}
  2250. local myUserID = app.room:getMyUserId()
  2251. app.room.cards[myUserID] = newCardList
  2252. self:createCard(false,myUserID,nil)
  2253. end
  2254. --用户吃(手动)
  2255. function changpaiRoomView:Chi(viewId,card,onEnd)
  2256. logD("function do Chi")
  2257. logE("changpaiRoomView chi:",card)
  2258. local chilist = {}
  2259. --吃的牌放下面
  2260. table.insert(chilist, self.chiCard)
  2261. table.insert(chilist, card)
  2262. logE("changpaiRoomView chilist:",chilist)
  2263. local nUserID = app.room:getUserIdByViewId(viewId)
  2264. local mType = ZPDef.CardType.CARD_TYPE_GROUP_OUT
  2265. --[[
  2266. if viewId == 1 then
  2267. mType = ZPDef.CardType.CARD_TYPE_OPCARD_1
  2268. elseif viewId == 2 then
  2269. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  2270. elseif viewId == 3 then
  2271. mType = ZPDef.CardType.CARD_TYPE_OPCARD_3
  2272. elseif viewId == 4 then
  2273. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  2274. end
  2275. ]]
  2276. for k,v in ipairs(chilist) do
  2277. self:createOpOutcard(viewId,mType,v,1)
  2278. end
  2279. if viewId == self:getMeViewId() then
  2280. self:removeHandByNums(card,1)
  2281. self:neatenCard(true)
  2282. end
  2283. if onEnd then
  2284. onEnd()
  2285. end
  2286. end
  2287. --用户碰(手动)
  2288. function changpaiRoomView:Peng(viewId,card,onEnd)
  2289. logD("function do Peng")
  2290. logE("changpaiRoomView Peng:",card)
  2291. local nUserID = app.room:getUserIdByViewId(viewId)
  2292. local mType = ZPDef.CardType.CARD_TYPE_GROUP_OUT
  2293. --[[
  2294. if viewId == 1 then
  2295. mType = ZPDef.CardType.CARD_TYPE_OPCARD_1
  2296. elseif viewId == 2 then
  2297. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  2298. elseif viewId == 3 then
  2299. mType = ZPDef.CardType.CARD_TYPE_OPCARD_3
  2300. elseif viewId == 4 then
  2301. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  2302. end
  2303. ]]
  2304. self:createOpOutcard(viewId,mType,card,3)
  2305. if viewId == self:getMeViewId() then
  2306. self:removeHandByNums(card,2)
  2307. self:neatenCard(true)
  2308. end
  2309. if onEnd then
  2310. onEnd()
  2311. end
  2312. end
  2313. --用户偷(手动)
  2314. function changpaiRoomView:Tou(viewId,card,onEnd)
  2315. logD("function do Tou")
  2316. logE("changpaiRoomView Tou:",card)
  2317. local nUserID = app.room:getUserIdByViewId(viewId)
  2318. local mType = ZPDef.CardType.CARD_TYPE_GROUP_OUT
  2319. --[[
  2320. if viewId == 1 then
  2321. mType = ZPDef.CardType.CARD_TYPE_OPCARD_1
  2322. elseif viewId == 2 then
  2323. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  2324. elseif viewId == 3 then
  2325. mType = ZPDef.CardType.CARD_TYPE_OPCARD_3
  2326. elseif viewId == 4 then
  2327. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  2328. end
  2329. ]]
  2330. self:createOpOutcard(viewId,mType,card,3)
  2331. if viewId == self:getMeViewId() then
  2332. self:removeHandByNums(card,3)
  2333. self:neatenCard(true)
  2334. end
  2335. local list = self.handCardValueLocal
  2336. if onEnd then
  2337. onEnd()
  2338. end
  2339. end
  2340. --用户巴(手动)
  2341. function changpaiRoomView:Ba(viewId,card,onEnd)
  2342. logD("function do Ba")
  2343. logE("changpaiRoomView Ba:",card)
  2344. local nUserID = app.room:getUserIdByViewId(viewId)
  2345. local mType = ZPDef.CardType.CARD_TYPE_GROUP_OUT
  2346. local operateCode = self.operationSuccessCode
  2347. --[[
  2348. if viewId == 1 then
  2349. mType = ZPDef.CardType.CARD_TYPE_OPCARD_1
  2350. elseif viewId == 2 then
  2351. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  2352. elseif viewId == 3 then
  2353. mType = ZPDef.CardType.CARD_TYPE_OPCARD_3
  2354. elseif viewId == 4 then
  2355. mType = ZPDef.CardType.CARD_TYPE_OPCARD_4
  2356. end
  2357. ]]
  2358. self:cleanOpOutCard(viewId,card)
  2359. --self:createOpOutcard(viewId,mType,card,1)
  2360. if viewId == self:getMeViewId() then
  2361. self:removeHandByNums(card,1)
  2362. self:neatenCard(true)
  2363. end
  2364. if onEnd then
  2365. onEnd()
  2366. end
  2367. end
  2368. function changpaiRoomView:doOperation(operationType,viewId,card,onEnd)
  2369. if operationType == ZPDef.OpType.OP_TYPE_CHI then
  2370. self:Chi(viewId,card,onEnd)
  2371. self:showOperatorTip(viewId,operationType)
  2372. elseif operationType == ZPDef.OpType.OP_TYPE_PENG then
  2373. self:Peng(viewId,card,onEnd)
  2374. self:showOperatorTip(viewId,operationType)
  2375. elseif operationType == ZPDef.OpType.OP_TYPE_BA then
  2376. self:Ba(viewId,card,onEnd)
  2377. self:showOperatorTip(viewId,operationType)
  2378. elseif operationType == ZPDef.OpType.OP_TYPE_TOU then
  2379. self:Tou(viewId,card,onEnd)
  2380. self:showOperatorTip(viewId,operationType)
  2381. elseif operationType == ZPDef.OpType.OP_TYPE_HU then
  2382. self:showOperatorTip(viewId,operationType)
  2383. end
  2384. end
  2385. --用户行为提示
  2386. function changpaiRoomView:showOperatorTip(viewId,mType)
  2387. if self.isBaopei and self.isBaopei == 1 and mType == ZPDef.OpType.OP_TYPE_CHI then
  2388. mType = -56 --吃后包赔
  2389. end
  2390. self.PlayerView:showOperatorTip(viewId,mType)
  2391. end
  2392. --弃牌动画
  2393. --断线重连的时候,不需要动画
  2394. --[[
  2395. isShowAni:是否展示弃牌动画
  2396. disCard:弃牌
  2397. viewId:视图ID
  2398. isDianPaoPeng:碰胡规则,点炮碰,弃牌要显示透明形态
  2399. ]]
  2400. function changpaiRoomView:playQiPaiAni(isShowAni,disCard,viewId,onEnd,isDianPaoPeng)
  2401. local outCardname = string.format("ImageView_outCardImg_%d",viewId)
  2402. local outCardPoint = string.format("Layout_outCardPoint_%d",viewId)
  2403. local giveupCardname = string.format("Layout_giveUp_%d",viewId)
  2404. if self.colorType == ZPDef.ColorType.YELLOW then
  2405. self.littleCardScale = 0.9
  2406. else
  2407. self.littleCardScale = 0.9
  2408. end
  2409. --牌的图片
  2410. local outCardImg = self.ui.Items[outCardname]
  2411. --牌的图片父节点
  2412. local outCardLayout = self.ui.Items[outCardPoint]
  2413. --弃牌的layout
  2414. local giveUpLayout = self.ui.Items[giveupCardname]
  2415. --获取弃牌节点存在的数量
  2416. local count = giveUpLayout:getChildrenCount()
  2417. --创建一张精灵
  2418. local mSprite = cc.ImageView:createNode()
  2419. mSprite:setScale(self.littleCardScale)
  2420. local finalFileName = ZPFuc.getZPCardImgByValue(disCard,ZPDef.CardType.CARD_TYPE_SMALL,self.colorType)
  2421. mSprite:loadTextureFromPlist(finalFileName)
  2422. mSprite:setScale(0.45)
  2423. mSprite:setVisible(false)
  2424. mSprite:setAnchorPoint(cc.p(0,0))
  2425. mSprite.value = disCard
  2426. giveUpLayout:addChild(mSprite)
  2427. local width = mSprite:getContentSize().width*0.5 * self.littleCardScale;
  2428. local height = mSprite:getContentSize().height*0.5* self.littleCardScale;
  2429. local getHeightCount = function (count)
  2430. local num = 6
  2431. if viewId == 2 then
  2432. num = 9
  2433. elseif viewId == self:getMeViewId() then
  2434. num = 7
  2435. end
  2436. if count >= num then
  2437. return math.floor(count / num)
  2438. else
  2439. return 0
  2440. end
  2441. end
  2442. local x = 0
  2443. if viewId == 2 then
  2444. x = count % 9
  2445. elseif viewId == self:getMeViewId() then
  2446. x = count % 7
  2447. else
  2448. x = count % 6
  2449. end
  2450. local tarPos
  2451. if viewId == 1 then
  2452. local adjustPos = cc.p(width * x,height * getHeightCount(count))
  2453. tarPos = cc.p(adjustPos.x,0 - adjustPos.y)
  2454. elseif viewId == 2 then
  2455. local adjustPos = cc.p(width * x,getHeightCount(count) * height)
  2456. tarPos = cc.p(adjustPos.x,0 - adjustPos.y)
  2457. elseif viewId == 3 then
  2458. local adjustPos = cc.p(width * x,height * getHeightCount(count))
  2459. tarPos = cc.p(0 + adjustPos.x,0 - adjustPos.y)
  2460. elseif viewId == self:getMeViewId() then
  2461. local adjustPos = cc.p(width * x,height * getHeightCount(count))
  2462. tarPos = cc.p(adjustPos.x,0 - adjustPos.y)
  2463. end
  2464. mSprite:setPosition(tarPos)
  2465. --动画显示
  2466. if not isShowAni then
  2467. mSprite:setVisible(true)
  2468. if isDianPaoPeng and isDianPaoPeng == 1 then
  2469. if self.colorType == ZPDef.ColorType.White then
  2470. mSprite:setColor(cc.c3b(255,223,125))
  2471. else
  2472. mSprite:setColor(cc.c3b(255,226,111))
  2473. end
  2474. end
  2475. else
  2476. local fileName = ZPFuc.getZPCardImgByValue(disCard,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  2477. --弃牌
  2478. local giveSprite = cc.ImageView:createNode()
  2479. giveSprite:loadTextureFromPlist(fileName)
  2480. giveSprite:setScale(self.outCardScale)
  2481. giveUpLayout:addChild(giveSprite)
  2482. giveSprite:setVisible(false)
  2483. local spriteSizeWidth = giveSprite:getContentSize().width * self.outCardScale
  2484. local spriteSizeHeight = giveSprite:getContentSize().height * self.outCardScale
  2485. local worldPos = outCardImg:convertToWorldSpace(outCardImg:getPosition())
  2486. local nodePos = giveUpLayout:convertToNodeSpace(worldPos)
  2487. --调整上下2个玩家的坐标和牌的角度
  2488. if viewId == 2 or viewId == 4 then
  2489. --nodePos = cc.p(nodePos.x - spriteSizeWidth,nodePos.y - spriteSizeHeight/2)
  2490. --giveSprite:setEulerRotation(cc.vec3(0,0,90))
  2491. end
  2492. giveSprite:setPosition(nodePos)
  2493. local mSpawn = cc.Spawn:create(cc.MoveTo:create(self.gameSpeedConfig.QI_PAI_TIME,tarPos),cc.ScaleTo:create(self.gameSpeedConfig.QI_PAI_TIME,self.outCardScale - 0.7))
  2494. giveSprite:runAction(cc.Sequence:create(cc.DelayTime:create(0.3),cc.CallFunc:create(function()
  2495. outCardLayout:setVisible(false)
  2496. giveSprite:setVisible(true)
  2497. end),mSpawn,cc.CallFunc:create(function()
  2498. mSprite:setVisible(true)
  2499. if isDianPaoPeng and isDianPaoPeng == 1 then
  2500. if self.colorType == ZPDef.ColorType.White then
  2501. mSprite:setColor(cc.c3b(255,223,125))
  2502. else
  2503. mSprite:setColor(cc.c3b(255,226,111))
  2504. end
  2505. end
  2506. end),cc.RemoveSelf:create()))
  2507. --要求弃牌飞到一半,摸牌就开始摸了
  2508. mSprite:runAction(cc.Sequence:create(cc.DelayTime:create(0.4 + self.gameSpeedConfig.QI_PAI_TIME/2),cc.CallFunc:create(function ()
  2509. if onEnd then
  2510. onEnd()
  2511. end
  2512. end)))
  2513. end
  2514. end
  2515. function changpaiRoomView:onUserGetCardOperteResponse(data)
  2516. local function runonUserGetCardOperte(onEnd)
  2517. log("2000000000-changpaiRoomView - (runonUserGetCardOperte)")
  2518. logE("runonUserGetCardOperte :"..table.tostring(data.response))
  2519. if data.response.nUserId == app.room:getMyUserId() then
  2520. if data.response.TouoperateCode ~= ZPDef.OpCode.OP_ERROR or data.response.BaoperateCode ~= ZPDef.OpCode.OP_ERROR then
  2521. local operationCardlist = {}
  2522. local opeateCode = 0
  2523. local ishu = data.response.ishu
  2524. local hasGuo = true
  2525. self.outCard = 0
  2526. if #data.response.BacardList > 0 then
  2527. operationCardlist[data.response.BaoperateCode] = data.response.BacardList
  2528. opeateCode = getNumOr(opeateCode,data.response.BaoperateCode)
  2529. end
  2530. --操作码
  2531. if #data.response.ToucardList > 0 then
  2532. operationCardlist[data.response.TouoperateCode] = data.response.ToucardList
  2533. opeateCode = getNumOr(opeateCode,data.response.TouoperateCode)
  2534. end
  2535. if ishu == 1 then
  2536. opeateCode = getNumOr(opeateCode,ZPDef.OpCode.OP_HU)
  2537. end
  2538. if ishu == 1 and self.isQiShou then
  2539. hasGuo = false
  2540. end
  2541. if not self.isQiShou and ishu == 1 then
  2542. operationCardlist[ZPDef.OpCode.OP_HU] = {}
  2543. table.insert(operationCardlist[ZPDef.OpCode.OP_HU],self.moValue)
  2544. end
  2545. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  2546. self.operationLocalCode = opeateCode
  2547. if self.operationLocalCode > 0 then
  2548. self:showOperation(opeateCode,operationCardlist,self.isQiShou,hasGuo)
  2549. self:setGuideView(false)
  2550. self.bOutCard = false
  2551. end
  2552. --self:setTotalTuoNum(data.response.totalTuoNum)
  2553. self.PlayerView:setPlayerTuoShu(viewId,data.response.totalTuoNum)
  2554. end
  2555. end
  2556. local operations = {}
  2557. --操作码
  2558. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  2559. operations[viewId] = {}
  2560. operations[viewId].nUserId = data.response.nUserId
  2561. operations[viewId].isCanOpereate = 1
  2562. self:showDelayTimeTip(operations)
  2563. if onEnd then
  2564. onEnd()
  2565. end
  2566. end
  2567. log("2000000000-changpaiRoomView - addCallBack(runonUserGetCardOperte)")
  2568. self:addCallBack(runonUserGetCardOperte);
  2569. end
  2570. function changpaiRoomView:playMoPaiAni(leftCardNum,turnOverCard,viewId,mainOpCode,showCardFlag,onEnd,isNotShowAni,isBaopeiChi,chiOpCardList)
  2571. self.isMoPaiOperator = true
  2572. --重置出牌坐标
  2573. self:resetOutCardPoint()
  2574. --图片
  2575. local outCardname = string.format("ImageView_outCardImg_%d",viewId)
  2576. local outCardLayoutName = string.format("Layout_outCardPoint_%d",viewId)
  2577. local mSprite = self.ui.Items[outCardname]
  2578. local srcPos = mSprite:getPosition()
  2579. local fileName = ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  2580. local fileNameReal = ZPFuc.getZPCardImgByValue(turnOverCard,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  2581. self.ui.Items[outCardLayoutName]:setVisible(true)
  2582. if viewId == self:getMeViewId() then
  2583. mSprite:loadTextureFromPlist(fileNameReal)
  2584. end
  2585. --公谱出牌不串不哨立马亮牌,看到亮牌的听得到牌的音效
  2586. if mainOpCode ~= ZPDef.OpCode.OP_CANCEL and mainOpCode ~= ZPDef.OpCode.OP_ERROR then
  2587. mSprite:loadTextureFromPlist(fileNameReal)
  2588. else
  2589. if showCardFlag == 1 then
  2590. mSprite:loadTextureFromPlist(fileNameReal)
  2591. if not isNotShowAni then
  2592. local nUserId = app.room:getUserIdByViewId(viewId)
  2593. local userInfo=app.room:getUserInfo(nUserId)
  2594. if userInfo then
  2595. if turnOverCard > 0 then
  2596. ZPSound.PlayZPSound(userInfo.sex,turnOverCard)
  2597. end
  2598. end
  2599. end
  2600. else
  2601. mSprite:loadTextureFromPlist(fileName)
  2602. end
  2603. end
  2604. self:changeOutCardLight(true)
  2605. local function callback()
  2606. local operationCardlist = {}
  2607. if mainOpCode ~= ZPDef.OpCode.OP_CANCEL and mainOpCode ~= ZPDef.OpCode.OP_ERROR then
  2608. operationCardlist[ZPDef.OpCode.OP_PENG] = {}
  2609. table.insert(operationCardlist[ZPDef.OpCode.OP_PENG],turnOverCard)
  2610. operationCardlist[ZPDef.OpCode.OP_BA_FAN] = {}
  2611. table.insert(operationCardlist[ZPDef.OpCode.OP_BA_FAN],turnOverCard)
  2612. operationCardlist[ZPDef.OpCode.OP_HU] = {}
  2613. table.insert(operationCardlist[ZPDef.OpCode.OP_HU],turnOverCard)
  2614. operationCardlist[ZPDef.OpCode.OP_CHI] = {}
  2615. for k,v in ipairs(chiOpCardList or {}) do
  2616. table.insert(operationCardlist[ZPDef.OpCode.OP_CHI],v)
  2617. end
  2618. end
  2619. if mainOpCode ~= ZPDef.OpCode.OP_CANCEL and mainOpCode ~= ZPDef.OpCode.OP_ERROR then
  2620. self.EatOperationCode = mainOpCode
  2621. self:showOperation(mainOpCode,operationCardlist,self.isQiShou,true)
  2622. end
  2623. end
  2624. if isNotShowAni then
  2625. mSprite:setPosition(srcPos)
  2626. callback()
  2627. if onEnd then
  2628. onEnd()
  2629. end
  2630. return
  2631. else
  2632. local outCardLightName = string.format("ImageView_outCardLight_%d",viewId)
  2633. self.ui.Items[outCardLightName]:setVisible(false)
  2634. mSprite:setScale(0)
  2635. if showCardFlag ~= 1 then
  2636. mSprite:loadTextureFromPlist(fileName)
  2637. --起始坐标调整和角度,扫为横的出来
  2638. if viewId == self:getMeViewId() then
  2639. mSprite:setEulerRotation(cc.vec3(0,0,0))
  2640. beginPos = cc.p(srcPos.x,srcPos.y + 200)
  2641. elseif viewId == 1 then
  2642. mSprite:setEulerRotation(cc.vec3(0,0,-90))
  2643. beginPos = cc.p(srcPos.x - 200 ,srcPos.y)
  2644. elseif viewId == 2 then
  2645. mSprite:setEulerRotation(cc.vec3(0,0,0))
  2646. beginPos = cc.p(srcPos.x,srcPos.y - 100)
  2647. elseif viewId == 3 then
  2648. mSprite:setEulerRotation(cc.vec3(0,0,-90))
  2649. beginPos = cc.p(srcPos.x + 200 ,srcPos.y-50)
  2650. end
  2651. mSprite:setPosition(beginPos)
  2652. --目标调整、角度
  2653. if viewId == 1 then
  2654. srcPos = cc.p(srcPos.x + 250,srcPos.y)
  2655. elseif viewId == 2 then
  2656. srcPos = cc.p(srcPos.x,srcPos.y+50)
  2657. elseif viewId == 3 then
  2658. srcPos = cc.p(srcPos.x - 250,srcPos.y-50)
  2659. elseif viewId == 4 then
  2660. srcPos = cc.p(srcPos.x,srcPos.y-100)
  2661. end
  2662. mSprite:setScale(1)
  2663. mSprite:runAction(cc.Sequence:create(cc.MoveTo:create(0.3,srcPos),cc.CallFunc:create(function ()
  2664. self.ui.Items[outCardLightName]:setVisible(true)
  2665. end),cc.CallFunc:create(function()
  2666. --恢复原来的角度
  2667. if viewId == self:getMeViewId() then
  2668. mSprite:setEulerRotation(cc.vec3(0,0,90))
  2669. elseif viewId == 1 then
  2670. mSprite:setEulerRotation(cc.vec3(0,0,0))
  2671. elseif viewId == 2 then
  2672. mSprite:setEulerRotation(cc.vec3(0,0,90))
  2673. elseif viewId == 3 then
  2674. mSprite:setEulerRotation(cc.vec3(0,0,0))
  2675. end
  2676. self.ui.Items[outCardLayoutName]:setVisible(false)
  2677. self:setCircleCardLeftPanelView(true,viewId,leftCardNum)
  2678. callback()
  2679. if onEnd then
  2680. onEnd()
  2681. end
  2682. end)))
  2683. else
  2684. if mainOpCode ~= ZPDef.OpCode.OP_CANCEL and mainOpCode ~= ZPDef.OpCode.OP_ERROR then
  2685. local nUserId = app.room:getUserIdByViewId(viewId)
  2686. local userInfo=app.room:getUserInfo(nUserId)
  2687. if userInfo then
  2688. ZPSound.PlayZPSound(userInfo.sex,turnOverCard)
  2689. end
  2690. end
  2691. --播放摸牌动画(这里最好用出牌器的坐标进行转换,暂时这样调整吧)
  2692. if viewId == self:getMeViewId() then
  2693. beginPos = cc.p(srcPos.x,srcPos.y + 200)
  2694. elseif viewId == 1 then
  2695. beginPos = cc.p(srcPos.x - 300 ,srcPos.y)
  2696. elseif viewId == 2 then
  2697. beginPos = cc.p(srcPos.x ,srcPos.y - 200)
  2698. elseif viewId == 3 then
  2699. beginPos = cc.p(srcPos.x + 300 ,srcPos.y)
  2700. end
  2701. mSprite:setPosition(beginPos)
  2702. local mSpawn = cc.Spawn:create(cc.ScaleTo:create(self.gameSpeedConfig.MO_PAI_TIME,1.0),cc.MoveTo:create(self.gameSpeedConfig.MO_PAI_TIME,srcPos))
  2703. mSprite:runAction(cc.Sequence:create(mSpawn,cc.CallFunc:create(function ()
  2704. self.ui.Items[outCardLightName]:setVisible(true)
  2705. --显示指示器
  2706. self:setCircleCardLeftPanelView(true,viewId,leftCardNum)
  2707. end),cc.DelayTime:create(0.15),cc.CallFunc:create(function()
  2708. callback()
  2709. if onEnd then
  2710. onEnd()
  2711. end
  2712. end)))
  2713. end
  2714. end
  2715. end
  2716. --摸牌
  2717. function changpaiRoomView:onMoPai(data)
  2718. local function runOnMoPai(onEnd)
  2719. local response = data.response
  2720. local nUserId = response.nUserId
  2721. local turnOverCard = response.turnOverCard
  2722. local code = response.mainOpCode
  2723. local leftCardNum = response.leftCardNum
  2724. --local operations = response.operations
  2725. local isBaopeiChi = response.Baopeichi
  2726. local chiOpCardlist = response.chiOpCardList
  2727. if isBaopeiChi == 1 then
  2728. self.isTishi = true
  2729. end
  2730. self.isBiChi = isBaopeiChi
  2731. local viewId = app.room:getViewIdByUserId(nUserId)
  2732. self.EatOperationCode = code
  2733. self.outCard = turnOverCard
  2734. self.moPaiViewId = viewId
  2735. self:showDelayTimeTip()
  2736. --更新剩余牌数
  2737. self:playMoPaiAni(leftCardNum,turnOverCard,viewId,code,1,onEnd,false,isBaopeiChi,chiOpCardlist)
  2738. if self.bankerBaoPao then
  2739. self.bankerBaoPao = nil
  2740. self:showTiPaiBtn(true)
  2741. --小家不能看牌时,牌堆牌显示剩余张数
  2742. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  2743. self:setCircleCardLeftPanelView(true,viewId,19)
  2744. end
  2745. end
  2746. if self:getIsMeUId(nUserId) then
  2747. --检测是否少牌
  2748. self:checkCardAndRecover()
  2749. end
  2750. --[[ --结束 一定要等到摸牌动画结束才结束整个摸牌流程
  2751. if onEnd then
  2752. onEnd()
  2753. end--]]
  2754. end
  2755. log("2000000000-ZPRoomView - addCallBack(runOnMoPai)")
  2756. self:addCallBack(runOnMoPai)
  2757. end
  2758. -- 小局结算
  2759. function changpaiRoomView:onGameXiaoJuResponse(data)
  2760. local function runGameXiaoJuResponse(onEnd)
  2761. self:hideOperation()
  2762. self.ui.Items.Button_tipai:setVisible(false)
  2763. self.PlayerView:stopAndHideBaoAnim()
  2764. self.PlayerView:hideLeftCard()
  2765. self.ui.Items.ImageView_tou_tip:setVisible(false)
  2766. --显示所有底牌
  2767. local response = data.response;
  2768. --标记单局结束
  2769. self.isGameOver = true
  2770. --禁止出牌
  2771. self.bOutCard = false
  2772. local roomInfo = app.room.roomInfo
  2773. --结束原因
  2774. roomInfo.stopFlag = response.stopFlag
  2775. --赢家uid, -1则下面6个字段是无用
  2776. roomInfo.winUserId = response.winUserId
  2777. --点炮胡时,表示为点炮用户
  2778. roomInfo.dianPaoUserId = response.dianPaoUserId
  2779. --胡的类型(如天胡、地胡 ,自摸胡等)
  2780. roomInfo.huType = response.huTypes
  2781. --多少个玩家
  2782. roomInfo.playList = response.playList
  2783. --底牌信息
  2784. roomInfo.dipaiList = response.dipaiList
  2785. --胡牌牌值
  2786. roomInfo.huCard = response.huCard
  2787. --是否大局结束,结束是1
  2788. roomInfo.isGameOver = response.isGameOver
  2789. --胡牌信息
  2790. roomInfo.hupaiInfo = response.hupaiInfo
  2791. --是否自摸胡
  2792. roomInfo.isZiMoHu = response.isZiMoHu
  2793. local function showChaPai()
  2794. self:setLiangPaiVisible(true)
  2795. end
  2796. local isSomebodyHuPai = false
  2797. for i,v in pairs(roomInfo.hupaiInfo) do
  2798. local viewId = app.room:getViewIdByUserId(v.huPaiUid)
  2799. roomInfo.dianPaoUserId = v.dianPaoUid
  2800. roomInfo.baopeiUserid = app.room:getUserIdBySeatId(v.BaoPeiUid)
  2801. roomInfo.fourNormolNum = v.fourNormolNum
  2802. roomInfo.fourHongNum = v.fourHongNum
  2803. roomInfo.threeHongNum = v.threeHongNum
  2804. roomInfo.huCard = v.huCard
  2805. self.PlayerView:setPlayerHuXi(v.huPaiHuShu)
  2806. roomInfo.huType = v.huTypes
  2807. self:playHuEffect(viewId,showChaPai)
  2808. isSomebodyHuPai = true
  2809. end
  2810. --所有的暗偎默认亮起一张
  2811. --self:showLastAnWeiPai()
  2812. --完成底牌展示
  2813. self.xiaojuChaPaiView:showDiPai()
  2814. --完成手牌展示
  2815. for k,v in pairs(roomInfo.playList) do
  2816. local cardData = app.room:serverCardToMyCard(v.handCard)
  2817. if not roomInfo.memberList[v.nUserId] then
  2818. roomInfo.memberList[v.nUserId] = {}
  2819. end
  2820. roomInfo.memberList[v.nUserId].cardList = {}
  2821. roomInfo.memberList[v.nUserId].cardList = cardData
  2822. local tuoNum = v.totalTuoNum
  2823. local viewId = app.room:getViewIdByUserId(v.nUserId)
  2824. self.PlayerView:setPlayerTuoShu(viewId,tuoNum)
  2825. --[[logE("XiaoJu nUserID:"..v.nUserId)
  2826. logE("XiaoJu cardList:"..table.tostring(cardData))--]]
  2827. end
  2828. self.xiaojuChaPaiView:liangShouPai(false)
  2829. --玩家分数
  2830. for k,v in pairs(roomInfo.playList) do
  2831. local viewId = app.room:getViewIdByUserId(k)
  2832. local nScore = v.nTotalMoney
  2833. local memberInfo = app.room.roomInfo.memberList[k]
  2834. --[[roomInfo.memberList[v.nUserId].nPlayerFlag = 0--]]
  2835. memberInfo.nTotalMoney = nScore
  2836. self.PlayerView:setPlayerScore(viewId,nScore)
  2837. end
  2838. --结束原因表现
  2839. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG or (not isSomebodyHuPai and roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_TUOGUAN_DISMISS) then
  2840. showChaPai()
  2841. --播放黄庄动画
  2842. local userInfo=app.room:getUserInfo(app.user.loginInfo.uid)
  2843. if userInfo then
  2844. ZPSound.PlayHuangZhuang(userInfo.sex)
  2845. end
  2846. self.xiaojuChaPaiView:PlayHuangZhuangAni(true)
  2847. elseif roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_LONG_NOT_END then
  2848. -- showConfirmDialog("游戏长久未打完,超过房间存在时间,本局结束",function()
  2849. -- logE("超时回到大厅")
  2850. -- self:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
  2851. -- --房间号
  2852. -- local roomid = app.room.roomInfo.nShowTableId
  2853. -- --app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId, roomid))
  2854. -- gotoMainView(app.gameId,roomid)
  2855. -- end)))
  2856. -- end,nil)
  2857. end
  2858. local function nextCallBackFun()
  2859. self:resetGameData()
  2860. app.room.roomInfo.tingCards = {}
  2861. end
  2862. local function showAllJieSuan()
  2863. if self.RoomCountAllViewUI then
  2864. if not self.RoomCountAllViewUI:isVisible() then
  2865. self.RoomCountAllViewUI:playAni()
  2866. end
  2867. self.RoomCountAllViewUI:setVisible(true)
  2868. self:showGameOverAward()
  2869. end
  2870. end
  2871. if app.room.roomInfo.isGameOver == 0 then
  2872. self.xiaojuView = changpaiRoomXiaoJuView:new(nextCallBackFun,false,self.colorType)
  2873. else
  2874. self.xiaojuView = changpaiRoomXiaoJuView:new(showAllJieSuan,false,self.colorType)
  2875. end
  2876. self:addChild(self.xiaojuView)
  2877. self.xiaojuView:setVisible(false)
  2878. --结束
  2879. if onEnd then
  2880. onEnd()
  2881. end
  2882. end
  2883. log("2000000000-changpaiRoomView - addCallBack(runGameXiaoJuResponse)" )
  2884. self:addCallBack(runGameXiaoJuResponse);
  2885. end
  2886. function changpaiRoomView:onQiangBaResponese(data)
  2887. log("2000000000-changpaiRoomView - addCallBack(onQiangBaResponese)" )
  2888. local function runQiangBa(onEnd)
  2889. local response = data.response
  2890. local nUserId = response.nUserId
  2891. local Card = response.nCard
  2892. local code = response.mainOpCode
  2893. local viewId = app.room:getViewIdByUserId(nUserId)
  2894. local operationCardlist = {}
  2895. operationCardlist[ZPDef.OpCode.OP_HU] = {}
  2896. table.insert(operationCardlist[ZPDef.OpCode.OP_HU],Card)
  2897. if code > 0 then
  2898. self:showOperation(code,operationCardlist,false,true)
  2899. end
  2900. if self:getIsMeUId(nUserId) then
  2901. --检测是否少牌
  2902. self:checkCardAndRecover()
  2903. end
  2904. --结束
  2905. if onEnd then
  2906. onEnd()
  2907. end
  2908. end
  2909. log("2000000000-ZPRoomView - addCallBack(runQiangBa)")
  2910. self:addCallBack(runQiangBa)
  2911. end
  2912. --弃牌
  2913. function changpaiRoomView:onQiPai(data)
  2914. changpaiRoomView.super.onQiPai(self, data)
  2915. local function runOnQiPai(onEnd)
  2916. self:hideOperation()
  2917. --结束
  2918. if onEnd then
  2919. onEnd()
  2920. end
  2921. end
  2922. log("2000000000-changpaiRoomView - addCallBack(runOnQiPai)")
  2923. self:addCallBack(runOnQiPai)
  2924. end
  2925. --游戏消息
  2926. function changpaiRoomView:bindGameMessage()
  2927. changpaiRoomView.super.bindGameMessage(self)
  2928. --起手操作提示
  2929. self:bindEvent(app.room , "onUserOperateResponse", handler(self , self.onUserOperateResponse));
  2930. --起手操作成功
  2931. self:bindEvent(app.room , "onBroadCastQiShouOperate", handler(self , self.onUserOperateSuccess));
  2932. --广播玩家进牌
  2933. self:bindEvent(app.room , "onBroadCastUserGetCard", handler(self , self.onBroadCastUserGetCard));
  2934. --广播头家出牌
  2935. self:bindEvent(app.room , "onBroadCastBankerOutCard", handler(self , self.onBroadCastBankerOutCard));
  2936. --通知打出的牌可能包赔
  2937. self:bindEvent(app.room , "onOutCardIsBaoPeiResponse", handler(self , self.onOutCardIsBaoPeiResponse));
  2938. --通知进牌后操作提示
  2939. self:bindEvent(app.room , "onUserGetCardOperteResponse", handler(self , self.onUserGetCardOperteResponse));
  2940. --刷新手牌
  2941. self:bindEvent(app.room , "onReflashHandcardsResponese" , handler(self , self.onReflashHandcardsResponese));
  2942. --抢巴操作通知
  2943. self:bindEvent(app.room , "onQiangBaResponese" , handler(self , self.onQiangBaResponese));
  2944. --切换视图
  2945. self:bindEvent(app , ZPDef.ZPEvent.ChangeViewType, handler(self, self.changeViewType))
  2946. --过巴操作
  2947. self:bindEvent(app.room, "onGuoBaResponse", handler(self, self.onGuoBaResponse))
  2948. -- 托管
  2949. self:bindEvent(app.room , ZPDef.ZPEvent.HostingRequest, handler(self, self.onHostingRequest))
  2950. end
  2951. function changpaiRoomView:changeViewType(event)
  2952. if event and event.desktopType and self.desktopType~=event.desktopType then
  2953. self.desktopType=event.desktopType
  2954. end
  2955. if event and event.colorType and self.desktopType~=event.colorType then
  2956. self.colorType=event.colorType
  2957. self:initMySelfCardPos()
  2958. if self.xiaojuChaPaiView then
  2959. self.xiaojuChaPaiView:setCardColorType(event.colorType)
  2960. end
  2961. end
  2962. self:loadTextureCache()
  2963. self.ui:sendMsg(app.room,ZPDef.ZPEvent.GetTableInfo)
  2964. end
  2965. function changpaiRoomView:showOperation(mainOpCode,viewId,card,hasGuo)
  2966. self.operationView:setVisible(true)
  2967. self.operationView:setSameParame(self.outCard,self.handCardValueLocal)
  2968. local ret1 = bit32.band(mainOpCode,ZPDef.OpCode.OP_HU)
  2969. if ret1 > 0 and self.baoJiaoStatus == 1 then
  2970. hasGuo = false
  2971. end
  2972. if self.isBiChi and self.isBiChi == 2 then
  2973. hasGuo = false
  2974. end
  2975. self.operationView:showOperation(mainOpCode,viewId,card,hasGuo,self.isTishi,self.colorType)
  2976. --检测是否少牌
  2977. --self:neatenCard(true)--无感知的整理一次手牌
  2978. self:checkCardAndRecover()
  2979. self.isTishi = false
  2980. end
  2981. function changpaiRoomView:hideOperation()
  2982. self.operationView:hideSelf()
  2983. end
  2984. --判断列数是否是砍牌
  2985. function changpaiRoomView:getCurrentColIsKan(list)
  2986. local isKan = false
  2987. if list[1] and list[2] and list[3] then
  2988. if list[1] == list[2] and list[2] == list[3] then
  2989. isKan = true
  2990. end
  2991. end
  2992. return false
  2993. end
  2994. --判断列数是否是龙
  2995. function changpaiRoomView:getCurrentColIsLong(list)
  2996. local isLong = false
  2997. if list[1] and list[2] and list[3] and list[4] then
  2998. if list[1] == list[2] and list[2] == list[3] and list[3] == list[4] then
  2999. isLong = true
  3000. end
  3001. end
  3002. return false
  3003. end
  3004. function changpaiRoomView:resetGameData()
  3005. changpaiRoomView.super.resetGameData(self)
  3006. self.isQiShou = true
  3007. self.moValue = 0
  3008. for i = 1,ZPDef.GameMaxPlayer do
  3009. self.PlayerView:setPlayerTuoShu(i, 0)
  3010. end
  3011. self.isBiChi = 0
  3012. --self:setTotalTuoNum(0)
  3013. self.handCardItem = {}
  3014. self:cleanOpOutCard()
  3015. self.PlayerView:hideBaoJiao()
  3016. self.baoJiaoStatus = 0
  3017. self.isTishi = false
  3018. self.moLieshu = 0
  3019. self.myHandCardNums = 0
  3020. end
  3021. --设置总坨数
  3022. --[[
  3023. function changpaiRoomView:setTotalTuoNum(num)
  3024. self.ui.Items.Text_tuoNum:setText(tostring(num))
  3025. end
  3026. ]]
  3027. --隐藏出牌点
  3028. function changpaiRoomView:setOutCardVisible(bVisible,viewId,card,isSend,onEnd,isNoShowAni)
  3029. for i = 1 ,ZPDef.GameMaxPlayer do
  3030. local name = string.format("Layout_outCardPoint_%d",i)
  3031. self.ui.Items[name]:setVisible(false)
  3032. end
  3033. --重置出牌坐标
  3034. self:resetOutCardPoint()
  3035. --显示出牌
  3036. if bVisible then
  3037. self.isMoPaiOperator = false
  3038. self:changeOutCardLight(false)
  3039. local name = string.format("Layout_outCardPoint_%d",viewId)
  3040. local mLayout = self.ui.Items[name]
  3041. mLayout:setVisible(true)
  3042. local imgName = string.format("ImageView_outCardImg_%d",viewId)
  3043. local fileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  3044. local mSprite = self.ui.Items[imgName]
  3045. local srcPos = mSprite:getPosition()
  3046. self.ui.Items[imgName]:loadTextureFromPlist(fileName)
  3047. local beginPos
  3048. local time = self.gameSpeedConfig.CHU_PAI_TIME
  3049. if viewId == self:getMeViewId() then
  3050. beginPos = self.ui.Items.ImageView_handTempCard:getPosition()
  3051. beginPos = mSprite:getParent():convertToNodeSpace(beginPos)
  3052. else
  3053. if viewId == 1 then
  3054. beginPos = cc.p(srcPos.x + 400,srcPos.y)
  3055. elseif viewId == 2 then
  3056. beginPos = cc.p(srcPos.x,srcPos.y + 200)
  3057. elseif viewId == 3 then
  3058. beginPos = cc.p(srcPos.x - 400,srcPos.y)
  3059. end
  3060. end
  3061. mSprite:setPosition(beginPos)
  3062. mSprite:setScale(0)
  3063. if isNoShowAni then
  3064. mSprite:setScale(1)
  3065. mSprite:setPosition(srcPos)
  3066. if onEnd then
  3067. onEnd()
  3068. end
  3069. return
  3070. end
  3071. local spawn = cc.Spawn:create(cc.ScaleTo:create(time,1,1),cc.MoveTo:create(time,srcPos))
  3072. local seq = cc.Sequence:create(spawn,cc.CallFunc:create(function ()
  3073. if isSend then
  3074. local request = ZPMessage.OutCard:new()
  3075. request.nCard = card
  3076. --默认包赔为0
  3077. request.baoPei = 0
  3078. logE("changpaiRoomView:setOutCardVisible"..table.tostring(request))
  3079. self.ui:sendMsg(app.room, "sendOutCard", request, function(status, response)
  3080. logE("changpaiRoomView sendOutCard() response = ", table.tostring(response))
  3081. end)
  3082. end
  3083. if onEnd then
  3084. onEnd()
  3085. end
  3086. end))
  3087. mSprite:runAction(seq)
  3088. end
  3089. end
  3090. function changpaiRoomView:getMoCardPos()
  3091. local showColNum = self:getVisibleCardLayoutNum()
  3092. local orederPos = cc.p(900,-80)
  3093. if showColNum == 0 then
  3094. return orederPos
  3095. end
  3096. if showColNum <= self.lieShuMax then
  3097. --根据当前存在的列数获取一个枚举列表,让手牌的列数重新旋转到指定新的列数
  3098. local list = self.lieshulist[showColNum]
  3099. local youIndex = 0
  3100. for k = 1,self.lieShuMax do
  3101. if #self.handCardValueLocal[k] > 0 then
  3102. youIndex = youIndex + 1
  3103. end
  3104. end
  3105. local index = list[youIndex] + 1 -- 3 4 5 6 7 8 摸牌的位置要和手牌隔开
  3106. local tarPos = self.boxPosList4[index]
  3107. orederPos.x = tarPos.x + 10
  3108. orederPos.y = tarPos.y
  3109. end
  3110. return orederPos
  3111. end
  3112. function changpaiRoomView:getMoCardLieMax()
  3113. local showColNum = self:getVisibleCardLayoutNum()
  3114. logD("changpaiRoomView getMoCardLieMax",showColNum)
  3115. if showColNum == 0 then
  3116. return 5
  3117. end
  3118. local tempLieshu = self.lieShuMax + 1
  3119. if showColNum <= tempLieshu then
  3120. --根据当前存在的列数获取一个枚举列表,让手牌的列数重新旋转到指定新的列数
  3121. local list = self.lieshulist[showColNum]
  3122. local youIndex = 0
  3123. for k = 1,self.lieShuMax do
  3124. if #self.handCardValueLocal[k] > 0 then
  3125. youIndex = youIndex + 1
  3126. end
  3127. end
  3128. local index = list[youIndex] + 1 -- 3 4 5 6 7 8 摸牌的位置要和手牌隔开
  3129. return index
  3130. end
  3131. return 5
  3132. end
  3133. function changpaiRoomView:setColorWhite()
  3134. if app.room:isLittleFamily() and not ZPFuc.getLittleIsCanLookCard() then
  3135. return
  3136. end
  3137. self.ui.Items.Button_OutCard:setEnabled(false)
  3138. local tempLieshu = self.lieShuMax + 1
  3139. for col = 1, tempLieshu do
  3140. for row = 1,self.hangShuMax do
  3141. if not self.handCardRoot[col].imgList[row].isKan then
  3142. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  3143. end
  3144. end
  3145. end
  3146. end
  3147. function changpaiRoomView:requestFlashHandCard()
  3148. local request = ZPMessage.ReflashHandCard:new()
  3149. request.isFflash = 1
  3150. logE("reflashHandCard:"..table.tostring(request))
  3151. self.ui:sendMsg(app.room, "reflashHandCard", request, function(status, response)
  3152. logE("changpaiRoomView reflashHandCard() response = ", table.tostring(response))
  3153. end)
  3154. end
  3155. --检测是否少牌,如果少牌则恢复 --目前在抓牌,出牌成功,和显示操作三个地方检测少牌情况
  3156. function changpaiRoomView:checkCardAndRecover()
  3157. --当前的手牌数
  3158. local curCardNum = 0
  3159. --当前显示的手牌数
  3160. local curShowNum = 0
  3161. --实际手牌数
  3162. local factCardNum = 0
  3163. --计算当前手牌数
  3164. for i,cards in pairs(self.handCardValueLocal) do
  3165. for j,card in pairs(cards) do
  3166. if card and card > 0 then
  3167. curCardNum = curCardNum + 1
  3168. end
  3169. end
  3170. end
  3171. --计算当前显示的手牌数
  3172. local tempLieshu = self.lieShuMax + 1
  3173. for i = 1,tempLieshu do
  3174. if self.handCardRoot[i].ui:isVisible() then
  3175. for j = 1,self.hangShuMax do
  3176. if self.handCardRoot[i].imgList[j]:isVisible() and self.handCardRoot[i].imgList[j]:getOpacity() == 255
  3177. and self.handCardRoot[i].imgList[j].value then
  3178. curShowNum = curShowNum + 1
  3179. end
  3180. end
  3181. end
  3182. end
  3183. --计算备份数据的手牌数(以这个数据为准)
  3184. for i,cards in pairs(self.handCardValueBak) do
  3185. for j,card in pairs(cards) do
  3186. if card and card > 0 then
  3187. factCardNum = factCardNum + 1
  3188. end
  3189. end
  3190. end
  3191. logD("checkCardAndRecover curCardNum="..curCardNum.." curShowNum="..curShowNum.." factCardNum="..factCardNum)
  3192. if curCardNum ~= factCardNum or curShowNum ~= factCardNum then
  3193. print("checkCardAndRecover curCardNum="..curCardNum.." curShowNum="..curShowNum.." factCardNum="..factCardNum)
  3194. logD("checkCardAndRecover self.handCardValueBak---",table.tostring(self.handCardValueBak));
  3195. logD("checkCardAndRecover self.handCardValueLocal---",table.tostring(self.handCardValueLocal));
  3196. --self:onTransferCard(self.handCardValueBak)
  3197. self:requestFlashHandCard()
  3198. --uploadLogs("changpaipaishaopai")
  3199. end
  3200. end
  3201. --如果牌正在掉落的时候,不允许操作!
  3202. --落牌检测
  3203. function changpaiRoomView:downCard()
  3204. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  3205. return
  3206. end
  3207. --是否需要掉落
  3208. local bDown = false
  3209. local temphangshu = self.hangShuMax - 1
  3210. for i = 1,self.lieShuMax do
  3211. if self.handCardRoot[i].ui:isVisible() then
  3212. for j = 1, temphangshu do
  3213. for k = j+1,self.hangShuMax do
  3214. if not self.handCardRoot[i].imgList[j]:isVisible() and self.handCardRoot[i].imgList[k]:isVisible() then
  3215. --底部
  3216. local firstValue = self.handCardRoot[i].imgList[j].value
  3217. --顶部
  3218. local secondeValue = self.handCardRoot[i].imgList[k].value
  3219. --插入
  3220. --数据交换
  3221. local tempValue = nil
  3222. tempValue = self.handCardRoot[i].imgList[j].value
  3223. self.handCardRoot[i].imgList[j].value = self.handCardRoot[i].imgList[k].value
  3224. self.handCardRoot[i].imgList[k].value = tempValue
  3225. --换底数据
  3226. --[[local tempHuanDi = nil
  3227. tempHuanDi = self.handCardRoot[i].imgList[j].isHuanDi
  3228. self.handCardRoot[i].imgList[j].isHuanDi = self.handCardRoot[i].imgList[k].isHuanDi
  3229. self.handCardRoot[i].imgList[k].isHuanDi = tempHuanDi--]]
  3230. --ui交换
  3231. self.handCardRoot[i].imgList[k]:setVisible(false)
  3232. local fileName = ZPFuc.getZPCardImgByValue(self.handCardRoot[i].imgList[j].value,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  3233. self.handCardRoot[i].imgList[j]:loadTextureFromPlist(fileName)
  3234. self.handCardRoot[i].imgList[j]:setVisible(true)
  3235. --听牌标签
  3236. local visibleA = self.handCardRoot[i].imgList[j]:getChildren()[1]:isVisible()
  3237. local visibleB = self.handCardRoot[i].imgList[k]:getChildren()[1]:isVisible()
  3238. self.handCardRoot[i].imgList[j]:getChildren()[1]:setVisible(visibleB)
  3239. self.handCardRoot[i].imgList[k]:getChildren()[1]:setVisible(visibleA)
  3240. --落牌动画
  3241. local lieshu = self.ui.Items.ImageView_handTempCard.lieshu
  3242. local value = self.ui.Items.ImageView_handTempCard.value
  3243. --if self.handCardRoot[i].imgList[j].value == value and i == lieshu then
  3244. -- self:goBackWithAni(self.handCardRoot[i].imgList[j])
  3245. --else
  3246. local recordPos = self.handCardRoot[i].imgList[j]:getParent():getPosition()
  3247. self.handCardRoot[i].imgList[j]:getParent():setPosition(self.handCardRoot[i].imgList[k]:getParent():getPosition())
  3248. local act = cc.MoveTo:create(self.gameSpeedConfig.OPCARDTIME,recordPos)
  3249. --self.handCardRoot[i].imgList[j]:getParent():stopAllActions()
  3250. self.handCardRoot[i].imgList[j]:getParent():runAction(act)
  3251. --end
  3252. bDown = true
  3253. end
  3254. end
  3255. end
  3256. end
  3257. end
  3258. --判断是否有掉落
  3259. if not bDown then
  3260. self.isGodHand = false
  3261. else
  3262. local seq = cc.Sequence:create(cc.DelayTime:create(0.25),cc.CallFunc:create(function ()
  3263. self.isGodHand = false
  3264. end))
  3265. self.ui:runAction(seq)
  3266. end
  3267. end
  3268. --整理牌
  3269. function changpaiRoomView:neatenCard(isNotShowAni)
  3270. --logE("neatenCard -------- ", debug.traceback())
  3271. --摆放摸牌
  3272. --self:reflashHandCards()
  3273. --是否短暂屏蔽点击牌事件
  3274. self:downCard()
  3275. self:RankCard(isNotShowAni)
  3276. self:unLockYouPai()
  3277. if app.room.roomInfo.disCard then
  3278. local num = table.nums(app.room.roomInfo.disCard)
  3279. if num > 0 then
  3280. self:lockYouPai(app.room.roomInfo.disCard)
  3281. end
  3282. end
  3283. if self.baoJiaoStatus == 1 then
  3284. self:lockMyHandCards()
  3285. end
  3286. end
  3287. --注册点击事件
  3288. function changpaiRoomView:registerCardTouch()
  3289. local function getPosOO()
  3290. local nodeTouch = self.ui.Items.Layout_Touch;
  3291. local posTouch = nodeTouch:getWorldPosition()
  3292. local poaAnchor = nodeTouch:getAnchorPoint()
  3293. local sizeTouch = nodeTouch:getContentSize();
  3294. local posOO = { x = posTouch.x - sizeTouch.width * poaAnchor.x , y = posTouch.y - sizeTouch.height * poaAnchor.y}
  3295. return posOO;
  3296. end
  3297. --触摸
  3298. for k,v in ipairs(self.handCardItem) do
  3299. local function onTouchBegan(touch)
  3300. --[[if app.room:isLittleFamily() then
  3301. --showTooltip("小家禁止操作")
  3302. return
  3303. end--]]
  3304. if self.isGodHand then
  3305. --showTooltip("禁止操作")
  3306. return
  3307. end
  3308. local posOO = getPosOO()
  3309. local localPos = touch:getLocation();
  3310. local pos = cc.p(localPos.x - posOO.x, localPos.y - posOO.y);
  3311. local lieshu = v.lieshu
  3312. local hangshu = v.hangshu
  3313. local value = v.value
  3314. local isKan = v.isKan
  3315. if isKan then
  3316. --showTooltip("坎牌不可移动")
  3317. return
  3318. end
  3319. self.handCardRoot[lieshu].ui:setVisible(true)
  3320. if value == nil then
  3321. return
  3322. end
  3323. --playZiPaiSelectCardVoice()
  3324. logE("88888888-=============onTouchBegan1================")
  3325. logE("88888888-isKan:")
  3326. logE(isKan)
  3327. logE("88888888-touch lieshu:",lieshu)
  3328. logE("88888888-touch hangshu:",hangshu)
  3329. logE("88888888-touch value:",value)
  3330. if value - 16 > 0 then
  3331. logE("玩家点了"..lieshu.."列"..hangshu.."行的大"..value - 16)
  3332. else
  3333. logE("玩家点了"..lieshu.."列"..hangshu.."行的小"..value)
  3334. end
  3335. if isKan then
  3336. logE("该牌为坎牌")
  3337. else
  3338. logE("该牌不是坎牌")
  3339. end
  3340. logE("88888888-card :"..table.tostring(self.handCardValueLocal))
  3341. logE("88888888-=============onTouchBegan2================")
  3342. v:setOpacity(0)
  3343. if self.ui.Items.ImageView_handTempCard.cIdx ~= k then
  3344. self:setColorWhite()
  3345. v:setColor(ZPDef.ColorConfig.TOUCH_CARD_COLOR)
  3346. self.ui.Items.Button_OutCard:setEnabled(true)
  3347. elseif self.ui.Items.ImageView_handTempCard.cIdx == k then
  3348. if v:getColor().r == ZPDef.ColorConfig.TOUCH_CARD_COLOR.r and v:getColor().g == ZPDef.ColorConfig.TOUCH_CARD_COLOR.g and v:getColor().b == ZPDef.ColorConfig.TOUCH_CARD_COLOR.b then
  3349. --self:setColorWhite()
  3350. --self.ui.Items.Button_OutCard:setEnabled(false)
  3351. if v.value == nil then
  3352. showTooltip("牌已经操作过!")
  3353. return
  3354. end
  3355. if not self.bOutCard then
  3356. self:setColorWhite()
  3357. self.ui.Items.Button_OutCard:setEnabled(false)
  3358. return
  3359. end
  3360. self.ui.Items.ImageView_handTempCard:setVisible(false)
  3361. v:setOpacity(0)
  3362. self:sendOutCard(v.value)
  3363. logE("玩家出牌:"..v.value)
  3364. self.bOutCard = false
  3365. self.isGodHand = true;
  3366. --记录数据
  3367. local lieshu = v.lieshu
  3368. local hangshu = v.hangshu
  3369. local value = v.value
  3370. self.ui.Items.ImageView_handTempCard.lieshu = lieshu
  3371. self.ui.Items.ImageView_handTempCard.hangshu = hangshu
  3372. self.ui.Items.ImageView_handTempCard.value = value
  3373. self.ui.Items.ImageView_handTempCard.index = k
  3374. return
  3375. else
  3376. v:setColor(ZPDef.ColorConfig.TOUCH_CARD_COLOR)
  3377. self.ui.Items.Button_OutCard:setEnabled(true)
  3378. end
  3379. end
  3380. self:showTingPaiView(v.value)
  3381. --出牌线
  3382. self:setOutCardLineVisible(true)
  3383. --临时牌
  3384. self.ui.Items.ImageView_handTempCard.cIdx = k
  3385. self.ui.Items.ImageView_handTempCard.lieshu = lieshu
  3386. self.ui.Items.ImageView_handTempCard.hangshu = hangshu
  3387. self.ui.Items.ImageView_handTempCard.value = value
  3388. self.ui.Items.ImageView_handTempCard.index = k
  3389. self.ui.Items.ImageView_handTempCard:setVisible(true)
  3390. self.ui.Items.ImageView_handTempCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(value,ZPDef.CardType.CARD_TYPE_HAND,self.colorType))
  3391. self.ui.Items.ImageView_handTempCard:setPosition(pos)
  3392. end
  3393. local function onTouchMove(touch)
  3394. if self.isGodHand then
  3395. --showTooltip("end 禁止操作")
  3396. return
  3397. end
  3398. local posOO = getPosOO()
  3399. local localPos = touch:getLocation();
  3400. local pos = cc.p(localPos.x - posOO.x, localPos.y - posOO.y);
  3401. self.ui.Items.ImageView_handTempCard:setPosition(pos)
  3402. end
  3403. local function onTouchEnd(touch)
  3404. if self.isGodHand then
  3405. --showTooltip("end 禁止操作")
  3406. return
  3407. end
  3408. logE("88888888-=============onTouchEnd1================")
  3409. if not self.ui.Items.ImageView_handTempCard:isVisible() then
  3410. --showTooltip("End 临时牌阻止了事件")
  3411. v:setOpacity(255)
  3412. self.ui.Items.ImageView_handTempCard:setVisible(false)
  3413. return
  3414. end
  3415. self.ui.Items.ImageView_handTempCard:setVisible(false)
  3416. --出牌线
  3417. self:setOutCardLineVisible(false)
  3418. if v.isKan then
  3419. return
  3420. end
  3421. if not v.value then
  3422. return
  3423. end
  3424. v:setOpacity(255)
  3425. --回到原点动画
  3426. self:goBackWithAni(v,0.15)
  3427. logE("88888888-=============onTouchEnd2================")
  3428. end
  3429. local function onTouchCancel(touch)
  3430. if self.isGodHand then
  3431. --showTooltip("禁止操作")
  3432. return
  3433. end
  3434. self:setColorWhite()
  3435. logE("88888888-=============onTouchCancel 1================")
  3436. --出牌线
  3437. self:setOutCardLineVisible(false)
  3438. if not self.ui.Items.ImageView_handTempCard:isVisible() then
  3439. --showTooltip("cancel 临时牌阻止了事件")
  3440. v:setOpacity(255)
  3441. self.ui.Items.ImageView_handTempCard:setVisible(false)
  3442. return
  3443. end
  3444. self.ui.Items.ImageView_handTempCard:setVisible(false)
  3445. if v.isKan then
  3446. return
  3447. end
  3448. if not v.value then
  3449. return
  3450. end
  3451. v:setOpacity(255)
  3452. --临时牌
  3453. self.ui.Items.ImageView_handTempCard:setVisible(false)
  3454. local touchPos = touch:getLocation()
  3455. -------------------------------------------------------
  3456. -------------------------------------------------------
  3457. local hitCount = 0
  3458. local hitItem = {}
  3459. for i = #self.handCardItem - 1,1,-1 do
  3460. local mSprite = self.handCardItem[i]
  3461. local posNode = mSprite:convertToNodeSpace(touchPos);
  3462. local width = mSprite:getContentSize().width
  3463. local height = mSprite:getContentSize().height
  3464. --不可以用getWorldPosition(),因为会出现旋转后,可点区域会停留在原来的地方。
  3465. local x = mSprite:getPosition().x
  3466. local y = mSprite:getPosition().y
  3467. local mRect = cc.Rectangle:new(x,y,width,height)
  3468. if mRect:contains(posNode.x,posNode.y) then
  3469. hitCount = hitCount + 1
  3470. hitItem[hitCount] = mSprite
  3471. break
  3472. --[[--干掉for循环
  3473. if hitCount == 3 then
  3474. break
  3475. end--]]
  3476. end
  3477. end
  3478. --处理多层点击穿透:如果是3个,取第三个,如果是2个,取第二个,如果是一个,取第一个
  3479. local curItem = hitItem[#hitItem]
  3480. if curItem then
  3481. logE("cancel hitCount :"..hitCount)
  3482. if curItem.value == nil then
  3483. logE("88888888-=============curItem.value == nil 1================")
  3484. logE("88888888-=============执行牌插入,插入位置为空的================")
  3485. --牌插入逻辑:
  3486. --数组数据更新
  3487. local curLieShu = hitItem[#hitItem].lieshu
  3488. local curHangShu = hitItem[#hitItem].hangshu
  3489. local value = hitItem[#hitItem].value
  3490. logE("88888888-self.handCardValueLocal[v.lieshu]:"..table.tostring(self.handCardValueLocal[v.lieshu]))
  3491. logE("88888888-self.handCardValueLocal[curLieShu]:"..table.tostring(self.handCardValueLocal[curLieShu]))
  3492. --行数
  3493. local row = v.hangshu
  3494. local lieshu = v.lieshu
  3495. logE("88888888-touch row :"..row)
  3496. logE("88888888-touch lieshu :"..lieshu)
  3497. --原来的数据删除
  3498. --if self.handCardRoot[lieshu].imgList[row].value == v.value then
  3499. table.remove(self.handCardValueLocal[lieshu],row)
  3500. --end
  3501. --在新的数据列里插入新的值
  3502. for i = 1,self.hangShuMax do
  3503. if self.handCardRoot[curLieShu].imgList[i].value == nil then
  3504. table.insert(self.handCardValueLocal[curLieShu],v.value)
  3505. break
  3506. end
  3507. end
  3508. --数据交换
  3509. local tempValue = nil
  3510. tempValue = v.value
  3511. v.value = hitItem[#hitItem].value
  3512. hitItem[#hitItem].value = tempValue
  3513. --ui更新
  3514. self.ui.Items.ImageView_handTempCard:setVisible(true)
  3515. v:setVisible(false)
  3516. local function callback()
  3517. self.ui.Items.ImageView_handTempCard:setVisible(false)
  3518. local cardvalue = hitItem[#hitItem].value or tempValue
  3519. if cardvalue then
  3520. local fileName = ZPFuc.getZPCardImgByValue(cardvalue,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  3521. hitItem[#hitItem]:loadTextureFromPlist(fileName)
  3522. hitItem[#hitItem]:setVisible(true)
  3523. hitItem[#hitItem]:setOpacity(255)
  3524. end
  3525. --听牌标签
  3526. if v:getChildren()[1]:isVisible() then
  3527. v:getChildren()[1]:setVisible(false)
  3528. hitItem[#hitItem]:getChildren()[1]:setVisible(true)
  3529. end
  3530. self.ui.Items.ImageView_handTempCard.lieshu = curLieShu
  3531. self.ui.Items.ImageView_handTempCard.hangshu = curHangShu
  3532. self:neatenCard()
  3533. end
  3534. --handTemp->tarPos action
  3535. if self.handCardRoot[curLieShu].imgList[curHangShu - 1] and
  3536. self.handCardRoot[curLieShu].imgList[curHangShu - 1].value then
  3537. local node = hitItem[#hitItem]
  3538. local nodeSize = node:getParent():getContentSize()
  3539. local nodePos = cc.pAdd(node:getWorldPosition(),cc.p(nodeSize.width/2,nodeSize.height/2))
  3540. local seq = cc.Sequence:create(cc.MoveTo:create(0,nodePos),cc.CallFunc:create(callback))--self.gameSpeedConfig.OPCARDTIME
  3541. self.ui.Items.ImageView_handTempCard:runAction(seq)
  3542. else
  3543. callback()
  3544. end
  3545. logE("88888888-=============curItem.value == nil 2================")
  3546. logE("88888888-=============执行牌插入结束================")
  3547. else
  3548. logE("88888888-=============cancel curItem.value exist 1================")
  3549. --数组数据更新
  3550. local curLieShu = hitItem[#hitItem].lieshu
  3551. local curHangShu = hitItem[#hitItem].hangshu
  3552. local value = hitItem[#hitItem].value
  3553. local isKan = hitItem[#hitItem].isKan
  3554. if isKan then
  3555. --showTooltip("坎牌不可拆")
  3556. return
  3557. end
  3558. --如果小于3则插入到空的那个
  3559. if self:getRowVisibleCount(curLieShu) < 5 then
  3560. logE("88888888-=============如果小于5则插入到空的那个================")
  3561. logE("88888888-=============执行牌插入到空的位置================")
  3562. --同列有多个牌相同的,找出对应点击的牌
  3563. local row = v.hangshu
  3564. local lieshu = v.lieshu
  3565. logE("88888888-row :"..row)
  3566. logE("88888888-lieshu :"..lieshu)
  3567. --原来的数据删除
  3568. table.remove(self.handCardValueLocal[lieshu],row)
  3569. --在新的数据列里插入新的值
  3570. local newRow = 0
  3571. for i = 1,self.hangShuMax do
  3572. if self.handCardRoot[curLieShu].imgList[i].value == nil then
  3573. newRow = i
  3574. table.insert(self.handCardValueLocal[curLieShu],v.value)
  3575. break
  3576. end
  3577. end
  3578. --数据交换
  3579. local tempValue = nil
  3580. tempValue = v.value
  3581. v.value = nil
  3582. self.handCardRoot[curLieShu].imgList[newRow].value = tempValue
  3583. logE("888888888-curLieShu:"..tostring(curLieShu))
  3584. logE("888888888-newRow:"..tostring(newRow))
  3585. --ui更新
  3586. v:setVisible(false)
  3587. local fileName = ZPFuc.getZPCardImgByValue(self.handCardRoot[curLieShu].imgList[newRow].value,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  3588. self.handCardRoot[curLieShu].imgList[newRow]:loadTextureFromPlist(fileName)
  3589. self.handCardRoot[curLieShu].imgList[newRow]:setVisible(true)
  3590. self.handCardRoot[curLieShu].imgList[newRow]:setOpacity(255)
  3591. --听牌标签
  3592. if v:getChildren()[1]:isVisible() then
  3593. v:getChildren()[1]:setVisible(false)
  3594. self.handCardRoot[curLieShu].imgList[newRow]:getChildren()[1]:setVisible(true)
  3595. end
  3596. logE("88888888-======================after insert card=========================")
  3597. logE("88888888-first item lieshu:"..v.lieshu)
  3598. logE("88888888-first item value:"..0)
  3599. self:neatenCard()
  3600. logE("88888888-=============如果小于5则插入到空的那个 结束================")
  3601. logE("88888888-=============执行牌插入到空的位置 结束================")
  3602. else
  3603. logE("88888888-=============该列满5个牌只能交换================")
  3604. logE("88888888-=============执行牌交换================")
  3605. if value > 0 then
  3606. logE("被交换的牌为"..value)
  3607. end
  3608. --牌交换:
  3609. --同列有多个牌相同的,找出对应点击的牌
  3610. local rowFirst = v.hangshu
  3611. local rowSecond = curHangShu
  3612. logE("88888888-rowFirst 第一个交换的行数:"..rowFirst)
  3613. logE("88888888-rowSecond 第二个交换的行数:"..rowSecond)
  3614. logE("88888888-原始列数数据:"..table.tostring(self.handCardValueLocal[v.lieshu]))
  3615. logE("88888888-交换列数数据:"..table.tostring(self.handCardValueLocal[curLieShu]))
  3616. --原来的数据删除
  3617. if self.handCardRoot[v.lieshu].imgList[rowFirst].value == v.value then
  3618. table.remove(self.handCardValueLocal[v.lieshu],rowFirst)
  3619. table.insert(self.handCardValueLocal[v.lieshu],rowFirst,value)
  3620. end
  3621. --原来的数据删除
  3622. if self.handCardRoot[curLieShu].imgList[rowSecond].value == value then
  3623. table.remove(self.handCardValueLocal[curLieShu],rowSecond)
  3624. table.insert(self.handCardValueLocal[curLieShu],rowSecond,v.value)
  3625. end
  3626. logE("88888888-删除后的原始列数数据:"..table.tostring(self.handCardValueLocal[v.lieshu]))
  3627. logE("88888888-删除后的列数数据:"..table.tostring(self.handCardValueLocal[curLieShu]))
  3628. logE("查看数据:")
  3629. logE("88888888-first item lieshu:"..v.lieshu)
  3630. logE("88888888-first item value:"..v.value)
  3631. logE("88888888-second item lieshu:"..curItem.lieshu)
  3632. logE("88888888-second item value:"..curItem.value)
  3633. logE("查看数据完毕")
  3634. --数据交换
  3635. local tempValue = nil
  3636. tempValue = v.value
  3637. v.value = hitItem[#hitItem].value
  3638. hitItem[#hitItem].value = tempValue
  3639. --ui交换
  3640. local fileName = ZPFuc.getZPCardImgByValue(v.value,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  3641. v:loadTextureFromPlist(fileName)
  3642. fileName = ZPFuc.getZPCardImgByValue(hitItem[#hitItem].value,ZPDef.CardType.CARD_TYPE_HAND,self.colorType)
  3643. hitItem[#hitItem]:loadTextureFromPlist(fileName)
  3644. local srcVisible = v:getChildren()[1]:isVisible()
  3645. local changeVisible = hitItem[#hitItem]:getChildren()[1]:isVisible()
  3646. --听牌标签
  3647. hitItem[#hitItem]:getChildren()[1]:setVisible(srcVisible)
  3648. v:getChildren()[1]:setVisible(changeVisible)
  3649. logE("交换完毕,查看数据:")
  3650. logE("88888888-first item lieshu:"..v.lieshu)
  3651. logE("88888888-first item value:"..v.value)
  3652. logE("88888888-second item lieshu:"..hitItem[#hitItem].lieshu)
  3653. logE("88888888-second item value:"..hitItem[#hitItem].value)
  3654. logE("查看数据完毕")
  3655. logE("88888888-=============牌交换 结束================")
  3656. logE("88888888=============cancel curItem.value exist 2================")
  3657. end
  3658. end
  3659. else
  3660. --@part:牌取消回来,出牌逻辑的实现
  3661. --判断是否大于出牌点
  3662. if touchPos.y > self.ui.Items.ImageView_line:getPosition().y and self.bOutCard then
  3663. if app.room:isLittleFamily() then
  3664. return
  3665. end
  3666. --比牌的时候,在比牌间隔点到了牌,拖出去报错
  3667. if v.value == nil then
  3668. showTooltip("牌已经操作过!")
  3669. return
  3670. end
  3671. --send sender
  3672. v:setOpacity(0)
  3673. self:sendOutCard(v.value)
  3674. logE("玩家出牌:"..v.value)
  3675. self.bOutCard = false
  3676. self.isGodHand = true;
  3677. --记录数据
  3678. local lieshu = v.lieshu
  3679. local hangshu = v.hangshu
  3680. local value = v.value
  3681. self.ui.Items.ImageView_handTempCard.lieshu = lieshu
  3682. self.ui.Items.ImageView_handTempCard.hangshu = hangshu
  3683. self.ui.Items.ImageView_handTempCard.value = value
  3684. self.ui.Items.ImageView_handTempCard.index = k
  3685. else
  3686. logE("牌回到原来的位置")
  3687. --回到原点动画
  3688. self:goBackWithAni(v,0.15)
  3689. end
  3690. end
  3691. -------------------------------------------------------
  3692. -------------------------------------------------------
  3693. logE("88888888=============onTouchCancel 2================")
  3694. logE("88888888-onTouchCancel :card :"..table.tostring(self.handCardValueLocal))
  3695. end
  3696. v:setTouchEnabled(true)
  3697. v:registerTouchEvent(onTouchBegan, onTouchMove, onTouchEnd, onTouchCancel)
  3698. end
  3699. end
  3700. --隐藏剩余牌层
  3701. function changpaiRoomView:setCircleCardLeftPanelView(bVisible,viewId,leftNum)
  3702. self.leftNum = leftNum
  3703. self:setFaPaiQiPanelView(bVisible,viewId,leftNum)
  3704. if viewId and not self.isRecordStart and not self.isQiShou then
  3705. self.PlayerView:setPClockVisible(viewId,true)
  3706. end
  3707. end
  3708. --胡牌特效
  3709. function changpaiRoomView:playHuEffect(viewId,onEnd,isRecontect)
  3710. --[[ --黄庄了直接return
  3711. if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
  3712. return
  3713. end--]]
  3714. logE("changpaiRoomView playHuEffect",app.room.roomInfo.huType,viewId)
  3715. local nUserID = app.room:getUserIdByViewId(viewId)
  3716. if (app.room.roomInfo.huType and app.room.roomInfo.huType >= 0) and (app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL) then
  3717. local userInfo=app.room:getUserInfo(nUserID)
  3718. if userInfo then
  3719. ZPSound.PlayOperateSound(userInfo.sex,4)
  3720. --if ZPFuc.isZiMo(app.room.roomInfo.huType) then
  3721. --ZPSound.PlayOperateSound(userInfo.sex,11)
  3722. --else
  3723. --ZPSound.PlayOperateSound(userInfo.sex,4)
  3724. --end
  3725. end
  3726. end
  3727. local name = string.format("Layout_outCardPoint_%d",viewId)
  3728. local mLayout = self.ui.Items[name]
  3729. local huEffectUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_effectHu.ui")
  3730. local pos = mLayout:getPosition()
  3731. if viewId == self:getMeViewId() then
  3732. local centerPos = cc.Director:getInstance():getVisibleSize()
  3733. local pos = cc.p(centerPos.width/2,centerPos.height/2 - 70)
  3734. huEffectUI:setPosition(pos)
  3735. elseif viewId == 1 then
  3736. huEffectUI:setPosition(cc.pAdd(pos,cc.p(90,-30)))
  3737. elseif viewId == 2 then
  3738. huEffectUI:setPosition(cc.pAdd(pos,cc.p(0,20)))
  3739. elseif viewId == 3 then
  3740. huEffectUI:setPosition(cc.pAdd(pos,cc.p(-70,-30)))
  3741. end
  3742. self.ui.Items.Layout_Player_HuEffect:addChild(huEffectUI,2)
  3743. local pPos = cc.p(0,0)
  3744. for k,v in pairs(self.playerPos) do
  3745. if k == viewId then
  3746. --pPos = v.headPos
  3747. if viewId == 2 then
  3748. pPos.y = v.headPos.y + 25
  3749. pPos.x = v.headPos.x
  3750. elseif viewId == 1 then
  3751. pPos.y = v.headPos.y + 15
  3752. pPos.x = v.headPos.x
  3753. elseif viewId == 3 then
  3754. pPos.y = v.headPos.y + 15
  3755. pPos.x = v.headPos.x
  3756. elseif viewId == 4 then
  3757. pPos.y = v.headPos.y + 15
  3758. pPos.x = v.headPos.x
  3759. end
  3760. end
  3761. end
  3762. local mSpawn = cc.Spawn:create(cc.MoveTo:create(0.5,pPos),cc.ScaleTo:create(0.3,0.5))
  3763. huEffectUI:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),mSpawn))
  3764. --动画展现
  3765. if app.room.roomInfo.huType and app.room.roomInfo.huType >= 0 then
  3766. local name = ""
  3767. local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
  3768. local nWinerId = app.room.roomInfo.winUserId
  3769. local winerViewId = app.room:getViewIdByUserId(nWinerId)
  3770. if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then--app.room.roomInfo.huType == 0 and
  3771. name = "zp_room_chapai_jiao.png"--显示叫(表示听牌了)
  3772. --elseif ZPFuc.isZiMo(app.room.roomInfo.huType) then
  3773. --name = "zp_room_chapai_zimo.png"
  3774. else
  3775. name = "zp_room_chapai_hu.png"--string.format(ZPDef.TipFile.HU,app.room.roomInfo.huType)
  3776. end
  3777. huEffectUI.Items.ImageView_huType:loadTextureFromPlist(name)
  3778. end
  3779. isRecontect = true--不显示动画
  3780. if isRecontect then
  3781. huEffectUI.Items.ImageView_Light:setVisible(false)
  3782. huEffectUI.Items.ImageView_Point:setVisible(false)
  3783. huEffectUI.Items.ImageView_Coin:setVisible(false)
  3784. self:showPaoImage()
  3785. self:runAction(cc.Sequence:create(cc.DelayTime:create(0.8),cc.CallFunc:create(function ()
  3786. if onEnd then
  3787. onEnd()
  3788. end
  3789. end)))
  3790. return
  3791. end
  3792. local mSpawn1 = cc.Spawn:create(cc.ScaleTo:create(0.3,1.0),cc.RotateBy:create(2,-120*6))
  3793. huEffectUI.Items.ImageView_Point:runAction(mSpawn1)
  3794. local mSpawn2 = cc.Spawn:create(cc.ScaleTo:create(0.3,1.0),cc.RotateBy:create(2,120*6))
  3795. huEffectUI.Items.ImageView_Light:runAction(mSpawn2)
  3796. huEffectUI.Items.ImageView_Coin:setScale(0)
  3797. local mSeq1 = cc.Sequence:create(cc.ScaleTo:create(0.3,1))
  3798. huEffectUI.Items.ImageView_Coin:runAction(mSeq1)
  3799. huEffectUI.Items.ImageView_huType:setScale(2)
  3800. huEffectUI.Items.ImageView_huType:setOpacity(0)
  3801. local mSeq2 = cc.Sequence:create(cc.DelayTime:create(0.6),cc.FadeIn:create(0),cc.ScaleTo:create(0.2,1.0))
  3802. huEffectUI.Items.ImageView_huType:runAction(mSeq2)
  3803. huEffectUI:runAction(cc.Sequence:create(cc.DelayTime:create(2.2),cc.CallFunc:create(function()
  3804. huEffectUI.Items.ImageView_Light:setVisible(false)
  3805. huEffectUI.Items.ImageView_Point:setVisible(false)
  3806. huEffectUI.Items.ImageView_Coin:setVisible(false)
  3807. self:showPaoImage()
  3808. if onEnd then
  3809. onEnd()
  3810. end
  3811. end)))
  3812. end
  3813. --点炮显示
  3814. function changpaiRoomView:showPaoImage()
  3815. if app.room.roomInfo.dianPaoUserId and app.room.roomInfo.dianPaoUserId >= 0 then
  3816. local dianPaoViewId = app.room:getViewIdByUserId(app.room.roomInfo.dianPaoUserId)
  3817. --点炮精灵
  3818. local mSprite = cc.ImageView:createNode()
  3819. mSprite:loadTextureFromPlist("zp_room_chapai_dianpao.png")
  3820. --if dianPaoViewId == 2 then
  3821. --mSprite:setEulerRotation(cc.vec3(0, 0, -90))
  3822. --end
  3823. local name = string.format("Layout_outCardPoint_%d",dianPaoViewId)
  3824. local mLayout = self.ui.Items[name]
  3825. local pos = mLayout:getPosition()
  3826. if dianPaoViewId == self:getMeViewId() then
  3827. local centerPos = cc.Director:getInstance():getVisibleSize()
  3828. local pos = cc.p(centerPos.width/2,centerPos.height/2 - 70)
  3829. mSprite:setPosition(pos)
  3830. elseif dianPaoViewId == 1 then
  3831. mSprite:setPosition(cc.pAdd(pos,cc.p(90,-30)))
  3832. elseif dianPaoViewId == 2 then
  3833. mSprite:setPosition(cc.pAdd(pos,cc.p(0,20)))
  3834. elseif dianPaoViewId == 3 then
  3835. mSprite:setPosition(cc.pAdd(pos,cc.p(-70,-30)))
  3836. end
  3837. self.ui.Items.Layout_Player_HuEffect:addChild(mSprite,2)
  3838. local pPos = cc.p(0,0)
  3839. for k,v in pairs(self.playerPos) do
  3840. if k == dianPaoViewId then
  3841. --pPos = v.headPos
  3842. if dianPaoViewId == 2 then
  3843. pPos.y = v.headPos.y + 5
  3844. pPos.x = v.headPos.x - 5
  3845. elseif dianPaoViewId == 1 then
  3846. pPos.y = v.headPos.y + 5
  3847. pPos.x = v.headPos.x
  3848. elseif dianPaoViewId == 3 then
  3849. pPos.y = v.headPos.y + 5
  3850. pPos.x = v.headPos.x + 5
  3851. elseif dianPaoViewId == 4 then
  3852. pPos.y = v.headPos.y + 5
  3853. pPos.x = v.headPos.x + 5
  3854. end
  3855. end
  3856. end
  3857. local mSpawn = cc.Spawn:create(cc.MoveTo:create(0.5,pPos),cc.ScaleTo:create(0.3,0.5))
  3858. mSprite:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),mSpawn))
  3859. end
  3860. end
  3861. -- 大局结算
  3862. function changpaiRoomView:onGameDaJuResponse(data)
  3863. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  3864. local function runGameDaJuResponse(onEnd)
  3865. local response = data.response.playList
  3866. -- 打开结算
  3867. local view = ZPRoomCountAllView:new(response,data.response.endTime);
  3868. view:setAnchorPoint(cc.p(0.5, 0.5));
  3869. local visibleSize = getVisibleSize()
  3870. view:setPosition(cc.p(visibleSize.width/2,visibleSize.height/2))
  3871. self:addChild(view);
  3872. self.RoomCountAllViewUI = view;
  3873. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
  3874. if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_LONG_NOT_END then
  3875. view:playAni()
  3876. self:showGameOverAward()
  3877. else
  3878. if not app.room.roomInfo.nShowDismiss then
  3879. log("2000000000-onGameDaJuResponse --------- zhengchangjiesu ")
  3880. view:setVisible(false);
  3881. else
  3882. log("2000000000-onGameDaJuResponse --------- yichangjiesu ")
  3883. --结算直接播放动画
  3884. view:playAni()
  3885. self:showGameOverAward()
  3886. end
  3887. end
  3888. if onEnd then
  3889. onEnd()
  3890. end
  3891. end
  3892. log("2000000000-ZPRoomView - addCallBack(runGameDaJuResponse)")
  3893. self:addCallBack(runGameDaJuResponse);
  3894. end
  3895. --从手牌找与牌值相等的牌,没有再找加起来可以成14的,没有再找点数相同的
  3896. function changpaiRoomView:findCardPos(card)
  3897. local secondDstCard
  3898. logE("changpaiRoomView - findCardPos",card)
  3899. secondDstCard = 14 - tempCardVlue[tonumber(card)]
  3900. local threeDstCard = tempCardVlue[tonumber(card)]
  3901. --第一目标
  3902. local dstCol1,dstRow1
  3903. --第二目标
  3904. local dstCol2,dstRow2
  3905. --第三目标
  3906. local dstCol3,dstRow3
  3907. --第四目标
  3908. local dstCol4,dstRow4
  3909. --第一次找到值时,赋值一次,
  3910. local firstSet = true
  3911. local isEnd = false
  3912. for col = self.lieShuMax, 1, -1 do
  3913. for row = 5, 1, -1 do
  3914. --if self.handCardRoot[col].imgList[row].value == card then
  3915. --牌值相同的
  3916. if self.handCardValueLocal[col][row] == card and #self.handCardValueLocal[col] < 5 then
  3917. dstCol1 = col
  3918. dstRow1 = #self.handCardValueLocal[col]+1
  3919. isEnd = true
  3920. break
  3921. end
  3922. --if self.handCardRoot[col].imgList[row].value == secondDstCard then
  3923. --点数加起来等于十四的
  3924. local tempCard = tempCardVlue[tonumber(self.handCardValueLocal[col][row])]
  3925. if tempCard == secondDstCard and #self.handCardValueLocal[col] < 5 then
  3926. dstCol2 = col
  3927. dstRow2 = #self.handCardValueLocal[col]+1
  3928. end
  3929. --点数一样的
  3930. if tempCard == threeDstCard and #self.handCardValueLocal[col] < 5 then
  3931. dstCol3 = col
  3932. dstRow3 = #self.handCardValueLocal[col]+1
  3933. end
  3934. if firstSet and self.handCardValueLocal[col][row] then
  3935. if col == self.lieShuMax then
  3936. --最多只存在8列 最多只有16张牌 只要判断到第六列就可以了
  3937. local secondLieshu = self.lieShuMax - 1
  3938. local thirdLieshu = self.lieShuMax - 2
  3939. if #self.handCardValueLocal[col] < self.hangShuMax then
  3940. firstSet = false
  3941. dstCol4 = col
  3942. dstRow4 = #self.handCardValueLocal[col]+1
  3943. elseif #self.handCardValueLocal[secondLieshu] < self.hangShuMax then
  3944. firstSet = false
  3945. dstCol4 = secondLieshu
  3946. dstRow4 = #self.handCardValueLocal[col]+1
  3947. elseif #self.handCardValueLocal[thirdLieshu] < self.hangShuMax then
  3948. firstSet = false
  3949. dstCol4 = thirdLieshu
  3950. dstRow4 = #self.handCardValueLocal[col]+1
  3951. end
  3952. else
  3953. firstSet = false
  3954. dstCol4 = col + 1
  3955. dstRow4 = 1
  3956. end
  3957. end
  3958. --[[
  3959. if firstSet and self.handCardValueLocal[col][row] then
  3960. firstSet = false
  3961. dstCol4 = col + 1
  3962. dstRow4 = 1
  3963. end
  3964. ]]
  3965. end
  3966. if isEnd then
  3967. break
  3968. end
  3969. end
  3970. if dstCol1 then
  3971. return dstCol1,dstRow1
  3972. end
  3973. if dstCol2 then
  3974. return dstCol2,dstRow2
  3975. end
  3976. if dstCol3 then
  3977. return dstCol3,dstRow3
  3978. end
  3979. if dstCol4 then
  3980. return dstCol4,dstRow4
  3981. end
  3982. if firstSet then --手里面没有列数了
  3983. return 5,1
  3984. end
  3985. end
  3986. --获取该列显示了几个
  3987. function changpaiRoomView:getRowVisibleCount(lieshu)
  3988. local count = 0
  3989. for k = 1, 5 do
  3990. if self.handCardRoot[lieshu].imgList[k] and self.handCardRoot[lieshu].imgList[k]:isVisible() then
  3991. count = count + 1
  3992. end
  3993. end
  3994. return count
  3995. end
  3996. --显示提牌按钮
  3997. function changpaiRoomView:showTiPaiBtn(vis)
  3998. vis = vis or false
  3999. self.ui.Items.Button_tipai:setVisible(vis)
  4000. end
  4001. --牌UI调整
  4002. function changpaiRoomView:RankCard(isNotShowAni)
  4003. --如果列小于最大列数则需要调整UI
  4004. local showColNum = self:getVisibleCardLayoutNum()
  4005. if showColNum == 0 then
  4006. self:getLocalHuShu()
  4007. return
  4008. end
  4009. local tempLieshu = self.lieShuMax + 1
  4010. if showColNum <= tempLieshu then
  4011. --根据当前存在的列数获取一个枚举列表,让手牌的列数重新旋转到指定新的列数
  4012. local list = self.lieshulist[showColNum]
  4013. local blankList = self.lieshuBlanklist[showColNum]
  4014. local youIndex = 0
  4015. local wuIndex = 0
  4016. --card data
  4017. local handCardValueLocalTemp = {}
  4018. local handCardRootTemp = {}
  4019. for k = 1,tempLieshu do
  4020. if #self.handCardValueLocal[k] <= 0 then
  4021. wuIndex = wuIndex + 1
  4022. local blankIndex = blankList[wuIndex] -- 1 2 9 10
  4023. local tarPos = self.boxPosList4[blankIndex]
  4024. if isNotShowAni then
  4025. self.handCardRoot[k].ui:setPosition(tarPos)
  4026. else
  4027. self.handCardRoot[k].ui:stopAllActions()
  4028. self.handCardRoot[k].ui:runAction(cc.MoveTo:create(self.gameSpeedConfig.OPCARDTIME,tarPos))
  4029. end
  4030. --列数修改
  4031. for i = 1,self.hangShuMax do
  4032. self.handCardRoot[k].imgList[i].lieshu = blankIndex
  4033. end
  4034. self.handCardRoot[k].ui:setLocalZOrder(blankIndex)
  4035. handCardValueLocalTemp[blankIndex] = self.handCardValueLocal[k]
  4036. handCardRootTemp[blankIndex] = self.handCardRoot[k]
  4037. else
  4038. youIndex = youIndex + 1
  4039. local index = list[youIndex] -- 3 4 5 6 7 8
  4040. local tarPos = self.boxPosList4[index]
  4041. if isNotShowAni then
  4042. self.handCardRoot[k].ui:setPosition(tarPos)
  4043. else
  4044. self.handCardRoot[k].ui:stopAllActions()
  4045. self.handCardRoot[k].ui:runAction(cc.MoveTo:create(self.gameSpeedConfig.OPCARDTIME,tarPos))
  4046. end
  4047. --列数修改
  4048. for i = 1,self.hangShuMax do
  4049. self.handCardRoot[k].imgList[i].lieshu = index
  4050. end
  4051. --self.handCardRoot[k].ui:setLocalZOrder(index)
  4052. handCardValueLocalTemp[index] = self.handCardValueLocal[k]
  4053. handCardRootTemp[index] = self.handCardRoot[k]
  4054. end
  4055. end
  4056. --牌数据
  4057. self.handCardValueLocal = handCardValueLocalTemp
  4058. handCardValueLocalTemp = {}
  4059. --牌
  4060. self.handCardRoot = handCardRootTemp
  4061. handCardRootTemp = {}
  4062. --logE("RankCard 排序后: "..table.tostring(self.handCardValueLocal))
  4063. end
  4064. self:getLocalHuShu()
  4065. end
  4066. --备份的手牌数据,只对此数据使用的接口
  4067. function changpaiRoomView:rankDeletOneBakCard(card)
  4068. local isEnd = false
  4069. --倒叙遍历1-10列
  4070. local tempLieshu = self.lieShuMax + 1
  4071. for col = tempLieshu,1,-1 do --列数
  4072. for row = self.hangShuMax,1,-1 do --行数
  4073. if self.handCardValueBak[col] and self.handCardValueBak[col][row] and card == self.handCardValueBak[col][row] then --判断值是否相等
  4074. logE("delete bakcard ============= :"..card)
  4075. table.remove(self.handCardValueBak[col],row)
  4076. isEnd = true
  4077. break
  4078. end
  4079. end
  4080. if isEnd then
  4081. break
  4082. end
  4083. end
  4084. end
  4085. --隐藏出牌按钮
  4086. function changpaiRoomView:setGuideView(bVisible)
  4087. if app.room:isLittleFamily() then
  4088. bVisible = false
  4089. end
  4090. self.ui.Items.Layout_tips:setVisible(bVisible)
  4091. --self.ui.Items.Button_OutCard:setVisible(bVisible)
  4092. self.ui.Items.Button_OutCard:setVisible(false)
  4093. self.ui.Items.Button_OutCard:setEnabled(false)
  4094. if bVisible then
  4095. self.ui.Items.ImageView_3:playClip("tip")
  4096. end
  4097. end
  4098. ---
  4099. -- 托管通知
  4100. -- @param data
  4101. -- @return
  4102. --
  4103. function changpaiRoomView:onHostingRequest( data )
  4104. local response = data.response
  4105. if response.nUserId == app.user.loginInfo.uid then
  4106. if response.status == 1 then --托管状态
  4107. self.toolView:showTuoGuan(true)
  4108. elseif response.status == 0 then--取消托管状态
  4109. self.toolView:showTuoGuan(false)
  4110. end
  4111. end
  4112. local isTuoGuan = response.status == 1;
  4113. local viewId = app.room:getViewIdByUserId(response.nUserId)
  4114. self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
  4115. end
  4116. --操作错误 --容错处理
  4117. function changpaiRoomView:onOperationError(data)
  4118. local function runOnOperationError(onEnd)
  4119. log("2000000000-ZPRoomView - (runOnOperationError)")
  4120. --恢复操作面板
  4121. --self.operationView:touchEatOneCardCallBack()
  4122. self.ui:sendMsg(app.room,ZPDef.ZPEvent.GetTableInfo)
  4123. if onEnd then
  4124. onEnd()
  4125. end
  4126. end
  4127. log("2000000000-ZPRoomView - addCallBack(runOnOperationError)")
  4128. self:addCallBack(runOnOperationError)
  4129. end
  4130. return changpaiRoomView