No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

4747 líneas
148 KiB

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