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

5602 lines
184 KiB

  1. local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  2. local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
  3. local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound")
  4. local ZPMessage = ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage")
  5. local ZPRoomPlayerView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomPlayerView")
  6. local ZPRoomToolView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomToolView")
  7. local ZPRoomXiaoJuChaPaiView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomXiaoJuChaPaiView")
  8. local ZPRoomXiaoJuView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomXiaoJuView")
  9. local ZPRoomOperationView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomOperationView")
  10. local ZPRoomCard=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomCard")
  11. local ZPRoomCountAllView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomCountAllView")
  12. local ZPRoomPiaoFenView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomPiaoFenView")
  13. local ZPRoomSettingView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomSettingView")
  14. local ZPRoomQuickStartView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomQuickStartView")
  15. local ZPWanFa=ZPFramework.ImportWanFa("luaScript.SubGameDefine.ZiPai.ZPWanFa")
  16. local ZPRoomView = class("ZPRoomView", cc.UIView)
  17. function ZPRoomView:ctor()
  18. ZPRoomView.super.ctor(self);
  19. self.Time = nil
  20. --枚举矩形区域:用于重新排列
  21. self.lieshulist = {}
  22. self.lieshulist[1] = {6}
  23. self.lieshulist[2] = {6,7}
  24. self.lieshulist[3] = {5,6,7}
  25. self.lieshulist[4] = {5,6,7,8}
  26. self.lieshulist[5] = {4,5,6,7,8}
  27. self.lieshulist[6] = {4,5,6,7,8,9}
  28. self.lieshulist[7] = {3,4,5,6,7,8,9}
  29. self.lieshulist[8] = {3,4,5,6,7,8,9,10}
  30. self.lieshulist[9] = {2,3,4,5,6,7,8,9,10}
  31. self.lieshulist[10] = {1,2,3,4,5,6,7,8,9,10}
  32. self.lieshulist[11] = {1,2,3,4,5,6,7,8,9,10,11}
  33. self.lieshulist[12] = {1,2,3,4,5,6,7,8,9,10,11,12}
  34. self.lieshulist[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13}
  35. self.lieshulist[14] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14}
  36. self.lieshulist[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
  37. --枚举矩形非填充区域
  38. self.lieshuBlanklist ={}
  39. self.lieshuBlanklist[1] = {1,2,3,4,5,7,8,9,10,11,12,13,14,15}
  40. self.lieshuBlanklist[2] = {1,2,3,4,5,8,9,10,11,12,13,14,15}
  41. self.lieshuBlanklist[3] = {1,2,3,4,8,9,10,11,12,13,14,15}
  42. self.lieshuBlanklist[4] = {1,2,3,4,9,10,11,12,13,14,15}
  43. self.lieshuBlanklist[5] = {1,2,3,9,10,11,12,13,14,15}
  44. self.lieshuBlanklist[6] = {1,2,3,10,11,12,13,14,15}
  45. self.lieshuBlanklist[7] = {1,2,10,11,12,13,14,15}
  46. self.lieshuBlanklist[8] = {1,2,11,12,13,14,15}
  47. self.lieshuBlanklist[9] = {1,11,12,13,14,15}
  48. self.lieshuBlanklist[10] = {11,12,13,14,15}
  49. self.lieshuBlanklist[11] = {12,13,14,15}
  50. self.lieshuBlanklist[12] = {13,14,15}
  51. self.lieshuBlanklist[13] = {14,15}
  52. self.lieshuBlanklist[14] = {15}
  53. self.lieshuBlanklist[15] = {}
  54. --牌Layout UI
  55. self.handCardRoot = {}
  56. --手牌数组UI
  57. self.handCardItem = {}
  58. --牌数据UI
  59. self.handCardValueLocal = {}
  60. --手牌数据备份
  61. self.handCardValueBak = {}
  62. --扇形最大列数
  63. self.lieShuMax = 15
  64. --扇形最大行数
  65. self.hangShuMax = 4
  66. --是否出牌
  67. self.bOutCard = false
  68. --出牌缩放倍数
  69. self.outCardScale = 0.95
  70. --弃牌桌面牌资源缩放倍数
  71. self.littleCardScale = 1--35/64 --(35为牌背大小,64为大牌大小)
  72. --组合牌之间的间隔
  73. self.cardInterval = 0
  74. self.verticleInterval = 15
  75. self.moPaiViewId = 1
  76. --操作码
  77. self.operationLocalCode = 0
  78. --玩家跑牌次数
  79. self.playerZhao = {}
  80. --重置跑牌次数
  81. for i = 1,ZPDef.GameMaxPlayer do
  82. self.playerZhao[i] = 0
  83. end
  84. --是否摸牌操作
  85. self.isMoPaiOperator = false
  86. --出牌的值
  87. self.outCard = 1
  88. --正在执行删除牌操作的时候,保护删除是正常,避免少牌可能性出现
  89. self.isGodHand = false
  90. --是否不需要出牌就听牌了
  91. self.isNoCardTingPai = false
  92. --听牌本地数据
  93. self.tingCardLocal = {}
  94. --桌面胡息
  95. self.tableHuXiList = {}
  96. end
  97. function ZPRoomView:loadRoomUI()
  98. local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_fangjian.ui");
  99. self.ui = ui;
  100. self:addChild(ui);
  101. end
  102. function ZPRoomView:onEnter()
  103. ZPRoomView.super.onEnter(self)
  104. --ui load
  105. self:loadRoomUI();
  106. --self.ui.Items.ImageView_test:setVisible(false)
  107. self:setDiPaiVisible(false)
  108. --初始化音效类型
  109. self:doSound()
  110. -- 初始化GPS组件
  111. self:initGpsComponent();
  112. --加载纹理缓存
  113. self:loadTextureCache()
  114. --房间菜单
  115. self:initRoomMenu()
  116. --初始化工具层
  117. self:initToolLayer()
  118. --初始化游戏事件按钮
  119. self:initGameButton()
  120. --初始化基础节点
  121. self:initBaseNode()
  122. --水印
  123. self:initLogo()
  124. --默认状态
  125. self:defaultState()
  126. --监听事件
  127. self:bindAllEvent()
  128. --初始化游戏速度
  129. self:initGameSpeed();
  130. self:onGameReconnection()
  131. --起飞
  132. self:startGame()
  133. --播放音乐
  134. local cacheMusic = "gameBgMusic"..(ZPDef.GameID or app.gameId)
  135. local defaultValue = tonumber(loadUserInfo(cacheMusic)) or 1
  136. ZPSound.PlayGameBGM(defaultValue)
  137. self:initPlayGameAgain()
  138. end
  139. ---
  140. -- 初始化大结算再来一局
  141. -- @return
  142. --
  143. function ZPRoomView:initPlayGameAgain()
  144. local strGameInfo = app.room.roomInfo.strGameInfo
  145. local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0
  146. if not isInClub then
  147. logD("IPlayGameAgain.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局");
  148. return
  149. end
  150. local clubGameInfo = json.decode(strGameInfo) or {}
  151. if not clubGameInfo.ruleid then
  152. logD("IPlayGameAgain.initPlayGameAgain", "游戏包间id不存在,不能再来一局");
  153. return
  154. end
  155. dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid)
  156. end
  157. function ZPRoomView:initGameSpeed()
  158. --速度配置:
  159. if ZPFuc.getGameSpeed() == ZPDef.SPEED.NORMAL then
  160. self.gameSpeedConfig = ZPDef.GameTimeConfig;
  161. elseif ZPFuc.getGameSpeed() == ZPDef.SPEED.SLOW then
  162. self.gameSpeedConfig = ZPDef.GameTimeConfigSlow;
  163. else
  164. self.gameSpeedConfig = ZPDef.GameTimeConfig;
  165. end
  166. logD("当前游戏的速度配置:",table.tostring(self.gameSpeedConfig));
  167. end
  168. function ZPRoomView:doSound()--1 普通话 2 方言
  169. local ZiPaiLanguageType = "ZiPaiLanguageType"..app.gameId
  170. local languageType = tonumber(loadUserInfo(ZiPaiLanguageType)) or ZPDef.GameLanguageType.PU_TONG_HUA
  171. ZPSound.setCurLanguage(idx)
  172. end
  173. function ZPRoomView:startGame()
  174. --起飞
  175. app.net:onMsgResume()
  176. end
  177. function ZPRoomView:loadTextureCache()
  178. --听牌
  179. ZPFuc.loadSpriteFromFile("zp_base/res/ui/zy_fangjian/zipai_tingCard.plist")
  180. ZPFuc.loadSpriteFromFile("zp_base/res/ui/zy_fangjian/zipai_fangjian.plist")
  181. --字牌
  182. local cacheGameCard = "ZPCardType"..(ZPDef.GameID or app.gameId)
  183. local cardTypeRes = tonumber(loadUserInfo(cacheGameCard)) or ZPDef.defaultCardRes
  184. ZPFuc.loadSpriteFromFile(string.format("zp_base/res/ui/zy_fangjian/card/zp_tp%d_card.plist",cardTypeRes))
  185. end
  186. function ZPRoomView:initBaseNode()
  187. --自己的出生坐标,视图是4
  188. self.boxPosList4 = {}
  189. local weaveCardPos4 = self.ui.Items.Layout_StartPos:getPosition()
  190. for i = 1, self.lieShuMax do
  191. --矩形3
  192. self.boxPosList4[i] = cc.p(weaveCardPos4.x + 90 * (i - 1),weaveCardPos4.y)--手牌间隙改这里
  193. end
  194. --坐标记录
  195. self.srcOutCardPosList = {}
  196. self.scorePosList = {}
  197. for k = 1,ZPDef.GameMaxPlayer do
  198. local name = string.format("Layout_outCardPoint_%d",k)
  199. local imgName = string.format("ImageView_outCardImg_%d",k)
  200. self.ui.Items[name]:setScale(self.outCardScale)
  201. self.srcOutCardPosList[k] = self.ui.Items[imgName]:getPosition()
  202. --操作分数坐标
  203. --name = string.format("TextBMFont_Score_%d",k)
  204. --self.scorePosList[k] = self.ui.Items[name]:getPosition()
  205. end
  206. --初始化扎鸟
  207. self.PlayerView:initPlayerPiaoFenByRule()
  208. local timestr = os.date("%y-%m-%d %H:%M:%S")
  209. self.ui.Items.Text_systemTime:setText(timestr)
  210. --定时器
  211. if not self.Time then
  212. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function ()
  213. local timestr = os.date("%y-%m-%d %H:%M:%S")
  214. self.ui.Items.Text_systemTime:setText(timestr)--(getTimeString())
  215. end,1.0,false)
  216. end
  217. --听牌背景原始高度
  218. self.tingPaibgSrcHeight = self.ui.Items.ImageView_TingPai_bg:getContentSize().height
  219. end
  220. function ZPRoomView:onExit()
  221. ZPRoomView.super.onExit(self)
  222. --关闭定时器
  223. if self.Time then
  224. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  225. end
  226. if self.taiPaiTimer then
  227. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.taiPaiTimer)
  228. end
  229. app.room:dispatchEvent({name = "onGameOverResponse"});
  230. stopBGMusic()
  231. self:cleanCache()
  232. end
  233. ---
  234. -- 子游戏调用
  235. function ZPRoomView:intCleanCacheList(list)
  236. logD("ZPRoomView:intCleanCacheList", "弃用,请删除接口相关调用!")
  237. end
  238. ---
  239. -- 子游戏调用
  240. function ZPRoomView:addCleanCacheList(list)
  241. logD("ZPRoomView:addCleanCacheList", "弃用,请删除接口相关调用!")
  242. end
  243. ---
  244. -- 清除lua缓存
  245. -- @return
  246. --
  247. function ZPRoomView:cleanCache()
  248. local clearList = {'zp_base.luaScript'};
  249. local subGameConfig=getSubGameConfig(app.gameId) or {}
  250. table.insert(clearList, subGameConfig.rootName)
  251. while (subGameConfig and subGameConfig.fremworkId and subGameConfig.fremworkId > 0) do
  252. subGameConfig = getSubGameConfig(subGameConfig.fremworkId)
  253. if not subGameConfig or not subGameConfig.rootName then
  254. break
  255. end
  256. table.insert(clearList, subGameConfig.rootName)
  257. end
  258. local preload = package.loaded
  259. for luaPath, _ in pairs(package.loaded or {}) do
  260. for __, str in ipairs(clearList or {}) do
  261. local res = string.find( luaPath, str) or 0
  262. if res > 0 then
  263. package.loaded[luaPath] = nil
  264. end
  265. end
  266. end
  267. end
  268. function ZPRoomView:initGameButton()
  269. --出牌按钮
  270. self.ui.Items.Button_OutCard:registerClick(function ()
  271. local k = self.ui.Items.ImageView_handTempCard.cIdx
  272. local value = self.ui.Items.ImageView_handTempCard.value
  273. --send sender
  274. self.isGodHand = true;
  275. self.handCardItem[k]:setOpacity(0)
  276. self:setColorWhite()
  277. self:sendOutCard(value)
  278. self.bOutCard = false
  279. end)
  280. --提牌按钮
  281. self.ui.Items.Button_tipai:registerClick(function ()
  282. self:onTransferCard(self.handCardValueBak)
  283. end)
  284. --暂时屏蔽提牌功能
  285. self:showTiPaiBtn(true)
  286. --点击空白
  287. self.ui.Items.Layout_Touch:registerClick(nil, function ()
  288. --[[if self.messageView then
  289. self.messageView:onClickBG()
  290. end--]]
  291. --隐藏工具界面 详情
  292. if self.toolView.ui.Items.ImageView_Rule_bg then
  293. self.toolView.ui.Items.ImageView_Rule_bg:setVisible(false)
  294. end
  295. self.ui.Items.Layout_Rule:setVisible(false)
  296. self.ui.Items.Button_wanfa:setVisible(true)
  297. end)
  298. -- 玩法
  299. self.ui.Items.Button_wanfa:registerClick(function ()
  300. playBtnEffect()
  301. self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  302. self.ui.Items.Button_wanfa:setVisible(false)
  303. end)
  304. if app.room.roomInfo.nGameStartCount and app.room.roomInfo.nGameStartCount > 0 then
  305. self.ui.Items.Layout_Rule:setVisible(false)
  306. else
  307. self.ui.Items.Layout_Rule:setVisible(true)
  308. self.ui.Items.Button_wanfa:setVisible(false)
  309. self.ui.Items.Layout_Rule:runAction(cc.Sequence:create(
  310. cc.DelayTime:create(2),
  311. cc.CallFunc:create(function ()
  312. self.ui.Items.Layout_Rule:setVisible(false)
  313. self.ui.Items.Button_wanfa:setVisible(true)
  314. end)))
  315. end
  316. self.ui.Items.Text_Rule:setVisible(false)
  317. local bar = self.ui.Items.ListView:getVBar()
  318. bar:setVisible(false)
  319. end
  320. -- 设置房间信息
  321. function ZPRoomView:setRoomInfo()
  322. self.ui.Items.ListView:removeAllChildren()
  323. self.ui.Items.ListView:getInnerContainer():setAutoSize(true)
  324. local rules = ZPWanFa.getClubRuleInfo(app.room.roomInfo.strGameInfo)
  325. for k,v in pairs(rules) do
  326. local text = self.ui.Items.Text_Rule:getCopied()
  327. text:setVisible(true)
  328. if v.name == "封顶" then
  329. text:setString(tostring(v.name..v.value[1]))
  330. else
  331. text:setString(tostring(v.value[1]))
  332. end
  333. self.ui.Items.ListView:addChild(text)
  334. end
  335. self.ui.Items.ListView:jumpToTopOnSizeChanged();
  336. end
  337. function ZPRoomView:initToolLayer()
  338. --人物头像层
  339. self.PlayerView = ZPRoomPlayerView:new()
  340. self.ui.Items.Layout_Player:addChild(self.PlayerView)
  341. --操作界面(吃碰杠胡)
  342. self.operationView = ZPRoomOperationView:new(self)
  343. self.ui.Items.Layout_Tool:addChild(self.operationView)
  344. --加载工具层
  345. self.toolView = ZPRoomToolView:new()
  346. self.ui.Items.Layout_Tool:addChild(self.toolView)
  347. --[[ -- 添加语音相关的界面
  348. self.messageView = import("Views.Room.ZiPaiRoomMessageView"):new()
  349. self:addChild(self.messageView)--]]
  350. local headInfos = {}
  351. for k,v in pairs(self.PlayerView.allNodes) do
  352. if k == 2 then
  353. local pos = cc.pAdd(v.player:getPosition(),cc.p(39,39))
  354. table.insert(headInfos,{headPos=pos})
  355. elseif k == 4 then
  356. local pos = cc.pAdd(v.player:getPosition(),cc.p(50,50))
  357. table.insert(headInfos,{headPos=pos})
  358. elseif k == 3 then
  359. local pos = cc.pAdd(v.player:getPosition(),cc.p(50,50))
  360. table.insert(headInfos,{headPos=pos})
  361. elseif k == 1 then
  362. local pos = cc.pAdd(v.player:getPosition(),cc.p(185,50))
  363. table.insert(headInfos,{headPos=pos})
  364. end
  365. end
  366. -- self.messageView = require("luaScript.Views.Room.ChatView"):new({chatList=ZPDef.LUZHOUDAER_GAME_CHAT_TXT},headInfos,false)
  367. -- self.toolView.ui.Items.Layout_ChatView:addChild(self.messageView)
  368. -- --self.messageView:setBtnFace(cc.p(1232,134),"zp_room_btn_kjy.png")
  369. -- --self.messageView:setBtnVoice(cc.p(1232,50),"zp_room_btn_yuyin.png")
  370. -- self.messageView:setBtnFace(cc.p(0.9625, 0.1861111),"zp_room_btn_kjy.png")
  371. -- self.messageView:setBtnVoice(cc.p(0.9625, 0.0694444),"zp_room_btn_yuyin.png")
  372. -- 小局查牌界面
  373. self.xiaojuChaPaiView = ZPRoomXiaoJuChaPaiView:new()
  374. self.xiaojuChaPaiView:setVisible(false)
  375. --亮牌界面确定
  376. local function cb()
  377. --显示小局结算
  378. if self.xiaojuView then
  379. self.xiaojuView:setVisible(true)
  380. end
  381. end
  382. self.xiaojuChaPaiView:setQueDingCallBack(cb)
  383. self.xiaojuChaPaiView:showHuCardCallBack(handler(self , self.onShowHuCard))
  384. self:addChild(self.xiaojuChaPaiView)
  385. end
  386. --隐藏剩余牌层
  387. function ZPRoomView:setCircleCardLeftPanelView(bVisible,viewId,leftNum)
  388. self.leftNum = leftNum
  389. --[[self.ui.Items.Layout_circleCardLeft:setVisible(bVisible)
  390. for i = 1, ZPDef.GameMaxPlayer do
  391. local name = string.format("ImageView_arrow_%d",i)
  392. self.ui.Items[name]:setVisible(false)
  393. end
  394. self.ui.Items.Text_num:setText(tostring(self.leftNum))
  395. --乌龟壳
  396. if bVisible then
  397. local name = string.format("ImageView_arrow_%d",viewId)
  398. self.ui.Items[name]:setVisible(true)
  399. end--]]
  400. self:setFaPaiQiPanelView(bVisible,viewId,leftNum)
  401. if viewId and not self.isRecordStart then
  402. self.PlayerView:setPClockVisible(viewId,true)
  403. end
  404. end
  405. function ZPRoomView:setFaPaiQiPanelView(bVisible,viewId,leftNum)
  406. if viewId and leftNum then
  407. if not self.fapaiqiLeftCard then
  408. self.fapaiqiLeftCard = {}
  409. local bgsize = self.ui.Items.ImageView_card_bg:getContentSize()
  410. for i = 1,tonumber(leftNum) do
  411. self.fapaiqiLeftCard[i] = cc.ImageView:createNode()
  412. self.fapaiqiLeftCard[i]:loadTextureFromPlist("zp_room_fapaiqi_cardBg1.png")
  413. self.ui.Items.ImageView_card_bg:addChild(self.fapaiqiLeftCard[i])
  414. self.fapaiqiLeftCard[i]:setPosition(cc.p(bgsize.width/2,bgsize.height/2+i))
  415. end
  416. else
  417. for i = #self.fapaiqiLeftCard,leftNum+1,-1 do
  418. if self.fapaiqiLeftCard[i] then
  419. self.fapaiqiLeftCard[i]:removeFromParent()
  420. self.fapaiqiLeftCard[i] = nil
  421. end
  422. end
  423. end
  424. self.ui.Items.TextBMFont_leftCardNum:setText(tostring(self.leftNum))
  425. end
  426. end
  427. function ZPRoomView:defaultState()
  428. --队列初始化
  429. self.callbackQueue = {}
  430. self.callbackRunning = false
  431. self.PlayerView:setOffLine(false)
  432. self.PlayerView:setPlayerVisible(false)
  433. self:resetGameData()
  434. --第一局清理托管标志,后面每局开始不清理(不然会出现没有取消托管,托管标志不显示bug)
  435. self.PlayerView:setTuoGuanFlagVisible(false)
  436. end
  437. function ZPRoomView:resetGameData()
  438. logE("===========重置游戏数据===============")
  439. self.handCardRoot = {}
  440. self.handCardValueLocal = {}
  441. self.handCardValueBak = {}
  442. self:setOutCardLineVisible(false)
  443. self:setWetChatVisible(false)
  444. self:setBtnSitDownVisible(false)
  445. self:setOutCardVisible(false)
  446. self:setOperatorPanelView(false)
  447. self:setGuideView(false)
  448. self:setHandTempCardVisible(false)
  449. self:setCircleCardLeftPanelView(false)
  450. self:setLiangPaiVisible(false)
  451. self:setTingCardViewVisible(false)
  452. self:setDingPiaoVisible(false)
  453. self:setLayoutScoreTipVisible(false)
  454. if self.PlayerView then
  455. self.PlayerView:setReadyStateVisible(false)
  456. self.PlayerView:setBankerVisible()
  457. self.PlayerView:setOperatorTipVisible(false)
  458. self.PlayerView:setAllClockVisible(false)
  459. self.PlayerView:hideLeftCard()
  460. end
  461. --隐藏工具界面 详情
  462. if self.toolView.ui.Items.ImageView_Rule_bg then
  463. self.toolView.ui.Items.ImageView_Rule_bg:setVisible(false)
  464. end
  465. --隐藏操作吃界面
  466. self.operationView:setAllEatView(false)
  467. --操作码
  468. self.operationLocalCode = 0
  469. self.isMoPaiOperator = false
  470. self.isGameOver = false
  471. self.isTianHu = false
  472. self.isGodHand = false
  473. --听牌重置
  474. self.isNoCardTingPai = false
  475. self.tingCardLocal = {}
  476. self.tableHuXiList = {}
  477. --弃牌
  478. self.qiPaiList = {}
  479. --发牌器
  480. if self.ui.Items.ImageView_card_bg then
  481. self.ui.Items.ImageView_card_bg:removeAllChildren()
  482. end
  483. self.fapaiqiLeftCard = nil
  484. self.ui.Items.TextBMFont_leftCardNum:setText("0")
  485. --庄家爆牌标志
  486. self.bankerBaoPao = nil
  487. --移除所有的牌局
  488. self.ui.Items.LayoutMain_4:removeAllChildren()
  489. if self.ui.Items.Layout_Player_HuEffect then
  490. self.ui.Items.Layout_Player_HuEffect:removeAllChildren()
  491. end
  492. self:clearXJChaPaiView()
  493. for i = 1, ZPDef.GameMaxPlayer do
  494. local giveupName = string.format("Layout_giveUp_%d",i)
  495. local weaveCardName = string.format("Layout_player1Table_%d",i)
  496. --移除胡牌的时候点炮
  497. local outCardImgName = string.format("ImageView_outCardLight_%d",i)
  498. --重置开招次数
  499. self.playerZhao[i] = 0
  500. --弃牌数组
  501. self.qiPaiList[i] = {}
  502. self.ui.Items[weaveCardName]:removeAllChildren()
  503. self.ui.Items[giveupName]:removeAllChildren()
  504. self.ui.Items[outCardImgName]:removeAllChildren()
  505. end
  506. self.PlayerView:setHuXizero()
  507. if self.xiaojuView then
  508. self.xiaojuView:removeFromParent()
  509. self.xiaojuView = nil
  510. end
  511. if self.xiaojuChaPaiView then
  512. self.xiaojuChaPaiView:setVisible(false)
  513. end
  514. --停止一些动画
  515. self.ui:stopAllActions()
  516. logD("self.ui:stopAllActions()")
  517. end
  518. function ZPRoomView:setLayoutScoreTipVisible(bVisible,scoreData,isFirstHand,onEnd,isHuPai)
  519. --self.ui.Items.Layout_ScoreTip:setVisible(bVisible)
  520. end
  521. function ZPRoomView:setDingPiaoVisible(bVisible)
  522. if self.piaoView then
  523. self.piaoView:removeSelf()
  524. self.piaoView = nil
  525. end
  526. if bVisible then
  527. self.piaoView = ZPRoomPiaoFenView:new()
  528. self:addChild(self.piaoView)
  529. end
  530. end
  531. --重置出牌坐标
  532. function ZPRoomView:resetOutCardPoint()
  533. for i = 1 ,ZPDef.GameMaxPlayer do
  534. local imgName = string.format("ImageView_outCardImg_%d",i)
  535. local mSprite = self.ui.Items[imgName]
  536. mSprite:setPosition(self.srcOutCardPosList[i])
  537. end
  538. end
  539. --改变外发光颜色
  540. function ZPRoomView:changeOutCardLight(isMoPai)
  541. for i = 1 ,ZPDef.GameMaxPlayer do
  542. local outCardLightName = string.format("ImageView_outCardLight_%d",i)
  543. local light = self.ui.Items[outCardLightName]
  544. local fileName
  545. if isMoPai then
  546. fileName = ZPDef.LightType.BLUE
  547. else
  548. fileName = ZPDef.LightType.YELLOW
  549. end
  550. light:loadTextureFromPlist(fileName)
  551. end
  552. end
  553. --隐藏出牌点
  554. function ZPRoomView:setOutCardVisible(bVisible,viewId,card,isSend,onEnd,isNoShowAni)
  555. for i = 1 ,ZPDef.GameMaxPlayer do
  556. local name = string.format("Layout_outCardPoint_%d",i)
  557. self.ui.Items[name]:setVisible(false)
  558. end
  559. --重置出牌坐标
  560. self:resetOutCardPoint()
  561. --显示出牌
  562. if bVisible then
  563. self.isMoPaiOperator = false
  564. self:changeOutCardLight(false)
  565. local name = string.format("Layout_outCardPoint_%d",viewId)
  566. local mLayout = self.ui.Items[name]
  567. mLayout:setVisible(true)
  568. local imgName = string.format("ImageView_outCardImg_%d",viewId)
  569. local fileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_OUTCARD)
  570. local mSprite = self.ui.Items[imgName]
  571. local srcPos = mSprite:getPosition()
  572. self.ui.Items[imgName]:loadTextureFromPlist(fileName)
  573. self.ui.Items[imgName].value = card
  574. local beginPos
  575. local time = self.gameSpeedConfig.CHU_PAI_TIME
  576. if viewId == self:getMeViewId() then
  577. beginPos = self.ui.Items.ImageView_handTempCard:getPosition()
  578. beginPos = mSprite:getParent():convertToNodeSpace(beginPos)
  579. else
  580. if viewId == 1 then
  581. beginPos = cc.p(srcPos.x + 400,srcPos.y)
  582. elseif viewId == 2 then
  583. beginPos = cc.p(srcPos.x,srcPos.y + 200)
  584. elseif viewId == 3 then
  585. beginPos = cc.p(srcPos.x - 400,srcPos.y)
  586. end
  587. end
  588. mSprite:setPosition(beginPos)
  589. mSprite:setScale(0)
  590. if isNoShowAni then
  591. mSprite:setScale(1)
  592. mSprite:setPosition(srcPos)
  593. if onEnd then
  594. onEnd()
  595. end
  596. return
  597. end
  598. local spawn = cc.Spawn:create(cc.ScaleTo:create(time,1,1),cc.MoveTo:create(time,srcPos))
  599. local seq = cc.Sequence:create(spawn,cc.CallFunc:create(function ()
  600. if isSend then
  601. local request = ZPMessage.OutCard:new()
  602. request.nCard = card
  603. logE("ZPRoomView:setOutCardVisible"..table.tostring(request))
  604. self.ui:sendMsg(app.room, "sendOutCard", request, function (status, response)
  605. logE("ZPRoomView sendOutCard() response = ", table.tostring(response))
  606. end)
  607. end
  608. if onEnd then
  609. onEnd()
  610. end
  611. end))
  612. mSprite:runAction(seq)
  613. end
  614. end
  615. --设置出牌线为隐藏
  616. function ZPRoomView:setOutCardLineVisible(bVisible)
  617. self.ui.Items.ImageView_line:setVisible(bVisible)
  618. end
  619. --隐藏行为操作层
  620. function ZPRoomView:setOperatorPanelView(bVisible,operations)
  621. self.operationView:setOperatorPanelView(bVisible,operations)
  622. end
  623. --隐藏提示界面
  624. function ZPRoomView:setGuideView(bVisible)
  625. if app.room:isLittleFamily() then
  626. bVisible = false
  627. end
  628. self.ui.Items.Layout_tips:setVisible(bVisible)
  629. self.ui.Items.Button_OutCard:setVisible(bVisible)
  630. self.ui.Items.Button_OutCard:setEnabled(false)
  631. if bVisible then
  632. self.ui.Items.ImageView_3:playClip("tip")
  633. end
  634. end
  635. function ZPRoomView:setColorWhite()
  636. if app.room:isLittleFamily() and not ZPFuc.getLittleIsCanLookCard() then
  637. return
  638. end
  639. self.ui.Items.Button_OutCard:setEnabled(false)
  640. for col = 1, self.lieShuMax do
  641. for row = 1,self.hangShuMax do
  642. if not self.handCardRoot[col].imgList[row].isKan then
  643. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  644. end
  645. end
  646. end
  647. end
  648. --展示牌
  649. function ZPRoomView:setHandTempCardVisible(bVisible)
  650. self.ui.Items.ImageView_handTempCard:setVisible(bVisible)
  651. end
  652. --更新房间基础数据
  653. function ZPRoomView:updateRoomBaseData()
  654. --初始化背景
  655. local ZiPaigameBgPicture = "gameBgPicture"..(ZPDef.GameID or app.gameId)
  656. local idx2 = tonumber(loadUserInfo(ZiPaigameBgPicture)) or 4
  657. self:setTableImg(idx2)
  658. local roomInfo = app.room.roomInfo;
  659. -- 房间号
  660. self.ui.Items.Text_roomNum:setText(tostring(roomInfo.nShowTableId));
  661. --局数
  662. self:updateGameNums()
  663. --房间玩法
  664. --local ruleAll = ZPFuc.getRuleInfo();
  665. --self.toolView.ui.Items.Text_Rule:setText(ruleAll)
  666. self:setRoomInfo()
  667. self:onUserReadyResponse()
  668. for i = 1,ZPDef.GameMaxPlayer do
  669. self.PlayerView:updatePlayerInfo(i)
  670. end
  671. -- 是否显示邀请好友
  672. self:setWetChatVisible(app.room:getActualPlayerNum() < ZPFuc.getCreateRoomPlayerNum())
  673. self.toolView:showFastStart(true)
  674. if isReviewVersion() then
  675. self:setWetChatVisible(false);
  676. end
  677. -- 更新玩家手牌列表时,按需显示
  678. if app.room.roomInfo.nGameStartCount > 0 then
  679. self:setWetChatVisible(false)
  680. end
  681. if app.room.roomInfo.nGameStartCount == 0 then
  682. if self.ui.Items.Button_tipai then
  683. self.ui.Items.Button_tipai:setVisible(false)
  684. end
  685. end
  686. end
  687. function ZPRoomView:onGameReconnection()
  688. --logE("ZiPai当前版本号:"..ZPFuc.getZPCurVersion())
  689. --更新房间基础数据
  690. self:updateRoomBaseData()
  691. local roomInfo = app.room.roomInfo;
  692. --self:updateAllGpsInfo()
  693. --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0)
  694. --self:checkMyGpsNeedUpdate();
  695. --断线重连
  696. if roomInfo.nGameStartCount > 0 then
  697. local function runOnGameReconnection(onEnd)
  698. local roomInfo = app.room.roomInfo;
  699. --显示庄家
  700. self:updateBanker()
  701. self:showOwner()
  702. local myUserID = app.room:getMyRecordUserId()
  703. --解散状态
  704. local isDismiss = false
  705. local uid = 0
  706. for k,v in pairs(roomInfo.arrayTableInfo) do
  707. local viewId = app.room:getViewIdByUserId(k)
  708. local nOffLineState = v.nOnlineStatus
  709. --显示离线
  710. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  711. local viewId = app.room:getViewIdByUserId(k)
  712. --记录玩家解散状态 0:初始状态, 1:发起解散 2: 同意解散 3:不同意解散
  713. app.room.dismissInfo[k] = v.nDisbandStatus;
  714. --有人发起解散时才显示解散界面
  715. if v.nDisbandStatus == 1 then
  716. isDismiss = true
  717. uid = k
  718. end
  719. end
  720. self.PlayerView:setXiaoJiaFlagVis(true)
  721. --有人发起解散时才显示解散界面
  722. if isDismiss then
  723. app.room.roomInfo.nDismissStateTime = roomInfo.nDismissStateTime;
  724. app.room.roomInfo.nDismissToTalTime = roomInfo.nDismissToTalTime;
  725. local view = require("luaScript.Views.Room.RoomDismissView"):new(uid,app.room.roomInfo.memberList,roomInfo.nDismissStateTime)
  726. view:setAnchorPoint(cc.p(0.5, 0.5));
  727. app:showWaitDialog(view);
  728. end
  729. --如果一局结束,玩家点了准备,不再显示牌信息
  730. if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == 1
  731. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == 1
  732. then --游戏为停止或开始状态
  733. self:onUserReadyResponse()
  734. self.ui.Items.Button_tipai:setVisible(false)
  735. if onEnd then
  736. onEnd()
  737. end
  738. return
  739. end
  740. -- 托管状态恢复
  741. for k,v in pairs(roomInfo.tuoGuanInfo or {}) do
  742. local aiStatus = v.aiStatus;
  743. local nUserID = v.nUserID;
  744. local viewId = app.room:getViewIdByUserId(nUserID)
  745. local isTuoGuan = aiStatus == 1;
  746. if self:getIsMeUId(nUserID) then
  747. if isTuoGuan then
  748. self:showTuoGuan(true)
  749. self.isTuoGuan = true
  750. else
  751. self:showTuoGuan(false)
  752. self.isTuoGuan = false
  753. end
  754. end
  755. self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
  756. end
  757. --胡牌类型
  758. local huType = ZPDef.ReconnectHuType.NO_HU
  759. --状态显示
  760. if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
  761. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then --游戏为停止或开始状态
  762. self.ui.Items.Button_tipai:setVisible(false)
  763. --显示小局结算亮牌画布
  764. self:setLiangPaiVisible(true)
  765. --显示底牌
  766. self.xiaojuChaPaiView:showDiPai()
  767. --亮手牌
  768. huType = self.xiaojuChaPaiView:liangShouPai(true)
  769. local function nextCallBackFun()
  770. self:resetGameData()
  771. end
  772. self.xiaojuView = ZPRoomXiaoJuView:new(nextCallBackFun,true)
  773. self:addChild(self.xiaojuView)
  774. --播放黄庄动画
  775. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
  776. self.xiaojuChaPaiView:PlayHuangZhuangAni(false)
  777. end
  778. self.xiaojuView:setVisible(false)
  779. self:setBtnSitDownVisible(false)
  780. end
  781. local diPaiMax = table.nums(roomInfo.dipaiList)
  782. for k,v in pairs(roomInfo.arrayTableInfo) do
  783. local viewId = app.room:getViewIdByUserId(k)
  784. local nScore = v.nTotalMoney or 0
  785. --玩家分数
  786. self.PlayerView:setPlayerScore(viewId,nScore)
  787. --扎鸟
  788. self.PlayerView:setPlayerPiaoFen(viewId,v.nZhaBirdScore)
  789. --恢复手牌
  790. if k == myUserID then
  791. self:createCard(false,myUserID,nil)
  792. end
  793. --恢复爆牌动画
  794. if v.nBaoPaiStatus == 2 and not (ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
  795. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus) then
  796. self.PlayerView:playBaoAnim(viewId)
  797. end
  798. local hushu = 0
  799. --恢复组合牌
  800. for key,value in pairsByKeys(v.tableWeaveCard) do
  801. local list,operationType = ZPFuc.getZPCardList(value.card,value.type)
  802. local isShow = true
  803. local card = value.opcard
  804. hushu = hushu + value.hushu
  805. --记录真实数据
  806. --过滤:碰胡和偎胡,坎提胡,坎跑胡 的组合牌不显示,这些组合牌在self:liangShouPai()里后面插回手里
  807. if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
  808. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then
  809. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL then
  810. local nUserId = roomInfo.winUserId
  811. local viewId = app.room:getViewIdByUserId(nUserId)
  812. local huCard = roomInfo.huCard
  813. --不等于赢家的ID,组合牌就全部显示,赢家的需要判断
  814. if nUserId == k then
  815. if huType == ZPDef.ReconnectHuType.WEI_HU and operationType == ZPDef.OpType.OP_TYPE_MINGWEI and huCard == card then
  816. isShow = false
  817. elseif huType == ZPDef.ReconnectHuType.WEI_HU and operationType == ZPDef.OpType.OP_TYPE_ANWEI and huCard == card then
  818. isShow = false
  819. elseif huType == ZPDef.ReconnectHuType.PENG_HU and operationType == ZPDef.OpType.OP_TYPE_PENG and huCard == card then
  820. isShow = false
  821. elseif huType == ZPDef.ReconnectHuType.KAN_TI_HU and operationType == ZPDef.OpType.OP_TYPE_TI and huCard == card then
  822. isShow = false
  823. elseif huType == ZPDef.ReconnectHuType.KAN_PAO_HU and operationType == ZPDef.OpType.OP_TYPE_PAO and huCard == card then
  824. isShow = false
  825. end
  826. end
  827. end
  828. end
  829. --对于要显示的牌,除了一些普通的牌需要展示外,特殊的有:偎提胡,偎跑胡,碰跑胡,这个时候,组合牌还是显示偎,偎,跑的原先模样
  830. if isShow then
  831. if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
  832. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then
  833. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL or
  834. roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HU_DIRTY then
  835. local nUserId = roomInfo.winUserId
  836. local viewId = app.room:getViewIdByUserId(nUserId)
  837. --如果赢的是当前的人组合牌需要稍微处理下
  838. if nUserId == k then
  839. local huCard = roomInfo.huCard
  840. if operationType == ZPDef.OpType.OP_TYPE_TI and huCard == card and huType == ZPDef.ReconnectHuType.WEI_TI_HU then
  841. --偎提胡(结算亮一张偎牌,这里处理为明偎)
  842. operationType = ZPDef.OpType.OP_TYPE_MINGWEI
  843. elseif operationType == ZPDef.OpType.OP_TYPE_PAO and huCard == card and huType == ZPDef.ReconnectHuType.PENG_PAO_HU then
  844. --碰跑胡
  845. operationType = ZPDef.OpType.OP_TYPE_PENG
  846. elseif operationType == ZPDef.OpType.OP_TYPE_PAO and huCard == card and huType == ZPDef.ReconnectHuType.WEI_PAO_HU then
  847. --偎跑胡(结算亮一张偎牌,这里处理为明偎)
  848. operationType = ZPDef.OpType.OP_TYPE_MINGWEI
  849. end
  850. end
  851. end
  852. end
  853. list = ZPFuc.getOpCardFirstList(operationType,list,card)
  854. --上面吃或不吃不要用if else因为还可能都不成立
  855. local isMoPaiOrId = value.seatId
  856. self:recontactDoOperation(operationType,viewId,list,card,isMoPaiOrId)
  857. end
  858. end
  859. self.tableHuXiList[viewId] = hushu
  860. self.PlayerView:setPlayerHuXi(viewId,hushu)
  861. --self.PlayerView:setPlayerHuXi("油:"..tostring(hushu))
  862. end
  863. self:getLocalHuShu()
  864. for i = 1, 4 do
  865. local tt = self.qiPaiList[i]
  866. end
  867. --恢复弃牌
  868. for k,v in pairs(roomInfo.arrayTableInfo) do
  869. local viewId = app.room:getViewIdByUserId(v.nUserId)
  870. local qiList = self.qiPaiList[viewId]
  871. for key,value in pairs(v.desertedArea) do
  872. local card = value.card
  873. local maxQi = table.nums(qiList)
  874. if maxQi > 0 then
  875. --染色弃牌
  876. local isInQiList = false
  877. for qiK,qiCard in pairs(qiList) do
  878. if qiCard == value.card then
  879. --染色弃牌
  880. self:playQiPaiAni(false,value.card,viewId,nil,true)
  881. isInQiList = true
  882. qiList[qiK] = nil
  883. break
  884. end
  885. end
  886. if not isInQiList then
  887. self:playQiPaiAni(false,value.card,viewId,nil,false)
  888. end
  889. else
  890. --普通弃牌
  891. self:playQiPaiAni(false,value.card,viewId,nil,false)
  892. end
  893. end
  894. end
  895. --听牌显示
  896. local max = table.nums(app.room.roomInfo.tingCards)
  897. if max > 0 then
  898. self:setTingCardViewVisible(true,app.room.roomInfo.tingCards)
  899. end
  900. --显示玩家剩余手牌
  901. if app.room.roomInfo.offLineInfo and next(app.room.roomInfo.offLineInfo) ~= nil then
  902. for i,v in pairs(app.room.roomInfo.offLineInfo) do
  903. if v.extInfo then
  904. local extIf = json.decode(v.extInfo)
  905. if extIf.LeftCard and v.nUserId then
  906. local viewId = app.room:getViewIdByUserId(v.nUserId)
  907. self.PlayerView:setLeftCardNum(viewId,true,tonumber(extIf.LeftCard))
  908. end
  909. end
  910. end
  911. end
  912. --状态显示
  913. if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
  914. or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then --游戏为停止或开始状态
  915. self.PlayerView:hideLeftCard()
  916. --所有的暗偎默认亮起一张
  917. self:showLastAnWeiPai()
  918. --点炮显示
  919. self:showPaoImage()
  920. for hi,hv in pairs(app.room.roomInfo.hupaiInfo) do
  921. if hv.huPaiUid > -1 then
  922. local winerViewId = app.room:getViewIdByUserId(hv.huPaiUid)
  923. app.room.roomInfo.huType = hv.huTypes
  924. self:playHuEffect(winerViewId,nil,true)
  925. --self:setLayoutScoreTipVisible(true,playerList,false,nil,true)
  926. end
  927. end
  928. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TIAN_HU == roomInfo.nStatus
  929. or ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_TURN_OVER == roomInfo.nStatus
  930. or ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_OUTCARD == roomInfo.nStatus then -- 天胡,翻牌后等待玩家操作中,出牌后等待玩家操作中
  931. local nSeatId = roomInfo.showCardSeatId
  932. local nCard = roomInfo.showCard
  933. local operateCode = roomInfo.mainOpCode
  934. local viewId = app.room:getViewIdBySeatId(nSeatId)
  935. local nUserId = app.room:getUserIdBySeatId(nSeatId)
  936. --记录真实数据
  937. self.outCard = nCard
  938. self.EatOperationCode = operateCode
  939. self.moPaiViewId = viewId
  940. --显示剩余牌
  941. self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
  942. if ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TIAN_HU == roomInfo.nStatus then
  943. --标记天胡
  944. self.isTianHu = true
  945. if viewId == self:getMeViewId() then
  946. self:showOpeation(ZPDef.OpCode.OP_HU,viewId)
  947. end
  948. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_OUTCARD == roomInfo.nStatus then
  949. --是否已经操作过 0表示没有,非0表示已经提交了操作
  950. if operateCode ~= ZPDef.OpCode.OP_CANCEL and roomInfo.isSubmitOp == 0 then
  951. self:showOpeation(operateCode)
  952. self:setOutCardVisible(true,viewId,nCard,false,nil,true)
  953. elseif roomInfo.isSubmitOp == 1 or roomInfo.isSubmitOp == 0 then
  954. self:setOutCardVisible(true,viewId,nCard,false,nil,true)
  955. --playVoiceCardValue(nCard,nUserId)
  956. elseif roomInfo.isSubmitOp == 2 then --比牌不显示出牌或者摸牌
  957. self.operationView:touchEatOneCardCallBack(true)
  958. end
  959. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_TURN_OVER == roomInfo.nStatus then
  960. if roomInfo.isSubmitOp == 1 then
  961. operateCode = 0
  962. self:playMoPaiAni(diPaiMax,nCard,viewId,operateCode,roomInfo.showCardFlag,nil,true)
  963. elseif roomInfo.isSubmitOp == 0 then
  964. self:playMoPaiAni(diPaiMax,nCard,viewId,operateCode,roomInfo.showCardFlag,nil,true)
  965. elseif roomInfo.isSubmitOp == 2 then --比牌不显示出牌或者摸牌
  966. self.operationView:touchEatOneCardCallBack(true)
  967. end
  968. end
  969. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OUT_CARDS == roomInfo.nStatus then --等待玩家出牌中
  970. --显示底牌
  971. local viewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
  972. --显示剩余牌
  973. self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
  974. if viewId == self:getMeViewId() then
  975. self:setGuideView(true)
  976. self.bOutCard = true
  977. end
  978. elseif ZPDef.ReconnectState.GAME_STATUS_AUTO_DISCSRD == roomInfo.nStatus then --玩家自动弃牌中
  979. local nSeatId = roomInfo.showCardSeatId
  980. local nCard = roomInfo.disCard
  981. local viewId = app.room:getViewIdBySeatId(nSeatId)
  982. --显示剩余牌
  983. self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
  984. --弃牌
  985. self:playQiPaiAni(true,nCard,viewId,nil)
  986. elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_BAO == roomInfo.nStatus then --等待玩家爆牌中
  987. --爆牌中
  988. local viewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
  989. self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
  990. for k,v in pairs(roomInfo.arrayTableInfo) do
  991. local viewId = app.room:getViewIdByUserId(k)
  992. --等待爆牌状态
  993. if v.nBaoPaiStatus == 1 and k == app.user.loginInfo.uid then
  994. self.operationView:showBaoPaiOpView(true)
  995. end
  996. end
  997. end
  998. if onEnd then
  999. onEnd()
  1000. end
  1001. end
  1002. log("2000000000-ZPRoomView - self:addCallBack(runOnGameReconnection)" )
  1003. self:addCallBack(runOnGameReconnection)
  1004. else
  1005. --未开局正常坐下这里会进来
  1006. for k,v in pairs(roomInfo.memberList) do
  1007. local viewId = app.room:getViewIdByUserId(k)
  1008. local nOffLineState = v.nOnlineStatus or 1
  1009. --显示离线
  1010. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  1011. end
  1012. --未开局重连坐下
  1013. for k,v in pairs(roomInfo.arrayTableInfo or {}) do
  1014. local viewId = app.room:getViewIdByUserId(k)
  1015. local nOffLineState = v.nOnlineStatus
  1016. --显示离线
  1017. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  1018. end
  1019. end
  1020. end
  1021. --断线重连
  1022. function ZPRoomView:recontactDoOperation(operationType,viewId,list,card,isMoPaiOrId)
  1023. if operationType == ZPDef.OpType.OP_TYPE_CHI then
  1024. self:createEatView(card,viewId,list,false,nil,nil)
  1025. elseif operationType == ZPDef.OpType.OP_TYPE_PENG then
  1026. self:createPengView(viewId,list,false,isMoPaiOrId)
  1027. elseif operationType == ZPDef.OpType.OP_TYPE_ANWEI then
  1028. self:createWeiPaiView(viewId,list,false,false)
  1029. elseif operationType == ZPDef.OpType.OP_TYPE_MINGWEI then
  1030. self:createWeiPaiView(viewId,list,false,true)
  1031. elseif operationType == ZPDef.OpType.OP_TYPE_PAO or operationType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
  1032. self:createTiOrPaoView(false,viewId,list,false,nil)
  1033. elseif operationType == ZPDef.OpType.OP_TYPE_TI then
  1034. self:createTiOrPaoView(true,viewId,list,false,nil)
  1035. end
  1036. end
  1037. --隐藏微信按钮
  1038. function ZPRoomView:setWetChatVisible(bVisible)
  1039. self.toolView.ui.Items.btnInvite:setVisible(bVisible)
  1040. self.toolView:setInviteClubVisible(bVisible)
  1041. self.toolView:updateButtonPosition()
  1042. end
  1043. --隐藏准备按钮
  1044. function ZPRoomView:setBtnSitDownVisible(bVisible)
  1045. self.toolView.ui.Items.Button_Ready:setVisible(bVisible)
  1046. end
  1047. function ZPRoomView:bindAllEvent()
  1048. if self.isRecordScene then return end
  1049. --[[
  1050. 消息分类管理
  1051. ]]
  1052. --用户状态(包括准备,其他玩家进入或者离开通知,离线等)
  1053. self:bindUserStatedMessage()
  1054. --私人场消息(包括解散等)
  1055. self:bindPrivateMessage()
  1056. --游戏消息
  1057. self:bindGameMessage()
  1058. --游戏场景消息
  1059. self:bindGameSceneMessage()
  1060. --绑定更换桌布事件
  1061. self:bindEvent(app , "onChangeTable" , handler(self , self.onChangeTable));
  1062. --操作按钮点击事件
  1063. self:bindEvent(app , "onClickOpBtn" , handler(self , self.onClickOpBtn));
  1064. self:bindEvent(app , ZPDef.ZPEvent.ChangeViewType , handler(self , self.onChangeCard));
  1065. end
  1066. function ZPRoomView:onChangeCard(data)
  1067. self:loadTextureCache()
  1068. --手牌
  1069. for k,v in ipairs(self.handCardRoot) do
  1070. if v.ui:isVisible() then
  1071. for _,ui in ipairs(v.imgList) do
  1072. if ui.value then
  1073. local fileName = ZPFuc.getZPCardImgByValue(ui.value,ZPDef.CardType.CARD_TYPE_HAND)
  1074. if fileName ~= "" then
  1075. ui:loadTextureFromPlist(fileName)
  1076. end
  1077. end
  1078. end
  1079. end
  1080. end
  1081. --组合牌
  1082. for i = 1,4 do
  1083. local name = string.format("Layout_player1Table_%d",i)
  1084. local UnitCardNode = self.ui.Items[name]
  1085. if UnitCardNode then
  1086. for k,mLayout in ipairs(UnitCardNode:getChildren()) do
  1087. if mLayout.cardList ~= nil then
  1088. for idx,ui in ipairs(mLayout:getChildren()) do
  1089. if mLayout.cardList[idx] then
  1090. local fileName = ZPFuc.getZPCardImgByValue(mLayout.cardList[idx],ZPDef.CardType.CARD_TYPE_TABLE)
  1091. if fileName ~= "" then
  1092. ui:loadTextureFromPlist(fileName)
  1093. end
  1094. end
  1095. end
  1096. end
  1097. end
  1098. end
  1099. end
  1100. --出牌
  1101. for viewId = 1, 4 do
  1102. local imgName = string.format("ImageView_outCardImg_%d",viewId)
  1103. local mSprite = self.ui.Items[imgName]
  1104. if mSprite.value then
  1105. local fileName = ZPFuc.getZPCardImgByValue(mSprite.value,ZPDef.CardType.CARD_TYPE_OUTCARD)
  1106. if fileName ~= "" then
  1107. self.ui.Items[imgName]:loadTextureFromPlist(fileName)
  1108. end
  1109. end
  1110. end
  1111. --弃牌
  1112. for i = 1,4 do
  1113. local giveupCardname = string.format("Layout_giveUp_%d",i)
  1114. local giveUpLayout = self.ui.Items[giveupCardname]
  1115. for k,mSprite in ipairs(giveUpLayout:getChildren()) do
  1116. if mSprite.value then
  1117. local fileName = ZPFuc.getZPCardImgByValue(mSprite.value,ZPDef.CardType.CARD_TYPE_TABLE)
  1118. if fileName ~= "" then
  1119. mSprite:loadTextureFromPlist(fileName)
  1120. end
  1121. end
  1122. end
  1123. end
  1124. --吃牌
  1125. if self.operationView then
  1126. if self.operationView:getEatCardVisible() then
  1127. self.operationView:setEatBtnEnabledTrue()
  1128. --显示吃牌的节点
  1129. self.operationView:setEatCardView(false)
  1130. self.operationView:setEatCardBiView(false)
  1131. self.operationView:setEatCardSanBiView(false)
  1132. end
  1133. end
  1134. end
  1135. function ZPRoomView:onChangeTable(data)
  1136. local idx = data.idx
  1137. self:setTableImg(idx)
  1138. end
  1139. --点击了操作按钮,在等服务器下发消息回来之前,禁止拖动操作
  1140. function ZPRoomView:onClickOpBtn(data)
  1141. self.isGodHand = true
  1142. --防止一直卡住的情况
  1143. local seq = cc.Sequence:create(cc.DelayTime:create(2.0),cc.CallFunc:create(function ()
  1144. self.isGodHand = false
  1145. end))
  1146. self:runAction(seq)
  1147. end
  1148. function ZPRoomView:setTableImg(idx)
  1149. local name = string.format("res/ui/zy_fangjian/bg/fangjian_di_%d.png",idx)
  1150. --桌布
  1151. self.ui.Items.ImageView_bg:loadTexture(name)
  1152. local cacheGameBgPic = "gameBgPicture"..(ZPDef.GameID or app.gameId)
  1153. saveUserInfo(cacheGameBgPic,idx)
  1154. --self.toolView.ui.Items.ImageView_menubg:setVisible(false)
  1155. end
  1156. function ZPRoomView:initLogo()
  1157. if tolua.isnull(self.ui.Items.ImageView_Logo) then return end
  1158. if not (type(getSubGameRoomLogo) == 'function') then--大厅不支持此方法,则隐藏logo
  1159. self.ui.Items.ImageView_Logo:setVisible(false);
  1160. return
  1161. end
  1162. local strGameInfo = app.room.roomInfo.strGameInfo or ""
  1163. local gameInfo = json.decode(strGameInfo) or {}
  1164. local gamerule = tonumber(gameInfo.gamerule or 1)
  1165. local logofile = getSubGameRoomLogo(ZPDef.GameID or app.gameId,gamerule)
  1166. if logofile then
  1167. self.ui.Items.ImageView_Logo:loadTexture(logofile)
  1168. self.ui.Items.ImageView_Logo:setVisible(true);
  1169. else
  1170. self.ui.Items.ImageView_Logo:setVisible(false);
  1171. end
  1172. end
  1173. function ZPRoomView:initRoomMenu()
  1174. if not tolua.isnull(self.roomMenuView) then
  1175. return
  1176. end
  1177. local RoomMenuViewClass = require("zp_base.luaScript.Views.Components.ZPRoomMenuView");
  1178. self.roomMenuView = RoomMenuViewClass:new()
  1179. self:addChild(self.roomMenuView)
  1180. if self.ui.Items.Layout_Menu then
  1181. self.ui.Items.Layout_Menu:setVisible(false)
  1182. end
  1183. if self.ui.Items.Layout_menu then
  1184. self.ui.Items.Layout_menu:setVisible(false)
  1185. end
  1186. if self.ui.Items.Button_menu then
  1187. self.ui.Items.Button_menu:setVisible(false)
  1188. end
  1189. end
  1190. --用户状态消息
  1191. function ZPRoomView:bindUserStatedMessage()
  1192. --默认状态
  1193. self:bindEvent(app.room , "defaultState" , handler(self , self.defaultState));
  1194. -- 玩家准备
  1195. self:bindEvent(app.room , "onUserReadyResponse" , handler(self , self.onUserReadyResponse));
  1196. -- 其他玩家进入房间
  1197. self:bindEvent(app.room , "onOtherSitDownResponse" , handler(self , self.onOtherSitDownResponse));
  1198. -- 其他玩家退出房間
  1199. self:bindEvent(app.room , "onOtherLogoutResponse" , handler(self , self.onOtherLogoutResponse));
  1200. -- 其他玩家掉线
  1201. self:bindEvent(app.room , "onOtherDroppedResponse" , handler(self , self.onOtherDroppedResponse));
  1202. -- 用户T出
  1203. self:bindEvent(app.room , "onUserExitResponseRoom" , handler(self , self.onUserExitResponseRoom));
  1204. -- 玩家的GPS信息发生变化
  1205. self:bindEvent(app.room , "onGpsChangeResponse" , handler(self , self.onGpsChangeResponse));
  1206. end
  1207. --私人场消息
  1208. function ZPRoomView:bindPrivateMessage()
  1209. -- 玩家收到解散房间的请求
  1210. self:bindEvent(app.room , "onDismissResponse" , handler(self , self.onDismissResponse));
  1211. end
  1212. --游戏消息
  1213. function ZPRoomView:bindGameMessage()
  1214. -- 游戏开始
  1215. self:bindEvent(app.room , "onGameStartResponse" , handler(self , self.onGameStartResponse));
  1216. -- 开始给桌子上用户发牌
  1217. self:bindEvent(app.room , "onGameSendCardResponse" , handler(self , self.onGameSendCardResponse));
  1218. -- 系统发给自己可串可哨的消息
  1219. self:bindEvent(app.room , "onSystemOperationStart" , handler(self , self.onSystemOperationStart));
  1220. -- 广播桌子上所有玩家庄家起手操作
  1221. self:bindEvent(app.room , "onBankerOutCard", handler(self , self.onBankerOutCard));
  1222. -- 出牌错误
  1223. self:bindEvent(app.room , "onOutCardError", handler(self , self.onOutCardError));
  1224. -- 出牌成功
  1225. self:bindEvent(app.room , "onOutCardSuccess", handler(self , self.onOutCardSuccess));
  1226. -- 摸牌
  1227. self:bindEvent(app.room , "onMoPai", handler(self , self.onMoPai));
  1228. -- 弃牌
  1229. self:bindEvent(app.room , "onQiPai", handler(self , self.onQiPai));
  1230. -- 操作错误
  1231. self:bindEvent(app.room , "onOperationError", handler(self , self.onOperationError));
  1232. -- 先操作玩家
  1233. self:bindEvent(app.room , "onOperationFirst", handler(self , self.onOperationFirst));
  1234. -- 操作成功
  1235. self:bindEvent(app.room , "onOperationCodeSuccess", handler(self , self.onOperationCodeSuccess));
  1236. -- 听牌
  1237. self:bindEvent(app.room , "onTingCardResult",handler(self , self.onTingCardResult));
  1238. --打乱位置
  1239. self:bindEvent(app.room , "onChoicePlace",handler(self , self.onChoicePlace));
  1240. -- 爆牌
  1241. self:bindEvent(app.room , "onBaoPaiResponese",handler(self , self.onBaoPaiResponese));
  1242. -- 最后一张牌
  1243. self:bindEvent(app.room , "onLastCardResponse",handler(self , self.onLastCardResponse));
  1244. self:bindEvent(app.room , "onGameXiaoJuResponse" , handler(self , self.onGameXiaoJuResponse));
  1245. self:bindEvent(app.room , "onGameDaJuResponse" , handler(self , self.onGameDaJuResponse));
  1246. -- 立即开局
  1247. self:bindEvent(app.room , "onQuickStartResponse" , handler(self , self.onQuickStartResponse));
  1248. -- 获取刷新手牌
  1249. self:bindEvent(app.room , "onGetHandcardsResponese" , handler(self , self.onGetHandcardsResponese));
  1250. --托管结果
  1251. self:bindEvent(app.room , "onTuoGuanResponse",handler(self , self.onTuoGuanResponse));
  1252. end
  1253. --场景恢复
  1254. function ZPRoomView:bindGameSceneMessage()
  1255. local function onEnterRoomSuccess(event)
  1256. if tolua.isnull(self.ui) then
  1257. logE("self.is null")
  1258. return
  1259. end
  1260. logD("ZPRoomView onEnterRoomSuccess")
  1261. logD("ZPRoomView stopAllActions")
  1262. self:stopAllActions()
  1263. self:defaultState()
  1264. self:onGameReconnection()
  1265. self:startGame()
  1266. end
  1267. app.hall:addEventListener("onEnterRoomSuccess", onEnterRoomSuccess)
  1268. end
  1269. --自己的视图ID
  1270. function ZPRoomView:getMeViewId()
  1271. return ZPDef.MyViewID
  1272. end
  1273. --判断是否是自己的uid
  1274. function ZPRoomView:getIsMeUId(uid)
  1275. return uid == app.user.loginInfo.uid
  1276. end
  1277. function ZPRoomView:onGameSendCardResponse()
  1278. local function runGameSendCardResponse(onEnd)
  1279. self.PlayerView:stopAndHideBaoAnim()
  1280. log("2000000000-ZPRoomView - runGameSendCardResponse()" )
  1281. if self.taiPaiTimer then
  1282. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.taiPaiTimer)
  1283. end
  1284. --显示指示器
  1285. local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
  1286. local leftCardNum = 19
  1287. if app.room:getActualPlayerNum() == 2 then--and GameFunctions.getCurFangShu() == 0
  1288. leftCardNum = 39
  1289. end
  1290. self:setCircleCardLeftPanelView(true,bankerViewId,leftCardNum)
  1291. --发牌
  1292. self:createCard(true,app.user.loginInfo.uid,onEnd)
  1293. print("ding piao:"..table.tostring(app.room.roomInfo.memberList))
  1294. --self.ui.Items.Button_tipai:setVisible(true)
  1295. self.PlayerView:setLeftCardNum(1,true,20)
  1296. self.PlayerView:setLeftCardNum(3,true,20)
  1297. end
  1298. log("2000000000-ZPRoomView - addCallBack(runGameSendCardResponse)" )
  1299. self:addCallBack(runGameSendCardResponse);
  1300. end
  1301. function ZPRoomView:createCard(bShowAnimation,nUserID,onEnd)
  1302. logE("====================RoomView:createCard()===================");
  1303. local cardList = app.room.cards[nUserID]
  1304. if not cardList or table.nums(cardList) <= 0 then
  1305. --重连当自己没有手牌且有7方门子
  1306. if onEnd then
  1307. onEnd()
  1308. end
  1309. return
  1310. end
  1311. local lieshuMax = table.nums(cardList)
  1312. local RankCardList = {}
  1313. local colList = self.lieshulist[lieshuMax]
  1314. local blankList = self.lieshuBlanklist[lieshuMax]
  1315. local wuIndex = 0
  1316. local youIndex = 0
  1317. --重新调整
  1318. for k = 1,self.lieShuMax do
  1319. if not cardList[k] then
  1320. cardList[k] = {}
  1321. end
  1322. if table.nums(cardList[k]) <= 0 then
  1323. wuIndex = wuIndex + 1
  1324. local blankIndex = blankList[wuIndex] -- 1,10
  1325. if blankIndex then
  1326. RankCardList[blankIndex] = {}
  1327. end
  1328. else
  1329. youIndex = youIndex + 1
  1330. local index = colList[youIndex] -- 2,3,4,5,6,7,8,9
  1331. RankCardList[index] = cardList[k]
  1332. end
  1333. end
  1334. cardList = {}
  1335. cardList = RankCardList
  1336. logE("createCard Rank ok :"..table.tostring(cardList))
  1337. local index = 1
  1338. --不管有无数据,默认创建10列数据
  1339. for i = 1,self.lieShuMax do
  1340. local value = cardList[i] or {}
  1341. local isKan = self:getCurrentColIsKan(value)
  1342. local card = ZPRoomCard:new(value,ZPDef.CardType.CARD_TYPE_HAND,i,isKan)
  1343. local pos = self.boxPosList4[i]
  1344. card.ui:setPosition(pos)
  1345. self.ui.Items.LayoutMain_4:addChild(card.ui,1)
  1346. --数据记录
  1347. self.handCardRoot[i] = card
  1348. self.handCardValueLocal[i] = value
  1349. self.handCardValueBak[i] = clone(value)
  1350. --存储所有的单牌节点Image
  1351. for k = 1 ,self.hangShuMax do
  1352. self.handCardItem[index] = card.imgList[k]
  1353. index = index + 1
  1354. end
  1355. end
  1356. logE("create card finish self.handCardValueLocal : "..table.tostring(self.handCardValueLocal))
  1357. if bShowAnimation then
  1358. --发牌动画(10*0.1+ 0.15 = 1.15miao)
  1359. for k,v in ipairs(self.handCardRoot) do
  1360. if v.ui:isVisible() then
  1361. v.ui:setVisible(false)
  1362. local spawnTime = 0.3
  1363. local mSpawn = cc.Spawn:create(cc.FadeIn:create(spawnTime),cc.CallFunc:create(function ()
  1364. v.ui:setVisible(true)
  1365. --播放发牌声音
  1366. if k < table.nums(self.handCardRoot) - 4 then
  1367. playVoiceGiveCard()
  1368. end
  1369. end))
  1370. v.ui:runAction(cc.Sequence:create(cc.DelayTime:create(k * 0.05),mSpawn,cc.DelayTime:create(k * 0.05),cc.CallFunc:create(function ()
  1371. if k == self:getVisibleCardLayoutNum() then
  1372. --排序
  1373. self:RankCard()
  1374. --注册点击
  1375. self:registerCardTouch()
  1376. if onEnd then
  1377. onEnd()
  1378. end
  1379. end
  1380. end)))
  1381. end
  1382. end
  1383. else
  1384. --注册点击
  1385. self:registerCardTouch()
  1386. --排序
  1387. self:RankCard()
  1388. if onEnd then
  1389. onEnd()
  1390. end
  1391. end
  1392. end
  1393. --牌UI调整
  1394. function ZPRoomView:RankCard(isNotShowAni)
  1395. --如果列小于最大列数则需要调整UI
  1396. local showColNum = self:getVisibleCardLayoutNum()
  1397. if showColNum == 0 then
  1398. self:getLocalHuShu()
  1399. return
  1400. end
  1401. if showColNum <= self.lieShuMax then
  1402. --根据当前存在的列数获取一个枚举列表,让手牌的列数重新旋转到指定新的列数
  1403. local list = self.lieshulist[showColNum]
  1404. local blankList = self.lieshuBlanklist[showColNum]
  1405. local youIndex = 0
  1406. local wuIndex = 0
  1407. --card data
  1408. local handCardValueLocalTemp = {}
  1409. local handCardRootTemp = {}
  1410. for k = 1,self.lieShuMax do
  1411. if #self.handCardValueLocal[k] <= 0 then
  1412. wuIndex = wuIndex + 1
  1413. local blankIndex = blankList[wuIndex] -- 1 2 9 10
  1414. local tarPos = self.boxPosList4[blankIndex]
  1415. self.handCardRoot[k].ui:setPosition(tarPos)
  1416. --列数修改
  1417. for i = 1,self.hangShuMax do
  1418. self.handCardRoot[k].imgList[i].lieshu = blankIndex
  1419. end
  1420. self.handCardRoot[k].ui:setLocalZOrder(blankIndex)
  1421. handCardValueLocalTemp[blankIndex] = self.handCardValueLocal[k]
  1422. handCardRootTemp[blankIndex] = self.handCardRoot[k]
  1423. else
  1424. youIndex = youIndex + 1
  1425. local index = list[youIndex] -- 3 4 5 6 7 8
  1426. local tarPos = self.boxPosList4[index]
  1427. if isNotShowAni then
  1428. self.handCardRoot[k].ui:setPosition(tarPos)
  1429. else
  1430. --self.handCardRoot[k].ui:stopAllActions()
  1431. --self.handCardRoot[k].ui:setPosition(tarPos)
  1432. self.handCardRoot[k].ui:runAction(cc.MoveTo:create(self.gameSpeedConfig.OPCARDTIME,tarPos))
  1433. end
  1434. --列数修改
  1435. for i = 1,self.hangShuMax do
  1436. self.handCardRoot[k].imgList[i].lieshu = index
  1437. end
  1438. --self.handCardRoot[k].ui:setLocalZOrder(index)
  1439. handCardValueLocalTemp[index] = self.handCardValueLocal[k]
  1440. handCardRootTemp[index] = self.handCardRoot[k]
  1441. end
  1442. end
  1443. --牌数据
  1444. self.handCardValueLocal = handCardValueLocalTemp
  1445. handCardValueLocalTemp = {}
  1446. --牌
  1447. self.handCardRoot = handCardRootTemp
  1448. handCardRootTemp = {}
  1449. --logE("RankCard 排序后: "..table.tostring(self.handCardValueLocal))
  1450. end
  1451. self:getLocalHuShu()
  1452. end
  1453. --如果牌正在掉落的时候,不允许操作!
  1454. --落牌检测
  1455. function ZPRoomView:downCard()
  1456. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  1457. return
  1458. end
  1459. --是否需要掉落
  1460. local bDown = false
  1461. for i = 1,self.lieShuMax do
  1462. if self.handCardRoot[i].ui:isVisible() then
  1463. for j = 1,3 do
  1464. for k = 2,self.hangShuMax do
  1465. if not self.handCardRoot[i].imgList[j]:isVisible() and self.handCardRoot[i].imgList[k]:isVisible() and j < k then
  1466. --底部
  1467. local firstValue = self.handCardRoot[i].imgList[j].value
  1468. --顶部
  1469. local secondeValue = self.handCardRoot[i].imgList[k].value
  1470. --插入
  1471. --数据交换
  1472. local tempValue = nil
  1473. tempValue = self.handCardRoot[i].imgList[j].value
  1474. self.handCardRoot[i].imgList[j].value = self.handCardRoot[i].imgList[k].value
  1475. self.handCardRoot[i].imgList[k].value = tempValue
  1476. --换底数据
  1477. --[[local tempHuanDi = nil
  1478. tempHuanDi = self.handCardRoot[i].imgList[j].isHuanDi
  1479. self.handCardRoot[i].imgList[j].isHuanDi = self.handCardRoot[i].imgList[k].isHuanDi
  1480. self.handCardRoot[i].imgList[k].isHuanDi = tempHuanDi--]]
  1481. --ui交换
  1482. self.handCardRoot[i].imgList[k]:setVisible(false)
  1483. local cardValue = self.handCardRoot[i].imgList[j].value
  1484. if cardValue then
  1485. local fileName = ZPFuc.getZPCardImgByValue(cardValue,ZPDef.CardType.CARD_TYPE_HAND)
  1486. logD("ZPRoomView:downCard", "fileName:", fileName)
  1487. self.handCardRoot[i].imgList[j]:loadTextureFromPlist(fileName)
  1488. end
  1489. self.handCardRoot[i].imgList[j]:setVisible(true)
  1490. --听牌标签
  1491. local visibleA = self.handCardRoot[i].imgList[j]:getChildren()[1]:isVisible()
  1492. local visibleB = self.handCardRoot[i].imgList[k]:getChildren()[1]:isVisible()
  1493. self.handCardRoot[i].imgList[j]:getChildren()[1]:setVisible(visibleB)
  1494. self.handCardRoot[i].imgList[k]:getChildren()[1]:setVisible(visibleA)
  1495. --落牌动画
  1496. local lieshu = self.ui.Items.ImageView_handTempCard.lieshu
  1497. local value = self.ui.Items.ImageView_handTempCard.value
  1498. --if self.handCardRoot[i].imgList[j].value == value and i == lieshu then
  1499. -- self:goBackWithAni(self.handCardRoot[i].imgList[j])
  1500. --else
  1501. local recordPos = self.handCardRoot[i].imgList[j]:getParent():getPosition()
  1502. self.handCardRoot[i].imgList[j]:getParent():setPosition(self.handCardRoot[i].imgList[k]:getParent():getPosition())
  1503. local act = cc.MoveTo:create(self.gameSpeedConfig.OPCARDTIME,recordPos)
  1504. --self.handCardRoot[i].imgList[j]:getParent():stopAllActions()
  1505. self.handCardRoot[i].imgList[j]:getParent():runAction(act)
  1506. --end
  1507. bDown = true
  1508. end
  1509. end
  1510. end
  1511. end
  1512. end
  1513. --判断是否有掉落
  1514. if not bDown then
  1515. self.isGodHand = false
  1516. else
  1517. local seq = cc.Sequence:create(cc.DelayTime:create(1.25),cc.CallFunc:create(function ()
  1518. self.isGodHand = false
  1519. end))
  1520. self.ui:runAction(seq)
  1521. end
  1522. end
  1523. --整理牌
  1524. function ZPRoomView:neatenCard(isNotShowAni)
  1525. --logE("neatenCard -------- ", debug.traceback())
  1526. --是否短暂屏蔽点击牌事件
  1527. self:downCard()
  1528. self:RankCard(isNotShowAni)
  1529. end
  1530. function ZPRoomView:getVisibleCardLayoutNum()
  1531. local index = 0
  1532. for i,v in ipairs(self.handCardValueLocal) do
  1533. if #v > 0 then
  1534. index = index + 1
  1535. end
  1536. end
  1537. return index
  1538. end
  1539. --获取该列显示了几个
  1540. function ZPRoomView:getRowVisibleCount(lieshu)
  1541. local count = 0
  1542. for k = 1, 4 do
  1543. if self.handCardRoot[lieshu].imgList[k] and self.handCardRoot[lieshu].imgList[k]:isVisible() then
  1544. count = count + 1
  1545. end
  1546. end
  1547. return count
  1548. end
  1549. --判断列数是否是砍牌
  1550. function ZPRoomView:getCurrentColIsKan(list)
  1551. local isKan = false
  1552. if list[1] and list[2] and list[3] then
  1553. if list[1] == list[2] and list[2] == list[3] then
  1554. isKan = true
  1555. end
  1556. end
  1557. return isKan
  1558. end
  1559. --判断列数是否是龙
  1560. function ZPRoomView:getCurrentColIsLong(list)
  1561. local isLong = false
  1562. if list[1] and list[2] and list[3] and list[4] then
  1563. if list[1] == list[2] and list[2] == list[3] and list[3] == list[4] then
  1564. isLong = true
  1565. end
  1566. end
  1567. return isLong
  1568. end
  1569. function ZPRoomView:onTouchBegan(touch,k,v)
  1570. if self.isGodHand then
  1571. --showTooltip("禁止操作")
  1572. return
  1573. end
  1574. local posOO = self:getPosOO()
  1575. local localPos = touch:getLocation();
  1576. local pos = cc.p(localPos.x - posOO.x, localPos.y - posOO.y);
  1577. local lieshu = v.lieshu
  1578. local hangshu = v.hangshu
  1579. local value = v.value
  1580. local isKan = v.isKan
  1581. if isKan then
  1582. showTooltip("坎牌不可移动")
  1583. return
  1584. end
  1585. self.handCardRoot[lieshu].ui:setVisible(true)
  1586. if value == nil then
  1587. return
  1588. end
  1589. --playZiPaiSelectCardVoice()
  1590. logE("88888888-=============onTouchBegan1================")
  1591. logE("88888888-isKan:")
  1592. logE(isKan)
  1593. logE("88888888-touch lieshu:",lieshu)
  1594. logE("88888888-touch hangshu:",hangshu)
  1595. logE("88888888-touch value:",value)
  1596. if value - 16 > 0 then
  1597. logE("玩家点了"..lieshu.."列"..hangshu.."行的大"..value - 16)
  1598. else
  1599. logE("玩家点了"..lieshu.."列"..hangshu.."行的小"..value)
  1600. end
  1601. if isKan then
  1602. logE("该牌为坎牌")
  1603. else
  1604. logE("该牌不是坎牌")
  1605. end
  1606. logE("88888888-card :"..table.tostring(self.handCardValueLocal))
  1607. logE("88888888-=============onTouchBegan2================")
  1608. v:setOpacity(0)
  1609. if self.ui.Items.ImageView_handTempCard.cIdx ~= k then
  1610. self:setColorWhite()
  1611. v:setColor(ZPDef.ColorConfig.TOUCH_CARD_COLOR)
  1612. self.ui.Items.Button_OutCard:setEnabled(true)
  1613. logE("88888888-=============onTouchBegan3================")
  1614. elseif self.ui.Items.ImageView_handTempCard.cIdx == k then
  1615. 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
  1616. self:setColorWhite()
  1617. self.ui.Items.Button_OutCard:setEnabled(false)
  1618. else
  1619. v:setColor(ZPDef.ColorConfig.TOUCH_CARD_COLOR)
  1620. self.ui.Items.Button_OutCard:setEnabled(true)
  1621. end
  1622. logE("88888888-=============onTouchBegan4================")
  1623. end
  1624. self:showTingPaiView(v.value)
  1625. --出牌线
  1626. self:setOutCardLineVisible(true)
  1627. --临时牌
  1628. self.ui.Items.ImageView_handTempCard.cIdx = k
  1629. self.ui.Items.ImageView_handTempCard.lieshu = lieshu
  1630. self.ui.Items.ImageView_handTempCard.hangshu = hangshu
  1631. self.ui.Items.ImageView_handTempCard.value = value
  1632. self.ui.Items.ImageView_handTempCard.index = k
  1633. self.ui.Items.ImageView_handTempCard:setVisible(true)
  1634. self.ui.Items.ImageView_handTempCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(value,ZPDef.CardType.CARD_TYPE_HAND))
  1635. self.ui.Items.ImageView_handTempCard:setPosition(pos)
  1636. logE("88888888-=============onTouchBegan5================")
  1637. end
  1638. function ZPRoomView:onTouchMove(touch,k,v)
  1639. if self.isGodHand then
  1640. --showTooltip("end 禁止操作")
  1641. return
  1642. end
  1643. local posOO = self:getPosOO()
  1644. local localPos = touch:getLocation();
  1645. local pos = cc.p(localPos.x - posOO.x, localPos.y - posOO.y);
  1646. self.ui.Items.ImageView_handTempCard:setPosition(pos)
  1647. end
  1648. function ZPRoomView:onTouchEnd(touch,k,v)
  1649. logE("88888888-=============onTouchEnd1================")
  1650. if not self.ui.Items.ImageView_handTempCard:isVisible() then
  1651. --showTooltip("End 临时牌阻止了事件")
  1652. v:setOpacity(255)
  1653. self.ui.Items.ImageView_handTempCard:setVisible(false)
  1654. return
  1655. end
  1656. if self.isGodHand then
  1657. --showTooltip("end 禁止操作")
  1658. return
  1659. end
  1660. self.ui.Items.ImageView_handTempCard:setVisible(false)
  1661. --出牌线
  1662. self:setOutCardLineVisible(false)
  1663. if v.isKan then
  1664. return
  1665. end
  1666. if not v.value then
  1667. return
  1668. end
  1669. v:setOpacity(255)
  1670. --回到原点动画
  1671. self:goBackWithAni(v,0.15)
  1672. logE("88888888-=============onTouchEnd2================")
  1673. end
  1674. function ZPRoomView:onTouchCancel(touch,k,v)
  1675. self:setColorWhite()
  1676. logE("88888888-=============onTouchCancel 1================")
  1677. --出牌线
  1678. self:setOutCardLineVisible(false)
  1679. if not self.ui.Items.ImageView_handTempCard:isVisible() then
  1680. --showTooltip("cancel 临时牌阻止了事件")
  1681. v:setOpacity(255)
  1682. self.ui.Items.ImageView_handTempCard:setVisible(false)
  1683. logE("88888888-=============onTouchCancel11111111111")
  1684. return
  1685. end
  1686. if self.isGodHand then
  1687. --showTooltip("禁止操作")
  1688. return
  1689. end
  1690. self.ui.Items.ImageView_handTempCard:setVisible(false)
  1691. logE("88888888-=============onTouchCancel222222222222")
  1692. if v.isKan then
  1693. return
  1694. end
  1695. logE("88888888-=============onTouchCancel333333333333")
  1696. if not v.value then
  1697. return
  1698. end
  1699. logE("88888888-=============onTouchCancel4444444444444")
  1700. v:setOpacity(255)
  1701. --临时牌
  1702. self.ui.Items.ImageView_handTempCard:setVisible(false)
  1703. local touchPos = touch:getLocation()
  1704. -------------------------------------------------------
  1705. -------------------------------------------------------
  1706. local hitCount = 0
  1707. local hitItem = {}
  1708. for i = #self.handCardItem,1,-1 do
  1709. local mSprite = self.handCardItem[i]
  1710. local posNode = mSprite:convertToNodeSpace(touchPos);
  1711. local width = mSprite:getContentSize().width
  1712. local height = mSprite:getContentSize().height
  1713. --不可以用getWorldPosition(),因为会出现旋转后,可点区域会停留在原来的地方。
  1714. local x = mSprite:getPosition().x
  1715. local y = mSprite:getPosition().y
  1716. local mRect = cc.Rectangle:new(x,y,width,height)
  1717. if mRect:contains(posNode.x,posNode.y) then
  1718. hitCount = hitCount + 1
  1719. hitItem[hitCount] = mSprite
  1720. break
  1721. --[[--干掉for循环
  1722. if hitCount == 3 then
  1723. break
  1724. end--]]
  1725. end
  1726. end
  1727. --处理多层点击穿透:如果是3个,取第三个,如果是2个,取第二个,如果是一个,取第一个
  1728. local curItem = hitItem[#hitItem]
  1729. if curItem then
  1730. logE("cancel hitCount :"..hitCount)
  1731. if curItem.value == nil then
  1732. logE("88888888-=============curItem.value == nil 1================")
  1733. logE("88888888-=============执行牌插入,插入位置为空的================")
  1734. --牌插入逻辑:
  1735. --数组数据更新
  1736. local curLieShu = hitItem[#hitItem].lieshu
  1737. local curHangShu = hitItem[#hitItem].hangshu
  1738. local value = hitItem[#hitItem].value
  1739. logE("88888888-self.handCardValueLocal[v.lieshu]:"..table.tostring(self.handCardValueLocal[v.lieshu]))
  1740. logE("88888888-self.handCardValueLocal[curLieShu]:"..table.tostring(self.handCardValueLocal[curLieShu]))
  1741. --行数
  1742. local row = v.hangshu
  1743. local lieshu = v.lieshu
  1744. logE("88888888-touch row :"..row)
  1745. logE("88888888-touch lieshu :"..lieshu)
  1746. --原来的数据删除
  1747. --if self.handCardRoot[lieshu].imgList[row].value == v.value then
  1748. table.remove(self.handCardValueLocal[lieshu],row)
  1749. --end
  1750. --在新的数据列里插入新的值
  1751. for i = 1,self.hangShuMax do
  1752. if self.handCardRoot[curLieShu].imgList[i].value == nil then
  1753. table.insert(self.handCardValueLocal[curLieShu],v.value)
  1754. break
  1755. end
  1756. end
  1757. --数据交换
  1758. local tempValue = nil
  1759. tempValue = v.value
  1760. v.value = hitItem[#hitItem].value
  1761. hitItem[#hitItem].value = tempValue
  1762. --ui更新
  1763. self.ui.Items.ImageView_handTempCard:setVisible(true)
  1764. v:setVisible(false)
  1765. local function callback()
  1766. self.ui.Items.ImageView_handTempCard:setVisible(false)
  1767. local cardvalue = hitItem[#hitItem].value or tempValue
  1768. if cardvalue then
  1769. local fileName = ZPFuc.getZPCardImgByValue(cardvalue,ZPDef.CardType.CARD_TYPE_HAND)
  1770. logD("ZPRoomView:registerCardTouch", "fileName:", fileName)
  1771. hitItem[#hitItem]:loadTextureFromPlist(fileName)
  1772. hitItem[#hitItem]:setVisible(true)
  1773. hitItem[#hitItem]:setOpacity(255)
  1774. end
  1775. --听牌标签
  1776. if v:getChildren()[1]:isVisible() then
  1777. v:getChildren()[1]:setVisible(false)
  1778. hitItem[#hitItem]:getChildren()[1]:setVisible(true)
  1779. end
  1780. self.ui.Items.ImageView_handTempCard.lieshu = curLieShu
  1781. self.ui.Items.ImageView_handTempCard.hangshu = curHangShu
  1782. self:neatenCard()
  1783. end
  1784. --handTemp->tarPos action
  1785. if self.handCardRoot[curLieShu].imgList[curHangShu - 1] and
  1786. self.handCardRoot[curLieShu].imgList[curHangShu - 1].value then
  1787. local node = hitItem[#hitItem]
  1788. local nodeSize = node:getParent():getContentSize()
  1789. local nodePos = cc.pAdd(node:getWorldPosition(),cc.p(nodeSize.width/2,nodeSize.height/2))
  1790. local seq = cc.Sequence:create(cc.MoveTo:create(0,nodePos),cc.CallFunc:create(callback))--self.gameSpeedConfig.OPCARDTIME
  1791. self.ui.Items.ImageView_handTempCard:runAction(seq)
  1792. else
  1793. callback()
  1794. end
  1795. logE("88888888-=============curItem.value == nil 2================")
  1796. logE("88888888-=============执行牌插入结束================")
  1797. else
  1798. logE("88888888-=============cancel curItem.value exist 1================")
  1799. --数组数据更新
  1800. local curLieShu = hitItem[#hitItem].lieshu
  1801. local curHangShu = hitItem[#hitItem].hangshu
  1802. local value = hitItem[#hitItem].value
  1803. local isKan = hitItem[#hitItem].isKan
  1804. if isKan then
  1805. showTooltip("坎牌不可拆")
  1806. return
  1807. end
  1808. --如果小于3则插入到空的那个
  1809. if self:getRowVisibleCount(curLieShu) < 3 then
  1810. logE("88888888-=============如果小于3则插入到空的那个================")
  1811. logE("88888888-=============执行牌插入到空的位置================")
  1812. --同列有多个牌相同的,找出对应点击的牌
  1813. local row = v.hangshu
  1814. local lieshu = v.lieshu
  1815. logE("88888888-row :"..row)
  1816. logE("88888888-lieshu :"..lieshu)
  1817. --原来的数据删除
  1818. table.remove(self.handCardValueLocal[lieshu],row)
  1819. --在新的数据列里插入新的值
  1820. local newRow = 0
  1821. for i = 1,self.hangShuMax do
  1822. if self.handCardRoot[curLieShu].imgList[i].value == nil then
  1823. newRow = i
  1824. table.insert(self.handCardValueLocal[curLieShu],v.value)
  1825. break
  1826. end
  1827. end
  1828. --数据交换
  1829. local tempValue = nil
  1830. tempValue = v.value
  1831. v.value = nil
  1832. self.handCardRoot[curLieShu].imgList[newRow].value = tempValue
  1833. logE("888888888-curLieShu:"..tostring(curLieShu))
  1834. logE("888888888-newRow:"..tostring(newRow))
  1835. --ui更新
  1836. v:setVisible(false)
  1837. local fileName = ZPFuc.getZPCardImgByValue(self.handCardRoot[curLieShu].imgList[newRow].value,ZPDef.CardType.CARD_TYPE_HAND)
  1838. self.handCardRoot[curLieShu].imgList[newRow]:loadTextureFromPlist(fileName)
  1839. self.handCardRoot[curLieShu].imgList[newRow]:setVisible(true)
  1840. self.handCardRoot[curLieShu].imgList[newRow]:setOpacity(255)
  1841. --听牌标签
  1842. if v:getChildren()[1]:isVisible() then
  1843. v:getChildren()[1]:setVisible(false)
  1844. self.handCardRoot[curLieShu].imgList[newRow]:getChildren()[1]:setVisible(true)
  1845. end
  1846. logE("88888888-======================after insert card=========================")
  1847. logE("88888888-first item lieshu:"..v.lieshu)
  1848. logE("88888888-first item value:"..0)
  1849. self:neatenCard()
  1850. logE("88888888-=============如果小于3则插入到空的那个 结束================")
  1851. logE("88888888-=============执行牌插入到空的位置 结束================")
  1852. else
  1853. logE("88888888-=============该列满3个牌只能交换================")
  1854. logE("88888888-=============执行牌交换================")
  1855. if value - 16 > 0 then
  1856. logE("被交换的牌为大"..value - 16)
  1857. else
  1858. logE("被交换的牌为小"..value)
  1859. end
  1860. --牌交换:
  1861. --同列有多个牌相同的,找出对应点击的牌
  1862. local rowFirst = v.hangshu
  1863. local rowSecond = curHangShu
  1864. logE("88888888-rowFirst 第一个交换的行数:"..rowFirst)
  1865. logE("88888888-rowSecond 第二个交换的行数:"..rowSecond)
  1866. logE("88888888-原始列数数据:"..table.tostring(self.handCardValueLocal[v.lieshu]))
  1867. logE("88888888-交换列数数据:"..table.tostring(self.handCardValueLocal[curLieShu]))
  1868. --原来的数据删除
  1869. if self.handCardRoot[v.lieshu].imgList[rowFirst].value == v.value then
  1870. table.remove(self.handCardValueLocal[v.lieshu],rowFirst)
  1871. table.insert(self.handCardValueLocal[v.lieshu],rowFirst,value)
  1872. end
  1873. --原来的数据删除
  1874. if self.handCardRoot[curLieShu].imgList[rowSecond].value == value then
  1875. table.remove(self.handCardValueLocal[curLieShu],rowSecond)
  1876. table.insert(self.handCardValueLocal[curLieShu],rowSecond,v.value)
  1877. end
  1878. logE("88888888-删除后的原始列数数据:"..table.tostring(self.handCardValueLocal[v.lieshu]))
  1879. logE("88888888-删除后的列数数据:"..table.tostring(self.handCardValueLocal[curLieShu]))
  1880. logE("查看数据:")
  1881. logE("88888888-first item lieshu:"..v.lieshu)
  1882. logE("88888888-first item value:"..v.value)
  1883. logE("88888888-second item lieshu:"..curItem.lieshu)
  1884. logE("88888888-second item value:"..curItem.value)
  1885. logE("查看数据完毕")
  1886. --数据交换
  1887. local tempValue = nil
  1888. tempValue = v.value
  1889. v.value = hitItem[#hitItem].value
  1890. hitItem[#hitItem].value = tempValue
  1891. --ui交换
  1892. local fileName = ZPFuc.getZPCardImgByValue(v.value,ZPDef.CardType.CARD_TYPE_HAND)
  1893. v:loadTextureFromPlist(fileName)
  1894. fileName = ZPFuc.getZPCardImgByValue(hitItem[#hitItem].value,ZPDef.CardType.CARD_TYPE_HAND)
  1895. hitItem[#hitItem]:loadTextureFromPlist(fileName)
  1896. local srcVisible = v:getChildren()[1]:isVisible()
  1897. local changeVisible = hitItem[#hitItem]:getChildren()[1]:isVisible()
  1898. --听牌标签
  1899. hitItem[#hitItem]:getChildren()[1]:setVisible(srcVisible)
  1900. v:getChildren()[1]:setVisible(changeVisible)
  1901. logE("交换完毕,查看数据:")
  1902. logE("88888888-first item lieshu:"..v.lieshu)
  1903. logE("88888888-first item value:"..v.value)
  1904. logE("88888888-second item lieshu:"..hitItem[#hitItem].lieshu)
  1905. logE("88888888-second item value:"..hitItem[#hitItem].value)
  1906. logE("查看数据完毕")
  1907. logE("88888888-=============牌交换 结束================")
  1908. logE("88888888=============cancel curItem.value exist 2================")
  1909. end
  1910. end
  1911. else
  1912. --@part:牌取消回来,出牌逻辑的实现
  1913. --判断是否大于出牌点
  1914. if touchPos.y > self.ui.Items.ImageView_line:getPosition().y and self.bOutCard then
  1915. if app.room:isLittleFamily() then
  1916. return
  1917. end
  1918. --比牌的时候,在比牌间隔点到了牌,拖出去报错
  1919. if v.value == nil then
  1920. showTooltip("牌已经操作过!")
  1921. return
  1922. end
  1923. --send sender
  1924. v:setOpacity(0)
  1925. self:sendOutCard(v.value)
  1926. logE("玩家出牌:"..v.value)
  1927. self.bOutCard = false
  1928. self.isGodHand = true;
  1929. --记录数据
  1930. local lieshu = v.lieshu
  1931. local hangshu = v.hangshu
  1932. local value = v.value
  1933. self.ui.Items.ImageView_handTempCard.lieshu = lieshu
  1934. self.ui.Items.ImageView_handTempCard.hangshu = hangshu
  1935. self.ui.Items.ImageView_handTempCard.value = value
  1936. self.ui.Items.ImageView_handTempCard.index = k
  1937. else
  1938. logE("牌回到原来的位置")
  1939. --回到原点动画
  1940. self:goBackWithAni(v,0.15)
  1941. end
  1942. end
  1943. -------------------------------------------------------
  1944. -------------------------------------------------------
  1945. logE("88888888=============onTouchCancel 2================")
  1946. logE("88888888-onTouchCancel :card :"..table.tostring(self.handCardValueLocal))
  1947. end
  1948. function ZPRoomView:getPosOO()
  1949. local nodeTouch = self.ui.Items.Layout_Touch;
  1950. local posTouch = nodeTouch:getWorldPosition()
  1951. local poaAnchor = nodeTouch:getAnchorPoint()
  1952. local sizeTouch = nodeTouch:getContentSize();
  1953. local posOO = { x = posTouch.x - sizeTouch.width * poaAnchor.x , y = posTouch.y - sizeTouch.height * poaAnchor.y}
  1954. return posOO;
  1955. end
  1956. --注册点击事件
  1957. function ZPRoomView:registerCardTouch()
  1958. --触摸
  1959. for k,v in ipairs(self.handCardItem) do
  1960. v:setTouchEnabled(true)
  1961. v:registerTouchEvent(function (touch)
  1962. self:onTouchBegan(touch,k,v)
  1963. end ,
  1964. function (touch)
  1965. self:onTouchMove(touch,k,v)
  1966. end,
  1967. function (touch)
  1968. self:onTouchEnd(touch,k,v)
  1969. end,
  1970. function (touch)
  1971. self:onTouchCancel(touch,k,v)
  1972. end)
  1973. end
  1974. end
  1975. --牌回来动画
  1976. function ZPRoomView:goBackWithAni(node,time)
  1977. local moveTime = nil
  1978. if time then
  1979. moveTime = time
  1980. else
  1981. moveTime = self.gameSpeedConfig.OPCARDTIME
  1982. end
  1983. local recordPos = node:getParent():getPosition()
  1984. local handTempSize = self.ui.Items.ImageView_handTempCard:getContentSize()
  1985. local handTempPos = cc.pSub(self.ui.Items.ImageView_handTempCard:getPosition(), cc.p(handTempSize.width/2,handTempSize.height/2))
  1986. local tranPos = node:getParent():getParent():convertToNodeSpace(handTempPos)
  1987. node:getParent():setPosition(tranPos)
  1988. local act = cc.MoveTo:create(moveTime,recordPos)
  1989. node:getParent():runAction(act)
  1990. end
  1991. --玩家出牌操作
  1992. function ZPRoomView:sendOutCard(nCard)
  1993. if self.isGameOver then
  1994. return
  1995. end
  1996. self:IsTingPaiCard(nCard)
  1997. --直接给用户显示出牌效果,数据删除在出牌成功后,如果出牌失败,出牌效果消失,用户可以重新出牌哦
  1998. self:setOutCardVisible(true,self:getMeViewId(),nCard,true,nil,false)
  1999. end
  2000. -- 系统开局发可串可哨的消息
  2001. function ZPRoomView:onSystemOperationStart(data)
  2002. local function runSystemOperation(onEnd)
  2003. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  2004. if onEnd then
  2005. onEnd()
  2006. end
  2007. return
  2008. end
  2009. log("2000000000-ZPRoomView - (runSystemOperation)")
  2010. local nUserId = data.response.nUserId
  2011. local tiPaiList = data.response.tiPaiList
  2012. local nTotalYoushu = data.response.nTotalHuShu
  2013. local viewId = app.room:getViewIdByUserId(nUserId)
  2014. --提
  2015. local hushu = 0
  2016. for k,v in ipairs(tiPaiList) do
  2017. if v.hushu then
  2018. hushu = hushu + v.hushu
  2019. end
  2020. self.systemTiPai = true
  2021. if k == #tiPaiList then
  2022. self:doOperation(ZPDef.OpType.OP_TYPE_TI,viewId,v.card,false,onEnd())
  2023. else
  2024. self:doOperation(ZPDef.OpType.OP_TYPE_TI,viewId,v.card)
  2025. end
  2026. end
  2027. if #tiPaiList == 0 then
  2028. if onEnd then
  2029. onEnd()
  2030. end
  2031. end
  2032. self.tableHuXiList[viewId] = hushu
  2033. self.PlayerView:setPlayerHuXi(viewId,hushu)
  2034. if viewId == self:getMeViewId() then
  2035. self:neatenCard(true)
  2036. end
  2037. local leftHandCardNum = data.response.leftHandCardNum
  2038. self.PlayerView:setLeftCardNum(viewId,true,leftHandCardNum)
  2039. end
  2040. log("2000000000-ZPRoomView - addCallBack(runSystemOperation)")
  2041. self:addCallBack(runSystemOperation);
  2042. end
  2043. -- 广播桌子上所有玩家庄家起手操作
  2044. function ZPRoomView:onBankerOutCard(data)
  2045. local function runOnBankerOutCard(onEnd)
  2046. log("2000000000-ZPRoomView - (runOnBankerOutCard)")
  2047. logE("onBankerOutCard :"..table.tostring(data.response))
  2048. if data.response.nUserId == app.room:getMyUserId() then
  2049. if data.response.IsShouldOutCard > 0 then
  2050. self:setGuideView(true)
  2051. self.bOutCard = true
  2052. end
  2053. if data.response.mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
  2054. --操作码
  2055. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  2056. self.operationLocalCode = data.response.mainOpCode
  2057. self:showOpeation(data.response.mainOpCode,viewId)
  2058. self:setGuideView(false)
  2059. self.bOutCard = false
  2060. self.isTianHu = true
  2061. end
  2062. end
  2063. local operations = {}
  2064. --操作码
  2065. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  2066. operations[viewId] = {}
  2067. operations[viewId].nUserId = data.response.nUserId
  2068. operations[viewId].isCanOpereate = 1
  2069. self:showDelayTimeTip(operations)
  2070. if onEnd then
  2071. onEnd()
  2072. end
  2073. end
  2074. log("2000000000-ZPRoomView - addCallBack(runOnBankerOutCard)")
  2075. self:addCallBack(runOnBankerOutCard);
  2076. end
  2077. --庄家最后一张牌
  2078. function ZPRoomView:onLastCardResponse(data)
  2079. self.isGodHand = true
  2080. local function runShowBankerFirstCard(onEnd)
  2081. self:showLastCardAni(data,onEnd)
  2082. --[[if onEnd then
  2083. onEnd()
  2084. end--]]
  2085. end
  2086. self:addCallBack(runShowBankerFirstCard);
  2087. end
  2088. --从手牌找与牌值相等的牌,没有再找等值的大小牌,没有返回最后空列
  2089. function ZPRoomView:findCardPos(card)
  2090. local secondDstCard
  2091. if card - 10 > 0 then
  2092. secondDstCard = card - 16
  2093. else
  2094. secondDstCard = card + 16
  2095. end
  2096. --第一目标
  2097. local dstCol1,dstRow1
  2098. --第二目标
  2099. local dstCol2,dstRow2
  2100. --第一次找到值时,赋值一次,
  2101. local firstSet = true
  2102. local isEnd = false
  2103. for col = self.lieShuMax, 1, -1 do
  2104. for row = 4, 1, -1 do
  2105. --if self.handCardRoot[col].imgList[row].value == card then
  2106. if self.handCardValueLocal[col][row] == card and #self.handCardValueLocal[col] < 3 then
  2107. dstCol1 = col
  2108. dstRow1 = #self.handCardValueLocal[col]+1
  2109. isEnd = true
  2110. break
  2111. end
  2112. --if self.handCardRoot[col].imgList[row].value == secondDstCard then
  2113. if self.handCardValueLocal[col][row] == secondDstCard and #self.handCardValueLocal[col] < 3 then
  2114. dstCol2 = col
  2115. dstRow2 = #self.handCardValueLocal[col]+1
  2116. end
  2117. if firstSet and self.handCardValueLocal[col][row] then
  2118. firstSet = false
  2119. dstCol2 = col + 1
  2120. dstRow2 = 1
  2121. end
  2122. end
  2123. if isEnd then
  2124. break
  2125. end
  2126. end
  2127. if dstCol1 then
  2128. return dstCol1,dstRow1
  2129. end
  2130. if dstCol2 then
  2131. return dstCol2,dstRow2
  2132. end
  2133. end
  2134. --显示庄家第一张摸的牌动画
  2135. function ZPRoomView:showLastCardAni(data,onEnd)
  2136. local bankerViewId = app.room:getViewIdByUserId(data.response.nUserId)
  2137. local card = tonumber(data.response.firstCard) or tonumber(data.response.bankFirstGrabCard)
  2138. --自己或者小家且可以看牌的要把牌发到手里
  2139. local isMe = (tonumber(data.response.nUserId) == app.user.loginInfo.uid) or (app.room:isLittleFamily() and ZPFuc.getLittleIsCanLookCard() and app.room:getActualPlayerNum()==4)
  2140. if self:getMeViewId() == bankerViewId and isMe then
  2141. self:playMoPaiAni(self.leftNum,card,bankerViewId,0,1,nil,false)
  2142. local seq = cc.Sequence:create(cc.DelayTime:create(self.gameSpeedConfig.MO_PAI_TIME + 0.8),cc.CallFunc:create(function ()
  2143. local name = string.format("Layout_outCardPoint_%d",bankerViewId)
  2144. local mLayout = self.ui.Items[name]
  2145. mLayout:setVisible(false)
  2146. local srcPos = mLayout:getPosition()
  2147. self.ui.Items.ImageView_handTempCard:setVisible(true)
  2148. local fileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_HAND)
  2149. logD("ZPRoomView:showLastCardAni", "fileName:", fileName)
  2150. self.ui.Items.ImageView_handTempCard:loadTextureFromPlist(fileName)
  2151. self.ui.Items.ImageView_handTempCard:setPosition(srcPos)
  2152. local firstCol,firstRow = self:findCardPos(card)
  2153. local node = self.handCardRoot[firstCol].imgList[firstRow]
  2154. node.value = card
  2155. local nodeSize = node:getParent():getContentSize()
  2156. local nodePos = cc.pAdd(node:getWorldPosition(),cc.p(nodeSize.width/2,nodeSize.height/2))
  2157. local seq2 = cc.Sequence:create(cc.MoveTo:create(0.2,nodePos),cc.CallFunc:create(function ()
  2158. local firstCol1,firstRow1 = self:findCardPos(card)
  2159. --[[node = self.handCardRoot[firstCol1].imgList[firstCol1]
  2160. node.value = card--]]
  2161. node:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_HAND))
  2162. node:setVisible(true)
  2163. self.ui.Items.ImageView_handTempCard:setVisible(false)
  2164. self.ui.Items.ImageView_handTempCard:setScale(1.0)
  2165. self.ui.Items.ImageView_handTempCard:setOpacity(255)
  2166. self.handCardValueLocal[firstCol1][firstRow1] = card
  2167. table.insert(self.handCardValueBak[firstCol1],card)
  2168. --self.handCardValueBak[firstCol1][firstRow1] = card
  2169. if self:getCurrentColIsKan(self.handCardValueLocal[firstCol]) then
  2170. for i=1,3 do
  2171. self.handCardRoot[firstCol].imgList[i].isKan = true
  2172. self.handCardRoot[firstCol].imgList[i]:setColor(cc.c3b(125,125,125))
  2173. end
  2174. end
  2175. self.isGodHand = false
  2176. self:showTiPaiBtn(true)
  2177. --排序
  2178. self:RankCard(true)
  2179. if onEnd then
  2180. onEnd()
  2181. end
  2182. end))
  2183. self.ui.Items.ImageView_handTempCard:runAction(seq2)
  2184. end))
  2185. self:runAction(seq)
  2186. else
  2187. self:playMoPaiAni(self.leftNum,0xfa,bankerViewId,0,1,nil,false)
  2188. self.PlayerView:changeLeftCardNum(bankerViewId,1)
  2189. local name = string.format("Layout_outCardPoint_%d",bankerViewId)
  2190. --播放动画
  2191. self.ui.Items.ImageView_handTempCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_OUTCARD))--card
  2192. local mSprite = self.ui.Items[name]
  2193. local srcPos = mSprite:getPosition()
  2194. self.ui.Items.ImageView_handTempCard:setPosition(srcPos)
  2195. local tarPos = self.PlayerView:getPlayerPosByViewId(bankerViewId)
  2196. --self.ui.Items.ImageView_handTempCard:setEulerRotation(cc.vec3(0,0,90))
  2197. local time = 0.2
  2198. local spawn = cc.Spawn:create(cc.MoveTo:create(time,tarPos),cc.FadeOut:create(time),cc.ScaleTo:create(time,0))
  2199. local seq = cc.Sequence:create(cc.DelayTime:create(self.gameSpeedConfig.MO_PAI_TIME + 0.8),cc.CallFunc:create(function ()
  2200. self.ui.Items.ImageView_handTempCard:setVisible(true)
  2201. local name = string.format("Layout_outCardPoint_%d",bankerViewId)
  2202. local mLayout = self.ui.Items[name]
  2203. mLayout:setVisible(false)
  2204. end),spawn,cc.CallFunc:create(function ()
  2205. self.ui.Items.ImageView_handTempCard:setVisible(false)
  2206. self.ui.Items.ImageView_handTempCard:setScale(1.0)
  2207. self.ui.Items.ImageView_handTempCard:setOpacity(255)
  2208. self.ui.Items.ImageView_handTempCard:setEulerRotation(cc.vec3(0,0,0))
  2209. self.isGodHand = false
  2210. self:showTiPaiBtn(true)
  2211. if onEnd then
  2212. onEnd()
  2213. end
  2214. end))
  2215. self.ui.Items.ImageView_handTempCard:runAction(seq)
  2216. end
  2217. --小家不能看牌时,牌堆牌显示剩余张数
  2218. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  2219. if onEnd then
  2220. onEnd()
  2221. end
  2222. self:setCircleCardLeftPanelView(true,bankerViewId,19)
  2223. end
  2224. end
  2225. --出牌错误
  2226. function ZPRoomView:onOutCardError(data)
  2227. local function runOnOutCardError(onEnd)
  2228. logE("ZPRoomView:onOutCardError(), response = ", table.tostring(data.response))
  2229. log("2000000000-ZPRoomView - runOnOutCardError")
  2230. self.isGodHand = false--出牌错误了,可以操作牌
  2231. --隐藏出牌效果
  2232. self:setOutCardVisible(false)
  2233. --恢复出的那张牌的透明度
  2234. local index = self.ui.Items.ImageView_handTempCard.index
  2235. self.handCardItem[index]:setOpacity(255)
  2236. self.bOutCard = true
  2237. if onEnd then
  2238. onEnd()
  2239. end
  2240. end
  2241. log("2000000000-ZPRoomView - addCallBack(runOnOutCardError)")
  2242. self:addCallBack(runOnOutCardError)
  2243. end
  2244. function ZPRoomView:showDelayTimeTip(operations)
  2245. end
  2246. --出牌成功
  2247. function ZPRoomView:onOutCardSuccess(data)
  2248. logE("ZPRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  2249. local function runOnOutCardSuccess(onEnd)
  2250. log("2000000000-ZPRoomView - runOnOutCardSuccess")
  2251. --设置出牌动画隐藏
  2252. self:setGuideView(false)
  2253. local response = data.response
  2254. local nUserId = response.nOutCardUserId
  2255. local card = response.byOutCard
  2256. local operateCode = response.mainOpCode
  2257. local operations = response.operations
  2258. local isWuFu = response.nFuWuWarn
  2259. local leftHandCardNum = response.leftHandCardNum
  2260. local viewId = app.room:getViewIdByUserId(nUserId)
  2261. self.moPaiViewId = viewId
  2262. --隐藏出牌
  2263. self.bOutCard = false
  2264. --记录真实牌值
  2265. self.outCard = card
  2266. --记录操作码
  2267. self.EatOperationCode = operateCode
  2268. self:showDelayTimeTip(operations)
  2269. self.PlayerView:setLeftCardNum(viewId,true,leftHandCardNum)
  2270. --self.PlayerView:setNoOpTime(false,viewId)
  2271. logE("my userid :"..app.room:getMyUserId())
  2272. logE("out card response nUserId:"..nUserId)
  2273. local userInfo=app.room:getUserInfo(nUserId)
  2274. if userInfo then
  2275. ZPSound.PlayZPSound(userInfo.sex,card)
  2276. end
  2277. if (nUserId ~= app.room.roomInfo.nUserId and (not app.room:isLittleFamily())) then
  2278. if operateCode ~= ZPDef.OpCode.OP_CANCEL then
  2279. self:showOpeation(operateCode,viewId,card)
  2280. end
  2281. --其他玩家显示
  2282. self:setOutCardVisible(true,viewId,card,false,onEnd)
  2283. elseif app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  2284. if operateCode ~= ZPDef.OpCode.OP_CANCEL then
  2285. self:showOpeation(operateCode,viewId,card)
  2286. end
  2287. --其他玩家显示
  2288. self:setOutCardVisible(true,viewId,card,false,onEnd)
  2289. elseif app.room:isLittleFamily() and ZPFuc.getLittleIsCanLookCard() and nUserId ~= app.room.roomInfo.nUserId and app.room.roomInfo.nBankUid ~= nUserId then
  2290. if operateCode ~= ZPDef.OpCode.OP_CANCEL then
  2291. self:showOpeation(operateCode,viewId,card)
  2292. end
  2293. --其他玩家显示
  2294. self:setOutCardVisible(true,viewId,card,false,onEnd)
  2295. else
  2296. if self.isTuoGuan and self.isTuoGuan == true then
  2297. self:IsTingPaiCard(card)
  2298. end
  2299. local isLittleFamily1 = app.room:isLittleFamily() and 1 or 0
  2300. local getLittleIsCanLookCard1 = ZPFuc.getLittleIsCanLookCard() and 1 or 0
  2301. --logE("my print ============= :"..nUserId.." "..app.room.roomInfo.nUserId.." "..app.user.loginInfo.uid.." "..app.room.roomInfo.nBankUid.." "..isLittleFamily1.." "..getLittleIsCanLookCard1)
  2302. self.isGodHand = true
  2303. local function rankDeletOneCard(card)
  2304. local isEnd = false
  2305. --倒叙遍历1-10列
  2306. for col = self.lieShuMax,1,-1 do --列数
  2307. for row = self.hangShuMax,1,-1 do --行数
  2308. if card == self.handCardRoot[col].imgList[row].value then --判断值是否相等
  2309. logE("delete card1 ============= :"..card)
  2310. table.remove(self.handCardValueLocal[col],row)
  2311. --单张图片的值归nil
  2312. self.handCardRoot[col].imgList[row].value = nil
  2313. self.handCardRoot[col].imgList[row].isKan = false
  2314. --单个图片隐藏
  2315. self.handCardRoot[col].imgList[row]:setOpacity(255)
  2316. self.handCardRoot[col].imgList[row]:setVisible(false)
  2317. isEnd = true
  2318. break
  2319. end
  2320. end
  2321. if isEnd then
  2322. break
  2323. end
  2324. end
  2325. end
  2326. local index = self.ui.Items.ImageView_handTempCard.index
  2327. local lieshu = self.ui.Items.ImageView_handTempCard.lieshu
  2328. local row = self.ui.Items.ImageView_handTempCard.hangshu --self:getRowByIndex(index)
  2329. --说明:数据校验:弱网棋牌的通病(麻将出牌等一切可以允许玩家自己插牌的游戏,需要注意弱网情况,出牌会出现删错牌)
  2330. --判断该列是否有牌
  2331. if app.room:isLittleFamily() and ZPFuc.getLittleIsCanLookCard() then
  2332. rankDeletOneCard(card)
  2333. elseif self.handCardValueLocal[lieshu] ~= nil and table.nums(self.handCardValueLocal[lieshu]) > 0 then
  2334. --二次校验牌数据是否是出牌数据
  2335. local recordValue = self.handCardRoot[lieshu].imgList[row].value
  2336. if recordValue == card then
  2337. logE("delete card2 ============= :"..card)
  2338. table.remove(self.handCardValueLocal[lieshu],row)
  2339. --数据干掉
  2340. self.handCardRoot[lieshu].imgList[row].value = nil
  2341. self.handCardRoot[lieshu].imgList[row].isKan = false
  2342. --视图处理
  2343. self.handCardRoot[lieshu].imgList[row]:setOpacity(255)
  2344. self.handCardRoot[lieshu].imgList[row]:setVisible(false)
  2345. else
  2346. --随机删掉手里那张牌
  2347. rankDeletOneCard(card)
  2348. end
  2349. else
  2350. --随机删掉手里那张牌
  2351. rankDeletOneCard(card)
  2352. end
  2353. self:rankDeletOneBakCard(card)
  2354. self:neatenCard()
  2355. if onEnd then
  2356. onEnd()
  2357. end
  2358. --检查是否少牌
  2359. self:checkCardsByUidAndLeftCardNum(nUserId,leftHandCardNum)
  2360. self:checkCardAndRecover()
  2361. end
  2362. end
  2363. log("2000000000-ZPRoomView - addCallBack(runOnOutCardSuccess)")
  2364. self:addCallBack(runOnOutCardSuccess)
  2365. end
  2366. function ZPRoomView:showOpeation(mainOpCode,viewId,card)
  2367. self.operationView:setVisible(true)
  2368. self.operationView:setSameParame(self.outCard,self.handCardValueLocal)
  2369. self.operationView:showOpeation(mainOpCode,viewId,card)
  2370. --检测是否少牌
  2371. self:neatenCard(true)--无感知的整理一次手牌
  2372. self:checkCardAndRecover()
  2373. end
  2374. --执行操作(不包括过)
  2375. --[[
  2376. operationType:操作类型
  2377. viewId:视图ID
  2378. card:牌
  2379. isMoPaiOrId:为255的值表示从铺里摸的,如果是玩家放炮给人碰,则表示具体的seatId
  2380. ]]
  2381. function ZPRoomView:doOperation(operationType,viewId,card,isMoPaiOrId,onEnd)
  2382. if operationType == ZPDef.OpType.OP_TYPE_CHI then
  2383. self:Chi(viewId,card,onEnd)
  2384. elseif operationType == ZPDef.OpType.OP_TYPE_PENG then
  2385. self:Peng(viewId,card,isMoPaiOrId,onEnd)
  2386. self:showOperatorTip(viewId,operationType)
  2387. elseif operationType == ZPDef.OpType.OP_TYPE_MINGWEI then
  2388. self:WeiPai(viewId,card,true,onEnd)
  2389. self:showOperatorTip(viewId,operationType)
  2390. elseif operationType == ZPDef.OpType.OP_TYPE_ANWEI then
  2391. self:WeiPai(viewId,card,false,onEnd)
  2392. self:showOperatorTip(viewId,operationType)
  2393. elseif operationType == ZPDef.OpType.OP_TYPE_PAO or operationType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
  2394. self:showOperatorTip(viewId,operationType)
  2395. self:PaoPai(viewId,card,onEnd)
  2396. elseif operationType == ZPDef.OpType.OP_TYPE_TI then
  2397. self:showOperatorTip(viewId,operationType)
  2398. self:TiPai(viewId,card,onEnd,self.systemTiPai)
  2399. elseif operationType == ZPDef.OpType.OP_TYPE_HU then
  2400. self:showOperatorTip(viewId,operationType)
  2401. elseif operationType == ZPDef.OpType.BAO then
  2402. self:showOperatorTip(viewId,-55)
  2403. self.PlayerView:playBaoAnim(viewId)
  2404. end
  2405. end
  2406. --用户行为提示
  2407. function ZPRoomView:showOperatorTip(viewId,mType)
  2408. self.PlayerView:showOperatorTip(viewId,mType)
  2409. end
  2410. --用户明偎(自动)
  2411. --[[
  2412. @parm:isMingWei 是否明偎
  2413. ]]
  2414. function ZPRoomView:WeiPai(viewId,card,isMingWei,onEnd,isSystemOperation)
  2415. --是否轮到我
  2416. local bMeTurn = viewId == self:getMeViewId()
  2417. --自己是需要做数据删除的,他人不需要的
  2418. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  2419. elseif bMeTurn then--and not app.room:isLittleFamily()
  2420. --倒叙遍历1-10列
  2421. for col = self.lieShuMax,1,-1 do --列数
  2422. for row = self.hangShuMax,1,-1 do --行数
  2423. if card == self.handCardRoot[col].imgList[row].value then --判断值是否相等
  2424. table.remove(self.handCardValueLocal[col],row)
  2425. self:rankDeletOneBakCard(card)
  2426. --单张图片的值归nil
  2427. self.handCardRoot[col].imgList[row].value = nil
  2428. self.handCardRoot[col].imgList[row].isKan = false
  2429. --单个图片隐藏
  2430. self.handCardRoot[col].imgList[row]:setVisible(false)
  2431. self.handCardRoot[col].imgList[row]:setOpacity(255)
  2432. end
  2433. end
  2434. end
  2435. if not isSystemOperation then
  2436. self:neatenCard(true)
  2437. end
  2438. end
  2439. local list = {card,card,card}
  2440. if isSystemOperation then
  2441. self:createWeiPaiView(viewId,list,false,isMingWei)
  2442. else
  2443. self:createWeiPaiView(viewId,list,true,isMingWei)
  2444. end
  2445. if onEnd then
  2446. onEnd()
  2447. end
  2448. end
  2449. --创建偎牌的UI
  2450. function ZPRoomView:createWeiPaiView(viewId,list,isShowAni,isMingWei)
  2451. local card = list[1]
  2452. --是否轮到我
  2453. local bMeTurn = viewId == self:getMeViewId()
  2454. --更新自己(3张暗加一个数字(值分大小写))
  2455. --获取自己的出牌点
  2456. local name = string.format("Layout_player1Table_%d",viewId)
  2457. local UnitCardNode = self.ui.Items[name]
  2458. --获取出牌点的儿子数量
  2459. local count = UnitCardNode:getChildrenCount();
  2460. --数量即为列数
  2461. local col = count;
  2462. --牌大小
  2463. local mSprite = cc.ImageView:createNode()
  2464. local FileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE)
  2465. mSprite:loadTextureFromPlist(FileName)
  2466. local width = mSprite:getContentSize().width * self.littleCardScale + self.cardInterval
  2467. local height = mSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
  2468. --创建一个空的layout,layout放到组合牌点上
  2469. local mLayout = cc.Layout:createNode()
  2470. local endPos = nil
  2471. if bMeTurn then
  2472. endPos = cc.p(width * col,0)
  2473. elseif viewId == 1 then
  2474. endPos = cc.p(-width * col,0)
  2475. else
  2476. endPos = cc.p(width * col,0)
  2477. end
  2478. --开启触摸
  2479. mLayout:setTouchEnabled(true)
  2480. --设置锚点
  2481. mLayout:setAnchorPoint(cc.p(0,1))
  2482. --设置大小
  2483. mLayout:setSize(cc.size(width,height*3))
  2484. --layout数据存储:
  2485. --下面的牌数据:
  2486. mLayout.cardList = {}
  2487. if isMingWei then
  2488. mLayout.type = "mingwei"
  2489. else
  2490. mLayout.type = "anwei"
  2491. end
  2492. --查找layout的唯一性
  2493. mLayout:setName(string.format("%d",card))
  2494. --设置类型
  2495. mLayout:setTag(ZPDef.TableConst.TABLE_CONST_CAN_TOUCH)
  2496. for i = 1,3 do
  2497. local mWeiCard;
  2498. local row = i - 1;
  2499. if i > 1 then
  2500. --数据
  2501. mLayout.cardList[i] = card
  2502. --界面
  2503. mWeiCard = cc.ImageView:createNode()
  2504. mWeiCard:setScale(self.littleCardScale)
  2505. mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
  2506. mWeiCard:setPosition(width/2,0 + height * row - height /2);
  2507. mWeiCard:setTag(1)
  2508. mLayout:addChild(mWeiCard,3-i+1);
  2509. else
  2510. --数据
  2511. mLayout.cardList[i] = card
  2512. --界面
  2513. mWeiCard = cc.ImageView:createNode()
  2514. if isMingWei then
  2515. --明偎
  2516. mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(mLayout.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
  2517. else
  2518. if bMeTurn then
  2519. mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(mLayout.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
  2520. else
  2521. --暗偎
  2522. mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
  2523. end
  2524. end
  2525. mWeiCard:setScale(self.littleCardScale)
  2526. mWeiCard:setPosition(width/2,0 + height * row - height /2);
  2527. mWeiCard:setTag(1)
  2528. mLayout:addChild(mWeiCard,3-i+1);
  2529. end
  2530. end
  2531. if bMeTurn then
  2532. --注册点击事件
  2533. mLayout:registerClick(function ()
  2534. --获取TAG,name,tag表示类型,name表示抓取那个layout
  2535. for index,child in pairs(UnitCardNode:getChildren()) do
  2536. local tag = child:getTag()
  2537. if tag == ZPDef.TableConst.TABLE_CONST_CAN_TOUCH then
  2538. for i,v in pairs(child:getChildren()) do
  2539. if v:getTag() == 1 and i > 1 then
  2540. v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(child.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))
  2541. v:setScale(self.littleCardScale)
  2542. local seq = cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
  2543. v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))
  2544. end))
  2545. v:runAction(seq)
  2546. end
  2547. end
  2548. end
  2549. end
  2550. end)
  2551. end
  2552. UnitCardNode:addChild(mLayout);
  2553. --动画
  2554. if isShowAni then
  2555. self:playWeaveCardAni(mLayout,viewId,1,endPos,nil,1.0,true)
  2556. else
  2557. mLayout:setPosition(endPos)
  2558. end
  2559. end
  2560. --用户提牌(自动)
  2561. function ZPRoomView:TiPai(viewId,card,onEnd,isSystemOperation)
  2562. --是否轮到我
  2563. local bMeTurn = viewId == self:getMeViewId()
  2564. --自己是需要做数据删除的,他人不需要的
  2565. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  2566. elseif bMeTurn then --not app.room:isLittleFamily()
  2567. --倒叙遍历1-10列
  2568. for col = self.lieShuMax,1,-1 do --列数
  2569. for row = 4,1,-1 do --行数
  2570. if card == self.handCardRoot[col].imgList[row].value then
  2571. table.remove(self.handCardValueLocal[col],row)
  2572. self:rankDeletOneBakCard(card)
  2573. --单张图片的值归nil
  2574. self.handCardRoot[col].imgList[row].value = nil
  2575. self.handCardRoot[col].imgList[row].isKan = false
  2576. --单个图片隐藏
  2577. self.handCardRoot[col].imgList[row]:setVisible(false)
  2578. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  2579. end
  2580. end
  2581. end
  2582. if not isSystemOperation then
  2583. self:neatenCard(true)
  2584. end
  2585. end
  2586. --更新自己
  2587. --1.查找桌面牌 偎提
  2588. --标志:
  2589. local bIsWeiTi = false
  2590. local name = string.format("Layout_player1Table_%d",viewId)
  2591. local UnitCardNode = self.ui.Items[name]
  2592. local chlidLayout = UnitCardNode:getChildByName(string.format("%d",card))
  2593. if chlidLayout then
  2594. local shaoCount = chlidLayout:getChildrenCount();
  2595. if chlidLayout.type == "mingwei" or chlidLayout.type == "anwei" then
  2596. bIsWeiTi = true
  2597. self.playerZhao[viewId] = self.playerZhao[viewId] + 1
  2598. --视图更新
  2599. --第三张
  2600. local mTiCard;
  2601. mTiCard = cc.ImageView:createNode()
  2602. local thirdSprite = chlidLayout:getChildren()[3]
  2603. local tarPos = cc.p(thirdSprite:getPositionX(),thirdSprite:getPositionY() + thirdSprite:getContentSize().height * self.littleCardScale);
  2604. mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
  2605. chlidLayout:addChild(mTiCard);
  2606. chlidLayout.cardList[4] = card
  2607. local function callback()
  2608. mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))
  2609. if onEnd then
  2610. onEnd()
  2611. end
  2612. end
  2613. --亮第一张
  2614. local firstSprite = chlidLayout:getChildren()[1]
  2615. firstSprite:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
  2616. --标记为提了
  2617. chlidLayout.type = "ti"
  2618. self:playWeaveCardAni(mTiCard,viewId,self.littleCardScale,tarPos,callback,0,false)
  2619. end
  2620. end
  2621. --如果桌面没有偎的牌
  2622. if not bIsWeiTi then
  2623. local list = {card,card,card,card}
  2624. if isSystemOperation then
  2625. self:createTiOrPaoView(true,viewId,list,false,onEnd)
  2626. else
  2627. self:createTiOrPaoView(true,viewId,list,true,onEnd)
  2628. end
  2629. end
  2630. end
  2631. --创建串或者开招的UI
  2632. function ZPRoomView:createTiOrPaoView(isTiPai,viewId,list,isShowAni,onEnd)
  2633. --是否轮到我
  2634. local bMeTurn = viewId == self:getMeViewId()
  2635. local card = list[1]
  2636. local name = string.format("Layout_player1Table_%d",viewId)
  2637. local UnitCardNode = self.ui.Items[name]
  2638. --获取出牌点的儿子数量
  2639. local count = UnitCardNode:getChildrenCount();
  2640. --数量即为列数
  2641. local col = count;
  2642. --牌大小
  2643. local mSprite = cc.ImageView:createNode()
  2644. local FileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE)
  2645. mSprite:loadTextureFromPlist(FileName)
  2646. local width = mSprite:getContentSize().width * self.littleCardScale + self.cardInterval
  2647. local height = mSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
  2648. --创建一个空的layout,layout放到组合牌点上
  2649. local mLayout = cc.Layout:createNode()
  2650. local endPos = nil
  2651. if bMeTurn then
  2652. endPos = cc.p(width * col,0)
  2653. elseif viewId == 1 then
  2654. endPos = cc.p(-width * col,0)
  2655. else
  2656. endPos = cc.p(width * col,0)
  2657. end
  2658. --开启触摸
  2659. mLayout:setTouchEnabled(true)
  2660. --设置锚点
  2661. mLayout:setAnchorPoint(cc.p(0,1))
  2662. --设置大小
  2663. mLayout:setSize(cc.size(width,height*4))
  2664. --layout数据存储:
  2665. --下面的牌数据:
  2666. mLayout.cardList = {}
  2667. --查找layout的唯一性
  2668. mLayout:setName(string.format("%d",card))
  2669. for i = 1,4 do
  2670. local row = i - 1;
  2671. --数据
  2672. mLayout.cardList[i] = card
  2673. --界面
  2674. local mWeiCard = cc.ImageView:createNode()
  2675. if isTiPai then
  2676. if i > 1 then
  2677. mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))
  2678. else
  2679. mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
  2680. end
  2681. else
  2682. mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))--显示真实牌值
  2683. end
  2684. mWeiCard:setScale(self.littleCardScale)
  2685. mWeiCard:setPosition(width/2,0 + height * row + height /2);
  2686. mWeiCard:setTag(1)
  2687. mLayout:addChild(mWeiCard,4-i+1);
  2688. end
  2689. if isTiPai then
  2690. mLayout.type = "ti"
  2691. --设置类型
  2692. mLayout:setTag(ZPDef.TableConst.TABLE_CONST_CAN_TOUCH)
  2693. else
  2694. mLayout.type = "pao"
  2695. --设置类型
  2696. mLayout:setTag(ZPDef.TableConst.TABLE_CONST_NO_TOUCH)
  2697. end
  2698. self.playerZhao[viewId] = self.playerZhao[viewId] + 1
  2699. if bMeTurn and isTiPai then
  2700. --注册点击事件
  2701. mLayout:registerClick(function ()
  2702. --获取TAG,name,tag表示类型,name表示抓取那个layout
  2703. for index,child in pairs(UnitCardNode:getChildren()) do
  2704. local tag = child:getTag()
  2705. if tag == ZPDef.TableConst.TABLE_CONST_CAN_TOUCH then
  2706. for i,v in pairs(child:getChildren()) do
  2707. if v:getTag() == 1 and i > 1 then
  2708. v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(child.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))
  2709. v:setScale(self.littleCardScale)
  2710. local seq = cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
  2711. v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))
  2712. end))
  2713. v:runAction(seq)
  2714. elseif v:getTag() == 2 then
  2715. --txt:setText("")
  2716. end
  2717. end
  2718. end
  2719. end
  2720. end)
  2721. end
  2722. --动画
  2723. UnitCardNode:addChild(mLayout);
  2724. if isShowAni then
  2725. self:playWeaveCardAni(mLayout,viewId,1,endPos,onEnd,0,true)
  2726. else
  2727. mLayout:setPosition(endPos)
  2728. end
  2729. --提完牌置false
  2730. self.systemTiPai = false
  2731. end
  2732. --用户跑牌(自动)
  2733. function ZPRoomView:PaoPai(viewId,card,onEnd)
  2734. --逻辑思考1:数据删除
  2735. --逻辑思考2:根据牌查找当前跑的牌是已经偎的牌或者碰牌的牌(桌面牌)
  2736. --是否轮到我
  2737. local bMeTurn = viewId == self:getMeViewId()
  2738. self.playerZhao[viewId] = self.playerZhao[viewId] + 1
  2739. --自己是需要做数据删除的,他人不需要的
  2740. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  2741. elseif bMeTurn then --and not app.room:isLittleFamily()
  2742. --倒叙遍历1-10列
  2743. for col = self.lieShuMax,1,-1 do --列数
  2744. for row = 4,1,-1 do --行数
  2745. if card == self.handCardRoot[col].imgList[row].value then
  2746. table.remove(self.handCardValueLocal[col],row)
  2747. self:rankDeletOneBakCard(card)
  2748. --单张图片的值归nil
  2749. self.handCardRoot[col].imgList[row].value = nil
  2750. self.handCardRoot[col].imgList[row].isKan = false
  2751. --单个图片隐藏
  2752. self.handCardRoot[col].imgList[row]:setVisible(false)
  2753. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  2754. end
  2755. end
  2756. end
  2757. self:neatenCard(true)
  2758. end
  2759. --更新自己
  2760. --1.查找桌面牌 碰牌
  2761. --标志:
  2762. local name = string.format("Layout_player1Table_%d",viewId)
  2763. local UnitCardNode = self.ui.Items[name]
  2764. local chlidLayout = UnitCardNode:getChildByName(string.format("%d",card))
  2765. local bIsPengPao = false
  2766. if chlidLayout then
  2767. if chlidLayout.type == "peng2" or chlidLayout.type == "peng3" then
  2768. bIsPengPao = true
  2769. --视图更新
  2770. if chlidLayout.type == "peng3" then
  2771. local mTiCard = cc.ImageView:createNode()
  2772. local thirdSprite = chlidLayout:getChildren()[1]
  2773. local height = thirdSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
  2774. local tarPos = cc.p(thirdSprite:getPositionX(),thirdSprite:getPositionY() + height);
  2775. mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
  2776. chlidLayout:addChild(mTiCard);
  2777. chlidLayout.cardList[4] = card
  2778. --ani
  2779. self:playWeaveCardAni(mTiCard,viewId,self.littleCardScale,tarPos,onEnd,0,false)
  2780. elseif chlidLayout.type == "peng2" then
  2781. --删除弃牌的牌
  2782. local nSeatId = chlidLayout.nSeatId
  2783. local viewId = app.room:getViewIdBySeatId(nSeatId)
  2784. local name = string.format("Layout_giveUp_%d",viewId)
  2785. local list = self.ui.Items[name]:getChildren()
  2786. for k,mCard in ipairs(list) do
  2787. if mCard.value == card then
  2788. mCard:removeFromParent()
  2789. break
  2790. end
  2791. end
  2792. self:updateQiPai(viewId)
  2793. --创建2个牌
  2794. for i = 1,2 do
  2795. local mTiCard = cc.ImageView:createNode()
  2796. local thirdSprite = chlidLayout:getChildren()[i + 1]
  2797. local tarPos = cc.p(thirdSprite:getPositionX(),thirdSprite:getPositionY() + thirdSprite:getContentSize().height * self.littleCardScale);
  2798. mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
  2799. mTiCard:setPosition(tarPos)
  2800. mTiCard:setScale(self.littleCardScale)
  2801. chlidLayout:addChild(mTiCard);
  2802. chlidLayout.cardList[3] = card
  2803. chlidLayout.cardList[4] = card
  2804. if i == 2 then
  2805. self:playWeaveCardAni(mTiCard,viewId,self.littleCardScale,tarPos,onEnd,0,false)
  2806. end
  2807. end
  2808. end
  2809. elseif chlidLayout.type == "mingwei" or chlidLayout.type == "anwei" then
  2810. bIsPengPao = true
  2811. --屏蔽点击
  2812. chlidLayout:setTouchEnabled(false)
  2813. chlidLayout:setTag(ZPDef.TableConst.TABLE_CONST_NO_TOUCH)
  2814. --显示偎起的牌
  2815. for i,v in ipairs(chlidLayout:getChildren()) do
  2816. --前3张
  2817. if v:getTag() == 1 and i < 4 then
  2818. v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(chlidLayout.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))
  2819. end
  2820. end
  2821. --视图更新
  2822. local mTiCard = cc.ImageView:createNode()
  2823. local thirdSprite = chlidLayout:getChildren()[1]
  2824. local tarPos = cc.p(thirdSprite:getPositionX(),thirdSprite:getPositionY() + thirdSprite:getContentSize().height * self.littleCardScale);
  2825. mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
  2826. chlidLayout:addChild(mTiCard);
  2827. chlidLayout.cardList[4] = card
  2828. self:playWeaveCardAni(mTiCard,viewId,self.littleCardScale,tarPos,onEnd,0,false)
  2829. end
  2830. chlidLayout.type = "pao"
  2831. end
  2832. if not bIsPengPao then
  2833. local list = {card,card,card,card}
  2834. self:createTiOrPaoView(false,viewId,list,true,onEnd)
  2835. end
  2836. end
  2837. --用户碰(自动)
  2838. function ZPRoomView:Peng(viewId,card,isMoPaiOrId,onEnd)
  2839. --是否轮到我
  2840. local bMeTurn = viewId == self:getMeViewId()
  2841. --自己是需要做数据删除的,他人不需要的
  2842. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  2843. elseif bMeTurn then --and not app.room:isLittleFamily()
  2844. --倒叙遍历1-10列
  2845. for col = self.lieShuMax,1,-1 do --列数
  2846. for row = self.hangShuMax,1,-1 do --行数
  2847. if card == self.handCardRoot[col].imgList[row].value then --判断值是否相等
  2848. table.remove(self.handCardValueLocal[col],row)
  2849. self:rankDeletOneBakCard(card)
  2850. --单张图片的值归nil
  2851. self.handCardRoot[col].imgList[row].value = nil
  2852. self.handCardRoot[col].imgList[row].isKan = false
  2853. --单个图片隐藏
  2854. logE("RoomView:Peng col:"..col)
  2855. logE("RoomView:Peng row:"..row)
  2856. self.handCardRoot[col].imgList[row]:setVisible(false)
  2857. self.handCardRoot[col].imgList[row]:setOpacity(255)
  2858. end
  2859. end
  2860. end
  2861. self:neatenCard(true)
  2862. end
  2863. local list = {card,card,card}
  2864. self:createPengView(viewId,list,true,isMoPaiOrId)
  2865. if onEnd then
  2866. onEnd()
  2867. end
  2868. end
  2869. --创建碰的UI
  2870. function ZPRoomView:createPengView(viewId,list,isShowAni,isMoPaiOrId)
  2871. --是否轮到我
  2872. local bMeTurn = viewId == self:getMeViewId()
  2873. local card = list[1]
  2874. --更新自己(3张暗加一个数字(值分大小写))
  2875. --获取自己的出牌点
  2876. local name = string.format("Layout_player1Table_%d",viewId)
  2877. local UnitCardNode = self.ui.Items[name]
  2878. --获取出牌点的儿子数量
  2879. local count = UnitCardNode:getChildrenCount();
  2880. --数量即为列数
  2881. local col = count;
  2882. --牌大小
  2883. local mSprite = cc.ImageView:createNode()
  2884. local FileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE)
  2885. mSprite:loadTextureFromPlist(FileName)
  2886. local width = mSprite:getContentSize().width * self.littleCardScale + self.cardInterval
  2887. local height = mSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
  2888. --创建一个空的layout,layout放到组合牌点上
  2889. local mLayout = cc.Layout:createNode()
  2890. --1.记录坐标
  2891. local endPos = nil
  2892. if bMeTurn then
  2893. endPos = cc.p(width * col,0)
  2894. elseif viewId == 1 then
  2895. endPos = cc.p(-width * col,0)
  2896. else
  2897. endPos = cc.p(width * col,0)
  2898. end
  2899. --设置锚点
  2900. mLayout:setAnchorPoint(cc.p(0,1))
  2901. --设置大小
  2902. mLayout:setSize(cc.size(width,height*3))
  2903. --layout数据存储:
  2904. --下面的牌数据:
  2905. mLayout.cardList = {}
  2906. --查找layout的唯一性
  2907. mLayout:setName(string.format("%d",card))
  2908. mLayout.type = "peng3"
  2909. mLayout:setTag(ZPDef.TableConst.TABLE_CONST_NO_TOUCH)
  2910. --判断是不是摸牌,如果是摸牌碰就3张,不是就2张,放炮的人显示一张牌为弃牌
  2911. local forTimeS = 3
  2912. for i = 1,forTimeS do
  2913. local mPengCard;
  2914. local row = i - 1;
  2915. --数据
  2916. mLayout.cardList[i] = card
  2917. --界面
  2918. mPengCard = cc.ImageView:createNode()
  2919. mPengCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
  2920. mPengCard:setScale(self.littleCardScale)
  2921. mPengCard:setPosition(width/2,0 + height * row - height /2);
  2922. mLayout:addChild(mPengCard,forTimeS-i+1);
  2923. end
  2924. UnitCardNode:addChild(mLayout);
  2925. --2.全部拷贝动画
  2926. if isShowAni then
  2927. self:playWeaveCardAni(mLayout,viewId,1,endPos,nil,1.0,true)
  2928. else
  2929. mLayout:setPosition(endPos)
  2930. end
  2931. end
  2932. --[[
  2933. node:节点
  2934. viewId:视图ID
  2935. targetBeiShu:起始倍数
  2936. tarPos:目标点
  2937. callback:回调
  2938. offY:坐标偏移倍数(高度)
  2939. isLayout:是否是容器true,单个牌是false
  2940. ]]
  2941. function ZPRoomView:playWeaveCardAni(node,viewId,targetBeiShu,tarPos,callback,offY,isLayout)
  2942. local childLayout = node:getParent()
  2943. local size
  2944. if isLayout then
  2945. size = node:getSize()
  2946. else
  2947. size = childLayout:getSize()
  2948. end
  2949. local pos = self.PlayerView.allNodes[viewId].tip:getWorldPosition()
  2950. local beginPos = childLayout:convertToNodeSpace(pos)
  2951. beginPos = cc.p(beginPos.x - size.width/2,beginPos.y + size.height * offY)
  2952. node:setPosition(beginPos);
  2953. --移动时间
  2954. local moveTime = 0.35
  2955. --初始倍数
  2956. local spawn = cc.Spawn:create(cc.ScaleTo:create(moveTime,targetBeiShu),cc.MoveTo:create(moveTime,tarPos))
  2957. local seq = cc.Sequence:create(cc.ScaleTo:create(0,1.5),cc.DelayTime:create(0.5),spawn,cc.CallFunc:create(function ()
  2958. if callback then
  2959. callback()
  2960. end
  2961. end))
  2962. node:runAction(seq)
  2963. end
  2964. --用户吃(手动)
  2965. function ZPRoomView:Chi(viewId,card,onEnd)
  2966. --根据code解码吃的种类
  2967. local list = {}
  2968. local index = 1
  2969. local operateCodeNum = table.nums(self.operationSuccessCode)
  2970. logE("ZPRoomView:Chi operateCodeNum:")
  2971. logE(operateCodeNum)
  2972. for k,v in ipairs(self.operationSuccessCode) do
  2973. local mType = v.nOperationCode
  2974. --左吃顺子
  2975. local ret1 = bit32.band(mType,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
  2976. --中吃顺子
  2977. local ret2 = bit32.band(mType,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
  2978. --右吃顺子
  2979. local ret3 = bit32.band(mType,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
  2980. --吃同色搭子(壹壹一,吃牌为一)
  2981. local ret4 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
  2982. --大小搭吃
  2983. local ret5 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
  2984. --二七十
  2985. local ret6 = bit32.band(mType,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  2986. --判断是否有吃牌组合
  2987. if ret1 > 0 then
  2988. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
  2989. index = index + 1
  2990. end
  2991. if ret2 > 0 then
  2992. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
  2993. index = index + 1
  2994. end
  2995. if ret3 > 0 then
  2996. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
  2997. index = index + 1
  2998. end
  2999. if ret4 > 0 then
  3000. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
  3001. index = index + 1
  3002. end
  3003. if ret5 > 0 then
  3004. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
  3005. index = index + 1
  3006. end
  3007. if ret6 > 0 then
  3008. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  3009. index = index + 1
  3010. end
  3011. end
  3012. logE("RoomView:Chi onEatCardCallBack list data:"..table.tostring(list))
  3013. --吃的牌数组
  3014. local chiPaiList = {}
  3015. local chiShowPaiList = {}
  3016. --比的牌数组
  3017. local biPaiList = {}
  3018. --下标
  3019. local nforCount = 1
  3020. for i = 1, #list do
  3021. for j = 1, 3 do
  3022. if i == 1 then
  3023. chiPaiList[nforCount] = list[i][j]
  3024. else
  3025. biPaiList[nforCount] = list[i][j]
  3026. end
  3027. nforCount = nforCount + 1
  3028. end
  3029. end
  3030. logE("RoomView: chi chiPaiList : "..table.tostring(chiPaiList))
  3031. logE("RoomView: chi biPaiList : "..table.tostring(biPaiList))
  3032. chiShowPaiList = DeepCopy(chiPaiList)
  3033. --是否轮到我
  3034. local bMeTurn = viewId == self:getMeViewId()
  3035. --自己是需要做数据删除的,他人不需要的
  3036. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  3037. elseif bMeTurn then--and not app.room:isLittleFamily()
  3038. self.isGodHand = true
  3039. --删除吃的那个牌
  3040. for i = #chiPaiList,1,-1 do
  3041. if chiPaiList[i] == card then
  3042. table.remove(chiPaiList,i)
  3043. break
  3044. end
  3045. end
  3046. logE("RoomView:Chi chiPaiList after delete: "..table.tostring(chiPaiList))
  3047. local isEnd = false
  3048. local i = 1
  3049. local indexWhile = 1
  3050. while chiPaiList[i] do
  3051. if indexWhile > 8 then
  3052. logE("RoomView:Chi death while")
  3053. break
  3054. end
  3055. indexWhile = indexWhile + 1
  3056. for col = self.lieShuMax,1,-1 do --列数
  3057. for row = self.hangShuMax,1,-1 do --行数
  3058. if chiPaiList[i] == self.handCardValueLocal[col][row] then --判断值是否相等
  3059. table.remove(self.handCardValueLocal[col],row)
  3060. self:rankDeletOneBakCard(chiPaiList[i])
  3061. --单张图片的值归nil
  3062. self.handCardRoot[col].imgList[row].value = nil
  3063. self.handCardRoot[col].imgList[row].isKan = false
  3064. --单个图片隐藏
  3065. self.handCardRoot[col].imgList[row]:setVisible(false)
  3066. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  3067. self.handCardRoot[col].imgList[row]:setOpacity(255)
  3068. i = i + 1
  3069. isEnd = true
  3070. self:downCard()
  3071. break
  3072. end
  3073. end
  3074. if isEnd then
  3075. isEnd = false
  3076. break
  3077. end
  3078. end
  3079. end
  3080. logE("RoomView:Chi Pai do end")
  3081. self:neatenCard(true)
  3082. end
  3083. --比牌操作
  3084. local function callback(onEnd)
  3085. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  3086. elseif bMeTurn then--and not app.room:isLittleFamily()
  3087. local isEnd = false
  3088. local i = 4
  3089. local indexWhile = 1
  3090. while biPaiList[i] do
  3091. if indexWhile > 16 then
  3092. logE("RoomView:Bi death while")
  3093. --self.toolView:onClickLog()
  3094. break
  3095. end
  3096. indexWhile = indexWhile + 1
  3097. for col = self.lieShuMax,1,-1 do --列数
  3098. for row = self.hangShuMax,1,-1 do --行数
  3099. if biPaiList[i] == self.handCardValueLocal[col][row] then --判断值是否相等
  3100. table.remove(self.handCardValueLocal[col],row)
  3101. self:rankDeletOneBakCard(biPaiList[i])
  3102. --单张图片的值归nil
  3103. self.handCardRoot[col].imgList[row].value = nil
  3104. self.handCardRoot[col].imgList[row].isKan = false
  3105. --单个图片隐藏
  3106. self.handCardRoot[col].imgList[row]:setVisible(false)
  3107. self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
  3108. self.handCardRoot[col].imgList[row]:setOpacity(255)
  3109. i = i + 1
  3110. isEnd = true
  3111. self:downCard()
  3112. break
  3113. end
  3114. end
  3115. if isEnd then
  3116. isEnd = false
  3117. break
  3118. end
  3119. end
  3120. end
  3121. self:neatenCard(true)
  3122. logE("RoomView:Bi Pai do end")
  3123. end
  3124. logE("biPaiList"..table.tostring(biPaiList))
  3125. self:createEatView(card,viewId,biPaiList,true,nil,nil)
  3126. if onEnd then
  3127. onEnd()
  3128. end
  3129. end
  3130. if operateCodeNum > 1 then
  3131. self:showOperatorTip(viewId,ZPDef.OpType.OP_TYPE_CHI)
  3132. local nUserID = app.room:getUserIdByViewId(viewId)
  3133. self:createEatView(card,viewId,chiShowPaiList,true,callback,onEnd)
  3134. else
  3135. self:showOperatorTip(viewId,ZPDef.OpType.OP_TYPE_CHI)
  3136. local nUserID = app.room:getUserIdByViewId(viewId)
  3137. self:createEatView(card,viewId,chiShowPaiList,true)
  3138. if onEnd then
  3139. onEnd()
  3140. end
  3141. end
  3142. end
  3143. --创建吃的UI
  3144. function ZPRoomView:createEatView(card,viewId,list,isShowAni,callbackFunc,onEnd)
  3145. --是否轮到我
  3146. local bMeTurn = viewId == self:getMeViewId()
  3147. --更新视图
  3148. --获取自己的出牌点
  3149. local name = string.format("Layout_player1Table_%d",viewId)
  3150. local UnitCardNode = self.ui.Items[name]
  3151. --牌大小
  3152. local mSprite = cc.ImageView:createNode()
  3153. local FileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE)
  3154. mSprite:loadTextureFromPlist(FileName)
  3155. local width = mSprite:getContentSize().width * self.littleCardScale + self.cardInterval
  3156. local height = mSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
  3157. local mLayout = nil
  3158. --list 反向操作
  3159. local tempList = {}
  3160. for k,v in pairsByKeys(list) do
  3161. table.insert(tempList,v)
  3162. end
  3163. local max = tempList[3]
  3164. tempList[3] = tempList[1]
  3165. tempList[1] = max
  3166. if #tempList > 4 then
  3167. local max = tempList[6]
  3168. tempList[6] = tempList[4]
  3169. tempList[4] = max
  3170. end
  3171. local endPos = nil
  3172. logE("tempList:"..table.tostring(tempList))
  3173. for k,weaveCard in pairsByKeys(tempList) do
  3174. if k % 3 == 1 then
  3175. --获取出牌点的儿子数量
  3176. local count = UnitCardNode:getChildrenCount();
  3177. --数量即为列数
  3178. local col = count;
  3179. --创建一个空的layout,layout放到组合牌点上
  3180. mLayout = cc.Layout:createNode()
  3181. mLayout:setTag(ZPDef.TableConst.TABLE_CONST_NO_TOUCH)
  3182. if bMeTurn then
  3183. endPos = cc.p(width * col,0)
  3184. elseif viewId == 1 then
  3185. endPos = cc.p(-width * col,0)
  3186. else
  3187. endPos = cc.p(width * col,0)
  3188. end
  3189. --设置锚点
  3190. mLayout:setAnchorPoint(cc.p(0,1))
  3191. --设置大小
  3192. mLayout:setSize(cc.size(width,height*3))
  3193. --layout数据存储:
  3194. mLayout.type = "chi"
  3195. mLayout.cardList = tempList
  3196. --顺子没用到
  3197. mLayout:setName("10086")
  3198. end
  3199. local cardShow = weaveCard
  3200. local row = (k % 3) - 1
  3201. if k % 3 == 0 then
  3202. row = 2
  3203. end
  3204. --界面
  3205. local mWeiCard = cc.ImageView:createNode()
  3206. mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE))
  3207. mWeiCard:setScale(self.littleCardScale)
  3208. mWeiCard:setPosition(width/2,0 + height * row - height /2);
  3209. mLayout:addChild(mWeiCard,#tempList-k+1);
  3210. if row == 2 then
  3211. --mWeiCard:setOpacity(125)
  3212. end
  3213. if k % 3 == 0 then
  3214. --动画
  3215. UnitCardNode:addChild(mLayout);
  3216. if isShowAni then
  3217. self:playWeaveCardAni(mLayout,viewId,1,endPos,nil,1.0,true)
  3218. else
  3219. mLayout:setPosition(endPos)
  3220. end
  3221. end
  3222. end
  3223. if callbackFunc then
  3224. logE("RoomView:bi Pai will do start")
  3225. self.ui:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
  3226. callbackFunc(onEnd)
  3227. end)))
  3228. end
  3229. end
  3230. --摸牌
  3231. function ZPRoomView:onMoPai(data)
  3232. local function runOnMoPai(onEnd)
  3233. local response = data.response
  3234. local nUserId = response.nUserId
  3235. local turnOverCard = response.turnOverCard
  3236. local code = response.mainOpCode
  3237. local leftCardNum = response.leftCardNum
  3238. local operations = response.operations
  3239. local showCardFlag = response.showCardFlag
  3240. local viewId = app.room:getViewIdByUserId(nUserId)
  3241. self.EatOperationCode = code
  3242. self.outCard = turnOverCard
  3243. self.moPaiViewId = viewId
  3244. self:showDelayTimeTip(operations)
  3245. --更新剩余牌数
  3246. self:playMoPaiAni(leftCardNum,turnOverCard,viewId,code,showCardFlag,onEnd)
  3247. if self.bankerBaoPao then
  3248. self.bankerBaoPao = nil
  3249. self:showTiPaiBtn(true)
  3250. --小家不能看牌时,牌堆牌显示剩余张数
  3251. if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
  3252. self:setCircleCardLeftPanelView(true,viewId,19)
  3253. end
  3254. end
  3255. if self:getIsMeUId(nUserId) then
  3256. --检测是否少牌
  3257. self:checkCardAndRecover()
  3258. end
  3259. end
  3260. log("2000000000-ZPRoomView - addCallBack(runOnMoPai)")
  3261. self:setLiangPaiVisible(false)--解决托管自动出牌的时候,查牌界面还存在
  3262. self:addCallBack(runOnMoPai)
  3263. end
  3264. --播放摸牌动画
  3265. --[[
  3266. leftCardNum:剩余牌
  3267. turnOverCard: 摸的牌
  3268. viewId:视图ID
  3269. mainOpCode:操作码
  3270. showCardFlag:是否显示牌 0;不能 1:能
  3271. isNotShowAni:不显示动画
  3272. ]]
  3273. function ZPRoomView:playMoPaiAni(leftCardNum,turnOverCard,viewId,mainOpCode,showCardFlag,onEnd,isNotShowAni)
  3274. self.isMoPaiOperator = true
  3275. --重置出牌坐标
  3276. self:resetOutCardPoint()
  3277. --图片
  3278. local outCardname = string.format("ImageView_outCardImg_%d",viewId)
  3279. local outCardLayoutName = string.format("Layout_outCardPoint_%d",viewId)
  3280. local mSprite = self.ui.Items[outCardname]
  3281. local srcPos = mSprite:getPosition()
  3282. local fileName = ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_OUTCARD)
  3283. local fileNameReal = ZPFuc.getZPCardImgByValue(turnOverCard,ZPDef.CardType.CARD_TYPE_OUTCARD)
  3284. self.ui.Items[outCardLayoutName]:setVisible(true)
  3285. if viewId == self:getMeViewId() then
  3286. mSprite:loadTextureFromPlist(fileNameReal)
  3287. end
  3288. --公谱出牌不串不哨立马亮牌,看到亮牌的听得到牌的音效
  3289. if mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
  3290. mSprite:loadTextureFromPlist(fileNameReal)
  3291. mSprite.value = turnOverCard
  3292. else
  3293. if showCardFlag == 1 then
  3294. mSprite:loadTextureFromPlist(fileNameReal)
  3295. mSprite.value = turnOverCard
  3296. if not isNotShowAni then
  3297. local nUserId = app.room:getUserIdByViewId(viewId)
  3298. local userInfo=app.room:getUserInfo(nUserId)
  3299. if userInfo then
  3300. if turnOverCard > 0 and turnOverCard < 32 then
  3301. ZPSound.PlayZPSound(userInfo.sex,turnOverCard)
  3302. end
  3303. end
  3304. end
  3305. else
  3306. mSprite:loadTextureFromPlist(fileName)
  3307. mSprite.value = 0xfa
  3308. end
  3309. end
  3310. self:changeOutCardLight(true)
  3311. local function callback()
  3312. if mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
  3313. self.EatOperationCode = mainOpCode
  3314. self:showOpeation(mainOpCode,viewId,turnOverCard)
  3315. end
  3316. end
  3317. if isNotShowAni then
  3318. mSprite:setPosition(srcPos)
  3319. callback()
  3320. if onEnd then
  3321. onEnd()
  3322. end
  3323. return
  3324. else
  3325. local outCardLightName = string.format("ImageView_outCardLight_%d",viewId)
  3326. self.ui.Items[outCardLightName]:setVisible(false)
  3327. mSprite:setScale(0)
  3328. if showCardFlag ~= 1 then
  3329. mSprite:loadTextureFromPlist(fileName)
  3330. --起始坐标调整和角度,扫为横的出来
  3331. if viewId == self:getMeViewId() then
  3332. mSprite:setEulerRotation(cc.vec3(0,0,0))
  3333. beginPos = cc.p(srcPos.x,srcPos.y + 200)
  3334. elseif viewId == 1 then
  3335. mSprite:setEulerRotation(cc.vec3(0,0,-90))
  3336. beginPos = cc.p(srcPos.x - 200 ,srcPos.y)
  3337. elseif viewId == 2 then
  3338. mSprite:setEulerRotation(cc.vec3(0,0,0))
  3339. beginPos = cc.p(srcPos.x,srcPos.y - 100)
  3340. elseif viewId == 3 then
  3341. mSprite:setEulerRotation(cc.vec3(0,0,-90))
  3342. beginPos = cc.p(srcPos.x + 200 ,srcPos.y-50)
  3343. end
  3344. mSprite:setPosition(beginPos)
  3345. --目标调整、角度
  3346. if viewId == 1 then
  3347. srcPos = cc.p(srcPos.x + 250,srcPos.y)
  3348. elseif viewId == 2 then
  3349. srcPos = cc.p(srcPos.x,srcPos.y+50)
  3350. elseif viewId == 3 then
  3351. srcPos = cc.p(srcPos.x - 250,srcPos.y-50)
  3352. elseif viewId == 4 then
  3353. srcPos = cc.p(srcPos.x,srcPos.y-100)
  3354. end
  3355. mSprite:setScale(1)
  3356. mSprite:runAction(cc.Sequence:create(cc.MoveTo:create(0.3,srcPos),cc.CallFunc:create(function ()
  3357. self.ui.Items[outCardLightName]:setVisible(true)
  3358. end),cc.CallFunc:create(function ()
  3359. --恢复原来的角度
  3360. if viewId == self:getMeViewId() then
  3361. mSprite:setEulerRotation(cc.vec3(0,0,90))
  3362. elseif viewId == 1 then
  3363. mSprite:setEulerRotation(cc.vec3(0,0,0))
  3364. elseif viewId == 2 then
  3365. mSprite:setEulerRotation(cc.vec3(0,0,90))
  3366. elseif viewId == 3 then
  3367. mSprite:setEulerRotation(cc.vec3(0,0,0))
  3368. end
  3369. self.ui.Items[outCardLayoutName]:setVisible(false)
  3370. self:setCircleCardLeftPanelView(true,viewId,leftCardNum)
  3371. callback()
  3372. if onEnd then
  3373. onEnd()
  3374. end
  3375. end)))
  3376. else
  3377. if mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
  3378. local nUserId = app.room:getUserIdByViewId(viewId)
  3379. local userInfo=app.room:getUserInfo(nUserId)
  3380. if userInfo then
  3381. ZPSound.PlayZPSound(userInfo.sex,turnOverCard)
  3382. end
  3383. end
  3384. --播放摸牌动画(这里最好用出牌器的坐标进行转换,暂时这样调整吧)
  3385. if viewId == self:getMeViewId() then
  3386. beginPos = cc.p(srcPos.x,srcPos.y + 200)
  3387. elseif viewId == 1 then
  3388. beginPos = cc.p(srcPos.x - 300 ,srcPos.y)
  3389. elseif viewId == 2 then
  3390. beginPos = cc.p(srcPos.x ,srcPos.y - 200)
  3391. elseif viewId == 3 then
  3392. beginPos = cc.p(srcPos.x + 300 ,srcPos.y)
  3393. end
  3394. mSprite:setPosition(beginPos)
  3395. local mSpawn = cc.Spawn:create(cc.ScaleTo:create(self.gameSpeedConfig.MO_PAI_TIME,1.0),cc.MoveTo:create(self.gameSpeedConfig.MO_PAI_TIME,srcPos))
  3396. mSprite:runAction(cc.Sequence:create(mSpawn,cc.CallFunc:create(function ()
  3397. self.ui.Items[outCardLightName]:setVisible(true)
  3398. --显示指示器
  3399. self:setCircleCardLeftPanelView(true,viewId,leftCardNum)
  3400. end),cc.DelayTime:create(0.15),cc.CallFunc:create(function ()
  3401. callback()
  3402. if onEnd then
  3403. onEnd()
  3404. end
  3405. end)))
  3406. end
  3407. end
  3408. end
  3409. --弃牌
  3410. function ZPRoomView:onQiPai(data)
  3411. local function runOnQiPai(onEnd)
  3412. logE("2000000000-ZPRoomView onQiPai : "..table.tostring(data.response))
  3413. local response = data.response
  3414. local nUserId = response.nUserId
  3415. local disCard = response.disCard
  3416. local viewId = app.room:getViewIdByUserId(nUserId)
  3417. self:playQiPaiAni(true,disCard,viewId,onEnd)
  3418. self.isGodHand = false
  3419. end
  3420. log("2000000000-ZPRoomView - addCallBack(runOnQiPai)")
  3421. self:addCallBack(runOnQiPai)
  3422. end
  3423. --弃牌动画
  3424. --断线重连的时候,不需要动画
  3425. --[[
  3426. isShowAni:是否展示弃牌动画
  3427. disCard:弃牌
  3428. viewId:视图ID
  3429. isDianPaoPeng:碰胡规则,点炮碰,弃牌要显示透明形态
  3430. ]]
  3431. function ZPRoomView:playQiPaiAni(isShowAni,disCard,viewId,onEnd,isDianPaoPeng)
  3432. local outCardname = string.format("ImageView_outCardImg_%d",viewId)
  3433. local outCardPoint = string.format("Layout_outCardPoint_%d",viewId)
  3434. local giveupCardname = string.format("Layout_giveUp_%d",viewId)
  3435. --牌的图片
  3436. local outCardImg = self.ui.Items[outCardname]
  3437. --牌的图片父节点
  3438. local outCardLayout = self.ui.Items[outCardPoint]
  3439. --弃牌的layout
  3440. local giveUpLayout = self.ui.Items[giveupCardname]
  3441. --获取弃牌节点存在的数量
  3442. local count = giveUpLayout:getChildrenCount()
  3443. --创建一张精灵
  3444. local mSprite = cc.ImageView:createNode()
  3445. mSprite:setScale(self.littleCardScale)
  3446. local finalFileName = ZPFuc.getZPCardImgByValue(disCard,ZPDef.CardType.CARD_TYPE_TABLE)
  3447. mSprite:loadTextureFromPlist(finalFileName)
  3448. mSprite:setVisible(false)
  3449. mSprite:setAnchorPoint(cc.p(0,0))
  3450. mSprite.value = disCard
  3451. giveUpLayout:addChild(mSprite)
  3452. local width = mSprite:getContentSize().width * self.littleCardScale;
  3453. local height = mSprite:getContentSize().height * self.littleCardScale;
  3454. local getHeightCount = function (count)
  3455. if count >= 6 then
  3456. return math.floor(count/6)
  3457. else
  3458. return 0
  3459. end
  3460. end
  3461. local x = count % 6
  3462. local tarPos
  3463. if viewId == 1 then
  3464. local adjustPos = cc.p(width * x,height * getHeightCount(count))
  3465. tarPos = cc.p(0 - adjustPos.x,0 - adjustPos.y)
  3466. elseif viewId == 2 then
  3467. local adjustPos = cc.p(width * x,getHeightCount(count) * height)
  3468. tarPos = cc.p(0 - adjustPos.x,0 - adjustPos.y)
  3469. elseif viewId == 3 then
  3470. local adjustPos = cc.p(width * x,height * getHeightCount(count))
  3471. tarPos = cc.p(0 + adjustPos.x,0 - adjustPos.y)
  3472. elseif viewId == self:getMeViewId() then
  3473. local adjustPos = cc.p(width * x,height * getHeightCount(count))
  3474. tarPos = cc.p(0 - adjustPos.x,0 - adjustPos.y)
  3475. end
  3476. mSprite:setPosition(tarPos)
  3477. --动画显示
  3478. if not isShowAni then
  3479. mSprite:setVisible(true)
  3480. if isDianPaoPeng then
  3481. mSprite:setColor(cc.c3b(125,125,125))
  3482. end
  3483. else
  3484. local fileName = ZPFuc.getZPCardImgByValue(disCard,ZPDef.CardType.CARD_TYPE_OUTCARD)
  3485. --弃牌
  3486. local giveSprite = cc.ImageView:createNode()
  3487. giveSprite:loadTextureFromPlist(fileName)
  3488. giveSprite:setScale(self.outCardScale)
  3489. giveUpLayout:addChild(giveSprite)
  3490. giveSprite:setVisible(false)
  3491. local spriteSizeWidth = giveSprite:getContentSize().width * self.outCardScale
  3492. local spriteSizeHeight = giveSprite:getContentSize().height * self.outCardScale
  3493. local worldPos = outCardImg:convertToWorldSpace(outCardImg:getPosition())
  3494. local nodePos = giveUpLayout:convertToNodeSpace(worldPos)
  3495. --调整上下2个玩家的坐标和牌的角度
  3496. if viewId == 2 or viewId == 4 then
  3497. --nodePos = cc.p(nodePos.x - spriteSizeWidth,nodePos.y - spriteSizeHeight/2)
  3498. --giveSprite:setEulerRotation(cc.vec3(0,0,90))
  3499. end
  3500. giveSprite:setPosition(nodePos)
  3501. 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))
  3502. giveSprite:runAction(cc.Sequence:create(cc.DelayTime:create(0.3),cc.CallFunc:create(function ()
  3503. outCardLayout:setVisible(false)
  3504. giveSprite:setVisible(true)
  3505. end),mSpawn,cc.CallFunc:create(function ()
  3506. mSprite:setVisible(true)
  3507. if isDianPaoPeng then
  3508. mSprite:setColor(cc.c3b(125,125,125))
  3509. end
  3510. end),cc.RemoveSelf:create()))
  3511. --要求弃牌飞到一半,摸牌就开始摸了
  3512. mSprite:runAction(cc.Sequence:create(cc.DelayTime:create(0.4 + self.gameSpeedConfig.QI_PAI_TIME/2),cc.CallFunc:create(function ()
  3513. if onEnd then
  3514. onEnd()
  3515. end
  3516. end)))
  3517. end
  3518. end
  3519. --更新弃牌区
  3520. function ZPRoomView:updateQiPai(viewId)
  3521. local giveupCardname = string.format("Layout_giveUp_%d",viewId)
  3522. local node = self.ui.Items[giveupCardname]
  3523. local list = node:getChildren()
  3524. local tt = {}
  3525. for k,mCard in pairs(list) do
  3526. table.insert(tt,mCard.value)
  3527. end
  3528. node:removeAllChildren()
  3529. for k,card in ipairs(tt) do
  3530. self:playQiPaiAni(false,card,viewId,nil)
  3531. end
  3532. end
  3533. --操作错误
  3534. function ZPRoomView:onOperationError(data)
  3535. local function runOnOperationError(onEnd)
  3536. log("2000000000-ZPRoomView - (runOnOperationError)")
  3537. --恢复操作面板
  3538. self.operationView:touchEatOneCardCallBack()
  3539. if onEnd then
  3540. onEnd()
  3541. end
  3542. end
  3543. log("2000000000-ZPRoomView - addCallBack(runOnOperationError)")
  3544. self:addCallBack(runOnOperationError)
  3545. end
  3546. --听牌结果
  3547. function ZPRoomView:onTingCardResult(data)
  3548. local function runTingCardResult(onEnd)
  3549. log("2000000000-ZPRoomView - (runTingCardResult)")
  3550. local response = data.response
  3551. local outCard = response.outCard
  3552. local tingCards = response.tingCards
  3553. app.room.roomInfo.tingCards = response.tingCards
  3554. local max = table.nums(tingCards)
  3555. if max > 0 then
  3556. self:setTingCardViewVisible(true,tingCards)
  3557. else
  3558. self:setTingCardViewVisible(false)
  3559. end
  3560. if onEnd then
  3561. onEnd()
  3562. end
  3563. local isCanBao = response.canBaoPai
  3564. if isCanBao == 1 then
  3565. self.operationView:showBaoPaiOpView(true)
  3566. end
  3567. end
  3568. log("2000000000-ZPRoomView - addCallBack(runTingCardResult)")
  3569. self:addCallBack(runTingCardResult)
  3570. end
  3571. function ZPRoomView:onChoicePlace(data)
  3572. local function runChoicePlace(onEnd)
  3573. log("2000000000-ZPRoomView - (runChoicePlace)")
  3574. local response = data.response
  3575. local placeList = response.place
  3576. --修改椅子号
  3577. local playerInfo = app.room.roomInfo.memberList
  3578. for k,v in pairs(placeList) do
  3579. playerInfo[v.nUserId].nSeatId = v.nSeatId
  3580. end
  3581. app.room:updateUserSeateShowId()
  3582. self:resetGameData()
  3583. self:onGameReconnection()
  3584. if onEnd then
  3585. onEnd()
  3586. end
  3587. end
  3588. log("2000000000-ZPRoomView - addCallBack(runChoicePlace)")
  3589. self:addCallBack(runChoicePlace)
  3590. end
  3591. function ZPRoomView:setTingCardViewVisible(bVisible,tingCards)
  3592. if app.room:isLittleFamily() then
  3593. bVisible = false
  3594. end
  3595. self.ui.Items.Layout_TingPai:setVisible(bVisible)
  3596. if bVisible then
  3597. self.ui.Items.Layout_TingCard:removeAllChildren()
  3598. self.ui.Items.Layout_TingCardItem:setVisible(false)
  3599. --因为需要添加张数显示而增加的背景高度差
  3600. local tingCardOffHeight = 0
  3601. --听牌本地数据
  3602. self.tingCardLocal = {}
  3603. --只听模式
  3604. self.isNoCardTingPai = false
  3605. --显示听或者多
  3606. self:dealTingCard(tingCards)
  3607. for k,list in pairs(tingCards) do
  3608. local outCard = list.outCard
  3609. local valueList = list.tingCardValue
  3610. local imgType = list.imgType
  3611. --不显示标签,比如地胡,直接显示界面
  3612. if outCard == 0 then
  3613. self.isNoCardTingPai = true
  3614. for i,j in pairs(valueList) do
  3615. local tingCardNum = j.tingCardNum
  3616. local tingCard = j.tingCard
  3617. local tingPaiUI = self.ui.Items.Layout_TingCardItem:getCopied()
  3618. tingPaiUI.Items = getUIItems(tingPaiUI);
  3619. tingPaiUI:setVisible(true)
  3620. self.ui.Items.Layout_TingCard:addChild(tingPaiUI)
  3621. if tingCard then
  3622. local name = ZPFuc.getZPCardImgByValue(tingCard,ZPDef.CardType.CARD_TYPE_TABLE)
  3623. tingPaiUI.Items.ImageView_TingCard:loadTextureFromPlist(name)
  3624. end
  3625. tingPaiUI.Items.Text_TingCardNum:setText(tostring(tingCardNum).."张")
  3626. --听牌剩余多少张,隐藏,但代码保留吧
  3627. if self:setTingCardZhangShuVisible(tingPaiUI.Items.Text_TingCardNum) then
  3628. tingCardOffHeight = 20
  3629. end
  3630. end
  3631. --背景拉伸
  3632. local maxNum = table.nums(valueList)
  3633. if maxNum > 4 then
  3634. local newSizeWidth = maxNum * self.ui.Items.Layout_TingCardItem:getContentSize().width + 43
  3635. local srcHeight = self.tingPaibgSrcHeight + tingCardOffHeight
  3636. self.ui.Items.ImageView_TingPai_bg:setSize(cc.size(newSizeWidth,srcHeight))
  3637. self.ui.Items.Layout_TingCard:setPositionX(newSizeWidth/2)
  3638. else
  3639. local srcWidth = self.ui.Items.ImageView_TingPai_bg:getContentSize().width
  3640. local srcHeight = self.tingPaibgSrcHeight + tingCardOffHeight
  3641. self.ui.Items.ImageView_TingPai_bg:setSize(cc.size(srcWidth,srcHeight))
  3642. end
  3643. else
  3644. --需要显示标签,但不显示听牌界面,需要玩家点击标签后,出现听牌界面
  3645. self.ui.Items.Layout_TingPai:setVisible(false)
  3646. self.tingCardLocal[outCard] = valueList
  3647. --倒叙遍历1-10列
  3648. for col = self.lieShuMax,1,-1 do --列数
  3649. for row = self.hangShuMax,1,-1 do --行数
  3650. local card = self.handCardRoot[col].imgList[row].value
  3651. if outCard == card then --判断值是否相等
  3652. local node = self.handCardRoot[col].imgList[row]:getChildren()[1]
  3653. node:setVisible(true)
  3654. self:showMutilTypeTingFlag(imgType,node)
  3655. end
  3656. end
  3657. end
  3658. end
  3659. end
  3660. self.ui.Items.Layout_TingCard:requestDoLayout()
  3661. self.ui.Items.Layout_TingCard:doLayout()
  3662. else
  3663. self.isNoCardTingPai = false
  3664. self.tingCardLocal = {}
  3665. --所有的标签设置隐藏
  3666. if self.handCardRoot and table.nums(self.handCardRoot) > 0 then
  3667. for col = self.lieShuMax,1,-1 do --列数
  3668. for row = self.hangShuMax,1,-1 do --行数
  3669. if self.handCardRoot[col].imgList[row]:getChildren() then
  3670. local card = self.handCardRoot[col].imgList[row]:getChildren()[1]
  3671. if card then
  3672. self.handCardRoot[col].imgList[row]:getChildren()[1]:setVisible(false)
  3673. end
  3674. end
  3675. end
  3676. end
  3677. end
  3678. end
  3679. end
  3680. function ZPRoomView:dealTingCard(tingCards)
  3681. if not tingCards or table.nums(tingCards) == 0 then
  3682. return
  3683. end
  3684. local imgType = {
  3685. ting = 1,
  3686. duo = 2
  3687. }
  3688. local tt = {}
  3689. for k,v in ipairs(tingCards) do
  3690. table.insert(tt,v)
  3691. end
  3692. table.sort(tt, function (a,b)
  3693. if not a or not b then
  3694. return
  3695. end
  3696. return table.nums(a.tingCardValue) < table.nums(b.tingCardValue)
  3697. end)
  3698. local maxIdx = table.nums(tt)
  3699. for k,v in ipairs(tt) do
  3700. v.imgType = imgType.ting
  3701. end
  3702. if #tt[1].tingCardValue ~= #tt[maxIdx].tingCardValue then
  3703. for k,v in ipairs(tt) do
  3704. if #v.tingCardValue == #tt[maxIdx].tingCardValue then
  3705. v.imgType = imgType.duo
  3706. end
  3707. end
  3708. end
  3709. tingCards = tt
  3710. end
  3711. function ZPRoomView:setTingCardZhangShuVisible(node)
  3712. if node then
  3713. node:setVisible(false)
  3714. end
  3715. return false
  3716. end
  3717. function ZPRoomView:showMutilTypeTingFlag(imgType,node)
  3718. --[[if tingCardTypeNum and tingCardTypeNum > 1 then
  3719. node:loadTexture("zp_base/res/ui/zy_fangjian/zipai_fangjian_new/zipai_fangjian_new_duo.png")
  3720. else
  3721. node:loadTexture("zp_base/res/ui/zy_fangjian/zipai_fangjian_new/zipai_fangjian_new_ting.png")
  3722. end--]]
  3723. end
  3724. --[[
  3725. touchcCard:触摸传进来的牌
  3726. 功能:点击哪个牌显示听什么牌
  3727. ]]
  3728. function ZPRoomView:showTingPaiView(touchcCard)
  3729. if touchcCard then
  3730. local valueList = self.tingCardLocal[touchcCard]
  3731. if valueList then
  3732. --因为需要添加张数显示而增加的背景高度差
  3733. local tingCardOffHeight = 0
  3734. logE("showTingPaiView valueList"..table.tostring(valueList))
  3735. self.ui.Items.Layout_TingCard:removeAllChildren()
  3736. self.ui.Items.Layout_TingCardItem:setVisible(false)
  3737. for i,j in pairs(valueList) do
  3738. local tingCardNum = j.tingCardNum
  3739. local tingCard = j.tingCard
  3740. local tingPaiUI = self.ui.Items.Layout_TingCardItem:getCopied()
  3741. tingPaiUI.Items = getUIItems(tingPaiUI);
  3742. tingPaiUI:setVisible(true)
  3743. self.ui.Items.Layout_TingCard:addChild(tingPaiUI)
  3744. if tingCard then
  3745. local name = ZPFuc.getZPCardImgByValue(tingCard,ZPDef.CardType.CARD_TYPE_TABLE)
  3746. tingPaiUI.Items.ImageView_TingCard:loadTextureFromPlist(name)
  3747. end
  3748. tingPaiUI.Items.Text_TingCardNum:setText(tostring(tingCardNum).."张")
  3749. --听牌剩余多少张,隐藏,但代码保留吧
  3750. if self:setTingCardZhangShuVisible(tingPaiUI.Items.Text_TingCardNum) then
  3751. tingCardOffHeight = 20
  3752. end
  3753. end
  3754. --背景拉伸
  3755. local maxNum = table.nums(valueList)
  3756. if maxNum > 4 then
  3757. local newSizeWidth = maxNum * self.ui.Items.Layout_TingCardItem:getContentSize().width + 43
  3758. local srcHeight = self.tingPaibgSrcHeight + tingCardOffHeight
  3759. self.ui.Items.ImageView_TingPai_bg:setSize(cc.size(newSizeWidth,srcHeight))
  3760. self.ui.Items.Layout_TingCard:setPositionX(newSizeWidth/2)
  3761. else
  3762. local srcWidth = self.ui.Items.ImageView_TingPai_bg:getContentSize().width
  3763. local srcHeight = self.tingPaibgSrcHeight + tingCardOffHeight
  3764. self.ui.Items.ImageView_TingPai_bg:setSize(cc.size(srcWidth,srcHeight))
  3765. end
  3766. self.ui.Items.Layout_TingCard:requestDoLayout()
  3767. self.ui.Items.Layout_TingCard:doLayout()
  3768. self.ui.Items.Layout_TingPai:setVisible(true)
  3769. else
  3770. if not self.isNoCardTingPai then
  3771. self.ui.Items.Layout_TingPai:setVisible(false)
  3772. end
  3773. end
  3774. end
  3775. end
  3776. --[[
  3777. outCard:出的牌
  3778. ]]
  3779. function ZPRoomView:IsTingPaiCard(outCard)
  3780. if outCard then
  3781. local data = self.tingCardLocal[outCard]
  3782. if data then
  3783. --标记只听模式
  3784. self.isNoCardTingPai = true
  3785. else
  3786. self.isNoCardTingPai = false
  3787. end
  3788. self.tingCardLocal = {}
  3789. --倒叙遍历1-10列
  3790. for col = self.lieShuMax,1,-1 do --列数
  3791. for row = self.hangShuMax,1,-1 do --行数
  3792. local card = self.handCardRoot[col].imgList[row]:getChildren()[1]
  3793. if card then
  3794. self.handCardRoot[col].imgList[row]:getChildren()[1]:setVisible(false)
  3795. end
  3796. end
  3797. end
  3798. end
  3799. end
  3800. -- 先操作玩家
  3801. function ZPRoomView:onOperationFirst(data)
  3802. local function runOnOperationFirst(onEnd)
  3803. log("2000000000-ZPRoomView - (runOnOperationFirst)")
  3804. local nUserId = data.response.nUserId
  3805. local viewId = app.room:getViewIdByUserId(nUserId)
  3806. if viewId == self:getMeViewId() then
  3807. --隐藏出牌面板
  3808. self:setOperatorPanelView(false,nil)
  3809. --隐藏吃牌面板
  3810. self.operationView:setEatCardView(false)
  3811. end
  3812. local operations = {}
  3813. operations[viewId] = {}
  3814. operations[viewId].nUserId = nUserId
  3815. operations[viewId].isCanOpereate = 0
  3816. self:showDelayTimeTip(operations)
  3817. if onEnd then
  3818. onEnd()
  3819. end
  3820. end
  3821. log("2000000000-ZPRoomView - addCallBack(runOnOperationFirst)")
  3822. self:addCallBack(runOnOperationFirst)
  3823. end
  3824. -- 操作成功
  3825. function ZPRoomView:onOperationCodeSuccess(data)
  3826. local function runOnOperationSuccess(onEnd)
  3827. log("2000000000-ZPRoomView - (runOnOperationSuccess)")
  3828. logE("ZPRoomView:onOperationCodeSuccess :"..table.tostring(data.response))
  3829. local response = data.response
  3830. local nUserID = response.nUserId
  3831. local card = response.card
  3832. local bIsOutCard = response.isShouldOutCard > 0
  3833. local codeCountList = response.OperationCodeList
  3834. local weaveCardList = response.weaveCardList
  3835. local playerList = response.playerList
  3836. local maxWeave = table.nums(weaveCardList)
  3837. local totalHuShu = response.totalHuShu
  3838. local leftHandCardNum = response.leftHandCardNum
  3839. local isMoPaiOrId = -1
  3840. --app.room.roomInfo.huType = response.huType
  3841. --点炮胡时,表示为点炮用户
  3842. app.room.roomInfo.dianPaoSeatId = response.dianPaoSeatId
  3843. --碰胡规则
  3844. if maxWeave > 0 then
  3845. isMoPaiOrId = weaveCardList[maxWeave].seatId
  3846. end
  3847. --记录操作成功
  3848. self.operationSuccessCode = codeCountList
  3849. self.outCard = card
  3850. --视图ID
  3851. local viewId = app.room:getViewIdByUserId(nUserID)
  3852. self.tableHuXiList[viewId] = totalHuShu
  3853. self.PlayerView:setPlayerHuXi(viewId,totalHuShu)
  3854. self.PlayerView:setLeftCardNum(viewId,true,leftHandCardNum)
  3855. --self.PlayerView:setNoOpTime(false,viewId)
  3856. if bIsOutCard then
  3857. for k,v in pairs(app.room.roomInfo.memberList) do
  3858. local operations = {}
  3859. operations[viewId] = {}
  3860. operations[viewId].nUserId = v.nUserId
  3861. operations[viewId].isCanOpereate = 0
  3862. self:showDelayTimeTip(operations)
  3863. end
  3864. end
  3865. local operations = {}
  3866. operations[viewId] = {}
  3867. operations[viewId].nUserId = nUserID
  3868. operations[viewId].isCanOpereate = bIsOutCard and 1 or 0
  3869. self:showDelayTimeTip(operations)
  3870. --隐藏handTemp
  3871. if viewId == self:getMeViewId() then
  3872. self.isGodHand = true
  3873. --出牌动画 setGuideView延迟了0.5
  3874. self:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
  3875. self:setColorWhite()
  3876. if #codeCountList == 1 and codeCountList[1].nOperationCode == 0 then--点击过的时候设置可以点牌
  3877. self.isGodHand = false
  3878. end
  3879. end)))
  3880. self.ui.Items.ImageView_handTempCard:setVisible(false)
  3881. end
  3882. --显示指示器
  3883. if bIsOutCard and codeCountList[1].nOperationCode ~= 0 then
  3884. self:setCircleCardLeftPanelView(true,viewId,self.leftNum)
  3885. end
  3886. --隐藏操作层
  3887. self:setOperatorPanelView(false,nil)
  3888. --判断自己是否需要出牌
  3889. if bIsOutCard and viewId == self:getMeViewId()
  3890. and codeCountList[1].nOperationCode ~= 0
  3891. and codeCountList[1].nOperationCode ~= ZPDef.OpCode.OP_HU then
  3892. self:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
  3893. self:setGuideView(true)
  3894. end)))
  3895. self.bOutCard = true
  3896. end
  3897. if self.isTianHu and viewId == self:getMeViewId() then
  3898. self.isTianHu = false
  3899. self:setGuideView(true)
  3900. self.bOutCard = true
  3901. end
  3902. --隐藏吃牌层
  3903. self.operationView:setEatCardView(false)
  3904. --执行操作
  3905. local code = codeCountList[1].nOperationCode
  3906. logE("ZPRoomView:onOperationCodeSuccess nOperationCode:"..code)
  3907. local operations = ZPFuc.getZPOperationType(code,false,self.playerZhao[viewId] > 0)
  3908. local operationType = operations[1]
  3909. --体验:等待0.5秒结束
  3910. if operationType == ZPDef.OpType.OP_TYPE_MINGWEI
  3911. or operationType == ZPDef.OpType.OP_TYPE_ANWEI
  3912. or operationType == ZPDef.OpType.OP_TYPE_PAO
  3913. or operationType == ZPDef.OpType.OP_TYPE_CHONG_PAO
  3914. or operationType == ZPDef.OpType.OP_TYPE_TI
  3915. or operationType == ZPDef.OpType.OP_TYPE_PENG then
  3916. --明偎,暗偎,跑,重跑,提牌
  3917. self:runAction(cc.Sequence:create(cc.DelayTime:create(self.gameSpeedConfig.CAO_ZUO_PAI_TIME),cc.CallFunc:create(function ()
  3918. --隐藏出牌层
  3919. self:setOutCardVisible(false)
  3920. self:doOperation(operationType,viewId,card,isMoPaiOrId,onEnd)
  3921. --检查是否少牌
  3922. self:checkCardsByUidAndLeftCardNum(nUserID,leftHandCardNum)
  3923. if codeCountList[1].nOperationCode ~= 0 then
  3924. self:runAction(cc.Sequence:create(cc.DelayTime:create(0.3),cc.CallFunc:create(function ()
  3925. self:setLayoutScoreTipVisible(true,playerList)
  3926. end)))
  3927. end
  3928. end)))
  3929. elseif operationType ~= ZPDef.OpType.OP_TYPE_HU and operationType ~= ZPDef.OpType.OP_TYPE_CANCEL and operationType ~= nil then
  3930. --吃碰操作
  3931. --隐藏出牌层
  3932. self:setOutCardVisible(false)
  3933. self:doOperation(operationType,viewId,card,isMoPaiOrId,onEnd)
  3934. --检查是否少牌
  3935. --self:checkCardsByUidAndLeftCardNum(nUserID,leftHandCardNum)
  3936. elseif operationType == ZPDef.OpType.OP_TYPE_HU then
  3937. --胡牌操作
  3938. --1.隐藏引导出牌动画2.显示胡了哪张牌,3.播放胡牌特效
  3939. self:setGuideView(false)
  3940. local imgName = string.format("ImageView_outCardImg_%d",self.moPaiViewId)
  3941. local mSprite = self.ui.Items[imgName]
  3942. if self.outCard ~= 0 then
  3943. local fileName = ZPFuc.getZPCardImgByValue(self.outCard,ZPDef.CardType.CARD_TYPE_OUTCARD)
  3944. mSprite:loadTextureFromPlist(fileName)
  3945. end
  3946. if codeCountList[1].nOperationCode ~= 0 then
  3947. self:runAction(cc.Sequence:create(cc.DelayTime:create(0),cc.CallFunc:create(function ()
  3948. self:setLayoutScoreTipVisible(true,playerList,false,onEnd,true)
  3949. app.room.roomInfo.winUserId = nUserID
  3950. --self:playHuEffect(viewId,onEnd)
  3951. if self.leftNum and not self.isTianHu and card ~= 0 and app.room.roomInfo.dianPaoSeatId == -1 and viewId == self.moPaiViewId then
  3952. self:playMoPaiAni(self.leftNum,card,viewId,0,1,nil,true)
  3953. end
  3954. if onEnd then
  3955. onEnd()
  3956. end
  3957. --点炮显示
  3958. --[[if app.room.roomInfo.dianPaoSeatId >= 0 then
  3959. local dianPaoViewId = app.room:getViewIdBySeatId(app.room.roomInfo.dianPaoSeatId)
  3960. local name = string.format("ImageView_outCardLight_%d",dianPaoViewId)
  3961. local img = self.ui.Items[name]
  3962. local size = img:getContentSize()
  3963. --点炮精灵
  3964. local mSprite = cc.ImageView:createNode()
  3965. mSprite:loadTextureFromPlist("zipai_room_pao.png")
  3966. img:addChild(mSprite)
  3967. mSprite:setPosition(cc.p(size.width/2,size.height/2))
  3968. if dianPaoViewId == 2 or dianPaoViewId == 4 then
  3969. --旋转为正常
  3970. mSprite:setEulerRotation(cc.vec3(0,0,-90))
  3971. end
  3972. end--]]
  3973. end)))
  3974. end
  3975. else
  3976. --self:showOperatorTip(viewId,ZPDef.OpType.OP_TYPE_CANCEL)
  3977. --过
  3978. self:doOperation(ZPDef.OpType.OP_TYPE_CANCEL,viewId,card,isMoPaiOrId,nil)
  3979. if onEnd then
  3980. onEnd()
  3981. end
  3982. --检查是否少牌
  3983. self:checkCardsByUidAndLeftCardNum(nUserID,leftHandCardNum)
  3984. end
  3985. end
  3986. log("2000000000-ZPRoomView - addCallBack(runOnOperationSuccess)")
  3987. self:addCallBack(runOnOperationSuccess)
  3988. end
  3989. --检测是否少牌
  3990. function ZPRoomView:checkCardsByUidAndLeftCardNum(nUserID,leftHandCardNum)
  3991. if nUserID == app.user.loginInfo.uid then
  3992. local a = leftHandCardNum
  3993. local b = self:getBakCardsNum()
  3994. if leftHandCardNum and leftHandCardNum > 0 and self:getBakCardsNum() ~= leftHandCardNum then
  3995. self.ui:sendMsg(app.room, "callGetHandcardsRequest");
  3996. end
  3997. end
  3998. end
  3999. --点炮显示
  4000. function ZPRoomView:showPaoImage()
  4001. if app.room.roomInfo.dianPaoUserId and app.room.roomInfo.dianPaoUserId >= 0 then
  4002. local dianPaoViewId = app.room:getViewIdByUserId(app.room.roomInfo.dianPaoUserId)
  4003. local name = string.format("ImageView_outCardLight_%d",dianPaoViewId)
  4004. local img = self.ui.Items[name]
  4005. local size = img:getContentSize()
  4006. --点炮精灵
  4007. local mSprite = cc.ImageView:createNode()
  4008. mSprite:loadTextureFromPlist("zp_room_chapai_dianpao.png")
  4009. img:addChild(mSprite)
  4010. mSprite:setPosition(cc.p(size.width/2,size.height/2))
  4011. if dianPaoViewId == 1 or dianPaoViewId == 3 then
  4012. mSprite:setPositionY(35)
  4013. end
  4014. end
  4015. end
  4016. --胡牌特效
  4017. function ZPRoomView:playHuEffect(viewId,onEnd,isRecontect)
  4018. --[[ --黄庄了直接return
  4019. if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
  4020. return
  4021. end--]]
  4022. local nUserID = app.room:getUserIdByViewId(viewId)
  4023. if (app.room.roomInfo.huType and app.room.roomInfo.huType >= 0) and (not (app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG)) then
  4024. local userInfo=app.room:getUserInfo(nUserID)
  4025. if userInfo then
  4026. if ZPFuc.isZiMo(app.room.roomInfo.huType) then
  4027. ZPSound.PlayOperateSound(userInfo.sex,11)
  4028. else
  4029. ZPSound.PlayOperateSound(userInfo.sex,4)
  4030. end
  4031. end
  4032. end
  4033. local name = string.format("Layout_outCardPoint_%d",viewId)
  4034. local mLayout = self.ui.Items[name]
  4035. local huEffectUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_effectHu.ui")
  4036. local pos = mLayout:getPosition()
  4037. if viewId == self:getMeViewId() then
  4038. local centerPos = cc.Director:getInstance():getVisibleSize()
  4039. local pos = cc.p(centerPos.width/2,centerPos.height/2 - 70)
  4040. huEffectUI:setPosition(pos)
  4041. elseif viewId == 1 then
  4042. huEffectUI:setPosition(cc.pAdd(pos,cc.p(90,-30)))
  4043. elseif viewId == 2 then
  4044. huEffectUI:setPosition(cc.pAdd(pos,cc.p(0,20)))
  4045. elseif viewId == 3 then
  4046. huEffectUI:setPosition(cc.pAdd(pos,cc.p(-70,-30)))
  4047. end
  4048. self.ui.Items.Layout_Player_HuEffect:addChild(huEffectUI,2)
  4049. --动画展现
  4050. if app.room.roomInfo.huType and app.room.roomInfo.huType >= 0 then
  4051. local name = ""
  4052. local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
  4053. local nWinerId = app.room.roomInfo.winUserId
  4054. local winerViewId = app.room:getViewIdByUserId(nWinerId)
  4055. if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then--app.room.roomInfo.huType == 0 and
  4056. name = "zp_room_chapai_jiao.png"--显示叫(表示听牌了)
  4057. elseif ZPFuc.isZiMo(app.room.roomInfo.huType) then
  4058. name = "zp_room_chapai_zimo.png"
  4059. else
  4060. name = "zp_room_chapai_hu.png"--string.format(ZPDef.TipFile.HU,app.room.roomInfo.huType)
  4061. end
  4062. huEffectUI.Items.ImageView_huType:loadTextureFromPlist(name)
  4063. end
  4064. isRecontect = true--不显示动画
  4065. if isRecontect then
  4066. huEffectUI.Items.ImageView_Light:setVisible(false)
  4067. huEffectUI.Items.ImageView_Point:setVisible(false)
  4068. huEffectUI.Items.ImageView_Coin:setVisible(false)
  4069. self:showPaoImage()
  4070. self:runAction(cc.Sequence:create(cc.DelayTime:create(0.8),cc.CallFunc:create(function ()
  4071. if onEnd then
  4072. onEnd()
  4073. end
  4074. end)))
  4075. return
  4076. end
  4077. local mSpawn1 = cc.Spawn:create(cc.ScaleTo:create(0.3,1.0),cc.RotateBy:create(2,-120*6))
  4078. huEffectUI.Items.ImageView_Point:runAction(mSpawn1)
  4079. local mSpawn2 = cc.Spawn:create(cc.ScaleTo:create(0.3,1.0),cc.RotateBy:create(2,120*6))
  4080. huEffectUI.Items.ImageView_Light:runAction(mSpawn2)
  4081. huEffectUI.Items.ImageView_Coin:setScale(0)
  4082. local mSeq1 = cc.Sequence:create(cc.ScaleTo:create(0.3,1))
  4083. huEffectUI.Items.ImageView_Coin:runAction(mSeq1)
  4084. huEffectUI.Items.ImageView_huType:setScale(2)
  4085. huEffectUI.Items.ImageView_huType:setOpacity(0)
  4086. local mSeq2 = cc.Sequence:create(cc.DelayTime:create(0.6),cc.FadeIn:create(0),cc.ScaleTo:create(0.2,1.0))
  4087. huEffectUI.Items.ImageView_huType:runAction(mSeq2)
  4088. huEffectUI:runAction(cc.Sequence:create(cc.DelayTime:create(2.2),cc.CallFunc:create(function ()
  4089. huEffectUI.Items.ImageView_Light:setVisible(false)
  4090. huEffectUI.Items.ImageView_Point:setVisible(false)
  4091. huEffectUI.Items.ImageView_Coin:setVisible(false)
  4092. self:showPaoImage()
  4093. if onEnd then
  4094. onEnd()
  4095. end
  4096. end)))
  4097. end
  4098. function ZPRoomView:addCallBack(callback)
  4099. table.insert(self.callbackQueue, callback)
  4100. logE(" #self.callbackQueue:".. #self.callbackQueue)
  4101. --高延迟情况下,执行快速播放,15条是没有标准,根据实际调整的
  4102. --if #self.callbackQueue >= 15 then
  4103. --cc.Director:getInstance():getScheduler():setTimeScale(5.0)
  4104. --else
  4105. cc.Director:getInstance():getScheduler():setTimeScale(1.0)
  4106. --end
  4107. local function runFunc()
  4108. log("2000000000 - runNextFunc() size = ", #self.callbackQueue )
  4109. if #self.callbackQueue <= 0 then
  4110. self.callbackRunning = false
  4111. return
  4112. end
  4113. --logE("2000000001 - ", debug.traceback())
  4114. local func = self.callbackQueue[1]
  4115. table.remove(self.callbackQueue,1)
  4116. self.callbackRunning = true
  4117. func(function ()
  4118. self.callbackRunning = false;
  4119. runFunc();
  4120. end)
  4121. end
  4122. log("self.callbackRunning:",self.callbackRunning)
  4123. if not self.callbackRunning then
  4124. runFunc();
  4125. end
  4126. end
  4127. -- 其他玩家坐下成功
  4128. function ZPRoomView:onOtherSitDownResponse(data)
  4129. if not data or not data.nSeatShowId then
  4130. return
  4131. end
  4132. --local nSeatShowId = data.nSeatShowId;
  4133. --local nUserId = app.room:getUserIdByViewId(nSeatShowId)
  4134. --self:checkGpsDistance(nUserId,true);
  4135. self:onUserReadyResponse()
  4136. -- 是否显示邀请好友
  4137. self:setWetChatVisible(app.room:getActualPlayerNum() < ZPFuc.getCreateRoomPlayerNum())
  4138. if isReviewVersion() then
  4139. self:setWetChatVisible(false);
  4140. end
  4141. if app.room.roomInfo.nGameStartCount > 0 then
  4142. self:setWetChatVisible(false)
  4143. end
  4144. self.toolView:showFastStart(true)
  4145. if not tolua.isnull(self.quickStartView) then
  4146. self.quickStartView:removeView()
  4147. self.quickStartView = nil
  4148. end
  4149. end
  4150. function ZPRoomView:onOtherLogoutResponse(data)
  4151. local jushu = app.room.roomInfo.nGameStartCount or 0
  4152. if (not data or not data.nUserId or not data.nSeatShowId) or jushu > 0 then
  4153. return
  4154. end
  4155. local function test(onEnd)
  4156. local memberList = app.room.roomInfo.memberList
  4157. memberList[data.nUserId] = nil
  4158. app.room:updateUserSeateShowId()
  4159. self:onUserReadyResponse()
  4160. --更新GPS
  4161. --self:updateAllGpsInfo()
  4162. --self:checkGpsDistance()
  4163. -- 是否显示邀请好友
  4164. self:setWetChatVisible(app.room:getActualPlayerNum() < ZPFuc.getCreateRoomPlayerNum())
  4165. if isReviewVersion() then
  4166. self:setWetChatVisible(false);
  4167. end
  4168. if app.room.roomInfo.nGameStartCount > 0 then
  4169. self:setWetChatVisible(false)
  4170. end
  4171. self.toolView:updateButtonPosition()
  4172. self.toolView:showFastStart(true)
  4173. if not tolua.isnull(self.quickStartView) then
  4174. self.quickStartView:removeView()
  4175. self.quickStartView = nil
  4176. end
  4177. logE("88888-onOtherLogoutResponse onEnd")
  4178. if onEnd then
  4179. onEnd()
  4180. end
  4181. end
  4182. self:addCallBack(test)
  4183. end
  4184. function ZPRoomView:updateGameNums()
  4185. -- 更新当前局数
  4186. local roomInfo = app.room.roomInfo
  4187. local curCount = roomInfo.nGameStartCount or 0
  4188. local str = string.format("%02d/%02d局", curCount, roomInfo.nTotalGameNum)
  4189. self.ui.Items.Text_JuShu:setText(str);
  4190. end
  4191. -- 游戏开始
  4192. function ZPRoomView:onGameStartResponse()
  4193. local function runGameStartResponse(onEnd)
  4194. log("2000000000-ZPRoomView - runGameStartResponse()" )
  4195. --重置玩家数据
  4196. self:resetGameData()
  4197. app.room.roomInfo.tingCards = {}
  4198. --标志一局结束
  4199. app.room.roomInfo.nStatus = ZPDef.ReconnectState.GAME_STATUS_INIT
  4200. --写入数据
  4201. for k,v in pairs(app.room.roomInfo.memberList) do
  4202. v.nPlayerFlag = 2
  4203. end
  4204. --更新玩家状态状态
  4205. self:onUserReadyResponse()
  4206. -- 隐藏邀请好友
  4207. self:setWetChatVisible(false)
  4208. self.toolView:showFastStart(false)
  4209. -- 更新局数
  4210. self:updateGameNums()
  4211. --更新位置
  4212. if app.room.roomInfo.xiaoSeatId and app.room.roomInfo.xiaoSeatId >= 0 and app.room:getActualPlayerNum()==4 then
  4213. app.room:updateUserSeateShowId(app.room.roomInfo.xiaoSeatId)
  4214. self.PlayerView:setXiaoJiaFlagVis(true)
  4215. else
  4216. app.room:updateTableView(true)
  4217. end
  4218. self.PlayerView:setPlayerVisible(false)
  4219. for k,v in pairs(app.room.roomInfo.memberList) do
  4220. local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
  4221. self.PlayerView:updatePlayerInfo(nSeatShowId)
  4222. end
  4223. --更新庄家
  4224. self:updateBanker()
  4225. if onEnd then
  4226. onEnd()
  4227. end
  4228. end
  4229. log("2000000000-ZPRoomView - addCallBack(runGameStartResponse)" )
  4230. self:addCallBack(runGameStartResponse);
  4231. end
  4232. function ZPRoomView:setLiangPaiVisible(bVisible)
  4233. if not tolua.isnull(self.xiaojuChaPaiView) then
  4234. self.xiaojuChaPaiView:setVisible(bVisible)
  4235. end
  4236. end
  4237. -- 小局结算
  4238. function ZPRoomView:onGameXiaoJuResponse(data)
  4239. local function runGameXiaoJuResponse(onEnd)
  4240. self.ui.Items.Button_tipai:setVisible(false)
  4241. self.PlayerView:stopAndHideBaoAnim()
  4242. self.PlayerView:hideLeftCard()
  4243. --显示所有底牌
  4244. local response = data.response;
  4245. --标记单局结束
  4246. self.isGameOver = true
  4247. --禁止出牌
  4248. self.bOutCard = false
  4249. local roomInfo = app.room.roomInfo
  4250. --结束原因
  4251. roomInfo.stopFlag = response.stopFlag
  4252. --是否是解散结束的
  4253. app.room.roomInfo.nShowDismiss = (roomInfo.stopFlag == 8 or roomInfo.stopFlag == 9)
  4254. --赢家uid, -1则下面6个字段是无用
  4255. roomInfo.winUserId = response.winUserId
  4256. --点炮胡时,表示为点炮用户
  4257. roomInfo.dianPaoUserId = response.dianPaoUserId
  4258. --胡的类型(如天胡、地胡 ,自摸胡等)
  4259. roomInfo.huType = response.huTypes
  4260. --多少个玩家
  4261. roomInfo.playList = response.playList
  4262. --底牌信息
  4263. roomInfo.dipaiList = response.dipaiList
  4264. --胡牌牌值
  4265. roomInfo.huCard = response.huCard
  4266. --是否大局结束,结束是1
  4267. roomInfo.isGameOver = response.isGameOver
  4268. --胡牌信息
  4269. roomInfo.hupaiInfo = response.hupaiInfo or {}
  4270. local function showChaPai()
  4271. self:setLiangPaiVisible(true)
  4272. end
  4273. for i,v in pairs(roomInfo.hupaiInfo) do
  4274. local viewId = app.room:getViewIdByUserId(v.huPaiUid)
  4275. roomInfo.dianPaoUserId = v.dianPaoUid
  4276. roomInfo.huCard = v.huCard
  4277. self.PlayerView:setPlayerHuXi(v.huPaiHuShu)
  4278. roomInfo.huType = v.huTypes
  4279. self:playHuEffect(viewId,showChaPai)
  4280. end
  4281. --所有的暗偎默认亮起一张
  4282. self:showLastAnWeiPai()
  4283. --完成底牌展示
  4284. self.xiaojuChaPaiView:showDiPai()
  4285. --如果大局结算了
  4286. if roomInfo.isGameOver == 1 then
  4287. showChaPai()
  4288. end
  4289. --完成手牌展示
  4290. for k,v in pairs(roomInfo.playList) do
  4291. local cardData = app.room:serverCardToMyCard(v.handCard)
  4292. if not roomInfo.memberList[v.nUserId] then
  4293. roomInfo.memberList[v.nUserId] = {}
  4294. end
  4295. roomInfo.memberList[v.nUserId].cardList = {}
  4296. roomInfo.memberList[v.nUserId].cardList = cardData
  4297. local viewId = app.room:getViewIdByUserId(k)
  4298. roomInfo.memberList[v.nUserId].weaveCardNum = self:getWeaveCardsNum(viewId)
  4299. --[[logE("XiaoJu nUserID:"..v.nUserId)
  4300. logE("XiaoJu cardList:"..table.tostring(cardData))--]]
  4301. end
  4302. self.xiaojuChaPaiView:liangShouPai(false)
  4303. --玩家分数
  4304. for k,v in pairs(roomInfo.playList) do
  4305. local viewId = app.room:getViewIdByUserId(k)
  4306. local nScore = v.nTotalMoney
  4307. local memberInfo = app.room.roomInfo.memberList[k]
  4308. --[[roomInfo.memberList[v.nUserId].nPlayerFlag = 0--]]
  4309. memberInfo.nTotalMoney = nScore
  4310. self.PlayerView:setPlayerScore(viewId,nScore)
  4311. end
  4312. --结束原因表现
  4313. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
  4314. showChaPai()
  4315. --播放黄庄动画
  4316. self.xiaojuChaPaiView:PlayHuangZhuangAni(true)
  4317. elseif roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_LONG_NOT_END then
  4318. logD("游戏长久未打完,超过房间存在时间,本局结束")
  4319. -- showConfirmDialog("游戏长久未打完,超过房间存在时间,本局结束",function()
  4320. -- logE("超时回到大厅")
  4321. -- self:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
  4322. -- --房间号
  4323. -- local roomid = app.room.roomInfo.nShowTableId
  4324. -- --app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId, roomid))
  4325. -- gotoMainView(app.gameId,roomid)
  4326. -- end)))
  4327. -- end,nil)
  4328. end
  4329. local function nextCallBackFun()
  4330. self:resetGameData()
  4331. app.room.roomInfo.tingCards = {}
  4332. end
  4333. local function showAllJieSuan()
  4334. if self.RoomCountAllViewUI then
  4335. if not self.RoomCountAllViewUI:isVisible() then
  4336. self.RoomCountAllViewUI:playAni()
  4337. end
  4338. self.RoomCountAllViewUI:setVisible(true)
  4339. self:showGameOverAward()
  4340. end
  4341. end
  4342. if not tolua.isnull(self.xiaojuView) then
  4343. self.xiaojuView:removeFromParent()
  4344. self.xiaojuView = nil
  4345. end
  4346. if app.room.roomInfo.isGameOver == 0 then
  4347. self.xiaojuView = ZPRoomXiaoJuView:new(nextCallBackFun)
  4348. else
  4349. self.xiaojuView = ZPRoomXiaoJuView:new(showAllJieSuan)
  4350. end
  4351. self:addChild(self.xiaojuView)
  4352. self.xiaojuView:setVisible(false)
  4353. --结束
  4354. if onEnd then
  4355. onEnd()
  4356. end
  4357. end
  4358. log("2000000000-ZPRoomView - addCallBack(runGameXiaoJuResponse)" )
  4359. self:addCallBack(runGameXiaoJuResponse);
  4360. end
  4361. --显示暗偎的最后一个牌
  4362. function ZPRoomView:showLastAnWeiPai()
  4363. for i = 1 ,ZPDef.GameMaxPlayer do
  4364. local name = string.format("Layout_player1Table_%d",i)
  4365. local UnitCardNode = self.ui.Items[name]
  4366. for k,chlidLayout in pairs(UnitCardNode:getChildren()) do
  4367. if chlidLayout.type == "anwei" then
  4368. local node = chlidLayout:getChildren()[1]
  4369. local card = chlidLayout.cardList[1]
  4370. node:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
  4371. end
  4372. end
  4373. end
  4374. end
  4375. -- 大局结算
  4376. function ZPRoomView:onGameDaJuResponse(data)
  4377. local function runGameDaJuResponse(onEnd)
  4378. local response = data.response.playList
  4379. -- 打开结算
  4380. local view = ZPRoomCountAllView:new(response,data.response.endTime);
  4381. view:setAnchorPoint(cc.p(0.5, 0.5));
  4382. local visibleSize = getVisibleSize()
  4383. view:setPosition(cc.p(visibleSize.width/2,visibleSize.height/2))
  4384. self:addChild(view);
  4385. self.RoomCountAllViewUI = view;
  4386. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
  4387. if true then--app.room.roomInfo.nGameStartCount == app.room.roomInfo.nTotalGameNum and not app.room.roomInfo.nShowDismiss
  4388. log("2000000000-onGameDaJuResponse --------- zhengchangjiesu ")
  4389. view:setVisible(false);
  4390. else
  4391. log("2000000000-onGameDaJuResponse --------- yichangjiesu ")
  4392. --结算直接播放动画
  4393. view:playAni()
  4394. self:showGameOverAward()
  4395. end
  4396. if onEnd then
  4397. onEnd()
  4398. end
  4399. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  4400. end
  4401. log("2000000000-ZPRoomView - addCallBack(runGameDaJuResponse)")
  4402. self:showTuoGuan(false)--大结算隐藏托管界面
  4403. self:addCallBack(runGameDaJuResponse);
  4404. end
  4405. function ZPRoomView:onUserReadyResponse()
  4406. self.PlayerView:setPlayerVisible(false)
  4407. local uids = {}
  4408. for k,v in pairs(app.room.roomInfo.memberList) do
  4409. local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
  4410. self.PlayerView:setPlayerReadyState(nSeatShowId,(v.nPlayerFlag == 1))
  4411. self.PlayerView:updatePlayerInfo(nSeatShowId)
  4412. if v.nUserId and v.nUserId > 0 then
  4413. uids[v.nUserId] = true
  4414. end
  4415. end
  4416. local nUserId = app.user.loginInfo.uid
  4417. local memberInfo = app.room.roomInfo.memberList[nUserId]
  4418. if app.room.roomInfo.nGameStartCount > 0 then
  4419. self:setBtnSitDownVisible(false)
  4420. else
  4421. self:setBtnSitDownVisible(memberInfo.nPlayerFlag == 0)
  4422. end
  4423. --邀请按钮
  4424. if not self.toolView.ui.Items.Button_Ready:isVisible() then
  4425. self.toolView:updateButtonPosition()
  4426. end
  4427. if not tolua.isnull(self.roomMenuView) then
  4428. if app.room.roomInfo.nGameStartCount > 0 then
  4429. self.roomMenuView:setButtonEnabled("Leave", false)
  4430. end
  4431. if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= app.user.loginInfo.uid then
  4432. self.roomMenuView:setButtonEnabled("Dismiss", false)
  4433. else
  4434. self.roomMenuView:setButtonEnabled("Dismiss", true)
  4435. end
  4436. self.roomMenuView:checkCanDismiss()
  4437. end
  4438. end
  4439. -- 玩家收到解散房间的请求
  4440. function ZPRoomView:onDismissResponse(event)
  4441. if not event or not event.response then
  4442. return
  4443. end
  4444. logD("onDismissResponse() response = ", table.tostring(event.response))
  4445. local response = event.response
  4446. --当前时间
  4447. app.room.roomInfo.nDismissStateTime = response.timeLeft
  4448. --总的时间
  4449. app.room.roomInfo.nDismissToTalTime = response.timeLeft --服务器没发解散总时间来。那么就和一开始收到的解散剩余时间一致
  4450. --显示解散(此标志会影响闹钟时间会冻住)
  4451. app.room.roomInfo.nShowDismiss = true
  4452. if response.operateType == 1 then
  4453. if response.memberList ~= nil then
  4454. for k,v in pairs(response.memberList) do
  4455. if v.dismissState == 1 then
  4456. local view = require("luaScript.Views.Room.RoomDismissView"):new(v.nUserId,app.room.roomInfo.memberList,response.timeLeft)
  4457. view:setAnchorPoint(cc.p(0.5, 0.5));
  4458. app:showWaitDialog(view);
  4459. return
  4460. end
  4461. end
  4462. else
  4463. local view = require("luaScript.Views.Room.RoomDismissView"):new(response.nUserId,app.room.roomInfo.memberList,response.timeLeft)
  4464. view:setAnchorPoint(cc.p(0.5, 0.5));
  4465. app:showWaitDialog(view);
  4466. end
  4467. else
  4468. local memberStatus={}
  4469. if response.memberList ~= nil then
  4470. for k,v in pairs(response.memberList) do
  4471. table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
  4472. end
  4473. else
  4474. table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
  4475. end
  4476. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus});
  4477. end
  4478. end
  4479. --更新庄家
  4480. function ZPRoomView:updateBanker()
  4481. --隐藏所有的庄家标志
  4482. self.PlayerView:setBankerVisible()
  4483. --只显示当前的庄家座位号
  4484. local nBankerSeatId = app.room.roomInfo.nBankSeatId
  4485. local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
  4486. if self.PlayerView:setPlayerBankerVisible(viewId,true) then
  4487. else
  4488. showTooltip("庄家椅子号"..nBankerSeatId.."不匹配")
  4489. end
  4490. end
  4491. --显示房主
  4492. function ZPRoomView:showOwner()
  4493. self.PlayerView:setOwnerVisible()
  4494. --只显示当前的庄家座位号
  4495. local nBankerSeatId = app.room.roomInfo.nRoomOwnedUid
  4496. local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
  4497. self.PlayerView:setPlayerBankerVisible(viewId,true)
  4498. end
  4499. function ZPRoomView:onOtherDroppedResponse(data)
  4500. if not data.response.nUserId then
  4501. return
  4502. end
  4503. local nUserId = data.response.nUserId
  4504. local nDroppedStatus = data.response.nDroppedStatus
  4505. local memberInfo = app.room.roomInfo.memberList[nUserId]
  4506. if memberInfo then
  4507. memberInfo.nOnlineStatus = nDroppedStatus == 1 and 0 or 1
  4508. end
  4509. local viewId = app.room:getViewIdByUserId(nUserId)
  4510. app.room.offLineUid[tonumber(nUserId)] = (nDroppedStatus == 1)
  4511. if nDroppedStatus == 0 then--如果上线了 离线时间置0
  4512. app.room.offLineTime[tonumber(nUserId)] = 0
  4513. self.PlayerView:reSetClockTime(viewId)
  4514. end
  4515. self.PlayerView:setPlayerOffLine(nDroppedStatus == 1,viewId)
  4516. end
  4517. function ZPRoomView:onUserExitResponseRoom(data)
  4518. local function runUserExitResponseRoom(onEnd)
  4519. log("2000000000-ZPRoomView - runUserExitResponseRoom()" )
  4520. local response = data.response
  4521. --房间号
  4522. local roomid = app.room.roomInfo.nShowTableId
  4523. -- 0: 不退出, 1: 退出
  4524. if response.logoutFlag == 1 then
  4525. --app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId, roomid));
  4526. gotoMainView(app.gameId,roomid)
  4527. end
  4528. app.room:dispatchEvent({name = "onUserExitResponseHall"});
  4529. logE("88888-onUserExitResponseRoom onEnd")
  4530. if onEnd then
  4531. onEnd()
  4532. end
  4533. end
  4534. log("2000000000-ZPRoomView - addCallBack(runUserExitResponseRoom)" )
  4535. self:addCallBack(runUserExitResponseRoom);
  4536. end
  4537. -- 服务器广播玩家数据发生变化
  4538. function ZPRoomView:onGpsChangeResponse(data)
  4539. logD("ZPRoomView:onGpsChangeResponse()")
  4540. if not data or not data.nUserId then
  4541. return
  4542. end
  4543. local roomInfo = app.room.roomInfo
  4544. local nUserId = data.nUserId
  4545. logD("ZPRoomView:onGpsChangeResponse()", tostring(nUserId))
  4546. self:checkGpsDistance(nUserId,roomInfo.nGameStartCount==0)
  4547. end
  4548. function ZPRoomView:initGpsComponent()
  4549. if self.isRecordScene then return end--回放场景直接return
  4550. local versionCode = getAppVersionCode()
  4551. versionCode = tonumber(versionCode) or 0
  4552. logD("ZPRoomView:initGpsComponent() versionCode = ", versionCode)
  4553. logD("ZPRoomView:initGpsComponent() isReviewVersion = ", isReviewVersion()==true and 1 or 0)
  4554. if isReviewVersion() or cc.Application:getInstance():getTargetPlatform() == 0 then
  4555. self.ui.Items.Button_GPS:setVisible(false)
  4556. return
  4557. end
  4558. -- 创建 gps 组件
  4559. --self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponent"):new(self.ui.Items.Button_GPS)
  4560. local function exitRoomCallback()
  4561. local isGameStart = app.room.roomInfo.nGameStartCount > 0
  4562. if isGameStart then
  4563. app.room:requestDismissRoom(1)
  4564. else
  4565. self.ui:sendMsg(app.room, "callLeaveRequest");
  4566. end
  4567. end
  4568. local function dismissCallback()
  4569. app.room:requestDismissRoom(1)
  4570. end
  4571. self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(4,self.ui.Items.Button_GPS,exitRoomCallback,exitRoomCallback)
  4572. self:addChild(self.gpsComponent)
  4573. -- GPS 按钮
  4574. self.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView))
  4575. -- 我的GPS数据发生变化时检测是否需要通知服务器
  4576. --self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate))
  4577. --self.isInitCheckGps = false
  4578. -- 进入时检测一遍我的GPS数据是否需要更新
  4579. --self:checkMyGpsNeedUpdate()
  4580. end
  4581. -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新
  4582. --[[function ZPRoomView:checkMyGpsNeedUpdate(event)
  4583. if self.isRecordScene then return end--回放场景直接return
  4584. logD("ZPRoomView:checkMyGpsNeedUpdate()")
  4585. if self.isInitCheckGps and not event then
  4586. return
  4587. end
  4588. self.isInitCheckGps = true
  4589. local nMyUserId = app.user.loginInfo.uid
  4590. local myMemberInfo = app.room.roomInfo.memberList[nMyUserId]
  4591. if myMemberInfo then
  4592. local userInfo = json.decode(myMemberInfo.userInfo)
  4593. if userInfo then
  4594. local gpsInfo = userInfo.gpsInfo
  4595. local isNewest = app.user:isGpsInfoNewest(gpsInfo)
  4596. logD("ZPRoomView:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest))
  4597. if not isNewest then
  4598. app.room:onGpsChangeRequest();
  4599. else
  4600. logD("ZPRoomView:checkMyGpsNeedUpdate() gpsInfo is newest")
  4601. end
  4602. else
  4603. logD("ZPRoomView:checkMyGpsNeedUpdate() userInfo is nil")
  4604. end
  4605. else
  4606. logD("ZPRoomView:checkMyGpsNeedUpdate() myMemberInfo is nil")
  4607. end
  4608. end--]]
  4609. -- 更新所有玩家的信息到GPS组件
  4610. function ZPRoomView:updateAllGpsInfo()
  4611. if self.isRecordScene then return end--回放场景直接return
  4612. local userInfoList = {}
  4613. for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do
  4614. local nSeatId = memberInfo.nSeatId
  4615. local userInfo = memberInfo.userInfo
  4616. if userInfo then
  4617. local userInfo2 = json.decode(userInfo)
  4618. if userInfo2 then
  4619. userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
  4620. end
  4621. end
  4622. end
  4623. if self.gpsComponent then
  4624. self.gpsComponent:updateUserInfos(userInfoList)
  4625. end
  4626. end
  4627. -- 检测玩家与其他玩家之间的距离
  4628. -- 如果不传参数,则检测所有玩家相互之间的距离
  4629. --[[function ZPRoomView:checkGpsDistance(curUserId,isOpenGpsView)
  4630. if self.isRecordScene then return end--回放场景直接return
  4631. self:updateAllGpsInfo()
  4632. if self.gpsComponent then
  4633. local isDanger = self.gpsComponent:checkGpsDistance(curUserId)
  4634. if isDanger and isOpenGpsView then
  4635. self:showGpsView()
  4636. showTooltip("玩家距离过近或者未开启GPS!")
  4637. end
  4638. end
  4639. end--]]
  4640. -- 显示GPS界面
  4641. function ZPRoomView:showGpsView()
  4642. if self.isRecordScene then return end--回放场景直接return
  4643. logD("ZPRoomView:showGpsView()")
  4644. playBtnEffect()
  4645. local isGameStart = app.room.roomInfo.nGameStartCount > 0
  4646. -- self:updateAllGpsInfo()
  4647. if self.gpsComponent then
  4648. self.gpsComponent:showGpsView(isGameStart)
  4649. end
  4650. end
  4651. --清理小局查牌界面
  4652. function ZPRoomView:clearXJChaPaiView()
  4653. self.xiaojuChaPaiView:clearView()
  4654. end
  4655. --爆牌结果
  4656. function ZPRoomView:onBaoPaiResponese(data)
  4657. local function runBaoPai(onEnd)
  4658. log("2000000000-ZPRoomView - (runBaoPai)")
  4659. local response = data.response
  4660. local uid = response.nUserId
  4661. local viewId = app.room:getViewIdByUserId(uid)
  4662. --玩家选择了爆牌 播放爆牌动画
  4663. if response.optType == 1 then
  4664. self:showOperatorTip(viewId,-55)
  4665. self.PlayerView:playBaoAnim(viewId)
  4666. local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
  4667. if bankerViewId == viewId then
  4668. self.bankerBaoPao = true
  4669. end
  4670. end
  4671. if uid == app.user.loginInfo.uid or app.room:isLittleFamily() then
  4672. self.operationView:showBaoPaiOpView(false)
  4673. end
  4674. self:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
  4675. if onEnd then
  4676. onEnd()
  4677. end
  4678. end)))
  4679. end
  4680. self:addCallBack(runBaoPai)
  4681. end
  4682. --显示胡的牌
  4683. function ZPRoomView:onShowHuCard(showViewId,huCard)
  4684. local roomInfo = app.room.roomInfo
  4685. if roomInfo.dianPaoUserId == -1 and showViewId then
  4686. if huCard ~= 0 then
  4687. self:playMoPaiAni(table.nums(roomInfo.dipaiList),huCard,showViewId,0,1,nil,true)
  4688. end
  4689. else
  4690. self:setOutCardVisible(true,showViewId,huCard,false,nil,true)
  4691. end
  4692. end
  4693. --totalHuShu桌面油数
  4694. function ZPRoomView:showLocalHuXi(totalHuShu)
  4695. local viewId = self:getMeViewId()
  4696. local myHuXi = self.tableHuXiList[viewId] or 0
  4697. local huShuLocal = totalHuShu--self:getLocalHuShu(self.handCardValueLocal)
  4698. --只显示桌面胡数
  4699. myHuXi = myHuXi-- + huShuLocal
  4700. self.PlayerView:setPlayerHuXi(viewId,myHuXi)
  4701. end
  4702. --@parm:手牌列表
  4703. function ZPRoomView:getLocalHuShu(list)
  4704. local function calcHuShu(sList)
  4705. --[[if not list then
  4706. list = self.handCardValueLocal
  4707. end--]]
  4708. local hushu = 0
  4709. local xiaoOneErSan,xiaoErQiShi,daOneErSan,daErQiShi,xiaoYiWuShi,daYiWuShi = 0,0,0,0,0,0
  4710. --扑克多少张,从1-20,key分别代表小写到大写的1-10,value代表有多少张数
  4711. local m_cbCardIndex = ZPFuc.switchToCardIndex(sList)
  4712. --坎牌判断
  4713. if self:getCurrentColIsLong(sList) then--比砍多6,手牌龙会自动放下去,所以这里暂时不用计算
  4714. elseif self:getCurrentColIsKan(sList) then
  4715. if sList[1] - 16 > 0 then
  4716. if ZPFuc.getIsErQiShi(sList[1]) then
  4717. return 12
  4718. else
  4719. return 9
  4720. end
  4721. else
  4722. if ZPFuc.getIsErQiShi(sList[1]) then
  4723. return 9
  4724. else
  4725. return 6
  4726. end
  4727. end
  4728. else
  4729. --油数判断:以列为单位
  4730. --判断有多少个123
  4731. local lieMaxNum = table.nums(sList)
  4732. if lieMaxNum == 3 and m_cbCardIndex[1] >= 1 and m_cbCardIndex[2] >= 1 and m_cbCardIndex[3] >= 1 then
  4733. return 3
  4734. elseif lieMaxNum == 3 and m_cbCardIndex[11] >= 1 and m_cbCardIndex[12] >= 1 and m_cbCardIndex[13] >= 1 then
  4735. return 6
  4736. elseif lieMaxNum == 3 and m_cbCardIndex[2] >= 1 and m_cbCardIndex[7] >= 1 and m_cbCardIndex[10] >= 1 then
  4737. return 6
  4738. elseif lieMaxNum == 3 and m_cbCardIndex[12] >= 1 and m_cbCardIndex[17] >= 1 and m_cbCardIndex[20] >= 1 then
  4739. return 9
  4740. --泸州大贰没有1,5,10
  4741. elseif lieMaxNum == 3 and m_cbCardIndex[1] >= 1 and m_cbCardIndex[5] >= 1 and m_cbCardIndex[10] >= 1 then
  4742. --return 3
  4743. elseif lieMaxNum == 3 and m_cbCardIndex[11] >= 1 and m_cbCardIndex[15] >= 1 and m_cbCardIndex[20] >= 1 then
  4744. --return 6
  4745. end
  4746. end
  4747. return 0
  4748. end
  4749. local totalHuShu = 0
  4750. for i,handCard in ipairs(self.handCardRoot) do
  4751. local tCards = {}
  4752. local hushu = 0
  4753. for j=1,4 do
  4754. if handCard.imgList[j] and handCard.imgList[j].value and handCard.imgList[j]:isVisible() then
  4755. table.insert(tCards,handCard.imgList[j].value)
  4756. handCard.imgList[j]:setOpacity(255)
  4757. end
  4758. end
  4759. hushu = calcHuShu(tCards)
  4760. totalHuShu = totalHuShu + hushu
  4761. if next(tCards) == nil then
  4762. handCard.textHuShuBg:setVisible(false)
  4763. else
  4764. handCard.textHuShuBg:setVisible(true)
  4765. handCard.textHuShu:setText(hushu.."胡")
  4766. end
  4767. end
  4768. self:showLocalHuXi(totalHuShu)
  4769. --self.PlayerView:setPlayerHuXi(self:getMeViewId(),totalHuShu)
  4770. return totalHuShu
  4771. end
  4772. -- 立即开始
  4773. function ZPRoomView:onQuickStartResponse(event)
  4774. log("2000000000-ZPRoomView - runnQuickStartResponse()" )
  4775. if not event or not event.response then
  4776. return
  4777. end
  4778. logE("onQuickStartResponse() response = ", event.response)
  4779. local response = event.response
  4780. local isStart = true
  4781. local selectNums = table.nums(app.room.quickStartInfo)
  4782. for i,v in pairs(app.room.quickStartInfo) do
  4783. if v > 1 then
  4784. --有人投过票
  4785. isStart = false
  4786. end
  4787. end
  4788. if tolua.isnull(self.quickStartView) and isStart then
  4789. for i,v in pairs(app.room.quickStartInfo) do
  4790. if v == 1 then
  4791. self.quickStartView = ZPRoomQuickStartView:new(i);
  4792. self.quickStartView:setAnchorPoint(cc.p(0.5, 0.5));
  4793. app:showWaitDialog(self.quickStartView);
  4794. log("onQuickStartResponse() v = 1 "..i )
  4795. return
  4796. else
  4797. local startuid = 0
  4798. for i,v in pairs(app.room.quickStartInfo) do
  4799. if v == 1 then
  4800. startuid = i
  4801. end
  4802. end
  4803. self.quickStartView = ZPRoomQuickStartView:new(startuid);
  4804. self.quickStartView:setAnchorPoint(cc.p(0.5, 0.5));
  4805. app:showWaitDialog(self.quickStartView);
  4806. log("onQuickStartResponse() v ~= 1 "..i )
  4807. return
  4808. end
  4809. end
  4810. end
  4811. end
  4812. --刷新手牌
  4813. function ZPRoomView:onGetHandcardsResponese(event)
  4814. log("2000000000-ZPRoomView - onGetHandcardsResponese()" )
  4815. logD("onGetHandcardsResponese self.handCardValueBak---",table.tostring(self.handCardValueBak));
  4816. logD("onGetHandcardsResponese self.handCardValueLocal---",table.tostring(self.handCardValueLocal));
  4817. uploadLogs("zipaishaopai2")
  4818. self.ui.Items.LayoutMain_4:removeAllChildren()
  4819. self.handCardRoot = {}
  4820. self.handCardItem = {}
  4821. self.handCardValueLocal = {}
  4822. self.handCardValueBak = {}
  4823. local myUserID = app.room:getMyUserId()
  4824. self:createCard(false,myUserID,nil)
  4825. end
  4826. function ZPRoomView:setDiPaiVisible(vis)
  4827. self.ui.Items.ImageView_DiPai:setVisible(vis)
  4828. self.ui.Items.Layout_dipai:setVisible(vis)
  4829. end
  4830. --多维数组转 一维数组
  4831. function ZPRoomView:ChangeDataToVector(data)
  4832. local tt = {}
  4833. for i = 1, self.lieShuMax do
  4834. for j = 1, self.hangShuMax do
  4835. if data[i][j] then
  4836. table.insert(tt,data[i][j])
  4837. end
  4838. end
  4839. end
  4840. return tt
  4841. end
  4842. function ZPRoomView:onTransferCard(list,type1)--提牌 恢复至发牌阶段时的牌
  4843. if self.isGodHand then--此字段为true时,禁止拖动操作
  4844. return
  4845. end
  4846. if self.clickSpaceT then
  4847. return
  4848. end
  4849. if app.room:isLittleFamily() and not ZPFuc.getLittleIsCanLookCard() then--小家且不能看牌时,不能提牌
  4850. return
  4851. end
  4852. logD("ZPRoomView:onTransferCard self.handCardValueBak---",table.tostring(list));
  4853. logD("ZPRoomView:onTransferCard self.handCardValueLocal---",table.tostring(self.handCardValueLocal));
  4854. self:runAction(cc.Sequence:create(cc.DelayTime:create(2.0),cc.CallFunc:create(function ()
  4855. self.clickSpaceT = nil
  4856. end)))
  4857. self.clickSpaceT = true
  4858. if #list <= 0 then
  4859. return
  4860. end
  4861. local handCard = self:ChangeDataToVector(list)
  4862. local cardList = ZPFuc.switchToCardIndexForRecord(handCard)
  4863. local sendCardResult = app.room:rankHandCard(cardList)
  4864. local newCardList
  4865. newCardList = app.room:serverCardToMyCard(sendCardResult)
  4866. self.curCardSortRule = 1
  4867. self.ui.Items.LayoutMain_4:removeAllChildren()
  4868. self.handCardRoot = {}
  4869. self.handCardItem = {}
  4870. self.handCardValueLocal = {}
  4871. self.handCardValueBak = {}
  4872. local myUserID = app.room:getMyUserId()
  4873. app.room.cards[myUserID] = newCardList
  4874. self:createCard(false,myUserID,nil)
  4875. self:getLocalHuShu()
  4876. if app.room.roomInfo.tingCards then
  4877. if self.bOutCard then
  4878. local max = table.nums(app.room.roomInfo.tingCards)
  4879. if max > 0 then
  4880. self:setTingCardViewVisible(true,app.room.roomInfo.tingCards)
  4881. end
  4882. else
  4883. end
  4884. end
  4885. end
  4886. --备份的手牌数据,只对此数据使用的接口
  4887. function ZPRoomView:rankDeletOneBakCard(card)
  4888. local isEnd = false
  4889. --倒叙遍历1-10列
  4890. for col = self.lieShuMax,1,-1 do --列数
  4891. for row = self.hangShuMax,1,-1 do --行数
  4892. if self.handCardValueBak[col] and self.handCardValueBak[col][row] and card == self.handCardValueBak[col][row] then --判断值是否相等
  4893. logE("delete bakcard ============= :"..card)
  4894. table.remove(self.handCardValueBak[col],row)
  4895. isEnd = true
  4896. break
  4897. end
  4898. end
  4899. if isEnd then
  4900. break
  4901. end
  4902. end
  4903. end
  4904. --显示提牌按钮
  4905. function ZPRoomView:showTiPaiBtn(vis)
  4906. vis = vis or false
  4907. if ZPDef.GameID == GAME_IDS.xuyongDaEr then
  4908. self.ui.Items.Button_tipai:setVisible(vis)
  4909. else
  4910. self.ui.Items.Button_tipai:setVisible(false)
  4911. end
  4912. end
  4913. --检测是否少牌,如果少牌则恢复 --目前在抓牌,出牌成功,和显示操作三个地方检测少牌情况
  4914. function ZPRoomView:checkCardAndRecover()
  4915. --当前的手牌数
  4916. local curCardNum = 0
  4917. --当前显示的手牌数
  4918. local curShowNum = 0
  4919. --实际手牌数
  4920. local factCardNum = 0
  4921. --计算当前手牌数
  4922. for i,cards in pairs(self.handCardValueLocal) do
  4923. for j,card in pairs(cards) do
  4924. if card and card > 0 then
  4925. curCardNum = curCardNum + 1
  4926. end
  4927. end
  4928. end
  4929. --计算当前显示的手牌数
  4930. for i = 1,self.lieShuMax do
  4931. if self.handCardRoot[i].ui:isVisible() then
  4932. for j = 1,self.hangShuMax do
  4933. if self.handCardRoot[i].imgList[j]:isVisible() and self.handCardRoot[i].imgList[j]:getOpacity() == 255
  4934. and self.handCardRoot[i].imgList[j].value then
  4935. curShowNum = curShowNum + 1
  4936. end
  4937. end
  4938. end
  4939. end
  4940. --计算备份数据的手牌数(以这个数据为准)
  4941. factCardNum = self:getBakCardsNum()
  4942. if curCardNum ~= factCardNum and curShowNum ~= factCardNum then
  4943. print("checkCardAndRecover curCardNum="..curCardNum.." curShowNum="..curShowNum.." factCardNum="..factCardNum)
  4944. logD("checkCardAndRecover self.handCardValueBak---",table.tostring(self.handCardValueBak));
  4945. logD("checkCardAndRecover self.handCardValueLocal---",table.tostring(self.handCardValueLocal));
  4946. self:onTransferCard(self.handCardValueBak)
  4947. uploadLogs("zipaishaopai")
  4948. end
  4949. end
  4950. --获取备份数据里面的牌的数量
  4951. function ZPRoomView:getBakCardsNum()
  4952. --实际手牌数
  4953. local factCardNum = 0
  4954. for i,cards in pairs(self.handCardValueBak) do
  4955. for j,card in pairs(cards) do
  4956. if card and card > 0 then
  4957. factCardNum = factCardNum + 1
  4958. end
  4959. end
  4960. end
  4961. return factCardNum
  4962. end
  4963. --获取吃碰牌的数量(桌面组合牌)
  4964. function ZPRoomView:getWeaveCardsNum(viewId)
  4965. if not viewId then return 0 end
  4966. local name = string.format("Layout_player1Table_%d",viewId)
  4967. local UnitCardNode = self.ui.Items[name]
  4968. if UnitCardNode then
  4969. local count = UnitCardNode:getChildrenCount();
  4970. return count
  4971. end
  4972. return 0
  4973. end
  4974. --显示隐藏托管
  4975. function ZPRoomView:showTuoGuan(isShow)
  4976. if isShow then
  4977. if not self.tuoguanView then
  4978. self.tuoguanView = import("zp_base.luaScript.Views.Room.ZPRoomTuoGuanView"):new()
  4979. self:addChild(self.tuoguanView)
  4980. end
  4981. else
  4982. if self.tuoguanView and not tolua.isnull(self.tuoguanView) then
  4983. self.tuoguanView:removeFromParent()
  4984. self.tuoguanView = nil
  4985. end
  4986. end
  4987. end
  4988. --托管结果协议
  4989. function ZPRoomView:onTuoGuanResponse(data)
  4990. local function runTuoGuanResponse(onEnd)
  4991. log("2000000000-ZPRoomView - (runTuoGuanResponse)")
  4992. local response = data.response
  4993. local userCnt = response.userCnt;
  4994. if userCnt then
  4995. --self:setTuoGuanAllVisible()
  4996. self.PlayerView:setTuoGuanFlagVisible(false)
  4997. for k,v in pairs(userCnt) do
  4998. local aiStatus = v.aiStatus;
  4999. local nUserID = v.nUserID;
  5000. local viewId = app.room:getViewIdByUserId(nUserID)
  5001. local isTuoGuan = aiStatus == 1;
  5002. if self:getIsMeUId(nUserID) then
  5003. if isTuoGuan then
  5004. self:showTuoGuan(true)
  5005. self.isTuoGuan = true
  5006. else
  5007. self:showTuoGuan(false)
  5008. self.isTuoGuan = false
  5009. end
  5010. end
  5011. self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
  5012. --self:showTuoGuanByViewId(viewId,isTuoGuan)
  5013. end
  5014. end
  5015. if onEnd then
  5016. onEnd()
  5017. end
  5018. end
  5019. log("2000000000-ZPRoomView - addCallBack(runTuoGuanResponse)")
  5020. self:addCallBack(runTuoGuanResponse)
  5021. end
  5022. --获取托管状态
  5023. function ZPRoomView:getTuoGuanState()
  5024. return self.isTuoGuan or false
  5025. end
  5026. ---
  5027. -- 显示抽奖界面
  5028. --
  5029. function ZPRoomView:showGameOverAward()
  5030. if not (dd and dd.IGameOverAward) then
  5031. return
  5032. end
  5033. self:runDelay(0.1, function ( )
  5034. -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
  5035. dd.IGameOverAward.showAwardView();
  5036. end)
  5037. end
  5038. return ZPRoomView;