25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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