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.

2972 lines
93 KiB

  1. local RoomView_ERDouDiZhu = class("RoomView_ERDouDiZhu", cc.UIView)
  2. local Functions = require("pk_erdoudizhu.luaScript.Functions_ERDouDiZhu")
  3. local defs = require("pk_erdoudizhu.luaScript.Def_ERDouDiZhu")
  4. local Messages = require("pk_erdoudizhu.luaScript.Protocol.ProtocolMessage_ERDouDiZhu")
  5. local PokerUtil = require('pk_erdoudizhu.luaScript.Views.Room.newPokerUtil')
  6. local DDZ_New_Effect_Helper = require("pk_erdoudizhu.luaScript.Views.Room.DDZNewEffectHelper"):new()
  7. local TuoGuanView = require('pk_erdoudizhu.luaScript.Views.Room.RoomTuoGuanView')
  8. local Card_Move_Up_Down_Time = 0.1 -- 手牌抬起下放动画时间
  9. local Card_Out_Down_Time = 0.15 -- 出牌下放动画时间
  10. local Card_Out_Down_Offset_Y = -5 -- 出牌下放位置
  11. function RoomView_ERDouDiZhu:ctor()
  12. RoomView_ERDouDiZhu.super.ctor(self)
  13. self._pokerUtil = nil
  14. self._isCanClickBg = true
  15. end
  16. function RoomView_ERDouDiZhu:initData()
  17. --事件队列
  18. self.callbackQueue = {}
  19. --手牌间距(越大越密集,越小越稀疏)
  20. self.handCardDif = 110
  21. --默认闹钟时间
  22. self.clockTime = 15
  23. --上家出的牌数据
  24. self.lastData = {}
  25. self:setLastData()
  26. end
  27. function RoomView_ERDouDiZhu:onEnter()
  28. RoomView_ERDouDiZhu.super.onEnter(self)
  29. --ui load
  30. local ui = loadUI("pk_erdoudizhu/res/ui/ui_fangjian/doudizhu_ui_fangjian.ui")
  31. self:addChild(ui)
  32. self.ui = ui
  33. -- 添加合图缓存
  34. self:addloadSpriteFrame()
  35. -- 添加扑克牌型提示文件
  36. self:initPokerUtil()
  37. --初始化属性数据
  38. self:initData()
  39. --初始化所有的玩家节点
  40. self:initPlayerNodes()
  41. --初始化工具层
  42. self:initToolLayer()
  43. -- 初始化GPS组件
  44. self:initGpsComponent()
  45. -- 初始化电量和信号
  46. self:initSingleComponent()
  47. -- 初始化扑克牌
  48. self:initPoker()
  49. --监听事件
  50. self:bindAllEvent()
  51. --显示桌面信息
  52. self:initDeskInfo()
  53. --初始游戏中按钮
  54. self:initGameButtons()
  55. --初始化玩法
  56. self:initGameRule()
  57. --播放音乐
  58. Functions.playMusic()
  59. --先收到8009再初始化的房间(房间还未监听8009事件),所以这里调用重连
  60. self:onGameReconnection()
  61. --恢复协议
  62. self:startGame()
  63. --测试
  64. --self.weaveCardList = self:getTip(self.handCards["" .. self:getMeViewId()])
  65. self:initPlayGameAgain()
  66. end
  67. function RoomView_ERDouDiZhu:addloadSpriteFrame()
  68. loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards.plist")
  69. -- 动画相关
  70. loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_shunzi/zy_ddz_CardFX_ShunZi_Sheet1.plist")
  71. loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_shunzi/zy_ddz_CardFX_ShunZi_Sheet2.plist")
  72. loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_bomb/zy_ddz_CardFX_ZhaDan_Sheet1.plist")
  73. loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_liandui/zy_ddz_CardFX_LianDui_Sprite_1.plist")
  74. loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_player/zy_game_jingbao/ddz_Ani_BJ.plist")
  75. loadSpriteFrameFile('pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_kingbomb/doudizhu_Ani_KingBomb.plist')
  76. end
  77. function RoomView_ERDouDiZhu:initPokerUtil()
  78. self._pokerUtil = PokerUtil:new()
  79. end
  80. function RoomView_ERDouDiZhu:initPoker()
  81. local changePoker = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose
  82. self:onNormalChangePoker({idx=changePoker})
  83. end
  84. function RoomView_ERDouDiZhu:onClickButtonDismiss( sender )
  85. playBtnEffect()
  86. local function onClickOk()
  87. app.room:requestDismissRoom(1)--发起解散
  88. end
  89. local function onClickCancel()
  90. end
  91. showConfirmDialog("确定要申请解散房间吗?", onClickOk, onClickCancel)
  92. end
  93. function RoomView_ERDouDiZhu:hideXiangQing(hideAction)
  94. self.xiangQingView.Items.Layout_XiangQing:setVisible(false)
  95. self.xiangQingView.Items.Layout_XQ_content:stopAllActions()
  96. self.xiangQingView.Items.ListView_Xq:setVisible(false)
  97. if hideAction == true then
  98. self.xiangQingView.Items.Layout_XQ_content:setPosition(self.xiangQingViewHidePos)
  99. self.xiangQingView.Items.Button_XiangQing:setVisible(true)
  100. else
  101. self.xiangQingView.Items.Layout_XQ_content:runAction(
  102. cc.Sequence:create(
  103. cc.MoveTo:create(0.35 , self.xiangQingViewHidePos),
  104. cc.CallFunc:create(function()
  105. self.xiangQingView.Items.Button_XiangQing:setVisible(true)
  106. end)
  107. )
  108. )
  109. end
  110. end
  111. function RoomView_ERDouDiZhu:initGameRule()
  112. self.xiangQingView = loadUI("pk_erdoudizhu/res/ui/ui_fangjian/doudizhu_ui_wanfa.ui")
  113. self.ui.Items.Layout_RuleView:addChild(self.xiangQingView)
  114. self.xiangQingView.Items.Button_XiangQing:setVisible(false)
  115. self.xiangQingView.Items.Layout_XiangQing:setVisible(true)
  116. local offsetX = 20
  117. self.xiangQingView.Items.Button_XiangQing:setPositionX(self.xiangQingView.Items.Button_XiangQing:getPositionX() + offsetX)
  118. self.xiangQingView.Items.Layout_XQ_content:setPositionX(self.xiangQingView.Items.Layout_XQ_content:getPositionX() + offsetX)
  119. local size = self.xiangQingView.Items.Layout_XQ_content:getContentSize()
  120. self.xiangQingViewShowPos = self.xiangQingView.Items.Layout_XQ_content:getPosition()
  121. self.xiangQingViewHidePos = cc.vec3(self.xiangQingViewShowPos.x,self.xiangQingViewShowPos.y + size.height,self.xiangQingViewShowPos.z)
  122. self.xiangQingView.Items.Button_XiangQing_Back:registerClick(handler(self , self.hideXiangQing))
  123. self.xiangQingView.Items.Layout_XiangQing:registerClick(handler(self , self.hideXiangQing))
  124. self.xiangQingView.Items.Layout_XQ_content:registerClick(handler(self , self.hideXiangQing))
  125. self.xiangQingView.Items.Button_XiangQing:registerClick(function()
  126. playBtnEffect()
  127. self.xiangQingView.Items.Button_XiangQing:setVisible(false)
  128. self.xiangQingView.Items.Layout_XQ_content:stopAllActions()
  129. self.xiangQingView.Items.Layout_XQ_content:runAction(
  130. cc.Sequence:create(
  131. cc.MoveTo:create(0.35 , self.xiangQingViewShowPos),
  132. cc.CallFunc:create(function()
  133. self.xiangQingView.Items.ListView_Xq:setVisible(true)
  134. self.xiangQingView.Items.Layout_XiangQing:setVisible(true)
  135. end)
  136. )
  137. )
  138. end)
  139. self.xiangQingView.Items.ListView_Xq:getVBar():setVisible(false)
  140. local roomInfo = app.room.roomInfo
  141. local ruleAll = Functions.getRuleStr()
  142. local wanfaList = string.split(ruleAll," ")
  143. local listviewSize = self.xiangQingView.Items.ListView_Xq:getContentSize()
  144. for i,v in pairs(wanfaList) do
  145. if v ~= "" and v ~= " " then
  146. local layout=cc.Layout:create()
  147. local wanfaText = cc.Text:createNode()
  148. wanfaText:setDefaults()
  149. local config = wanfaText:getFontConfig()
  150. config.fontSize = 24
  151. config.texColor = cc.c4b(255,192,101,255)
  152. wanfaText:setFontConfig(config)
  153. layout:setSize(cc.size(listviewSize.width,35))
  154. layout:addChild(wanfaText)
  155. wanfaText:setPosition(cc.p(listviewSize.width/2,15))
  156. wanfaText:setString(v)
  157. self.xiangQingView.Items.ListView_Xq:pushBackCustomItem(layout)
  158. end
  159. end
  160. if app.room.roomInfo.nGameStartCount > 0 then
  161. self:hideXiangQing(true)
  162. else
  163. self:runAction(cc.Sequence:create(
  164. cc.DelayTime:create(2),
  165. cc.CallFunc:create(self.hideXiangQing)
  166. ))
  167. end
  168. end
  169. function RoomView_ERDouDiZhu:defaultState()
  170. --队列初始化
  171. self.callbackQueue = {}
  172. self.callbackRunning = false
  173. --刷新按钮
  174. self:updateButtons()
  175. --刷新用户信息
  176. self:refreshPlayer(true)
  177. --隐藏地主底牌、炸弹等信息
  178. self:setBankerCardsVisible(false)
  179. -- 隐藏桌面信息
  180. self:isShowMiddleTips(false)
  181. self:isShowMiddleTipsForAll(false)
  182. -- 小结算
  183. if self.XiaoJuView then
  184. self.XiaoJuView:setVisible(false)
  185. end
  186. --是否开局
  187. if app.room.roomInfo.nGameStartCount > 0 then
  188. --隐藏加倍界面
  189. self:setAskBeiVisible(false)
  190. --隐藏叫分界面
  191. self:setAskLoardVisible(false)
  192. -- 隐藏让界面
  193. self:setRangVisible(false)
  194. -- 隐藏抢界面
  195. self:setQiangVisible(false)
  196. --隐藏玩家出牌操作信息
  197. self:hideAllOutCardOperation()
  198. --隐藏界面
  199. for _,v in pairs(app.room.roomInfo.memberList) do
  200. local viewId = app.room:getViewIdByUserId(v.nUserId)
  201. --隐藏桌面加倍标识
  202. -- self.PlayerView:setTipsVisible("tips_jiabei", false, viewId)
  203. --隐藏桌面叫分标识
  204. -- self.PlayerView:setTipsVisible("tips_jiaofen", false, viewId)
  205. self.PlayerView:setTipsVisibleExcept({}, viewId)
  206. --隐藏手牌
  207. local handLayout = self.ui.Items["Layout_Hand_" .. viewId]
  208. if handLayout then
  209. handLayout:removeAllChildren()
  210. if self.handCards then
  211. local handCards = self.handCards["" .. viewId]
  212. if handCards then
  213. self.handCards["" .. viewId] = nil
  214. end
  215. end
  216. end
  217. end
  218. end
  219. end
  220. function RoomView_ERDouDiZhu:onUserExitResponseRoom(data)
  221. local function runUserExitResponseRoom(onEnd)
  222. local response = data.response
  223. --房间号
  224. local roomid = app.room.roomInfo.nShowTableId
  225. app.room.roomInfo.tableOverFlag = response.tableOverFlag
  226. local tableOverFlag = response.tableOverFlag
  227. local nGameStartCount = app.room.roomInfo.nGameStartCount
  228. --长时间未开始强制退出,否则不退出
  229. if tableOverFlag ~= defs.TABLE_OVER_FLAG.TABLE_OVER_LONG_TIME_NO_START and nGameStartCount ~= 0 then
  230. response.logoutFlag = 0
  231. else
  232. response.logoutFlag = 1
  233. end
  234. if tableOverFlag == defs.TABLE_OVER_FLAG.TABLE_OVER_LONG_TIME_NO_START and nGameStartCount > 0 then
  235. -- 如果已经有牌局了,则显示结算界面,不踢到大厅
  236. response.logoutFlag = 0
  237. end
  238. --如果是自己点离开必须退出
  239. if app.room.roomInfo.bQuitRoom then
  240. response.logoutFlag = 1
  241. end
  242. --正常结束不提示,其他都要提示
  243. if tableOverFlag >= defs.TABLE_OVER_FLAG.TABLE_OVER_GROUP_DISBAND then
  244. showTooltip(defs.TABLE_OVER_FLAG_TEXT[tableOverFlag])
  245. end
  246. -- 0: 不退出, 1: 退出
  247. if response.logoutFlag == 1 then
  248. app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.LiuZhou, roomid))
  249. end
  250. app.room:dispatchEvent({name = "onUserExitResponseHall"})
  251. if onEnd then
  252. onEnd()
  253. end
  254. end
  255. self:addCallBack(runUserExitResponseRoom)
  256. end
  257. function RoomView_ERDouDiZhu:showProp(data)
  258. local response = data.response
  259. logE("RoomView_ERDouDiZhu:showProp response = "..table.tostring(response))
  260. --ui表现开始
  261. local uidStarId = response.uidStarId
  262. local uidEndId = response.uidEndId
  263. local propId = response.propId
  264. local isQunFa = response.isQunFa
  265. local beginViewId = app.room:getViewIdByUserId(uidStarId)
  266. local endViewId = app.room:getViewIdByUserId(uidEndId)
  267. if not self.allNodes[beginViewId] or not self.allNodes[endViewId]
  268. or not self.allNodes[endViewId].head or not self.allNodes[beginViewId].head then
  269. logE("场景还没初始化完成就收到道具消息果断return!")
  270. return
  271. end
  272. --播放动画
  273. if isQunFa == 1 then
  274. local onLineList = app.room.roomInfo.memberList
  275. for nUserId,v in pairs(onLineList) do
  276. local endViewId = app.room:getViewIdByUserId(nUserId)
  277. if endViewId ~= beginViewId then
  278. self.PropAniManager:playAnimation(self.allNodes[beginViewId].head,self.allNodes[endViewId].head,propId)
  279. end
  280. end
  281. else
  282. self.PropAniManager:playAnimation(self.allNodes[beginViewId].head,self.allNodes[endViewId].head,propId)
  283. end
  284. end
  285. function RoomView_ERDouDiZhu:initPlayerNodes()
  286. self.PlayerView = import("pk_erdoudizhu.luaScript.Views.Room.RoomPlayerView_ERDouDiZhu"):new()
  287. self.ui.Items.Layout_Player:addChild(self.PlayerView)
  288. end
  289. function RoomView_ERDouDiZhu:refreshPlayer(bVisible, viewId, playerInfo)
  290. if bVisible then
  291. self.PlayerView:updatePlayer(playerInfo, viewId)
  292. else
  293. self.PlayerView:hidePlayer(viewId)
  294. end
  295. local uids = {}
  296. for k,v in pairs(app.room.roomInfo.memberList) do
  297. uids[v.nUserId] = true
  298. end
  299. if self.messageView then
  300. self.messageView:setPlayerUids(uids)
  301. end
  302. end
  303. function RoomView_ERDouDiZhu:initToolLayer()
  304. --加载工具层
  305. self.toolView = import("pk_erdoudizhu.luaScript.Views.Room.RoomToolView_ERDouDiZhu"):new()
  306. self.ui.Items.Layout_Tool:addChild(self.toolView)
  307. --ChatView
  308. self.messageView = require("luaScript.Views.Room.ChatView"):new({chatList = defs.GAME_CHAT_TXT}, self.PlayerView:getChatViewPos(), true)
  309. self.toolView.ui.Items.Layout_ChatView:addChild(self.messageView)
  310. --设置语言
  311. self.messageView:setLanguage(Functions.getCurLanguage() == defs.LANGUAGE_TYPE.PU_TONG_HUA)
  312. --互动表情,语音
  313. self.messageView:setBtnFace(defs.FACE_POS)
  314. self.messageView:setBtnVoice(defs.VOICE_POS)
  315. self.messageView.ui.Items.Button_Face:loadTextureNormal("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png")
  316. self.messageView.ui.Items.Button_Face:loadTexturePressed("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png")
  317. self.messageView.ui.Items.Button_Face:loadTextureDisabled("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png")
  318. self.messageView.ui.Items.Button_Voice:loadTextureNormal("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png")
  319. self.messageView.ui.Items.Button_Voice:loadTexturePressed("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png")
  320. self.messageView.ui.Items.Button_Voice:loadTextureDisabled("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png")
  321. --是否屏蔽互动表情
  322. self.messageView:setPropEnabled((tonumber(loadUserInfo("HuDongBiaoQingKG" .. app.gameId)) or 1) == 1)--0关 1开
  323. --是否屏蔽屏蔽语音
  324. self.messageView:setVoiceEnabled((tonumber(loadUserInfo("PingBiYuYinKG" .. app.gameId)) or 1) == 1)--0关 1开
  325. --道具播放管理器
  326. self.PropAniManager = import("luaScript.Tools.PropAniPlayer"):new(self.ui.Items.Layout_Touch)
  327. -- if Functions.getIsForbidVoiceAndProp() then
  328. -- self.messageView:hideBtns()
  329. -- self.messageView:setPropEnabled(false)
  330. -- self.messageView:setVoiceEnabled(false)
  331. -- end
  332. if Functions.getIsForbidFace() then
  333. self.messageView:hideFace()
  334. self.messageView:setPropEnabled(false)
  335. end
  336. if Functions.getIsForbidVoice() then
  337. self.messageView:hideVoice()
  338. self.messageView:setVoiceEnabled(false)
  339. end
  340. end
  341. function RoomView_ERDouDiZhu:initGpsComponent()
  342. local versionCode = getAppVersionCode()
  343. versionCode = tonumber(versionCode) or 0
  344. logD("RoomView_ERDouDiZhu:initGpsComponent() versionCode = ", versionCode)
  345. if isReviewVersion() then
  346. self.toolView.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView))
  347. self.toolView.ui.Items.Button_GPS:setVisible(false)
  348. return
  349. end
  350. -- 创建 gps 组件
  351. self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponent"):new()
  352. -- GPS 按钮
  353. self.toolView.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView))
  354. -- 我的GPS数据发生变化时检测是否需要通知服务器
  355. self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate))
  356. -- 进入时检测一遍我的GPS数据是否需要更新
  357. self:checkMyGpsNeedUpdate()
  358. end
  359. -- 初始化电量和信号
  360. function RoomView_ERDouDiZhu:initSingleComponent()
  361. self.singleComponent = import("luaScript.Views.Room.RoomSinglePowerComponent"):new(self.ui.Items.ImageView_Single, self.ui.Items.LoadingBar_Power);
  362. end
  363. -- 注销电量、网络信号
  364. function RoomView_ERDouDiZhu:deInitSingleComponent()
  365. if self.singleComponent then
  366. self.singleComponent:exit()
  367. end
  368. end
  369. function RoomView_ERDouDiZhu:bindAllEvent()
  370. --用户状态(包括准备,其他玩家进入或者离开通知,离线等)
  371. self:bindUserStatedMessage()
  372. --私人场消息(包括解散等)
  373. self:bindPrivateMessage()
  374. --游戏消息
  375. self:bindGameMessage()
  376. --游戏场景消息
  377. self:bindGameSceneMessage()
  378. --绑定更换桌布事件
  379. self:bindEvent(app , "onChangeTable" , handler(self , self.onChangeTable))
  380. --发送道具
  381. self:bindEvent(app.room,"showProp" , handler(self , self.showProp))
  382. --绑定更换语言种类
  383. self:bindEvent(app , "onChangeLanguage" , handler(self , self.onChangeLanguage))
  384. --设置互动表情开关事件
  385. self:bindEvent(app.room,"ontSetPropEnabled" , handler(self , self.ontSetPropEnabled))
  386. --设置语音开关事件
  387. self:bindEvent(app.room,"onSetVoiceEnabled" , handler(self , self.onSetVoiceEnabled))
  388. -- 游戏设置里更换扑克
  389. self:bindEvent(app.room, "ddzNormalEvent_changePoker" , handler(self , self.onNormalChangePoker))
  390. -- 小结算内通知解散
  391. self:bindEvent(app.room, 'onResultInformDisMiss', handler(self, self.onClickButtonDismiss))
  392. -- 托管回复
  393. self:bindEvent(app.room , 'onHostingResponse', handler(self, self.onHostingResponse))
  394. end
  395. function RoomView_ERDouDiZhu:initDeskInfo()
  396. --设置房间号
  397. self.ui.Items.Text_roomNum:setText("房间号: " .. app.room.roomInfo.nShowTableId)
  398. -- 更新当前局数
  399. self:updateGameNums()
  400. --系统时间
  401. if not app.room.roomInfo.isRecord then
  402. self.ui.Items.Text_systemTime:stopAllActions()
  403. self.ui.Items.Text_systemTime:runActions(
  404. cc.RepeatForever:create(
  405. cc.Sequence:create(
  406. cc.CallFunc:create(function()
  407. self.ui.Items.Text_systemTime:setText(string.format("%s", os.date("%H:%M:%S", os.time())))
  408. end),
  409. cc.DelayTime:create(0.5)
  410. )
  411. )
  412. )
  413. end
  414. --刷新桌面背景和Logo
  415. self:setTableImg(Functions.getDefaultBg())
  416. end
  417. function RoomView_ERDouDiZhu:startGame()
  418. --起飞
  419. app.net:onMsgResume()
  420. end
  421. function RoomView_ERDouDiZhu:updateGameNums()
  422. -- 更新当前局数
  423. local roomInfo = app.room.roomInfo
  424. local curCount = roomInfo.nGameStartCount or 0
  425. local str = string.format("%02d / %02d", curCount, roomInfo.nTotalGameNum)
  426. self.ui.Items.Text_JuShu:setText(str)
  427. end
  428. function RoomView_ERDouDiZhu:onExit()
  429. RoomView_ERDouDiZhu.super.onExit(self)
  430. self:deInitSingleComponent()
  431. app.room:dispatchEvent({name = "onGameOverResponse"})
  432. stopBGMusic()
  433. self:cleanCache() -- jxtd 记得验证是否要删除
  434. end
  435. -- 清理缓存,用于测试
  436. function RoomView_ERDouDiZhu:cleanCache()
  437. local preload = package.loaded
  438. for k, v in pairs(package.loaded or {}) do
  439. local res1 = string.find( k, "pk_erdoudizhu.luaScript") or 0
  440. if res1 > 0 then
  441. package.loaded[k] = nil
  442. end
  443. end
  444. end
  445. -- 其他玩家坐下成功
  446. function RoomView_ERDouDiZhu:onOtherSitDownResponse(data)
  447. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  448. self:checkGpsDistance(data.response.nUserId)
  449. self:refreshPlayer(true, viewId, app.room.roomInfo.memberList[data.response.nUserId])
  450. self:updateButtons()
  451. if not tolua.isnull(self.quickStartView) then
  452. self.quickStartView:removeView()
  453. self.quickStartView = nil
  454. end
  455. end
  456. function RoomView_ERDouDiZhu:updateButtons()
  457. local nGameStartCount = app.room.roomInfo.nGameStartCount or 0
  458. if nGameStartCount > 0 then
  459. -- 准备按钮
  460. self.toolView:setReadyVisible(false)
  461. -- 是否显示邀请好友
  462. self.toolView:setInviteVisible(false)
  463. -- 离开按钮
  464. self.toolView:setLeaveEnabled(false)
  465. -- 解散按钮
  466. self.toolView:setDissmissEnabled(true)
  467. -- 显示是否可以解散
  468. self.toolView:checkCanDismiss()
  469. else
  470. local myUserId = app.room:getMyUserId()
  471. -- 是否显示邀请好友
  472. if isReviewVersion() then
  473. self.toolView:setInviteVisible(false)
  474. else
  475. self.toolView:setInviteVisible(table.nums(app.room.roomInfo.memberList) < app.room.roomInfo.nMaxPlayCount)
  476. end
  477. -- 准备按钮
  478. local readyState = app.room.roomInfo.memberList[myUserId].nPlayerFlag or 0
  479. self.toolView:setReadyVisible(readyState == 0)
  480. -- 离开按钮
  481. self.toolView:setLeaveEnabled(true)
  482. -- 解散按钮
  483. local nRoomOwnedUid = app.room.roomInfo.nRoomOwnedUid or 0
  484. self.toolView:setDissmissEnabled(nRoomOwnedUid == app.room:getMyUserId() and (not app.club_php.clubID or (app.club_php.clubID and app.club_php.clubID == 0)))
  485. end
  486. end
  487. function RoomView_ERDouDiZhu:onOtherDroppedResponse(data)
  488. if not data.response then
  489. return
  490. end
  491. self:setPlayerOffLine(data.response.nOnlineStatus == 0, app.room:getViewIdByUserId(data.response.nUserId))
  492. end
  493. function RoomView_ERDouDiZhu:setPlayerOffLine(bVisible, viewId, times)
  494. --离线
  495. self.PlayerView:setOffLineVisible(bVisible, viewId)
  496. --[[
  497. if bVisible then
  498. local startTime = os.time()
  499. self.allNodes[viewId].offLine:stopAllActions()
  500. self.allNodes[viewId].offLine:runAction(
  501. cc.RepeatForever:create(
  502. cc.Sequence:create(
  503. cc.CallFunc:create(function()
  504. local endTime = os.time()
  505. local difTime = endTime - startTime + (times or 0)
  506. local timeStr = string.format("%02d : %02d", difTime / 60, difTime % 60)
  507. self.allNodes[viewId].offLineTime:setText(timeStr)
  508. end),
  509. cc.DelayTime:create(1.0)
  510. )
  511. )
  512. )
  513. end
  514. --]]
  515. end
  516. function RoomView_ERDouDiZhu:onOtherLogoutResponse(data)
  517. self:refreshPlayer(false, data.response.viewId)
  518. self:updateButtons()
  519. end
  520. function RoomView_ERDouDiZhu:onUserReadyResponse(data)
  521. --自己准备
  522. if app.room:getMyUserId() == data.response.nUserId then
  523. --重置桌面
  524. self:defaultState()
  525. --更新按钮状态
  526. self:updateButtons()
  527. end
  528. --显示准备
  529. self.PlayerView:setReadyVisible(true, app.room:getViewIdByUserId(data.response.nUserId))
  530. end
  531. --用户状态消息
  532. function RoomView_ERDouDiZhu:bindUserStatedMessage()
  533. --默认状态
  534. self:bindEvent(app.room , "defaultState", handler(self , self.defaultState))
  535. -- 玩家准备
  536. self:bindEvent(app.room , "onUserReadyResponse", handler(self , self.onUserReadyResponse))
  537. -- 其他玩家进入房间
  538. self:bindEvent(app.room , "onOtherSitDownResponse", handler(self , self.onOtherSitDownResponse))
  539. -- 其他玩家退出房間
  540. self:bindEvent(app.room , "onOtherLogoutResponse", handler(self , self.onOtherLogoutResponse))
  541. -- 其他玩家掉线
  542. self:bindEvent(app.room , "onOtherDroppedResponse", handler(self , self.onOtherDroppedResponse))
  543. -- 用户T出
  544. self:bindEvent(app.room , "onUserExitResponseRoom", handler(self , self.onUserExitResponseRoom))
  545. -- 玩家的GPS信息发生变化
  546. self:bindEvent(app.room , "onGpsChangeResponse", handler(self , self.onGpsChangeResponse))
  547. end
  548. --私人场消息
  549. function RoomView_ERDouDiZhu:bindPrivateMessage()
  550. -- 玩家收到解散房间的请求
  551. self:bindEvent(app.room , "onDismissResponse", handler(self , self.onDismissResponse))
  552. end
  553. --场景恢复
  554. function RoomView_ERDouDiZhu:bindGameSceneMessage()
  555. app.hall:addEventListener("onEnterRoomSuccess", handler(self , self.onEnterRoomSuccess))
  556. end
  557. function RoomView_ERDouDiZhu:onEnterRoomSuccess()
  558. if tolua.isnull(self.ui) then
  559. logE("self.is null")
  560. return
  561. end
  562. self:stopAllActions()
  563. self:onGameReconnection()
  564. self:startGame()
  565. end
  566. function RoomView_ERDouDiZhu:onGameReconnection()
  567. --默认状态
  568. self:defaultState()
  569. --是否开局
  570. if app.room.roomInfo.nGameStartCount > 0 then
  571. --显示剩余手牌
  572. for _,v in pairs(app.room.roomInfo.memberList) do
  573. self.PlayerView:setLeftNumVisible(true, app.room:getViewIdByUserId(v.nUserId), table.nums(v.handCards))
  574. -- 恢复手牌
  575. self:initHandCards(v.handCards, app.room:getViewIdByUserId(v.nUserId))
  576. end
  577. --恢复手牌
  578. -- self:initHandCards(app.room.roomInfo.memberList[app.room:getMyUserId()].handCards, self:getMeViewId())
  579. --叫地主阶段
  580. if app.room.roomInfo.nStatus == defs.GAME_STATUS.ASK_LOARD then
  581. --当前操作位置
  582. self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  583. --显示方位
  584. self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime)
  585. --显示叫分/叫地主
  586. local tips = ''
  587. local gameMode = Functions.getGameMode()
  588. if gameMode == 1 then
  589. tips = 'tips_jiaodizhu'
  590. else
  591. tips = 'tips_jiaofen'
  592. end
  593. for k,v in pairs(app.room.roomInfo.memberList) do
  594. if v.bAskLoard == 1 then
  595. self.PlayerView:setTipsVisible(tips, true, app.room:getViewIdByUserId(v.nUserId), { askLoard = v.askLoard })
  596. end
  597. end
  598. --是否显示叫分
  599. if self.curViewId == self:getMeViewId() then
  600. self:setAskLoardVisible(true, app.room.roomInfo.opType == 1, gameMode)
  601. end
  602. -- 显示中间提示内容
  603. self:isShowMiddleTipsForAll(true)
  604. -- 抢地主阶段
  605. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.QIANG_LOARD then
  606. --当前操作位置
  607. self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  608. --显示方位
  609. self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime)
  610. for _, v in pairs(app.room.roomInfo.memberList) do
  611. local viewId = app.room:getViewIdByUserId(v.nUserId)
  612. if viewId ~= self.curViewId then
  613. if tonumber(v.bAskQiang) == 1 then
  614. self.PlayerView:setTipsVisible('tips_qiangdizhu', true, viewId, { opType = 1 })
  615. elseif tonumber(v.bAskLoard) == 1 then
  616. local tips = ''
  617. local gameMode = Functions.getGameMode()
  618. if gameMode == 1 then
  619. tips = 'tips_jiaodizhu'
  620. else
  621. tips = 'tips_jiaofen'
  622. end
  623. self.PlayerView:setTipsVisible(tips, true, viewId, { askLoard = v.askLoard })
  624. end
  625. end
  626. end
  627. --是否显示抢地主
  628. if self.curViewId == self:getMeViewId() then
  629. self:setQiangVisible(true)
  630. end
  631. -- 显示中间提示内容
  632. self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRangTotalNums)
  633. --加倍阶段
  634. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.ASK_BEI then
  635. --显示庄家
  636. self.PlayerView:setBankerVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.nBankerId))
  637. --显示加倍状态
  638. for k,v in pairs(app.room.roomInfo.memberList) do
  639. if v.bAskBei == 1 then
  640. self.PlayerView:setTipsVisible("tips_jiabei", true, app.room:getViewIdByUserId(v.nUserId), { askBei = v.askBei })
  641. else
  642. self.PlayerView:setClockVisibel(true, app.room:getViewIdByUserId(v.nUserId), 0)
  643. end
  644. end
  645. --是否显示加倍
  646. local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()]
  647. if myMemberInfo.bAskBei == 0 then
  648. self:setAskBeiVisible(true)
  649. end
  650. -- 显示中间提示内容
  651. self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRangTotalNums)
  652. -- 让牌阶段
  653. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.ASK_RANG then
  654. --当前操作位置
  655. self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  656. --显示方位
  657. self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime)
  658. --是否显示让
  659. if self.curViewId == self:getMeViewId() then
  660. -- local rangCount = Functions.getRangCount()
  661. -- if rangCount > 0 then
  662. self:setRangVisible(true, rangCount)
  663. -- end
  664. end
  665. -- 显示中间提示内容
  666. self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRangTotalNums)
  667. --打牌阶段
  668. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.PLAYING then
  669. --当前操作位置
  670. self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  671. --显示方位
  672. self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime)
  673. --显示庄家
  674. self.PlayerView:setBankerVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.nBankerId))
  675. --最后一手手牌
  676. if app.room:checkUserIDIsInTable(app.room.roomInfo.lastUserId) then
  677. local lastViewId = app.room:getViewIdByUserId(app.room.roomInfo.lastUserId)
  678. self:setOutCardsVisible(true, lastViewId, { cards = app.room.roomInfo.lastCards, opType = app.room.roomInfo.lastCardType })
  679. end
  680. -- 玩家过数据
  681. for k,v in pairs(app.room.roomInfo.memberList) do
  682. -- 显示过
  683. if v.nGuo and v.nGuo == 1 then
  684. self.PlayerView:setTipsVisible("tips_yaobuqi", true, app.room:getViewIdByUserId(v.nUserId))
  685. end
  686. end
  687. --是否显示操作
  688. if self.curViewId == self:getMeViewId() then
  689. self:setOperationVisible(true, app.room.roomInfo.opType)
  690. end
  691. if app.room.roomInfo.nBankerId == app.room:getMyUserId() then
  692. local rangCount = Functions.getRangCount()
  693. -- if rangCount > 0 then
  694. local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()]
  695. local otherHandCards = 0
  696. local otherViewId = 0
  697. -- 对方玩家的牌长度,因为只有2人,所以直接取非自己的即可。
  698. for _,v in pairs(app.room.roomInfo.memberList) do
  699. if v.nUserId ~= app.room:getMyUserId() then
  700. otherHandCards = table.nums(v.handCards)
  701. otherViewId = app.room:getViewIdByUserId(v.nUserId)
  702. end
  703. end
  704. self:isShowMiddleTips(true, app.room.roomInfo.nRangTotalNums)
  705. -- 因为删手牌是正序,所以这里使用逆序,避免删除掉
  706. for i = 1, tonumber(app.room.roomInfo.nRangTotalNums) do
  707. -- handCards[i]:setColor(cc.c3b(0xb3, 0xaa, 0xaa))--DOWN_COLOR
  708. self.handCards[''..otherViewId][i].isGrey = true
  709. self.handCards[''..otherViewId][i]:setGreyEnabled(true)
  710. end
  711. -- else
  712. -- self:isShowMiddleTips(false)
  713. -- end
  714. end
  715. --小局结算阶段
  716. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.ROUND_OVER then
  717. --服务器会推送一个结算消息
  718. --恢复最后一手出牌
  719. local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()]
  720. if myMemberInfo.nPlayerFlag == 0 then
  721. self:setOutCardsVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.lastUserId), { cards = app.room.roomInfo.lastCards, opType = app.room.roomInfo.lastCardType })
  722. end
  723. end
  724. --显示底牌和底分炸弹情况
  725. if app.room:checkUserIDIsInTable(app.room.roomInfo.nBankerId) and table.nums(app.room.roomInfo.bankerCards) > 0 then
  726. self:setBankerCardsVisible(true, app.room.roomInfo.bankerCards)
  727. else
  728. local bankCards = {{card = 0}, {card = 0}, {card = 0}}
  729. self:setBankerCardsVisible(true, bankCards)
  730. end
  731. --是否有人发起解散
  732. self:judgeDissmiss()
  733. end
  734. end
  735. function RoomView_ERDouDiZhu:setXiaoJuVisible(bVisible, data)
  736. if self.XiaoJuView then
  737. --显示
  738. self.XiaoJuView:setVisible(bVisible)
  739. end
  740. if bVisible then
  741. --显示玩家数据
  742. for _,v in pairs(data.memberList) do
  743. local viewId = app.room:getViewIdByUserId(v.nUserId)
  744. --显示剩余手牌
  745. if v.nUserId ~= app.room:getMyUserId() and v.nUserId ~= data.nWinId then
  746. self:setOutCardsVisible(true, viewId, { cards = v.handCards, maxLen = 10 })
  747. end
  748. --刷新分数
  749. self.PlayerView:updateScore(viewId, v.nTotalScore)
  750. end
  751. --显示小局结算
  752. if not self.XiaoJuView then
  753. function xiaYiJu()
  754. if app.room.roomInfo.isGameOver == 1 then
  755. -- self:goToHall()
  756. self:showDaJu(app.room.roomInfo._GameOverInfo)
  757. else
  758. self.ui:sendMsg(app.room, "callReadyRequest")
  759. end
  760. end
  761. self.XiaoJuView = import("pk_erdoudizhu.luaScript.Views.Room.RoomXiaoJuView_ERDouDiZhu"):new(xiaYiJu)
  762. self.ui.Items.Layout_XiaoJu:addChild(self.XiaoJuView)
  763. end
  764. --更新界面数据
  765. self.XiaoJuView:updateView(data)
  766. end
  767. end
  768. function RoomView_ERDouDiZhu:judgeDissmiss()
  769. local roomInfo = app.room.roomInfo
  770. --解散状态
  771. local uid = 0
  772. local isDismiss = false
  773. for k,v in pairs(roomInfo.memberList) do
  774. local viewId = app.room:getViewIdByUserId(k)
  775. --记录玩家解散状态 0:初始状态, 1:发起解散 2: 同意解散 3:不同意解散
  776. app.room.dismissInfo[k] = v.disbandStatus
  777. --有人发起解散时才显示解散界面
  778. if v.disbandStatus == 1 then
  779. isDismiss = true
  780. uid = k
  781. end
  782. end
  783. --有人发起解散时才显示解散界面
  784. if isDismiss then
  785. local memberList = {}
  786. for nUserId,memberInfo in pairs(roomInfo.memberList) do
  787. if app.room:checkUserIDIsInTable(nUserId) then
  788. memberList[nUserId] = memberInfo
  789. memberList[nUserId].nDisbandStatus = memberInfo.disbandStatus
  790. end
  791. end
  792. local view = import("luaScript.Views.Room.RoomDismissView"):new(uid, memberList, roomInfo.nDismissStateTime)
  793. view:setAnchorPoint(cc.p(0.5, 0.5))
  794. app:showWaitDialog(view)
  795. end
  796. end
  797. function RoomView_ERDouDiZhu:goToHall()
  798. app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.ERDouDiZhu))
  799. end
  800. function RoomView_ERDouDiZhu:leaveRoomRequest()
  801. app.room.roomInfo.bQuitRoom = true
  802. self.ui:sendMsg(app.room, "callLeaveRequest")
  803. end
  804. -- 服务器广播玩家数据发生变化
  805. function RoomView_ERDouDiZhu:onGpsChangeResponse(data)
  806. logD("RoomView_ERDouDiZhu:onGpsChangeResponse()")
  807. if not data or not data.nUserId then
  808. return
  809. end
  810. local nUserId = data.nUserId
  811. logD("RoomView_ERDouDiZhu:onGpsChangeResponse()", tostring(nUserId))
  812. self:checkGpsDistance(nUserId)
  813. end
  814. -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新
  815. function RoomView_ERDouDiZhu:checkMyGpsNeedUpdate()
  816. logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate()")
  817. local nMyUserId = app.user.loginInfo.uid
  818. local myMemberInfo = app.room.roomInfo.memberList[nMyUserId]
  819. if myMemberInfo then
  820. local userInfo = json.decode(myMemberInfo.userInfo)
  821. if userInfo then
  822. local gpsInfo = userInfo.gpsInfo
  823. local isNewest = app.user:isGpsInfoNewest(gpsInfo)
  824. logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest))
  825. if not isNewest then
  826. app.room:onGpsChangeRequest()
  827. else
  828. logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() gpsInfo is newest")
  829. end
  830. else
  831. logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() userInfo is nil")
  832. end
  833. else
  834. logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() myMemberInfo is nil")
  835. end
  836. end
  837. -- 更新所有玩家的信息到GPS组件
  838. function RoomView_ERDouDiZhu:updateAllGpsInfo()
  839. local userInfoList = {}
  840. for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do
  841. local nSeatId = memberInfo.nSeatId
  842. local userInfo = memberInfo.userInfo
  843. if userInfo then
  844. userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
  845. end
  846. end
  847. if self.gpsComponent then
  848. self.gpsComponent:updateUserInfos(userInfoList)
  849. end
  850. end
  851. -- 检测玩家与其他玩家之间的距离
  852. -- 如果不传参数,则检测所有玩家相互之间的距离
  853. function RoomView_ERDouDiZhu:checkGpsDistance(curUserId)
  854. if app.room.roomInfo.nGameStartCount > 0 then
  855. return
  856. end
  857. self:updateAllGpsInfo()
  858. if self.gpsComponent then
  859. self.gpsComponent:checkGpsDistance(curUserId)
  860. end
  861. end
  862. -- 显示GPS界面
  863. function RoomView_ERDouDiZhu:showGpsView()
  864. logD("RoomView_ERDouDiZhu:showGpsView()")
  865. local isGameStart = app.room.roomInfo.nGameStartCount > 0
  866. local exitRoomCallback = function()
  867. self.ui:sendMsg(app.room, "callLeaveRequest")
  868. end
  869. local dismissCallback = function()
  870. app.room:requestDismissRoom(1)
  871. end
  872. self:updateAllGpsInfo()
  873. if self.gpsComponent then
  874. self.gpsComponent:showGpsView(3, isGameStart, exitRoomCallback, dismissCallback)
  875. end
  876. end
  877. -- 玩家收到解散房间的请求
  878. function RoomView_ERDouDiZhu:onDismissResponse(event)
  879. logE("onDismissResponse() response = ", event.response)
  880. if not event or not event.response then
  881. return
  882. end
  883. local response = event.response
  884. --当前时间
  885. app.room.roomInfo.nDismissStateTime = response.timeLeft
  886. --总的时间,服务器没发解散总时间来。那么就和一开始收到的解散剩余时间一致
  887. app.room.roomInfo.nDismissToTalTime = response.timeLeft
  888. --显示解散(此标志会影响闹钟时间会冻住)
  889. app.room.roomInfo.nShowDismiss = true
  890. if response.operateType == 1 then
  891. local memberList = {}
  892. for nUserId,memberInfo in pairs(app.room.roomInfo.memberList) do
  893. if app.room:checkUserIDIsInTable(nUserId) then
  894. memberList[nUserId] = memberInfo
  895. end
  896. end
  897. if response.memberList ~= nil then
  898. for k,v in pairs(response.memberList) do
  899. if v.dismissState == 1 then
  900. local view = import("luaScript.Views.Room.RoomDismissView"):new(v.nUserId, memberList, app.room.roomInfo.nDismissStateTime)
  901. view:setAnchorPoint(cc.p(0.5, 0.5))
  902. app:showWaitDialog(view)
  903. return
  904. end
  905. end
  906. else
  907. local view = import("luaScript.Views.Room.RoomDismissView"):new(response.nUserId, memberList, app.room.roomInfo.nDismissStateTime)
  908. view:setAnchorPoint(cc.p(0.5, 0.5))
  909. app:showWaitDialog(view)
  910. end
  911. else
  912. local memberStatus={}
  913. if response.memberList ~= nil then
  914. for k,v in pairs(response.memberList) do
  915. table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
  916. end
  917. else
  918. table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
  919. end
  920. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus})
  921. end
  922. end
  923. function RoomView_ERDouDiZhu:addCallBack(callback)
  924. table.insert(self.callbackQueue, callback)
  925. logE(" #self.callbackQueue:".. #self.callbackQueue)
  926. --高延迟情况下,执行快速播放,15条是没有标准,根据实际调整的
  927. --if #self.callbackQueue >= 15 then
  928. --cc.Director:getInstance():getScheduler():setTimeScale(5.0)
  929. --else
  930. cc.Director:getInstance():getScheduler():setTimeScale(1.0)
  931. --end
  932. local function runFunc()
  933. log("2000000000 - runNextFunc() size = ", #self.callbackQueue )
  934. if #self.callbackQueue <= 0 then
  935. self.callbackRunning = false
  936. return
  937. end
  938. local func = self.callbackQueue[1]
  939. table.remove(self.callbackQueue,1)
  940. self.callbackRunning = true
  941. func(function()
  942. self.callbackRunning = false
  943. runFunc()
  944. end)
  945. end
  946. log("self.callbackRunning:",self.callbackRunning)
  947. if not self.callbackRunning then
  948. runFunc()
  949. end
  950. end
  951. function RoomView_ERDouDiZhu:onChangeTable(data)
  952. self:setTableImg(data.idx)
  953. end
  954. function RoomView_ERDouDiZhu:onChangeLanguage(data)
  955. local idx = data.idx
  956. if self.messageView then
  957. self.messageView:setLanguage(idx == defs.LANGUAGE_TYPE.PU_TONG_HUA)
  958. end
  959. end
  960. function RoomView_ERDouDiZhu:setTableImg(idx)
  961. --桌布
  962. self.ui.Items.ImageView_bg:loadTexture(defs.BG_Img[idx] and defs.BG_Img[idx] or defs.BG_Img[1])
  963. self:initLogo()
  964. end
  965. function RoomView_ERDouDiZhu:initLogo()
  966. if tolua.isnull(self.ui.Items.ImageView_Logo) then
  967. return
  968. end
  969. if not (type(getSubGameRoomLogo) == 'function') then
  970. self.ui.Items.ImageView_Logo:setVisible(false)
  971. return
  972. end
  973. local roomInfo = app.room.roomInfo
  974. local gameInfo = json.decode(roomInfo.strGameInfo or "")
  975. local gamerule = tonumber(gameInfo.gamerule or 1)
  976. roomInfo.gameId = roomInfo.gameId or app.gameId or 0
  977. local logofile = getSubGameRoomLogo(roomInfo.gameId, gamerule)
  978. if logofile then
  979. self.ui.Items.ImageView_Logo:loadTexture(logofile)
  980. self.ui.Items.ImageView_Logo:setVisible(true);
  981. else
  982. self.ui.Items.ImageView_Logo:setVisible(false);
  983. end
  984. --self.ui.Items.ImageView_Logo:setVisible(false)
  985. end
  986. function RoomView_ERDouDiZhu:ontSetPropEnabled(event)
  987. if self.messageView then
  988. self.messageView:setPropEnabled(event.value == 1)
  989. end
  990. end
  991. function RoomView_ERDouDiZhu:onSetVoiceEnabled(event)
  992. if self.messageView then
  993. self.messageView:setVoiceEnabled(event.value == 1)
  994. end
  995. end
  996. function RoomView_ERDouDiZhu:onNormalChangePoker(data)
  997. if data.idx > 2 and data.idx < 1 then
  998. return
  999. end
  1000. local temp = {
  1001. "pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards_old.plist",
  1002. "pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards.plist",
  1003. }
  1004. -- 删除缓存重新添加缓存
  1005. for i, v in ipairs(temp) do
  1006. cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile(v)
  1007. end
  1008. loadSpriteFrameFile(temp[data.idx])
  1009. -- 刷新当前手牌
  1010. if self.handCards then
  1011. for _, v in pairs(app.room.roomInfo.memberList) do
  1012. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1013. local handCardLayout = self.handCards["" .. viewId]
  1014. if handCardLayout then
  1015. for i, v in ipairs(handCardLayout) do
  1016. if v.refreshCard then
  1017. v:refreshCard()
  1018. end
  1019. end
  1020. self:rankHandCards(viewId, false)
  1021. end
  1022. end
  1023. end
  1024. -- 刷新当前出的牌
  1025. for _, v in pairs(app.room.roomInfo.memberList) do
  1026. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1027. local outCardLayout = self.ui.Items["Layout_Out_" .. viewId]
  1028. if outCardLayout then
  1029. for _, card in ipairs(outCardLayout:getChildren()) do
  1030. if card.refreshCard then
  1031. card:refreshCard()
  1032. end
  1033. end
  1034. end
  1035. end
  1036. end
  1037. --自己的视图ID
  1038. function RoomView_ERDouDiZhu:getMeViewId()
  1039. return defs.VIEW_ID.MY_VIEW_ID
  1040. end
  1041. function RoomView_ERDouDiZhu:cmd_0x8104_Resp(data)
  1042. function cmd_0x8104_RespEx(onEnd)
  1043. playVoice("pk_erdoudizhu/res/sound/doudizhu_common_began.ogg")
  1044. self.PlayerView:setLeftNumVisible(true, -1, 17)
  1045. self:setXiaoJuVisible(false, nil)
  1046. --更新局数
  1047. self:updateGameNums()
  1048. --更新按钮状态
  1049. self:updateButtons()
  1050. --隐藏所有准备
  1051. self:setAllReadyVisible(false)
  1052. -- 玩家托管状态还原
  1053. self:refreshPlayerAIStatus()
  1054. -- 显示左边内容
  1055. local bankCards = {{card = 0}, {card = 0}, {card = 0}}
  1056. self:setBankerCardsVisible(true, bankCards)
  1057. if onEnd then
  1058. onEnd()
  1059. end
  1060. end
  1061. self:addCallBack(cmd_0x8104_RespEx)
  1062. end
  1063. --显隐所有准备
  1064. function RoomView_ERDouDiZhu:setAllReadyVisible(bVisible)
  1065. for k,v in pairs(app.room.roomInfo.memberList) do
  1066. self.PlayerView:setReadyVisible(bVisible, app.room:getViewIdByUserId(v.nUserId))
  1067. end
  1068. end
  1069. function RoomView_ERDouDiZhu:cmd_0x8105_Resp(data)
  1070. function cmd_0x8105_RespEx(onEnd)
  1071. --加倍阶段,隐藏叫分相关界面
  1072. if data.response.nStatus == defs.GAME_STATUS.ASK_BEI then
  1073. self:setAskLoardVisible(false)
  1074. for _,v in pairs(app.room.roomInfo.memberList) do
  1075. self.PlayerView:setTipsVisibleExcept({'tips_jiaofen'}, app.room:getViewIdByUserId(v.nUserId))
  1076. end
  1077. -- 让牌阶段
  1078. elseif data.response.nStatus == defs.GAME_STATUS.ASK_RANG then
  1079. self:setAskLoardVisible(false)
  1080. for _,v in pairs(app.room.roomInfo.memberList) do
  1081. self.PlayerView:setTipsVisibleExcept({}, app.room:getViewIdByUserId(v.nUserId))
  1082. end
  1083. --打牌阶段,隐藏加倍相关界面
  1084. elseif data.response.nStatus == defs.GAME_STATUS.PLAYING then
  1085. self:setAskBeiVisible(false)
  1086. for _,v in pairs(app.room.roomInfo.memberList) do
  1087. -- self.PlayerView:setTipsVisible("tips_jiabei", false, app.room:getViewIdByUserId(v.nUserId))
  1088. self.PlayerView:setTipsVisibleExcept({}, app.room:getViewIdByUserId(v.nUserId))
  1089. end
  1090. -- 若处理打牌中,并且有让牌值,则置灰
  1091. if not app.room.roomInfo.isRecord then
  1092. for _, v in pairs(app.room.roomInfo.memberList) do
  1093. if v.nUserId ~= app.room:getMyUserId() and v.nUserId ~= app.room.roomInfo.nBankerId then
  1094. local vId = app.room:getViewIdByUserId(v.nUserId)
  1095. local handCards = self.handCards["" .. vId]
  1096. local cardNums = table.nums(handCards)
  1097. for i = 1, tonumber(app.room.roomInfo.nRang) do
  1098. -- handCards[i]:setColor(cc.c3b(0xb3, 0xaa, 0xaa))--DOWN_COLOR
  1099. handCards[i].isGrey = true
  1100. handCards[i]:setGreyEnabled(true)
  1101. end
  1102. end
  1103. end
  1104. end
  1105. end
  1106. if data.response.nStatus == defs.GAME_STATUS.SENDCARDS then
  1107. self.PlayerView:setLeftNumVisible(true, -1, 17)
  1108. end
  1109. -- 显示中间庄家让x 所有人
  1110. if app.room.roomInfo.nStatus then
  1111. if app.room.roomInfo.nStatus >= defs.GAME_STATUS.ASK_LOARD and app.room.roomInfo.nStatus <= defs.GAME_STATUS.ASK_RANG then
  1112. self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRang or 0)
  1113. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.PLAYING and app.room.roomInfo.nBankerId == app.room:getMyUserId() then
  1114. self:isShowMiddleTips(true, app.room.roomInfo.nRang)
  1115. else
  1116. self:isShowMiddleTipsForAll(false)
  1117. end
  1118. end
  1119. if onEnd then
  1120. onEnd()
  1121. end
  1122. end
  1123. self:addCallBack(cmd_0x8105_RespEx)
  1124. end
  1125. function RoomView_ERDouDiZhu:getCardType(card)
  1126. return self._pokerUtil:getCardType(card)
  1127. end
  1128. function RoomView_ERDouDiZhu:getCardValue(card)
  1129. return self._pokerUtil:getCardValue(card)
  1130. end
  1131. function RoomView_ERDouDiZhu:setCardUp(card)
  1132. card.isUp = true
  1133. self.selectCards["" .. card.cardNum] = card
  1134. -- card:setPosition(cc.pAdd(card.tarPos, cc.p(0, 35)))
  1135. -- 抬起动画
  1136. card:stopAllActions()
  1137. local moveTo = cc.MoveTo:create(Card_Move_Up_Down_Time, cc.pAdd(card.tarPos, cc.p(0, 28)))
  1138. card:runAction(moveTo)
  1139. end
  1140. function RoomView_ERDouDiZhu:setCardDown(card)
  1141. card.isUp = false
  1142. -- card:setPosition(card.tarPos)
  1143. -- 下放动画
  1144. card:stopAllActions()
  1145. local moveTo = cc.MoveTo:create(Card_Move_Up_Down_Time, card.tarPos)
  1146. card:runAction(moveTo)
  1147. end
  1148. function RoomView_ERDouDiZhu:handCardItemRegisterTouchEvent(handCard)
  1149. local nomalColor = cc.c3b(255,255,255)
  1150. local selectColor = cc.c3b(200,200,200)
  1151. function onTouchBegan(touch, event)
  1152. local target = event:getCurrentTarget()
  1153. local locationInNode = target:convertToNodeSpace(touch:getLocation())
  1154. local s = target:getContentSize()
  1155. local rect = cc.rect(0, 0, s.width, s.height)
  1156. if cc.rectContainsPoint(rect, locationInNode) then
  1157. self.touchBeganPos = touch:getLocation()
  1158. target:setColor(selectColor)
  1159. target.isHit = true
  1160. return true
  1161. else
  1162. return false
  1163. end
  1164. end
  1165. function onTouchMoved(touch, event)
  1166. local touchMovePos = touch:getLocation()
  1167. local direction = touchMovePos.x - self.touchBeganPos.x
  1168. local handCards = self.handCards["" .. self:getMeViewId()]
  1169. --灵敏度
  1170. if math.abs(direction) < 5 then
  1171. return
  1172. end
  1173. if handCards then
  1174. for k,v in ipairs(handCards) do
  1175. local needContain = true
  1176. if v.isHit then
  1177. local locationInWorld = v:getParent():convertToWorldSpace(v:getPosition())
  1178. if direction > 0 then
  1179. if touchMovePos.x > locationInWorld.x - v:getContentSize().width / 2 + (v:getContentSize().width - self.handCardDif) then
  1180. needContain = false
  1181. end
  1182. else
  1183. if touchMovePos.x < locationInWorld.x - v:getContentSize().width / 2 then
  1184. needContain = false
  1185. end
  1186. end
  1187. end
  1188. if needContain then
  1189. local cardSize = v:getContentSize()
  1190. local locationInNode = v:convertToNodeSpace(touch:getLocation())
  1191. local rectEx = cc.rect(0, 0, cardSize.width - self.handCardDif, cardSize.height)
  1192. if cc.rectContainsPoint(rectEx, locationInNode) then
  1193. v:setColor(selectColor)
  1194. v.isHit = true
  1195. else
  1196. v:setColor(nomalColor)
  1197. v.isHit = false
  1198. end
  1199. end
  1200. end
  1201. end
  1202. end
  1203. function onTouchEnded(touch, event)
  1204. local handCards = self.handCards["" .. self:getMeViewId()]
  1205. if handCards then
  1206. -- for k,v in ipairs(handCards) do
  1207. -- if v.isHit then
  1208. -- if v.isUp then
  1209. -- self:setCardDown(v)
  1210. -- else
  1211. -- self:setCardUp(v)
  1212. -- end
  1213. -- end
  1214. -- v:setColor(nomalColor)
  1215. -- v.isHit = false
  1216. -- end
  1217. local isAllNormal = true
  1218. for _,card in pairs(handCards) do
  1219. if card then
  1220. if card.isUp then
  1221. isAllNormal = false
  1222. break
  1223. end
  1224. end
  1225. end
  1226. local selectCards = {}
  1227. for k,card in ipairs(handCards) do
  1228. if card.isHit then
  1229. table.insert(selectCards, card.cardNum)
  1230. end
  1231. end
  1232. -- 过滤选择的牌(主动出牌)
  1233. if isAllNormal then
  1234. if #self.lastData.cards <= 0 then
  1235. if self._pokerUtil and self._pokerUtil.getCardInSelectCard then
  1236. selectCards = self._pokerUtil:getCardInSelectCard(selectCards)
  1237. end
  1238. end
  1239. end
  1240. for i, v in ipairs(selectCards) do
  1241. local node = self:getCardNodeByCardValue(v)
  1242. if node then
  1243. if node.isUp then
  1244. self:setCardDown(node)
  1245. else
  1246. self:setCardUp(node)
  1247. end
  1248. node:setColor(nomalColor)
  1249. node.isHit = false
  1250. end
  1251. end
  1252. for i, card in ipairs(handCards) do
  1253. if card.isHit then
  1254. card:setColor(nomalColor)
  1255. card.isHit = false
  1256. end
  1257. end
  1258. end
  1259. end
  1260. -- 创建一个事件监听器
  1261. local listener = cc.EventListenerTouchOneByOne:create()
  1262. --设置穿透属性
  1263. listener:setSwallowTouches(true)
  1264. --添加事件和回调
  1265. listener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN)
  1266. listener:registerScriptHandler(onTouchMoved, cc.Handler.EVENT_TOUCH_MOVED)
  1267. listener:registerScriptHandler(onTouchEnded, cc.Handler.EVENT_TOUCH_ENDED)
  1268. -- 得到事件派发器
  1269. local eventDispatcher = self:getEventDispatcher()
  1270. -- 将监听器注册到派发器中
  1271. eventDispatcher:addEventListenerWithSceneGraphPriority(listener, handCard)
  1272. end
  1273. function RoomView_ERDouDiZhu:initHandCardItem(card, viewId)
  1274. local switchEx = {}
  1275. local cardType = self:getCardType(card)
  1276. local cardValue = self:getCardValue(card)
  1277. local scaleEx = 0.35
  1278. local frameName = 'ddz_cards_%d_%d.png'
  1279. if card == 0 then
  1280. frameName = 'ddz_cards_0.png'
  1281. end
  1282. switchEx["1"] = function()
  1283. -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源
  1284. local card = cc.Sprite:createWithSpriteFrameName(string.format(frameName, cardType, cardValue)) -- 新资源
  1285. card:setAnchorPoint(cc.p(1, 1))
  1286. card:setScale(scaleEx)
  1287. return card
  1288. end
  1289. switchEx["2"] = function()
  1290. -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源
  1291. -- local card = cc.Sprite:createWithSpriteFrameName(string.format(frameName, cardType, cardValue)) -- 新资源
  1292. -- 使用iamgeview,使得可以置灰
  1293. local card = cc.ImageView:create()
  1294. card:loadTexture(string.format(frameName, cardType, cardValue), 1)
  1295. -- card:setAnchorPoint(cc.p(1, 1))
  1296. card:setScale(scaleEx)
  1297. return card
  1298. end
  1299. switchEx["3"] = function()
  1300. -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源
  1301. local card = cc.Sprite:createWithSpriteFrameName(string.format(frameName, cardType, cardValue)) -- 新资源
  1302. card:setAnchorPoint(cc.p(0, 1))
  1303. card:setScale(scaleEx)
  1304. return card
  1305. end
  1306. switchEx["4"] = function()
  1307. -- return cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源
  1308. return cc.Sprite:createWithSpriteFrameName(string.format(frameName, cardType, cardValue)) -- 新资源
  1309. -- local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", cardType, cardValue)) -- 新资源
  1310. -- card:setScale(scaleEx)
  1311. -- return card
  1312. end
  1313. local initFunc = switchEx["" .. viewId]
  1314. if initFunc then
  1315. local imageCard = nil
  1316. local imageCard = initFunc()
  1317. if imageCard then
  1318. imageCard.cardValue = cardValue -- 牌具体值1~13
  1319. imageCard.cardType = cardType -- 牌类型
  1320. imageCard.cardNum = card -- 牌的标准值
  1321. imageCard.refreshCard = function() -- 刷新卡牌
  1322. -- if card > 0 then
  1323. -- local cardPng = string.format("ddz_cards_%d_%d.png", cardType, cardValue)
  1324. local cardPng = string.format(frameName, cardType, cardValue)
  1325. if imageCard.setSpriteFrame then
  1326. imageCard:setSpriteFrame(cardPng)
  1327. elseif imageCard.loadTexture then
  1328. imageCard:loadTexture(string.format(frameName, cardType, cardValue), 1)
  1329. end
  1330. if imageCard.bankerMark then
  1331. local size = imageCard:getContentSize()
  1332. local offsetX, offsetY = self:getBankTagOffset()
  1333. imageCard.bankerMark:setPosition(cc.p(size.width * 0.72 + offsetX, size.height * 0.78 + offsetY))
  1334. end
  1335. -- end
  1336. end
  1337. if viewId == self:getMeViewId() then
  1338. self:handCardItemRegisterTouchEvent(imageCard)
  1339. end
  1340. -- 设置为庄家牌
  1341. if self:checkIsBankCard(imageCard.cardNum, viewId) then
  1342. imageCard.isBankCard = true
  1343. end
  1344. end
  1345. logE("initHandCardItem viewId " .. viewId .. "imageCard " .. imageCard.cardNum)
  1346. return imageCard
  1347. end
  1348. end
  1349. function RoomView_ERDouDiZhu:rankHandCards(viewId, ani)
  1350. local childs = self.handCards["" .. viewId]
  1351. if childs then
  1352. local isBanker = app.room.roomInfo.nBankerId and app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId
  1353. local childsNum = table.nums(childs)
  1354. local xDiff = -30 --x轴调整
  1355. local getPokerChoose = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose
  1356. local cardDif = (getPokerChoose == 1) and 96 or 110
  1357. if childsNum > 17 then -- 使得扑克超过17张的话,让扑克牌组挤一点
  1358. self.handCardDif = cardDif + 3 * (childsNum - 17)
  1359. else
  1360. self.handCardDif = cardDif
  1361. end
  1362. for k,v in ipairs(childs) do
  1363. local maxLen = 20
  1364. local kEx = tonumber(k)
  1365. local floor = math.floor(kEx / maxLen)
  1366. local mod = kEx % maxLen + (kEx >= maxLen and 1 or 0)
  1367. local childScale = v:getScale()
  1368. local childSize = v:getContentSize()
  1369. if viewId == defs.VIEW_ID.MY_VIEW_ID then
  1370. v.tarPos = cc.p(xDiff + (kEx - childsNum / 2) * (childSize.width - self.handCardDif) * childScale.x, childSize.height / 2 * childScale.y)
  1371. elseif viewId == defs.VIEW_ID.TOP_VIEW_ID then
  1372. --设置zOder
  1373. -- v:setLocalZOrder(maxLen * floor - kEx)
  1374. -- v.tarPos = cc.p((-1) * mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor)
  1375. v.tarPos = cc.p(xDiff + (kEx - childsNum / 2 + 1) * (childSize.width - cardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5)
  1376. elseif viewId == defs.VIEW_ID.LEFT_VIEW_ID then
  1377. v.tarPos = cc.p(mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor)
  1378. elseif viewId == defs.VIEW_ID.RIGHT_VIEW_ID then
  1379. v:setLocalZOrder(maxLen * floor - kEx)
  1380. v.tarPos = cc.p((-1) * mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor)
  1381. end
  1382. --庄家标识
  1383. if isBanker then
  1384. if v.isBankCard then
  1385. if v.cardNum ~= 0 then
  1386. if v.bankerMark then
  1387. v.bankerMark:setVisible(true)
  1388. else
  1389. v.bankerMark = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_bankerCardMark.png"))
  1390. local offsetX, offsetY = self:getBankTagOffset()
  1391. if app.room.roomInfo.isRecord then
  1392. if viewId ~= self:getMeViewId() then
  1393. offsetY = offsetY - 1.5
  1394. end
  1395. end
  1396. v.bankerMark:setPosition(cc.p(childSize.width * 0.72 + offsetX, childSize.height * 0.78 + offsetY))
  1397. v:addChild(v.bankerMark)
  1398. end
  1399. end
  1400. end
  1401. end
  1402. if ani then
  1403. v:stopAllActions()
  1404. v:runAction(cc.MoveTo:create(0.15, v.tarPos))
  1405. else
  1406. v:setPosition(v.tarPos)
  1407. end
  1408. end
  1409. end
  1410. end
  1411. function RoomView_ERDouDiZhu:initHandCards(handCards, viewId)
  1412. local handLayout = self.ui.Items["Layout_Hand_" .. viewId]
  1413. --手牌
  1414. self.handCards = self.handCards or {}
  1415. --选中的牌
  1416. self.selectCards = self.selectCards or {}
  1417. if handLayout then
  1418. handLayout:removeAllChildren()
  1419. --排序手牌
  1420. table.sort(handCards.Datas, function(a, b)
  1421. local cardValueA = self:getCardValue(a.card)
  1422. local cardValueB = self:getCardValue(b.card)
  1423. return cardValueA > cardValueB or cardValueA == cardValueB and self:getCardType(a.card) > self:getCardType(b.card)
  1424. end)
  1425. for k,v in ipairs(handCards.Datas) do
  1426. local imageCard = self:initHandCardItem(v.card, viewId)
  1427. if imageCard then
  1428. handLayout:addChild(imageCard)
  1429. end
  1430. end
  1431. self.handCards["" .. viewId] = handLayout:getChildren()
  1432. end
  1433. self:rankHandCards(viewId)
  1434. end
  1435. function RoomView_ERDouDiZhu:fapaiAni(onEnd)
  1436. self._isCanClickBg = false
  1437. local handCards = self.handCards["" .. self:getMeViewId()]
  1438. if not handCards then
  1439. logE("RoomView_ERDouDiZhu fapaiAni error")
  1440. if onEnd then
  1441. onEnd()
  1442. end
  1443. end
  1444. for k,v in ipairs(handCards) do
  1445. v:setPosition(cc.pAdd(v.tarPos, cc.p(1280, 0)))
  1446. v:runAction(
  1447. cc.Sequence:create(
  1448. cc.DelayTime:create(0.03 * tonumber(k)),
  1449. cc.MoveTo:create(0, v.tarPos),
  1450. cc.CallFunc:create(function()
  1451. --playVoice("pk_erdoudizhu/res/sound/doudizhu_common_fapai.ogg")
  1452. if tonumber(k) == table.nums(handCards) then
  1453. self._isCanClickBg = true
  1454. if onEnd then
  1455. onEnd()
  1456. end
  1457. end
  1458. end)
  1459. )
  1460. )
  1461. end
  1462. end
  1463. function RoomView_ERDouDiZhu:cmd_0x8106_Resp(data)
  1464. function cmd_0x8106_Resp(onEnd)
  1465. local handCards = app.room.roomInfo.memberList[data.response.nUserId].handCards
  1466. -- self:initHandCards(handCards, self:getMeViewId())
  1467. self:initHandCards(handCards, app.room:getViewIdByUserId(data.response.nUserId))
  1468. if data.response.nUserId == app.room:getMyUserId() then
  1469. if table.nums(handCards) == 20 then
  1470. local bankerCards = {}
  1471. for _,v in ipairs(app.room.roomInfo.bankerCards) do
  1472. table.insert(bankerCards, v.card)
  1473. end
  1474. --从手牌中上升地主牌
  1475. self:setHandCardsUp(self:getMeViewId(), bankerCards)
  1476. if onEnd then
  1477. onEnd()
  1478. end
  1479. else
  1480. self:fapaiAni(onEnd)
  1481. end
  1482. else
  1483. if onEnd then
  1484. onEnd()
  1485. end
  1486. end
  1487. end
  1488. self:addCallBack(cmd_0x8106_Resp)
  1489. end
  1490. -- 叫分界面/叫地主界面
  1491. function RoomView_ERDouDiZhu:setAskLoardVisible(bVisible, biJiao, nPlayMode)
  1492. -- 叫分模式
  1493. self.ui.Items.Layout_Ask_Loard_Mode_Score:setVisible(false)
  1494. self.ui.Items.Layout_Ask_Loard_Mode_DiZhu:setVisible(false)
  1495. if bVisible then
  1496. if nPlayMode == 1 then -- 叫地主
  1497. self.ui.Items.Layout_Ask_Loard_Mode_DiZhu:setVisible(true)
  1498. local curAskLoard = app.room.roomInfo.curAskLoard or 0
  1499. for i = 0, 1 do
  1500. local askLoardBtn = self.ui.Items["Button_Ask_Loard_D_" .. i]
  1501. if askLoardBtn then
  1502. if biJiao then
  1503. askLoardBtn:setEnabled(i == 1)
  1504. end
  1505. end
  1506. end
  1507. self.ui.Items.Layout_Ask_Loard_Mode_DiZhu_Buttons:requestDoLayout()
  1508. self.ui.Items.Layout_Ask_Loard_Mode_DiZhu_Buttons:doLayout()
  1509. elseif nPlayMode == 2 then -- 叫分
  1510. self.ui.Items.Layout_Ask_Loard_Mode_Score:setVisible(true)
  1511. local curAskLoard = app.room.roomInfo.curAskLoard or 0
  1512. for i = 0, 3 do
  1513. local askLoardBtn = self.ui.Items["Button_Ask_Loard_F_" .. i]
  1514. if askLoardBtn then
  1515. if biJiao then
  1516. askLoardBtn:setEnabled(i == 3)
  1517. else
  1518. askLoardBtn:setEnabled(not (i ~= 0 and i <= curAskLoard))
  1519. end
  1520. end
  1521. end
  1522. self.ui.Items.Layout_Ask_Loard_Mode_Score_Buttons:requestDoLayout()
  1523. self.ui.Items.Layout_Ask_Loard_Mode_Score_Buttons:doLayout()
  1524. end
  1525. end
  1526. end
  1527. -- 抢地主界面
  1528. function RoomView_ERDouDiZhu:setQiangVisible(bVisible)
  1529. self.ui.Items.Layout_Qiang:setVisible(bVisible)
  1530. end
  1531. -- 让牌界面
  1532. function RoomView_ERDouDiZhu:setRangVisible(bVisible, rangMaxCount)
  1533. self.ui.Items.Layout_Rang:setVisible(bVisible)
  1534. if bVisible then
  1535. for i = 0, 4 do
  1536. if i ~= 1 then
  1537. local rangLayout = self.ui.Items["Layout_Rang_" .. i]
  1538. if rangLayout then
  1539. rangLayout:setVisible(i <= rangMaxCount)
  1540. end
  1541. end
  1542. end
  1543. self.ui.Items.Layout_Rang_Buttons:requestDoLayout()
  1544. self.ui.Items.Layout_Rang_Buttons:doLayout()
  1545. end
  1546. end
  1547. function RoomView_ERDouDiZhu:setAskBeiVisible(bVisible)
  1548. self.ui.Items.Layout_Ask_Bei:setVisible(bVisible)
  1549. end
  1550. function RoomView_ERDouDiZhu:setOperationVisible(bVisible, opType)
  1551. self.ui.Items.Layout_Operation:setVisible(bVisible)
  1552. if bVisible then
  1553. -- opType: 0要不起(没有可压牌), 1可要可不要, 2必须出(轮到自己了)
  1554. if opType == 1 then
  1555. -- 这种风格是,全程没有变灰的按钮,直接就隐藏掉
  1556. self.ui.Items.Layout_Operation_BuChu:setVisible(bVisible)
  1557. self.ui.Items.Layout_Operation_TiShi:setVisible(bVisible)
  1558. self.ui.Items.Layout_Operation_ChuPai:setVisible(bVisible)
  1559. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(not bVisible)
  1560. -- 这种风格是,有变灰的按钮,不可点击,下面同理
  1561. --[[
  1562. self.ui.Items.Button_Operation_BuChu:setEnabled(bVisible)
  1563. self.ui.Items.Button_Operation_TiShi:setEnabled(bVisible)
  1564. self.ui.Items.Button_Operation_ChuPai:setEnabled(bVisible)
  1565. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false)
  1566. ]]
  1567. elseif opType == 2 then
  1568. self:setLastData()
  1569. self.ui.Items.Layout_Operation_BuChu:setVisible(not bVisible)
  1570. self.ui.Items.Layout_Operation_TiShi:setVisible(not bVisible) -- 轮到自己回合,提示按钮隐藏
  1571. self.ui.Items.Layout_Operation_ChuPai:setVisible(bVisible)
  1572. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(not bVisible)
  1573. --[[
  1574. self.ui.Items.Button_Operation_BuChu:setEnabled(not bVisible)
  1575. self.ui.Items.Button_Operation_TiShi:setEnabled(bVisible)
  1576. self.ui.Items.Button_Operation_ChuPai:setEnabled(bVisible)
  1577. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false)
  1578. ]]
  1579. else
  1580. self.ui.Items.Layout_Operation_BuChu:setVisible(not bVisible)
  1581. self.ui.Items.Layout_Operation_TiShi:setVisible(not bVisible)
  1582. self.ui.Items.Layout_Operation_ChuPai:setVisible(not bVisible)
  1583. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(bVisible)
  1584. --[[
  1585. self.ui.Items.Button_Operation_BuChu:setEnabled(bVisible)
  1586. self.ui.Items.Button_Operation_TiShi:setEnabled(not bVisible)
  1587. self.ui.Items.Button_Operation_ChuPai:setEnabled(not bVisible)
  1588. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false)
  1589. ]]
  1590. end
  1591. self.ui.Items.Layout_Operation_Buttons:requestDoLayout()
  1592. self.ui.Items.Layout_Operation_Buttons:doLayout()
  1593. --检测提示
  1594. self.tiShiCount = 1
  1595. local handCards = self.handCards["" .. self:getMeViewId()]
  1596. local handCardsValueTable = {} -- 玩家手牌值表
  1597. local lastDataValueTable = {} -- 上个牌数据值表
  1598. for i, v in pairs(handCards) do
  1599. table.insert(handCardsValueTable, v.cardNum)
  1600. end
  1601. for i, v in pairs(self.lastData.cards) do
  1602. table.insert(lastDataValueTable, v.cardNum)
  1603. end
  1604. -- 判断是否可以一手出完牌
  1605. if self._pokerUtil:checkIsCanOneOutCard(handCardsValueTable, lastDataValueTable) then
  1606. --self:setOperationVisible(false)
  1607. self:runAction(
  1608. cc.Sequence:create(
  1609. cc.DelayTime:create(0.5),
  1610. cc.CallFunc:create(function ()
  1611. self:setHandCardsUp(self:getMeViewId(), handCardsValueTable)
  1612. self:chuPai()
  1613. end)
  1614. )
  1615. )
  1616. end
  1617. -- 牌型提示
  1618. if self.ui.Items.Layout_Operation_TiShi:isVisible() then
  1619. self.weaveCardList = self:getTip(handCardsValueTable, lastDataValueTable)
  1620. end
  1621. end
  1622. end
  1623. function RoomView_ERDouDiZhu:setHandCardsUp(viewId, cards)
  1624. --下降所有牌
  1625. self:setAllHandCardDown(self:getMeViewId())
  1626. --上升指定牌
  1627. if self.handCards and cards then
  1628. local handCards = self.handCards["" .. viewId]
  1629. if handCards then
  1630. for k,v in ipairs(cards) do
  1631. for _,v2 in ipairs(handCards) do
  1632. if v == v2.cardNum then
  1633. self:setCardUp(v2)
  1634. end
  1635. end
  1636. end
  1637. end
  1638. end
  1639. end
  1640. function RoomView_ERDouDiZhu:setAllHandCardDown(viewId)
  1641. if self.handCards then
  1642. local handCards = self.handCards["" .. viewId]
  1643. if handCards then
  1644. for _,v in ipairs(handCards) do
  1645. self:setCardDown(v)
  1646. end
  1647. end
  1648. end
  1649. end
  1650. function RoomView_ERDouDiZhu:initGameButtons()
  1651. --桌面
  1652. self.ui.Items.ImageView_bg:registerClick(function()
  1653. --测试
  1654. --self:chuPai()
  1655. --self:tiShi()
  1656. --self:fapaiAni()
  1657. if not self._isCanClickBg then
  1658. return
  1659. end
  1660. --下降所有牌
  1661. self:setAllHandCardDown(self:getMeViewId())
  1662. end)
  1663. --叫分
  1664. self.ui.Items.Layout_Ask_Loard_Mode_Score:setVisible(false)
  1665. for i = 0, 3 do
  1666. local button = self.ui.Items["Button_Ask_Loard_F_" .. i]
  1667. if button then
  1668. button:registerClick(function()
  1669. playBtnEffect()
  1670. app.room:sendAskLoard(i)
  1671. end)
  1672. end
  1673. end
  1674. -- 叫地主按钮
  1675. self.ui.Items.Layout_Ask_Loard_Mode_DiZhu:setVisible(false)
  1676. for i = 0, 1 do
  1677. local button = self.ui.Items["Button_Ask_Loard_D_" .. i]
  1678. if button then
  1679. button:registerClick(function()
  1680. playBtnEffect()
  1681. app.room:sendAskLoard(i)
  1682. end)
  1683. end
  1684. end
  1685. -- 抢地主按钮
  1686. self.ui.Items.Layout_Qiang:setVisible(false)
  1687. for i = 0, 1 do
  1688. local button = self.ui.Items["Button_Qiang_" .. i]
  1689. if button then
  1690. button:registerClick(function()
  1691. playBtnEffect()
  1692. app.room:sendQiang(i)
  1693. end)
  1694. end
  1695. end
  1696. -- 让牌按钮
  1697. self.ui.Items.Layout_Rang:setVisible(false)
  1698. for i = 0, 4 do
  1699. if i ~= 1 then
  1700. local button = self.ui.Items["Button_Rang_" .. i]
  1701. if button then
  1702. button:registerClick(function()
  1703. playBtnEffect()
  1704. app.room:sendRang(i)
  1705. end)
  1706. end
  1707. end
  1708. end
  1709. --加倍
  1710. self.ui.Items.Layout_Ask_Bei:setVisible(false)
  1711. for i = 0, 1 do
  1712. local button = self.ui.Items["Button_Ask_Bei_" .. i]
  1713. if button then
  1714. button:registerClick(function()
  1715. playBtnEffect()
  1716. app.room:sendAskBei(i)
  1717. end)
  1718. end
  1719. end
  1720. --要不起,不出,提示,出牌
  1721. self.ui.Items.Layout_Operation:setVisible(false)
  1722. self.ui.Items.Button_Operation_YaoBuQi:registerClick(function()
  1723. playBtnEffect()
  1724. app.room:sendOperation({opType = 0, cards = {}})
  1725. end)
  1726. self.ui.Items.Button_Operation_BuChu:registerClick(function()
  1727. playBtnEffect()
  1728. app.room:sendOperation({opType = 0, cards = {}})
  1729. end)
  1730. self.ui.Items.Button_Operation_TiShi:registerClick(handler(self, self.tiShi))
  1731. self.ui.Items.Button_Operation_ChuPai:registerClick(handler(self, self.chuPai))
  1732. end
  1733. function RoomView_ERDouDiZhu:getCardsType(cards)
  1734. return self._pokerUtil:getCardsType(cards)
  1735. end
  1736. function RoomView_ERDouDiZhu:getTip(cards, lastData)
  1737. if cards and cards[1] and type(cards[1]) == 'userdata' then
  1738. logD('亲!现在调用getTip,cards数据是要传牌值,不是card节点啦!!!')
  1739. return
  1740. end
  1741. return self._pokerUtil:getTip(cards, lastData)
  1742. end
  1743. function RoomView_ERDouDiZhu:tiShi()
  1744. playBtnEffect()
  1745. if self.weaveCardList and table.nums(self.weaveCardList) > 0 then
  1746. function tiShiEx()
  1747. local weaveList = self.weaveCardList[self.tiShiCount]
  1748. if weaveList then
  1749. self:setHandCardsUp(self:getMeViewId(), weaveList)
  1750. self.tiShiCount = self.tiShiCount + 1
  1751. else
  1752. self.tiShiCount = 1
  1753. tiShiEx()
  1754. end
  1755. end
  1756. tiShiEx()
  1757. else
  1758. app.room:sendOperation({opType = 0, cards = {}})
  1759. end
  1760. end
  1761. function RoomView_ERDouDiZhu:chuPai()
  1762. playBtnEffect()
  1763. local handCards = self.handCards["" .. self:getMeViewId()]
  1764. if not handCards then
  1765. logE("RoomView_ERDouDiZhu chuPai error handCards is null")
  1766. end
  1767. --获取点中的牌
  1768. local cards = {}
  1769. local cardsEx = {}
  1770. for k,v in ipairs(handCards) do
  1771. if v:isVisible() and v.isUp then
  1772. table.insert(cards, v.cardNum)
  1773. table.insert(cardsEx, v)
  1774. end
  1775. end
  1776. --local typeEx = self:getCardsType(cardsEx)
  1777. --logE("RoomView_ERDouDiZhu chuPai type : " .. table.tostring(cardsEx))
  1778. logE("RoomView_ERDouDiZhu chuPai type : " .. table.tostring(cards))
  1779. app.room:sendOperation({opType = 1, cards = cards})
  1780. end
  1781. function RoomView_ERDouDiZhu:cmd_0x8108_Resp(data)
  1782. function cmd_0x8108_RespEx(onEnd)
  1783. --当前操作玩家
  1784. self.curViewId = app.room:getViewIdByUserId(data.response.nUserId)
  1785. --显示闹钟
  1786. self.PlayerView:setClockVisibel(true, self.curViewId, data.response.leftTime)
  1787. --显示叫分
  1788. if self.curViewId == self:getMeViewId() then
  1789. self:setAskLoardVisible(true, data.response.mustBanker == 1, data.response.nPlayMode)
  1790. end
  1791. if onEnd then
  1792. onEnd()
  1793. end
  1794. end
  1795. self:addCallBack(cmd_0x8108_RespEx)
  1796. end
  1797. function RoomView_ERDouDiZhu:cmd_0x8109_Resp(data)
  1798. function cmd_0x8109_RespEx(onEnd)
  1799. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1800. --隐藏叫分界面
  1801. self:setAskLoardVisible(false)
  1802. --隐藏闹钟
  1803. self.PlayerView:setClockVisibel(false, viewId)
  1804. --显示叫分/叫地主
  1805. local tips = ''
  1806. local soundTips = ''
  1807. if data.response.nPlayMode == 1 then
  1808. tips = 'tips_jiaodizhu'
  1809. soundTips = 'jiaodizhu'
  1810. else
  1811. tips = 'tips_jiaofen'
  1812. soundTips = 'jiaofen'
  1813. end
  1814. self.PlayerView:setTipsVisible(tips, true, viewId, {askLoard = data.response.askLoard})
  1815. --播放音效
  1816. Functions.playVoice(soundTips, data.response.askLoard, self.PlayerView:getPlayerData("sex", viewId))
  1817. if onEnd then
  1818. onEnd()
  1819. end
  1820. end
  1821. self:addCallBack(cmd_0x8109_RespEx)
  1822. end
  1823. function RoomView_ERDouDiZhu:setBankerAskLoard()
  1824. -- 隐藏叫分
  1825. do
  1826. self.ui.Items.Image_Score_Title:setVisible(false)
  1827. return
  1828. end
  1829. self.ui.Items.Text_AskLoard:setText(app.room.roomInfo.curAskLoard or 0)
  1830. end
  1831. function RoomView_ERDouDiZhu:setCurZhaDanNum()
  1832. -- 隐藏炸弹数
  1833. do
  1834. self.ui.Items.Image_Bomb_Title:setVisible(false)
  1835. return
  1836. end
  1837. self.ui.Items.Text_ZhaDan:setText(app.room.roomInfo.nBombs or 0)
  1838. end
  1839. function RoomView_ERDouDiZhu:setCurMultiple()
  1840. self.ui.Items.Text_BeiShu:setText(app.room.roomInfo.nMult or 0)
  1841. self.ui.Items.Layout_BeiShu_Info:setVisible(true)
  1842. end
  1843. function RoomView_ERDouDiZhu:setCurRang()
  1844. -- if Functions.getRangCount() <= 0 then
  1845. -- self.ui.Items.Layout_Rang_Info:setVisible(false)
  1846. -- return
  1847. -- end
  1848. self.ui.Items.Text_Rang:setText(app.room.roomInfo.nRang or 0)
  1849. self.ui.Items.Layout_Rang_Info:setVisible(true)
  1850. end
  1851. function RoomView_ERDouDiZhu:setCurDiPaiTypeAndMult()
  1852. local diType = app.room.roomInfo.diType or 0
  1853. local imgPath = 'pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/dipai_type/%s.png'
  1854. local imgMultPath = 'pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/dipai_type/doudizhu_mult_%s.png'
  1855. if diType > 0 then
  1856. if diType ~= defs.DI_TYPE.TYPE_TONGHUASHUN then -- 同花顺单独特殊处理
  1857. self.ui.Items.Layout_DiPai_Type_2:setVisible(false)
  1858. self.ui.Items.Layout_DiPai_Type_1:setVisible(true)
  1859. self.ui.Items.ImageView_DIPai_Type_1:loadTexture(string.format(imgPath, defs.DI_TYPE_IMAGE_PATH[diType]))
  1860. self.ui.Items.ImageView_DIPai_Type_Mult_1:loadTexture(string.format(imgMultPath, defs.DI_TYPE_MULT[diType]))
  1861. else
  1862. self.ui.Items.Layout_DiPai_Type_2:setVisible(true)
  1863. self.ui.Items.Layout_DiPai_Type_1:setVisible(true)
  1864. self.ui.Items.ImageView_DIPai_Type_1:loadTexture(string.format(imgPath, defs.DI_TYPE_IMAGE_PATH[defs.DI_TYPE.TYPE_TONGHUA]))
  1865. self.ui.Items.ImageView_DIPai_Type_Mult_1:loadTexture(string.format(imgMultPath, defs.DI_TYPE_MULT[defs.DI_TYPE.TYPE_TONGHUA]))
  1866. self.ui.Items.ImageView_DIPai_Type_2:loadTexture(string.format(imgPath, defs.DI_TYPE_IMAGE_PATH[defs.DI_TYPE.TYPE_SHUNZI]))
  1867. self.ui.Items.ImageView_DIPai_Type_Mult_2:loadTexture(string.format(imgMultPath, defs.DI_TYPE_MULT[defs.DI_TYPE.TYPE_SHUNZI]))
  1868. end
  1869. else
  1870. self.ui.Items.Layout_DiPai_Type_2:setVisible(false)
  1871. self.ui.Items.Layout_DiPai_Type_1:setVisible(false)
  1872. end
  1873. self.ui.Items.Layout_BankerInfo_1:requestDoLayout()
  1874. self.ui.Items.Layout_BankerInfo_1:doLayout()
  1875. end
  1876. function RoomView_ERDouDiZhu:setBankerCardsVisible(bVisible, bankerCards)
  1877. self.ui.Items.Layout_BankerInfo:setVisible(bVisible)
  1878. self.ui.Items.Layout_BankCard:setVisible(bVisible)
  1879. if bVisible then
  1880. for k,v in ipairs(bankerCards) do
  1881. local card = self.ui.Items["Image_BankerCard_" .. k]
  1882. if card then
  1883. -- card:loadTexture(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 旧资源
  1884. if v.card > 0 then
  1885. card:loadTexture(string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card)), 1) -- 新资源
  1886. elseif v.card == 0 then
  1887. card:loadTexture(string.format("ddz_cards_0.png"), 1) -- 新资源
  1888. end
  1889. end
  1890. end
  1891. self:setCurZhaDanNum()
  1892. self:setBankerAskLoard()
  1893. self:setCurMultiple()
  1894. self:setCurRang()
  1895. self:setCurDiPaiTypeAndMult()
  1896. end
  1897. self.ui.Items.Layout_BankerInfo_1:requestDoLayout()
  1898. self.ui.Items.Layout_BankerInfo_1:doLayout()
  1899. end
  1900. function RoomView_ERDouDiZhu:cmd_0x810a_Resp(data)
  1901. function cmd_0x810a_RespEx(onEnd)
  1902. self:runAction(
  1903. cc.Sequence:create(
  1904. cc.DelayTime:create(1.0),
  1905. cc.CallFunc:create(function()
  1906. local viewId = app.room:getViewIdByUserId(data.response.nBankerId)
  1907. --显示剩余手牌
  1908. self.PlayerView:setLeftNumVisible(true, viewId, 20)
  1909. --显示庄家
  1910. self.PlayerView:setBankerVisible(true, viewId)
  1911. --显示底牌和底分炸弹情况
  1912. self:setBankerCardsVisible(true, data.response.bankerCards)
  1913. -- 底牌显示的时候,即叫分结束,此时把叫分分数隐藏
  1914. self:setAllTipsVisible()
  1915. if onEnd then
  1916. onEnd()
  1917. end
  1918. end)
  1919. )
  1920. )
  1921. end
  1922. self:addCallBack(cmd_0x810a_RespEx)
  1923. end
  1924. function RoomView_ERDouDiZhu:setAllTipsVisible(bVisible)
  1925. for k,v in pairs(app.room.roomInfo.memberList) do
  1926. self.PlayerView:setTipsVisible("tips_jiaofen", false, app.room:getViewIdByUserId(v.nUserId))
  1927. end
  1928. end
  1929. function RoomView_ERDouDiZhu:cmd_0x810c_Resp(data)
  1930. function cmd_0x810c_RespEx(onEnd)
  1931. --显示加倍
  1932. self:setAskBeiVisible(true)
  1933. local function endCallback(viewId)
  1934. if Functions.getIsAutoAskBeiAfterTimeout() then
  1935. if viewId == self:getMeViewId() then
  1936. app.room:sendAskBei(0)
  1937. end
  1938. end
  1939. end
  1940. --显示闹钟
  1941. for k,v in pairs(app.room.roomInfo.memberList) do
  1942. self.PlayerView:setClockVisibel(true, app.room:getViewIdByUserId(v.nUserId), data.response.leftTime, endCallback)
  1943. end
  1944. if onEnd then
  1945. onEnd()
  1946. end
  1947. end
  1948. self:addCallBack(cmd_0x810c_RespEx)
  1949. end
  1950. function RoomView_ERDouDiZhu:cmd_0x810d_Resp(data)
  1951. function cmd_0x810d_RespEx(onEnd)
  1952. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1953. --隐藏加倍操作界面
  1954. if viewId == self:getMeViewId() then
  1955. self:setAskBeiVisible(false)
  1956. self:setAllHandCardDown(viewId)
  1957. end
  1958. --隐藏闹钟
  1959. self.PlayerView:setClockVisibel(false, viewId)
  1960. --显示加倍状态
  1961. self.PlayerView:setTipsVisible("tips_jiabei", true, viewId, { askBei = data.response.askBei })
  1962. --播放音效
  1963. Functions.playVoice("jiabei", data.response.askBei, self.PlayerView:getPlayerData("sex", viewId))
  1964. self:runAction(
  1965. cc.Sequence:create(
  1966. cc.DelayTime:create(0.5),
  1967. cc.CallFunc:create(function()
  1968. if onEnd then
  1969. onEnd()
  1970. end
  1971. end)
  1972. )
  1973. )
  1974. end
  1975. self:addCallBack(cmd_0x810d_RespEx)
  1976. end
  1977. function RoomView_ERDouDiZhu:hideAllOutCardOperation()
  1978. --隐藏玩家出牌操作信息
  1979. for _,v in pairs(app.room.roomInfo.memberList) do
  1980. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1981. --隐藏玩家的出牌
  1982. self:setOutCardsVisible(false, viewId)
  1983. --隐藏玩家的操作
  1984. self.PlayerView:setTipsVisible("tips_yaobuqi", false, viewId)
  1985. end
  1986. end
  1987. function RoomView_ERDouDiZhu:cmd_0x810e_Resp(data)
  1988. function cmd_0x810e_RespEx(onEnd)
  1989. --当前操作玩家
  1990. self.curViewId = app.room:getViewIdByUserId(data.response.nUserId)
  1991. local delayTime = 0
  1992. if data.response.opType == 2 then -- 如果是所有玩家都操作不要,即本家必须出牌
  1993. delayTime = 0.4
  1994. end
  1995. self:runAction(cc.Sequence:create(
  1996. cc.DelayTime:create(delayTime),
  1997. cc.CallFunc:create(function()
  1998. --隐藏玩家出牌操作信息
  1999. if data.response.opType == 2 then
  2000. self:hideAllOutCardOperation()
  2001. else
  2002. --隐藏玩家的出牌
  2003. self:setOutCardsVisible(false, self.curViewId)
  2004. --隐藏玩家的操作
  2005. self.PlayerView:setTipsVisible("tips_yaobuqi", false, self.curViewId)
  2006. end
  2007. --显示闹钟
  2008. self.PlayerView:setClockVisibel(true, self.curViewId, self.clockTime)
  2009. --显示操作
  2010. if self.curViewId == self:getMeViewId() then
  2011. self:setOperationVisible(true, data.response.opType)
  2012. end
  2013. if onEnd then
  2014. onEnd()
  2015. end
  2016. end)
  2017. ))
  2018. end
  2019. self:addCallBack(cmd_0x810e_RespEx)
  2020. end
  2021. function RoomView_ERDouDiZhu:cmd_0x810f_Resp(data)
  2022. function cmd_0x810f_RespEx(onEnd)
  2023. local errorMessage = {
  2024. [1] = "轮次错误",
  2025. [2] = "牌型错误",
  2026. [3] = "出牌错误",
  2027. }
  2028. --下降所有手牌
  2029. self:setAllHandCardDown(self.getMeViewId())
  2030. --显示错误信息
  2031. showTooltip(errorMessage[data.response.errorType] or "出牌错误")
  2032. if onEnd then
  2033. onEnd()
  2034. end
  2035. end
  2036. self:addCallBack(cmd_0x810f_RespEx)
  2037. end
  2038. function RoomView_ERDouDiZhu:setLastData(viewId, data)
  2039. if viewId and data then
  2040. local cardsEx = {}
  2041. local cardsValueTable = {}
  2042. for k,v in ipairs(data.cards) do
  2043. table.insert(cardsEx, { cardNum = v.card, cardValue = self:getCardValue(v.card), cardType = self:getCardType(v.card) })
  2044. table.insert(cardsValueTable, v.card)
  2045. end
  2046. local lastDataEx = self:getCardsType(cardsValueTable)
  2047. if lastDataEx then
  2048. for k,v in pairs(lastDataEx) do
  2049. self.lastData[k] = v
  2050. end
  2051. end
  2052. self.lastData.cards = cardsEx
  2053. self.lastData.viewId = viewId
  2054. --播放音效
  2055. Functions.playVoice("chupai", self.lastData, self.PlayerView:getPlayerData("sex", viewId))
  2056. else
  2057. self.lastData = {
  2058. min = 0,
  2059. cards = {},
  2060. viewId = 0,
  2061. cardType = 0,
  2062. }
  2063. end
  2064. end
  2065. function RoomView_ERDouDiZhu:setOutCardsVisible(bVisible, viewId, data)
  2066. logE("RoomView_ERDouDiZhu setOutCardsVisible data : ".. table.toString(data))
  2067. local outCardsLayout = self.ui.Items["Layout_Out_" .. viewId]
  2068. if outCardsLayout then
  2069. outCardsLayout:setVisible(bVisible)
  2070. if bVisible then
  2071. outCardsLayout:removeAllChildren()
  2072. if data.opType == 0 then
  2073. self.PlayerView:setTipsVisible("tips_yaobuqi", true, viewId)
  2074. --播放音效
  2075. Functions.playVoice("buyao", 0, self.PlayerView:getPlayerData("sex", viewId))
  2076. else
  2077. if not data.maxLen then
  2078. self:setLastData(viewId, data)
  2079. end
  2080. self:initOutCardItem(outCardsLayout, viewId, data)
  2081. end
  2082. end
  2083. end
  2084. end
  2085. function RoomView_ERDouDiZhu:initOutCardItem(outCardsLayout, viewId, data)
  2086. local cardScale = 0.5
  2087. local cardsLen = table.nums(data.cards)
  2088. local isBanker = app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId
  2089. for k,v in ipairs(data.cards) do
  2090. -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 旧资源
  2091. local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 新资源
  2092. if card then
  2093. -- 设置为庄家牌
  2094. if self:checkIsBankCard(v.card, viewId) then
  2095. card.isBankCard = true
  2096. end
  2097. local kEx = tonumber(k)
  2098. card:setScale(cardScale)
  2099. outCardsLayout:addChild(card)
  2100. local cardSize = card:getContentSize()
  2101. if viewId == 1 then
  2102. --左对齐
  2103. if data.maxLen then
  2104. local floor = math.floor(kEx / data.maxLen)
  2105. local mod = kEx % data.maxLen + (kEx >= data.maxLen and 1 or 0)
  2106. --设置zOder
  2107. card:setLocalZOrder(data.maxLen * floor - kEx)
  2108. card:setPosition(cc.p((-1) * mod * (cardSize.width - self.handCardDif) * cardScale, (-1) * cardSize.height * cardScale * 0.5 * floor))
  2109. else
  2110. --设置zOder
  2111. card:setLocalZOrder(cardsLen - kEx)
  2112. card:setPosition(cc.p((-1) * kEx * (cardSize.width - self.handCardDif) * cardScale, 0))
  2113. end
  2114. elseif viewId == 3 then
  2115. --右对齐
  2116. if data.maxLen then
  2117. local floor = math.floor(kEx / data.maxLen)
  2118. local mod = kEx % data.maxLen + (kEx >= data.maxLen and 1 or 0)
  2119. card:setPosition(cc.p(mod * (cardSize.width - self.handCardDif) * cardScale, (-1) * cardSize.height * cardScale * 0.5 * floor))
  2120. else
  2121. card:setPosition(cc.p(kEx * (cardSize.width - self.handCardDif) * cardScale, 0))
  2122. end
  2123. else
  2124. --居中
  2125. card:setPosition(cc.p((kEx - cardsLen / 2) * (cardSize.width - self.handCardDif) * cardScale, 0))
  2126. end
  2127. --庄家标识
  2128. if isBanker then
  2129. if card.isBankCard then
  2130. if card.bankerMark then
  2131. card.bankerMark:setVisible(true)
  2132. else
  2133. card.bankerMark = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_bankerCardMark.png"))
  2134. local offsetX, offsetY = self:getBankTagOffset()
  2135. card.bankerMark:setPosition(cc.p(cardSize.width * 0.72 + offsetX, cardSize.height * 0.7835 + offsetY))
  2136. card:addChild(card.bankerMark)
  2137. end
  2138. end
  2139. end
  2140. card:stopAllActions()
  2141. local moveTo = cc.MoveBy:create(Card_Out_Down_Time, cc.p(0, Card_Out_Down_Offset_Y))
  2142. card:runAction(moveTo)
  2143. -- 添加刷新牌的方法
  2144. card.refreshCard = function() -- 刷新卡牌
  2145. if v.card > 0 then
  2146. local cardPng = string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))
  2147. card:setSpriteFrame(cardPng)
  2148. if card.bankerMark then
  2149. local size = card:getContentSize()
  2150. local offsetX, offsetY = self:getBankTagOffset()
  2151. card.bankerMark:setPosition(cc.p(size.width * 0.72 + offsetX, size.height * 0.7835 + offsetY))
  2152. end
  2153. end
  2154. end
  2155. else
  2156. logE("RoomView_ERDouDiZhu initOutCardItem error".. table.toString(v))
  2157. end
  2158. end
  2159. --播放动画
  2160. if #self.lastData.cards > 0 then
  2161. local cardsEx = outCardsLayout:getChildren()
  2162. if #cardsEx > 0 then
  2163. local effect = nil
  2164. if self.lastData.cardType == defs.CARD_TYPE.SHUNZI then --顺子
  2165. -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_shunzi.plist", "shunzi%d.png", 1, 17, -1)
  2166. effect = DDZ_New_Effect_Helper:getShunziNew()
  2167. elseif self.lastData.cardType == defs.CARD_TYPE.SHUANGSHUN then --连对
  2168. -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_liandui.plist", "liandui%d.png", 1, 8, -1)
  2169. effect = DDZ_New_Effect_Helper:getLianduiNew()
  2170. elseif self.lastData.cardType == defs.CARD_TYPE.SANSHUN then --飞机
  2171. -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1)
  2172. effect = DDZ_New_Effect_Helper:getPlanNew()
  2173. elseif self.lastData.cardType == defs.CARD_TYPE.AIRPLANE_SINGLE then --飞机
  2174. -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1)
  2175. effect = DDZ_New_Effect_Helper:getPlanNew()
  2176. elseif self.lastData.cardType == defs.CARD_TYPE.AIRPLANE_DUAD then --飞机
  2177. -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1)
  2178. effect = DDZ_New_Effect_Helper:getPlanNew()
  2179. elseif self.lastData.cardType == defs.CARD_TYPE.BOMB then --炸弹
  2180. -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_zhadan.plist", "zhadan%d.png", 1, 17, -1)
  2181. effect = DDZ_New_Effect_Helper:getBombNew()
  2182. elseif self.lastData.cardType == defs.CARD_TYPE.BOMB_KING then --王炸
  2183. -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_zhadan.plist", "zhadan%d.png", 1, 17, -1)
  2184. effect = DDZ_New_Effect_Helper:getKingBombNew()
  2185. end
  2186. if effect then
  2187. effect:setScale(0.7)
  2188. effect:setPosition(cardsEx[toint(#cardsEx / 2)]:getPosition())
  2189. outCardsLayout:addChild(effect, 100)
  2190. if effect.onEnter and type(effect.onEnter)=='function' then
  2191. effect:onEnter()
  2192. end
  2193. end
  2194. end
  2195. end
  2196. end
  2197. function RoomView_ERDouDiZhu:deleteHandCards(viewId, cards, doAni)
  2198. local handCards = self.handCards["" .. viewId]
  2199. if handCards then
  2200. for k,v in ipairs(cards) do
  2201. logE("handCards v.card " .. v.card)
  2202. for k2,v2 in ipairs(handCards) do
  2203. logE("handCards v2.cardNum " .. v2.cardNum)
  2204. if v2.cardNum == v.card and not v2.isGrey then
  2205. v2:removeFromParent()
  2206. table.remove(handCards, k2)
  2207. break
  2208. end
  2209. end
  2210. end
  2211. self:rankHandCards(viewId, doAni)
  2212. end
  2213. end
  2214. -- 根据牌的标准值获取手牌节点
  2215. function RoomView_ERDouDiZhu:getCardNodeByCardValue(cardValue)
  2216. if self.handCards and cardValue then
  2217. local handCards = self.handCards["" .. self:getMeViewId()]
  2218. if handCards then
  2219. for _,cardNode in ipairs(handCards) do
  2220. if cardValue == cardNode.cardNum then
  2221. return cardNode
  2222. end
  2223. end
  2224. end
  2225. end
  2226. end
  2227. -- 判断是否是庄家牌
  2228. function RoomView_ERDouDiZhu:checkIsBankCard(card, viewId)
  2229. if not app.room.roomInfo.bankerCards then
  2230. return false
  2231. end
  2232. -- 只要是庄家,庄家的牌都显示为地主
  2233. local isBanker = app.room.roomInfo.nBankerId and app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId
  2234. return isBanker
  2235. -- 只有3张底牌显示
  2236. -- local temp = {}
  2237. -- for _,v in ipairs(app.room.roomInfo.bankerCards) do
  2238. -- table.insert(temp, v.card)
  2239. -- end
  2240. -- for i, v in ipairs(temp) do
  2241. -- if card == v then
  2242. -- return true
  2243. -- end
  2244. -- end
  2245. -- return false
  2246. end
  2247. -- 获得庄家标记偏移值
  2248. function RoomView_ERDouDiZhu:getBankTagOffset()
  2249. local getPokerChoose = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose
  2250. local offsetX = (getPokerChoose == 1) and 0 or 3
  2251. local offsetY = (getPokerChoose == 1) and 1 or -1.2
  2252. return offsetX, offsetY
  2253. end
  2254. function RoomView_ERDouDiZhu:cmd_0x8110_Resp(data)
  2255. function cmd_0x8110_RespEx(onEnd)
  2256. --隐藏玩家信息
  2257. if data.response.opType == 1 then
  2258. self:hideAllOutCardOperation()
  2259. end
  2260. --操作位置
  2261. local opViewId = app.room:getViewIdByUserId(data.response.nUserId)
  2262. --显示剩余手牌
  2263. self.PlayerView:setLeftNumVisible(true, opViewId, data.response.leftNum)
  2264. --隐藏操作
  2265. self:setOperationVisible(false)
  2266. --隐藏闹钟
  2267. self.PlayerView:setClockVisibel(false, opViewId)
  2268. --显示出牌
  2269. self:setOutCardsVisible(true, opViewId, {cards = data.response.cards, opType = data.response.opType})
  2270. --删除手牌
  2271. if opViewId == self:getMeViewId() then
  2272. self:deleteHandCards(opViewId, data.response.cards, true)
  2273. else
  2274. local nums = table.nums(data.response.cards)
  2275. local cards = {}
  2276. for i = 1, nums do
  2277. table.insert(cards, {card = 0})
  2278. end
  2279. self:deleteHandCards(opViewId, cards, true)
  2280. end
  2281. -- 改变中间提示
  2282. -- local rangCount = Functions.getRangCount()
  2283. -- if rangCount > 0 then
  2284. if app.room.roomInfo.nBankerId == app.room:getMyUserId() then
  2285. if opViewId ~= self:getMeViewId() then
  2286. local rang = app.room.roomInfo.memberList[app.room:getMyUserId()].askRangNum
  2287. local rangTotalCount = app.room.roomInfo.nRang
  2288. local otherHandCardCount = table.nums(self.handCards['' .. opViewId])
  2289. self:isShowMiddleTips(true, rangTotalCount)
  2290. end
  2291. end
  2292. -- end
  2293. if onEnd then
  2294. onEnd()
  2295. end
  2296. end
  2297. self:addCallBack(cmd_0x8110_RespEx)
  2298. end
  2299. function RoomView_ERDouDiZhu:cmd_0x8111_Resp(data)
  2300. function cmd_0x8111_RespEx(onEnd)
  2301. --设置底分
  2302. self:setBankerAskLoard()
  2303. --设置炸弹数
  2304. self:setCurZhaDanNum()
  2305. -- 设置倍数
  2306. self:setCurMultiple()
  2307. -- 设置让牌数
  2308. self:setCurRang()
  2309. -- 显示中间庄家让x 所有人
  2310. if app.room.roomInfo.nStatus then
  2311. if app.room.roomInfo.nStatus >= defs.GAME_STATUS.ASK_LOARD and app.room.roomInfo.nStatus <= defs.GAME_STATUS.ASK_RANG then
  2312. self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRang or 0)
  2313. end
  2314. end
  2315. if onEnd then
  2316. onEnd()
  2317. end
  2318. end
  2319. self:addCallBack(cmd_0x8111_RespEx)
  2320. end
  2321. function RoomView_ERDouDiZhu:cmd_0x8112_Resp(data)
  2322. function cmd_0x8112_RespEx(onEnd)
  2323. --显示春天动画
  2324. -- 去除春天动画
  2325. -- if data.response.nSpring == 1 then
  2326. -- local effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_spring.plist", "spring%d.png", 1, 22, -1)
  2327. -- if effect then
  2328. -- playVoice("pk_erdoudizhu/res/sound/doudizhu_common_spring.ogg")
  2329. -- effect:setPosition(cc.p(640, 360))
  2330. -- self:addChild(effect)
  2331. -- end
  2332. -- end
  2333. self:runAction(
  2334. cc.Sequence:create(
  2335. -- cc.DelayTime:create(1.0),
  2336. cc.DelayTime:create(0.5),
  2337. cc.CallFunc:create(function()
  2338. --隐藏界面
  2339. local winViewId = app.room:getViewIdByUserId(data.response.nWinId)
  2340. for _,v in pairs(app.room.roomInfo.memberList) do
  2341. local viewId = app.room:getViewIdByUserId(v.nUserId)
  2342. if viewId ~= winViewId then
  2343. --出牌界面
  2344. self:setOutCardsVisible(false, viewId)
  2345. end
  2346. --闹钟界面
  2347. self.PlayerView:setClockVisibel(false, viewId)
  2348. end
  2349. --显示小局结算
  2350. self:setXiaoJuVisible(true, data.response)
  2351. if onEnd then
  2352. onEnd()
  2353. end
  2354. end)
  2355. )
  2356. )
  2357. end
  2358. self:addCallBack(cmd_0x8112_RespEx)
  2359. end
  2360. function RoomView_ERDouDiZhu:showDaJu(data)
  2361. if not self.daJuView then
  2362. self.daJuView = import("pk_erdoudizhu.luaScript.Views.Room.RoomDaJuView_ERDouDiZhu"):new(data)
  2363. -- self.ui.Items.Layout_DaJu:addChild(self.daJuView)
  2364. self.daJuView:setAnchorPoint(cc.p(0.5, 0.5))
  2365. app:showWaitDialog(self.daJuView);
  2366. end
  2367. --更新界面
  2368. self.daJuView:updateView(data)
  2369. self:showGameOverAward()
  2370. end
  2371. function RoomView_ERDouDiZhu:cmd_0x8113_Resp(data)
  2372. function cmd_0x8113_RespEx(onEnd)
  2373. if self.tuoguanView then
  2374. self:showTuoGuan(false)
  2375. end
  2376. local isShow_XiaoJu = (self.XiaoJuView and self.XiaoJuView:isVisible()) or false
  2377. -- 如果之前没显示过小结算,或者是解散导致的结束,直接显示大结算
  2378. if not isShow_XiaoJu or app.room.roomInfo._stopFlag == 9 then
  2379. --隐藏小局结算
  2380. self:setXiaoJuVisible(false)
  2381. --显示总结算
  2382. self:showDaJu(data.response)
  2383. end
  2384. --关闭结算界面
  2385. app.room:dispatchEvent({ name = GAME_EVENT.DISSMISS_CLOSE })
  2386. if onEnd then
  2387. onEnd()
  2388. end
  2389. end
  2390. self:addCallBack(cmd_0x8113_RespEx)
  2391. end
  2392. function RoomView_ERDouDiZhu:cmd_0x8114_Resp(data)
  2393. function cmd_0x8114_RespEx(onEnd)
  2394. --重置桌面
  2395. self:defaultState()
  2396. if onEnd then
  2397. onEnd()
  2398. end
  2399. end
  2400. self:addCallBack(cmd_0x8114_RespEx)
  2401. end
  2402. ---
  2403. -- 初始化大结算再来一局
  2404. -- @return
  2405. --
  2406. function RoomView_ERDouDiZhu:initPlayGameAgain()
  2407. local strGameInfo = app.room.roomInfo.strGameInfo
  2408. local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0
  2409. if not isInClub then
  2410. logD("RoomView_ERDouDiZhu.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局");
  2411. return
  2412. end
  2413. local clubGameInfo = json.decode(strGameInfo) or {}
  2414. if not clubGameInfo.ruleid then
  2415. logD("RoomView_ERDouDiZhu.initPlayGameAgain", "游戏包间id不存在,不能再来一局");
  2416. return
  2417. end
  2418. dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid)
  2419. end
  2420. -- 托管通知
  2421. function RoomView_ERDouDiZhu:onHostingResponse( data )
  2422. local function onHostingResponseEx(onEnd)
  2423. local response = data.response
  2424. -- 如果是我,则显示托管layout界面
  2425. if response.nUserId == app.room:getMyUserId() then
  2426. if response.status == 1 then --托管状态
  2427. self:showTuoGuan(true)
  2428. elseif response.status == 0 then--取消托管状态
  2429. self:showTuoGuan(false)
  2430. end
  2431. end
  2432. local isTuoGuan = response.status == 1
  2433. local viewId = app.room:getViewIdByUserId(response.nUserId)
  2434. self.PlayerView:showTuoGuanByViewId(viewId, isTuoGuan)
  2435. if onEnd then
  2436. onEnd()
  2437. end
  2438. end
  2439. self:addCallBack(onHostingResponseEx)
  2440. end
  2441. --显示隐藏托管
  2442. function RoomView_ERDouDiZhu:showTuoGuan(isShow)
  2443. if not self.tuoguanView then
  2444. self.tuoguanView = TuoGuanView:new()
  2445. self:addChild(self.tuoguanView)
  2446. self.tuoguanView:setVisible(false)
  2447. end
  2448. self.tuoguanView:setVisible(isShow)
  2449. end
  2450. function RoomView_ERDouDiZhu:refreshPlayerAIStatus()
  2451. for _,v in pairs(app.room.roomInfo.memberList) do
  2452. local isTuoGuan = v.AIStatus == 1
  2453. print('RoomView_ERDouDiZhu:refreshPlayerAIStatus', v.nUserId, isTuoGuan)
  2454. self.PlayerView:showTuoGuanByViewId(app.room:getViewIdByUserId(v.nUserId), isTuoGuan)
  2455. end
  2456. end
  2457. --游戏消息
  2458. function RoomView_ERDouDiZhu:bindGameMessage()
  2459. self:bindEvent(app.room, "cmd_0x8104_Resp", handler(self, self.cmd_0x8104_Resp))
  2460. self:bindEvent(app.room, "cmd_0x8105_Resp", handler(self, self.cmd_0x8105_Resp))
  2461. self:bindEvent(app.room, "cmd_0x8106_Resp", handler(self, self.cmd_0x8106_Resp))
  2462. self:bindEvent(app.room, "cmd_0x8108_Resp", handler(self, self.cmd_0x8108_Resp))
  2463. self:bindEvent(app.room, "cmd_0x8109_Resp", handler(self, self.cmd_0x8109_Resp))
  2464. self:bindEvent(app.room, "cmd_0x810a_Resp", handler(self, self.cmd_0x810a_Resp))
  2465. self:bindEvent(app.room, "cmd_0x810c_Resp", handler(self, self.cmd_0x810c_Resp))
  2466. self:bindEvent(app.room, "cmd_0x810d_Resp", handler(self, self.cmd_0x810d_Resp))
  2467. self:bindEvent(app.room, "cmd_0x810e_Resp", handler(self, self.cmd_0x810e_Resp))
  2468. self:bindEvent(app.room, "cmd_0x810f_Resp", handler(self, self.cmd_0x810f_Resp))
  2469. self:bindEvent(app.room, "cmd_0x8110_Resp", handler(self, self.cmd_0x8110_Resp))
  2470. self:bindEvent(app.room, "cmd_0x8111_Resp", handler(self, self.cmd_0x8111_Resp))
  2471. self:bindEvent(app.room, "cmd_0x8112_Resp", handler(self, self.cmd_0x8112_Resp))
  2472. self:bindEvent(app.room, "cmd_0x8113_Resp", handler(self, self.cmd_0x8113_Resp))
  2473. self:bindEvent(app.room, "cmd_0x8114_Resp", handler(self, self.cmd_0x8114_Resp))
  2474. self:bindEvent(app.room, 'cmd_0x8123_Resp', handler(self, self.cmd_0x8123_Resp)) -- 通知抢地主
  2475. self:bindEvent(app.room, 'cmd_0x8124_Resp', handler(self, self.cmd_0x8124_Resp)) -- 抢地主结果
  2476. self:bindEvent(app.room, 'cmd_0x8121_Resp', handler(self, self.cmd_0x8121_Resp)) -- 通知让牌
  2477. self:bindEvent(app.room, 'cmd_0x8122_Resp', handler(self, self.cmd_0x8122_Resp)) -- 让牌结果
  2478. end
  2479. ---
  2480. -- 显示抽奖界面
  2481. --
  2482. function RoomView_ERDouDiZhu:showGameOverAward()
  2483. if not (dd and dd.IGameOverAward) then
  2484. return
  2485. end
  2486. self:runDelay(0.1, function ( )
  2487. -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
  2488. dd.IGameOverAward.showAwardView();
  2489. end)
  2490. end
  2491. -- 通知抢地主
  2492. function RoomView_ERDouDiZhu:cmd_0x8123_Resp(data)
  2493. function cmd_0x8123_RespEx(onEnd)
  2494. --当前操作玩家
  2495. self.curViewId = app.room:getViewIdByUserId(data.response.nUserId)
  2496. --显示闹钟
  2497. self.PlayerView:setClockVisibel(true, self.curViewId, data.response.leftTime)
  2498. -- 隐藏之前的提示内容
  2499. self.PlayerView:setTipsVisibleExcept({}, self.curViewId)
  2500. --显示抢地主
  2501. if self.curViewId == self:getMeViewId() then
  2502. self:setQiangVisible(true)
  2503. end
  2504. if onEnd then
  2505. onEnd()
  2506. end
  2507. end
  2508. self:addCallBack(cmd_0x8123_RespEx)
  2509. end
  2510. -- 抢地主结果
  2511. function RoomView_ERDouDiZhu:cmd_0x8124_Resp(data)
  2512. function cmd_0x8124_RespEx(onEnd)
  2513. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  2514. --隐藏抢地主界面
  2515. self:setQiangVisible(false)
  2516. --隐藏闹钟
  2517. self.PlayerView:setClockVisibel(false, viewId)
  2518. -- 隐藏之前的叫地主
  2519. self.PlayerView:setTipsVisibleExcept({}, viewId)
  2520. --显示叫分
  2521. self.PlayerView:setTipsVisible("tips_qiangdizhu", true, viewId, {opType = data.response.opType})
  2522. --播放音效
  2523. Functions.playVoice("qiangdizhu", data.response.opType, self.PlayerView:getPlayerData("sex", viewId))
  2524. if onEnd then
  2525. onEnd()
  2526. end
  2527. end
  2528. self:addCallBack(cmd_0x8124_RespEx)
  2529. end
  2530. -- 通知让牌
  2531. function RoomView_ERDouDiZhu:cmd_0x8121_Resp(data)
  2532. function cmd_0x8121_RespEx(onEnd)
  2533. --当前操作玩家
  2534. self.curViewId = app.room:getViewIdByUserId(data.response.nUserId)
  2535. --显示闹钟
  2536. self.PlayerView:setClockVisibel(true, self.curViewId, data.response.leftTime)
  2537. --显示让牌
  2538. if self.curViewId == self:getMeViewId() then
  2539. self:setRangVisible(true, data.response.nRangPai)
  2540. end
  2541. if onEnd then
  2542. onEnd()
  2543. end
  2544. end
  2545. self:addCallBack(cmd_0x8121_RespEx)
  2546. end
  2547. -- 让牌结果
  2548. function RoomView_ERDouDiZhu:cmd_0x8122_Resp(data)
  2549. function cmd_0x8122_RespEx(onEnd)
  2550. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  2551. --隐藏抢地主界面
  2552. self:setRangVisible(false)
  2553. --隐藏闹钟
  2554. self.PlayerView:setClockVisibel(false, viewId)
  2555. -- todo 显示和音效
  2556. --显示叫分
  2557. -- self.PlayerView:setTipsVisible("tips_jiaofen", true, viewId, {askLoard = data.response.askLoard})
  2558. --播放音效
  2559. -- Functions.playVoice("jiaofen", data.response.askLoard, self.PlayerView:getPlayerData("sex", viewId))
  2560. if onEnd then
  2561. onEnd()
  2562. end
  2563. end
  2564. self:addCallBack(cmd_0x8122_RespEx)
  2565. end
  2566. -- 中间提示内容(地主让x,对家出x,只有庄家可看)
  2567. function RoomView_ERDouDiZhu:isShowMiddleTips(isVisible, tip1, tip2)
  2568. self.ui.Items.Layout_Middle_Tips:setVisible(isVisible)
  2569. if not isVisible then
  2570. return
  2571. end
  2572. self.ui.Items.Layout_Middle_Tips_1:setVisible(false) -- 与另一个中间提示内容互斥
  2573. -- 增加对家显示不小于0
  2574. -- tip2 = (tonumber(tip2) > 0 and tip2 or 0)
  2575. self.ui.Items.Text_Tips_Rang_1:setText(tip1)
  2576. -- 计算对家牌
  2577. local otherHandCardCount = 0
  2578. for _, v in pairs(app.room.roomInfo.memberList) do
  2579. if v.nUserId ~= app.room:getMyUserId() then
  2580. local viewId = app.room:getViewIdByUserId(v.nUserId)
  2581. local otherHandCards = self.handCards["" .. viewId]
  2582. if otherHandCards and next(otherHandCards) then
  2583. otherHandCardCount = table.nums(otherHandCards)
  2584. end
  2585. end
  2586. end
  2587. local txtRang2 = otherHandCardCount - tonumber(tip1)
  2588. txtRang2 = (txtRang2 > 0) and txtRang2 or 0
  2589. self.ui.Items.Text_Tips_Rang_2:setText(txtRang2)
  2590. end
  2591. -- 中间提示内容(地主让x,两人都可看)
  2592. function RoomView_ERDouDiZhu:isShowMiddleTipsForAll(isVisible, tip)
  2593. self.ui.Items.Layout_Middle_Tips_1:setVisible(isVisible)
  2594. if not isVisible then
  2595. return
  2596. end
  2597. -- 叫分没有抢,所以不需要显示
  2598. if Functions.getGameMode() == 2 then
  2599. self.ui.Items.Layout_Middle_Tips_1:setVisible(false)
  2600. return
  2601. end
  2602. self.ui.Items.Layout_Middle_Tips:setVisible(false) -- 与另一个中间提示内容互斥
  2603. tip = tip or 0
  2604. self.ui.Items.Text_Tips_DiZhuRang_1:setText(tip)
  2605. end
  2606. return RoomView_ERDouDiZhu