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.

2541 lines
84 KiB

  1. require("luaScript.Views.Room.RoomFunctions")
  2. local MJRoomToolView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView")
  3. local MJRoomMessageView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomMessageView")
  4. local MJRoomPlayerView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView")
  5. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  6. local MJHandCardView=MJFramework.MJImport("mj.luaScript.Views.Game.MJHandCardView")
  7. local MJRoomXiaoJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomXiaoJuView")
  8. local MJRoomDaJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView")
  9. local MJRoomDismissView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDismissView")
  10. local MJRoomDirection=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection")
  11. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  12. local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  13. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  14. local MJAnimationCompnent=MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent")
  15. local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
  16. local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
  17. local MJRoomView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomView")
  18. local huamajiangRoomView = class("huamajiangRoomView", MJRoomView)
  19. local zhongNiaoTime=1.33
  20. local HU_EFFECT_TAG = 100
  21. function huamajiangRoomView:ctor()
  22. huamajiangRoomView.super.ctor(self)
  23. self.operates = {}
  24. MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
  25. end
  26. function huamajiangRoomView:loadUi()
  27. local ui = loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_roomView.ui")
  28. self.ui = ui
  29. self:addChild(ui)
  30. end
  31. function huamajiangRoomView:onEnter()
  32. huamajiangRoomView.super.onEnter(self)
  33. self.ZOrder = {};
  34. --获取是否贴鬼杠和是否自动对齐
  35. self:setCheckDefault()
  36. self:doSound()
  37. self:initLogo()
  38. end
  39. ---
  40. -- 更新logo
  41. -- @return
  42. --
  43. --[[function huamajiangRoomView:initLogo ()
  44. local config = getSubGameConfig(GAME_IDS.huamajiang or app.gameId)
  45. if config and config.logo then
  46. self.ui.Items.ImageView_Logo:loadTexture(config.logo,0);
  47. end
  48. if config.isShowLogo == false then
  49. self.ui.Items.ImageView_Logo:setVisible(false)
  50. end
  51. end--]]
  52. --- huamajiangRoomView:addToLayer 添加节点至指定层
  53. -- @param layerName 指定层级的名称,background(背景层)、game(游戏层)、anim(动画特效层)、popup(弹框层)、system(系统弹框层)
  54. -- @param node 要添加的节点
  55. -- @param zorder 指定的zorder
  56. function huamajiangRoomView:addToLayer(layerName, node, zorder)
  57. if layerName == "background" then
  58. layerName = "Layout_Background";
  59. elseif layerName == "game" then
  60. layerName = "Layout_Game";
  61. elseif layerName == "anim" then
  62. layerName = "Layout_Anim";
  63. elseif layerName == "popup" then
  64. layerName = "Layout_PopUp";
  65. elseif layerName == "system" then
  66. layerName = "Layout_System";
  67. end
  68. local layer = self.ui.Items[layerName];
  69. if not layer then
  70. self:addChild(node)
  71. return ;
  72. end
  73. self.ZOrder = self.ZOrder or {};
  74. self.ZOrder[layerName] = self.ZOrder[layerName] or 0;
  75. self.ZOrder[layerName] = zorder or (self.ZOrder[layerName] + 1);
  76. node:setLocalZOrder(self.ZOrder[layerName])
  77. layer:addChild(node);
  78. end
  79. function huamajiangRoomView:onExit()
  80. huamajiangRoomView.super.onExit(self)
  81. if self.SwapTime then
  82. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.SwapTime)
  83. end
  84. self:cleanCache()
  85. end
  86. function huamajiangRoomView:cleanCache()
  87. local preload = package.loaded
  88. for k, v in pairs(package.loaded or {}) do
  89. local res1 = string.find( k, "mj.luaScript") or 0
  90. local res2 = string.find( k, "mj_huamajiang.luaScript") or 0
  91. if res1 > 0 or res2 > 0 then
  92. package.loaded[k] = nil
  93. end
  94. end
  95. end
  96. function huamajiangRoomView:initView()
  97. --暂时隐藏牌数
  98. self.ui.Items.ImageView_CardNum:setVisible(false)
  99. -- 初始化玩家层
  100. self:initPlayerView();
  101. --加载工具层
  102. self:initToolView()
  103. --聊天层
  104. -- self:initChatView()
  105. -- 初始化方向
  106. self:initDirectionView();
  107. -- 初始化听牌组件
  108. self:initTingCardView();
  109. -- 初始化听牌按钮,动态创建的
  110. self:initTingBtnView();
  111. --定时器
  112. self.ui.Items.Text_Time:setText(MJFunction.getTimeString())
  113. if not self.Time then
  114. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function ()
  115. self.ui.Items.Text_Time:setText(MJFunction.getTimeString())
  116. end,1.0,false)
  117. end
  118. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false);
  119. end
  120. --- huamajiangRoomView:initPlayerView 初始化playerView
  121. function huamajiangRoomView:initPlayerView()
  122. if not self.playerView then
  123. self.playerView = MJRoomPlayerView:new()
  124. self:addToLayer("game", self.playerView, 6);
  125. end
  126. end
  127. --- huamajiangRoomView:initHandCardNodes 初始化手牌
  128. function huamajiangRoomView:initHandCardNodes ()
  129. local maxPlayCount = app.room.roomInfo:getMaxPlayerCount();
  130. if MJDefine.MJRoomPlayerSitConfig[maxPlayCount] then
  131. for k,v in pairs(MJDefine.MJRoomPlayerSitConfig[maxPlayCount]) do
  132. if self.playerHandCards[v] then
  133. self.playerHandCards[v]:removeFromParent();
  134. end
  135. self.playerHandCards[v] = MJHandCardView:new(v, self.desktopType);
  136. self:addToLayer("game", self.playerHandCards[v], v + 1);
  137. end
  138. end
  139. end
  140. --- huamajiangRoomView:initToolView 初始化工具栏
  141. function huamajiangRoomView:initToolView()
  142. if not self.toolView then
  143. self.toolView = MJRoomToolView:new(self.desktopType)
  144. self:addToLayer("game", self.toolView, 7);
  145. end
  146. self.toolView:setFlowVisible(false);
  147. end
  148. --- huamajiangRoomView:initDirectionView 初始化中间方向指示器
  149. function huamajiangRoomView:initDirectionView()
  150. if not self.direcionView then
  151. self.direcionView = MJRoomDirection:new(self.desktopType)
  152. self:addToLayer("background", self.direcionView);
  153. self.direcionView:setVisible(false)
  154. end
  155. end
  156. --- huamajiangRoomView:initTingCardView 初始化听牌组件
  157. function huamajiangRoomView:initTingCardView ()
  158. if not self._tingCardView then
  159. self._tingCardView = require("mj_huamajiang.luaScript.Views.Components.huamajiangTingCardView"):new();
  160. self:addToLayer("game", self._tingCardView, 6);
  161. self._tingCardView:setData(nil);
  162. self:setTingCardVisible(false);
  163. end
  164. end
  165. --- huamajiangRoomView:initChatView 初始化聊天语音
  166. function huamajiangRoomView:initChatView()
  167. -- 添加语音相关的界面
  168. local headInfos = {}
  169. for k,v in pairs(self.playerView.allNodes) do
  170. local pos = cc.pAdd(v.player:getPosition(),cc.p(38,66))
  171. table.insert(headInfos,{headPos=pos})
  172. end
  173. local ChatView = require("luaScript.Views.Room.ChatView");
  174. self.messageView = ChatView:new({
  175. chatList=MJDefine.MJChatTxt,
  176. faceList=MJDefine.MJFaceConfig
  177. }, headInfos, true)
  178. if self.toolView.ui.Items.Layout_Chat then
  179. self.toolView.ui.Items.Layout_Chat:addChild(self.messageView)
  180. else
  181. self.playerView.ui.Items.Layout_Player:addChild(self.messageView)
  182. end
  183. self.messageView:setBtnFace(cc.p(1236, 272), "room_menu3_room_btn_kjy.png")
  184. self.messageView:setBtnVoice(cc.p(1236, 187), "room_menu3_room_btn_yuyin.png")
  185. -- local voiceEnable = loadUserInfo("voiceEnable") or 1
  186. -- local propEnable = loadUserInfo("propEnable") or 1
  187. -- self.messageView:setVoiceEnabled(tonumber(voiceEnable)==1)
  188. -- self.messageView:setPropEnabled(tonumber(propEnable)==1)
  189. self:onChangeChatEnable()
  190. end
  191. --- huamajiangRoomView:initTingBtnView 初始化听牌按钮
  192. function huamajiangRoomView:initTingBtnView ()
  193. local huamajiangTingBtnView = import("mj_huamajiang.luaScript.Views.Components.huamajiangTingBtnView");
  194. local btnTing = huamajiangTingBtnView:new();
  195. btnTing:setCallback(handler(self, self.onBtnTingInfoClicked));
  196. btnTing:setPosition(cc.p(230, 158));
  197. self.btnTing = btnTing;
  198. self:addToLayer("game", self.btnTing, 8)
  199. end
  200. function huamajiangRoomView:doSound()--1 普通话 2 方言
  201. local bgmType = tonumber(loadUserInfo("huamajiang_bgm")) or 1
  202. MJSound.PlayGameBGM(bgmType)
  203. local cacheLan = "mj_language"..(MJDefine.GameID or app.gameId)
  204. local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2
  205. -- saveUserInfo("mj_language", defaultValue)
  206. MJSound.setSoundType(defaultValue)
  207. end
  208. --- huamajiangRoomView:changeGameBg 更换背景
  209. function huamajiangRoomView:changeGameBg()
  210. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色
  211. local value = loadUserInfo("mj_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD
  212. if value=="" or not value then
  213. value = MJDefine.DesktopType.TwoD
  214. saveUserInfo("mj_desktop_2d_mjType", value)
  215. end
  216. self.desktopType = value
  217. else
  218. self.desktopType = app.systemSetting.info.viewType
  219. end
  220. self:loadTextureCache()
  221. local defaultValue = tonumber(loadUserInfo("huamajiang_desktop_background")) or 2
  222. local bgData = MJDefine.CHANGE_GAME_BG[defaultValue]
  223. --更换2D桌面
  224. if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold then
  225. self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
  226. else
  227. self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
  228. end
  229. --记录当前的桌布类型(2d/3d)
  230. self.curDeskType = self.desktopType
  231. end
  232. function huamajiangRoomView:setCheckDefault()
  233. MJDefine.isAutomatic = true
  234. end
  235. --- huamajiangRoomView:onClickButtonShot 一键截屏
  236. function huamajiangRoomView:onClickButtonShot( sender )
  237. playBtnEffect()
  238. showScreenShot()
  239. end
  240. --- huamajiangRoomView:hideClub 隐藏俱乐部
  241. function huamajiangRoomView:hideClub()
  242. -- self.ui.Items.Button_Club:setVisible(false)
  243. if self.clubView and not tolua.isnull(self.clubView) then
  244. self.clubView:removeFromParent()
  245. self.clubView=nil
  246. end
  247. end
  248. function huamajiangRoomView:loadTextureCache()
  249. huamajiangRoomView.super.loadTextureCache(self)
  250. loadSpriteFrameFile("mj_huamajiang/res/zy_fangjian/anim/huamajiang_effect_guangxiao.plist")
  251. loadSpriteFrameFile("mj_huamajiang/res/zy_fangjian/anim/huamajiang_effect_guafeng.plist")
  252. loadSpriteFrameFile("mj_huamajiang/res/zy_fangjian/anim/huamajiang_effect_xiayu.plist")
  253. end
  254. --- huamajiangRoomView:initGameButton 初始化游戏按钮
  255. function huamajiangRoomView:initGameButton()
  256. --点击空白
  257. self.ui.Items.Layout_Touch:registerClick(nil, function ()
  258. -- 隐藏个人信息
  259. self.playerView:removePlayerInfoView()
  260. self.toolView:setMenuVisible(false)
  261. if self.playerHandCards[MJDefine.MyViewId] then
  262. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  263. end
  264. self.toolView:hideRule()
  265. self:setTingCardVisible(false);
  266. -- local preload = package.loaded
  267. -- for k, v in pairs(package.loaded or {}) do
  268. -- local res1 = string.find( k, "mj.luaScript.Common") or 0
  269. -- local res3 = string.find( k, "mj_huamajiang.luaScript.Views.3d") or 0
  270. -- local res4 = string.find( k, "mj_huamajiang.luaScript.Views.2d") or 0
  271. -- if res1 > 0 or res3 > 0 or res4 > 0 then
  272. -- package.loaded[k] = nil
  273. -- end
  274. -- end
  275. -- -- MJDefine.MJConfig = require("mj_huamajiang.luaScript.Views.2d.MJConfig_2d")
  276. -- -- MJDefine.MJConfig = require("mj_huamajiang.luaScript.Views.3d.MJConfig_3d")
  277. -- MJDefine.loadMJConfig("3d")
  278. -- local playerCount = 4
  279. -- app.room.roomInfo:setMaxPlayerCount(playerCount)
  280. -- self:initHandCardNodes()
  281. -- local cards = {}
  282. -- for i = 1, 11 do
  283. -- table.insert(cards, {card = math.random(17, 25)})
  284. -- end
  285. -- local groupCards = {
  286. -- {values = {41, 41, 41}, opType = 0x0004, fromViewId = 10001, showType = 2},
  287. -- -- {values = {41, 41, 41, 41}, opType = 0x0008, fromViewId = 10001, showType = 3},
  288. -- -- {values = {41, 41, 41, 41}, opType = 0x0020, fromViewId = 10001, showType = 4},
  289. -- -- {values = {41, 41, 41, 41}, opType = 0x0010, fromViewId = 10001, showType = 5},
  290. -- }
  291. -- local outCards = {}
  292. -- for i = 1, 33 do
  293. -- table.insert(outCards, {card = 41})
  294. -- -- table.insert(outCards, {card = math.random(17, 41)})
  295. -- end
  296. -- local huCards = {}
  297. -- for i = 1, 60 do
  298. -- table.insert(huCards, {huCard = 41, huType = 0})
  299. -- end
  300. -- if playerCount == 2 then
  301. -- self.playerHandCards[2]:onGetHuCard(huCards, true)
  302. -- self.playerHandCards[4]:onGetHuCard(huCards, true)
  303. -- else
  304. -- for i = 1, playerCount do
  305. -- -- self.playerHandCards[i]:createGroupCards(groupCards)
  306. -- -- self.playerHandCards[i]:createHandCards(cards)
  307. -- -- self.playerHandCards[i]:createOutCards(outCards)
  308. -- self.playerHandCards[i]:onGetHuCard(huCards, true)
  309. -- -- self.playerHandCards[i]:createOpenHandCards(cards)
  310. -- end
  311. -- end
  312. -- -- local node = cc.Node:create()
  313. -- -- local group = require(MJDefine.MJConfig_2d.GROUP_GANG):new({41, 41, 41, 41}, 4, 1)
  314. -- -- group:setScale(0.7)
  315. -- -- group:setPosition(cc.p(0, 15))
  316. -- -- node:addChild(group)
  317. -- -- for i = 1, 11 do
  318. -- -- local card = require(MJDefine.MJConfig_2d.MAHJONG_CARD):new(41, 4, MJDefine.MJConfig_2d.MJType.Out, i)
  319. -- -- card:setPositionX((i - 1) * 44 + 140)
  320. -- -- node:addChild(card)
  321. -- -- end
  322. -- -- node:setPosition(cc.p(100, 200))
  323. -- -- self:addChild(node)
  324. -- self.toolView:setVisible(false)
  325. end)
  326. --隐藏听牌模板
  327. self.ui.Items.Item_Ting:setVisible(false)
  328. self:setButtonTingInfoVisible(false);
  329. end
  330. --- huamajiangRoomView:onBankerBaoPai 通知庄家可以爆牌
  331. -- @param data
  332. function huamajiangRoomView:onBankerBaoPai(data)
  333. local function runBankerBaoPai(onEnd)
  334. local myUserId = app.room:getMyUserId()
  335. local viewId = app.room:getViewIdByUserId(myUserId)
  336. if data.response.nUserId == myUserId then
  337. self:showBaoJiao()
  338. self.playerHandCards[viewId]:setOutCardEnable(false)
  339. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting);
  340. self.isTing = true;
  341. self:setButtonTingInfoVisible(true);
  342. end
  343. if onEnd then
  344. onEnd()
  345. end
  346. end
  347. self:addCallBack(runBankerBaoPai)
  348. end
  349. --- huamajiangRoomView:onBaoPai 广播玩家爆牌
  350. -- @param data
  351. function huamajiangRoomView:onBaoPai(data)
  352. if data.response.isBaoPai == 1 then
  353. local effect=MJAnimationCompnent.CreateBaoEffect()
  354. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  355. local myUserId = app.room:getMyUserId()
  356. local userInfo=app.room:getUserInfoByViewId(viewId)
  357. --爆牌音效
  358. MJSound.PlayBaoSound(userInfo.sex)
  359. if effect then
  360. self.ui.Items.Layout_Player:addChild(effect)
  361. effect:setLocalZOrder(1000)
  362. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  363. end
  364. if myUserId == data.response.nUserId then
  365. self.playerHandCards[viewId]:lockHandCard()
  366. -- self.playerHandCards[viewId]:setOutCardEnable(false)
  367. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  368. self.isTing = true;
  369. self:setButtonTingInfoVisible(true);
  370. else
  371. --self.playerHandCards[viewId]:setOutCardEnable(true)
  372. end
  373. self.playerView:playBaoAnim(viewId)
  374. end
  375. if app.room:getMyUserId() == data.response.nUserId then
  376. self:hideBaoJiao()
  377. if (data.response.isBaoPai == 1 or data.response.isBaoPai == 2) then
  378. local tingpai = app.room.roomInfo:getGameRuleByKey("tingpai");
  379. if tingpai > 0 then
  380. -- self:setButtonTingInfoVisible(true);
  381. app.room.roomInfo.memberList[data.response.nUserId].nTingStatus = MJDefine.MJTingStatus.Ting;
  382. end
  383. end
  384. end
  385. end
  386. --- huamajiangRoomView:onGameSendCardResponse 开始发牌
  387. function huamajiangRoomView:onGameSendCardResponse()
  388. logD("huamajiangRoomView:onGameSendCardResponse", "开始发牌")
  389. --发牌的时候清除桌面上的飘
  390. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  391. local function runGameSendCardResponse(onEnd)
  392. log("2000000000-huamajiangRoomView - runGameSendCardResponse()" )
  393. self.isShowFanLuoBo = true;
  394. local myUserId = app.room:getMyUserId()
  395. for k,v in pairs(app.room.roomInfo.memberList) do
  396. local viewId = app.room:getViewIdByUserId(v.nUserId)
  397. if self.playerHandCards[viewId] then
  398. self.playerHandCards[viewId]:createHandCards(v.handCards)
  399. self.playerHandCards[viewId]:resetHandCards()
  400. end
  401. if v.isBaoPai == 1 and myUserId == v.nUserId then
  402. --self.playerHandCards[viewId]:showBaoPai()
  403. self:showBaoJiao()
  404. end
  405. end
  406. -- local effect=MJAnimationCompnent.CreateGameStart()
  407. -- self.ui.Items.Layout_Player:addChild(effect,5)
  408. -- MJSound.PlayStartGame()
  409. MJAnimationCompnent.CreateStartSendCards(self.playerHandCards, function ()
  410. self.playerHandCards[MJDefine.MyViewId]:refreshLuoBoCards()
  411. if onEnd then
  412. onEnd();
  413. end
  414. end)
  415. local gameurle = app.room.roomInfo:getGameRuleByKey()
  416. local count = table.nums(app.room.roomInfo.memberList);
  417. local totalCards = gameurle == 1 and 144 or 216;
  418. local specRule = app.room.roomInfo:getGameRuleByKey("specRule");
  419. local isQuPai = getNumBand(specRule, 0x80);
  420. if isQuPai > 0 then
  421. totalCards = totalCards - math.floor(totalCards / 3);
  422. end
  423. self.direcionView:updateCardNums(totalCards - count * 13 - 4);
  424. self.toolView:showTuoGuan(app.room.roomInfo.hosting==1)
  425. end
  426. log("2000000000-huamajiangRoomView - addCallBack(runGameSendCardResponse)" )
  427. self:addCallBack(runGameSendCardResponse);
  428. end
  429. function huamajiangRoomView:onUserReadyResponse(response)
  430. logD("huamajiangRoomView:onUserReadyResponse", "有玩家准备了")
  431. huamajiangRoomView.super.onUserReadyResponse(self,response)
  432. local roomInfo = app.room.roomInfo;
  433. local myUserId = app.room:getMyUserId()
  434. if response and response.nUserId==myUserId then
  435. self.playerView:clearBao()
  436. self.playerView:clearAllPiao()
  437. roomInfo:setLuoBoCards({});
  438. -- local roomInfo = app.room.roomInfo
  439. -- for k,v in pairs(roomInfo.memberList) do
  440. -- self.ui.Items.Layout_Player:removeChildByTag(HU_EFFECT_TAG)
  441. -- end
  442. local totalCards = 144;
  443. local specRule = app.room.roomInfo:getGameRuleByKey("specRule");
  444. local isQuPai = getNumBand(specRule, 0x80);
  445. if isQuPai > 0 then
  446. totalCards = totalCards - math.floor(totalCards / 3);
  447. end
  448. self.direcionView:updateCardNums(totalCards);
  449. end
  450. self:setButtonTingInfoVisible(false);
  451. end
  452. -- 广播桌子上所有玩家庄家起手操作 这里其实是发牌
  453. function huamajiangRoomView:onBankerOutCard(data)
  454. --[[ -- 庄家uid
  455. , defVar("nUserId", VT_Int, 0)
  456. -- 庄家操作类型
  457. , defVar("mainOpCode", VT_Short, 0)
  458. --庄家是否需要出牌0不需要 1:需要
  459. , defVar("IsShouldOutCard", VT_UChar, 0)--]]
  460. local function runOnBankerOutCard(onEnd)
  461. logD("huamajiangRoomView:onBankerOutCard", "玩家抓牌", table.tostring(data.response))
  462. -- if not data.response.nUserId then
  463. -- showTooltip("庄家起手操作nUserId is not exist")
  464. -- end
  465. local nUserId = data.response.nUserId
  466. local viewId = app.room:getViewIdByUserId(nUserId)
  467. local card= data.response.card
  468. local operates=data.response.operates
  469. local nSeatId=data.response.nSeatId
  470. local roomInfo = app.room.roomInfo;
  471. -- roomInfo.outCardUserId = data.response.nUserId
  472. if self.playerHandCards[viewId] then
  473. self.playerHandCards[viewId]:onGetCard(operates,card)
  474. end
  475. --先清除所有操作按钮
  476. --self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  477. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  478. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true)
  479. if viewId == MJDefine.MyViewId then
  480. local huCards = roomInfo.memberList[nUserId].huCards or {};
  481. -- 默认抓牌隐藏听牌按钮
  482. self:setButtonTingInfoVisible(false);
  483. if table.nums(huCards) > 0 then
  484. -- 如果玩家已经胡了,则不隐藏听牌按钮
  485. self:setButtonTingInfoVisible(true);
  486. --ljx 勾选自动胡则锁手牌
  487. local specRule = roomInfo:getGameRuleByKey("specRule") or 0;
  488. if getNumBand(specRule, 0x08) > 0 then
  489. self.playerHandCards[viewId]:lockHandCard(true);
  490. end
  491. end
  492. if operates and table.nums(operates)>0 then
  493. self.operates = operates
  494. else
  495. self.operates = {}
  496. end
  497. if self.playerHandCards[MJDefine.MyViewId] then
  498. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  499. local player = roomInfo.memberList[data.response.nUserId]
  500. if player and player.isBaoPai==1 then
  501. self.playerHandCards[MJDefine.MyViewId]:lockHandCard()
  502. end
  503. end
  504. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  505. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  506. -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  507. self:setTingCardVisible(false);
  508. end
  509. -- local myUserId = app.room:getMyUserId()
  510. -- if data.response.nUserId == myUserId then
  511. -- if self.playerHandCards[MJDefine.MyViewId] then
  512. -- self.playerHandCards[MJDefine.MyViewId]:pushTing()
  513. -- end
  514. -- end
  515. if type(data.response.nLeaveCardNum) == "number" then
  516. roomInfo:setLeaveCardNum(data.response.nLeaveCardNum);
  517. end
  518. self:updateGameNums()
  519. self.direcionView:updateDirection(nSeatId)
  520. if onEnd then
  521. onEnd()
  522. end
  523. end
  524. log("2000000000-huamajiangRoomView - addCallBack(runOnBankerOutCard)")
  525. self:addCallBack(runOnBankerOutCard);
  526. end
  527. function huamajiangRoomView:onTurnOutCard(data)
  528. local function runOnTurnOutCard(onEnd)
  529. logE("MJRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  530. log("2000000000-MJRoomView - runOnOutCard")
  531. if app.room.roomInfo:getLastOutViewId() ~= MJDefine.MyViewId then
  532. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  533. end
  534. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  535. -- local card= data.response.card
  536. -- if self.playerHandCards[viewId] then
  537. -- self.playerHandCards[viewId]:createOutCards(card)
  538. -- end
  539. if onEnd then
  540. onEnd()
  541. end
  542. end
  543. log("2000000000-MJRoomView - addCallBack(runOnTurnOutCard)")
  544. self:addCallBack(runOnTurnOutCard)
  545. end
  546. --出牌成功
  547. function huamajiangRoomView:onOutCardSuccess(data)
  548. logE("huamajiangRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  549. local function runOnOutCardSuccess(onEnd)
  550. log("2000000000-huamajiangRoomView - runOnOutCardSuccess---------")
  551. -- app.room.roomInfo.outCardUserId = data.response.nUserId
  552. local roomInfo = app.room.roomInfo;
  553. local nUserId = data.response.nUserId
  554. local viewId = app.room:getViewIdByUserId(nUserId)
  555. local card= data.response.card
  556. local operates=data.response.operates
  557. local opType = operates.opType
  558. if operates and table.nums(operates)>0 then
  559. self.operates = operates
  560. self:setTingCardVisible(false);
  561. else
  562. self.operates = {}
  563. end
  564. local function callback()
  565. -- roomInfo:LastOutViewId(nil)
  566. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  567. if onEnd then
  568. onEnd()
  569. end
  570. end
  571. -- self.lastOutCard = card
  572. if self.playerHandCards[viewId] then
  573. --(viewId~=MJDefine.MyViewId or player.isBaoPai == 1) and roomInfo:getLastOutViewId()~=MJDefine.MyViewId
  574. if viewId==MJDefine.MyViewId then
  575. local gameInfo = roomInfo:getGameRule();
  576. local zidonghu = getNumBand(gameInfo.specRule, 0x08) or 0;
  577. local player = roomInfo.memberList[nUserId]
  578. local function doOutCard(viewId, card, callback)
  579. self.playerHandCards[viewId]:onOutCard(card,callback)
  580. --音效
  581. local userInfo=app.room:getUserInfoByViewId(viewId)
  582. if userInfo then
  583. MJSound.PlayMJSound(userInfo.sex,card)
  584. end
  585. end
  586. if ((player.isBaoPai==1 or player.isBaoPai==2) and roomInfo:getLastOutViewId()~=MJDefine.MyViewId) then
  587. -- 点击爆牌的时候 前端已经打出牌 要判断上次出牌的人是不是自己 避免重复出牌
  588. doOutCard(viewId, card, callback)
  589. elseif (self.playerHandCards[viewId]:isLock() and zidonghu > 0) and roomInfo:getLastOutViewId()~=MJDefine.MyViewId then
  590. -- 或者牌锁定状态下,后端自动出牌时,前端需要移除手牌
  591. doOutCard(viewId, card, callback)
  592. elseif self.needDeleteOutCard and true == self.needDeleteOutCard then
  593. self.needDeleteOutCard = nil
  594. uploadLogs("huamajiangduopai")
  595. doOutCard(viewId, card, callback)
  596. elseif app.room.roomInfo.hosting == 1 then
  597. -- 托管状态下
  598. doOutCard(viewId, card, callback)
  599. else
  600. callback();
  601. end
  602. self.playerHandCards[viewId]:setTing(false)
  603. if gameInfo.tingpai > 0 then
  604. self._isOutCardTingCheck = true;
  605. self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting)
  606. end
  607. if table.nums(player.huCards) > 0 then
  608. -- 胡牌后,显示听牌按钮
  609. self:setButtonTingInfoVisible(true);
  610. end
  611. -- self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  612. self:setTingCardVisible(false);
  613. -- self.isTing = true;
  614. -- self:setButtonTingInfoVisible(true);
  615. else
  616. self.playerHandCards[viewId]:onOutCard(card,callback)
  617. end
  618. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId})
  619. else
  620. callback()
  621. end
  622. roomInfo:setLastOutViewId(viewId);
  623. end
  624. log("2000000000-huamajiangRoomView - addCallBack(runOnOutCardSuccess)")
  625. self:addCallBack(runOnOutCardSuccess)
  626. end
  627. --已经发送了过操作,此时就算再勾选贴鬼碰,也不会显示操作
  628. function huamajiangRoomView:onSendGuo()
  629. --发牌重置,主要用于贴鬼碰/杠
  630. MJDefine.isSendGuo = false
  631. self.operates = {}
  632. end
  633. -- 操作成功
  634. function huamajiangRoomView:onOperationCodeSuccess(data)
  635. local function runOnOperationSuccess(onEnd)
  636. local response = data.response
  637. local nUserId = response.nUserId
  638. local opType = response.opType
  639. local opCard = response.opCard
  640. local bIsOutCard = response.isNeedOutCard > 0
  641. local fromSeatId = response.fromSeatId
  642. local cardNum = response.cardNum or 0;
  643. local viewId = app.room:getViewIdByUserId(nUserId)
  644. local fromViewId = app.room:getViewIdBySeatId(fromSeatId)
  645. local opSeatId = app.room:getSeatIdByViewId(viewId)
  646. local fromUserId = app.room:getUserIdBySeatId(fromSeatId)
  647. if self.playerHandCards[viewId] then
  648. --组合一下牌
  649. local groups={
  650. self:getChangeGruopDatas({opType=opType, opCard=opCard, cardNum = cardNum, targetSeatId=opSeatId, opUserId=fromUserId})
  651. }
  652. --删除手中对应的牌
  653. local deleteCards
  654. for k,v in pairs(groups) do
  655. if v.showType==MJDefine.MJGroupType.Peng then
  656. self.playerHandCards[viewId]:removeHandCardByNum(opCard,2,v.cardNum)
  657. elseif v.showType==MJDefine.MJGroupType.Chi then
  658. --TODO:吃的牌删除两张
  659. elseif v.showType==MJDefine.MJGroupType.AnGang
  660. or v.showType==MJDefine.MJGroupType.MAnGang then
  661. if v.cardNum <= 4 then
  662. self.playerHandCards[viewId]:removeHandCardByNum(opCard,4,v.cardNum)
  663. else
  664. -- 多头杠移除1张手牌
  665. self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.cardNum)
  666. end
  667. else
  668. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  669. self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.cardNum)
  670. else
  671. self.playerHandCards[viewId]:removeHandCardByNum(opCard,3,v.cardNum)
  672. end
  673. end
  674. end
  675. --删除出去的牌 遍历哪些操作需要删除牌
  676. for k,v in pairs(MJDefine.MJOperateNeedRemoveCard) do
  677. if v==opType then
  678. self.playerHandCards[fromViewId]:removeOutCard(opCard)
  679. break
  680. end
  681. end
  682. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  683. self.playerHandCards[viewId]:buGang(opCard,cardNum)
  684. else
  685. self.playerHandCards[viewId]:createGroupCards(groups)--创建显示的牌
  686. end
  687. self.playerHandCards[viewId]:resetHandCards()
  688. self.playerHandCards[viewId]:hideOperate()
  689. self.playerHandCards[viewId]:setOutCardEnable(bIsOutCard)
  690. if self.playerHandCards[viewId]:isLock() then
  691. self.playerHandCards[viewId]:lockHandCard();
  692. end
  693. self.direcionView:updateDirection(app.room:getSeatIdByViewId(viewId))
  694. end
  695. local function guafengxiayuEffect()
  696. local effect
  697. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  698. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) then
  699. effect=MJAnimationCompnent.createGuaFengEffect()
  700. MJSound.PlayWindSound()
  701. elseif (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  702. effect=MJAnimationCompnent.createXiaYuEffect()
  703. MJSound.PlayRainSound()
  704. end
  705. if effect then
  706. self.ui.Items.Layout_Player:addChild(effect)
  707. effect:setLocalZOrder(1000)
  708. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  709. end
  710. end
  711. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  712. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) or (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  713. -- 花麻将直接播放刮风下雨效果,不播放“杠”字效果
  714. guafengxiayuEffect();
  715. else
  716. local effectCallback = function ()
  717. guafengxiayuEffect();
  718. end
  719. --播放动画
  720. local effect=MJAnimationCompnent.CreateOperareEffect(opType, effectCallback)--,onEnd)
  721. if effect then
  722. self.ui.Items.Layout_Player:addChild(effect);
  723. effect:setLocalZOrder(1000);
  724. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion());
  725. end
  726. end
  727. self:showOperateScore(response.optScore);
  728. --音效
  729. local userInfo=app.room:getUserInfo(nUserId)
  730. if userInfo then
  731. MJSound.PlayOperateSound(userInfo.sex,opType)
  732. end
  733. if viewId == MJDefine.MyViewId then
  734. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  735. self:setButtonTingInfoVisible(false)
  736. self.operates={}
  737. end
  738. --删除等待操作的显示
  739. if self.waitOperates and #self.waitOperates>0 then
  740. for k,v in pairs(self.waitOperates) do
  741. v:removeFromParent()
  742. end
  743. self.waitOperates={}
  744. end
  745. --[[if viewId == MJDefine.MyViewId and opType==MJDefine.MJOperateType.OPREATE_PENG then
  746. local cards = {opCard}
  747. self.playerHandCards[viewId]:cardEnabled(cards, true)
  748. end--]]
  749. -- 取消操作按钮
  750. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  751. if onEnd then
  752. onEnd()
  753. end
  754. end
  755. self:addCallBack(runOnOperationSuccess)
  756. end
  757. function huamajiangRoomView:test()
  758. self.playerHandCards={}
  759. self.playerHandCards[MJDefine.MyViewId] = MJHandCardView:new(MJDefine.MyViewId)
  760. -- self:addChild(self.playerHandCards[MJDefine.MyViewId])
  761. self:addToLayer("game", self.playerHandCards[MJDefine.MyViewId]);
  762. self.playerView = MJRoomPlayerView:new()
  763. -- self:addChild(self.playerView)
  764. self:addToLayer("game", self.playerView);
  765. end
  766. --飘状态停止
  767. function huamajiangRoomView:stopDirection()
  768. if not tolua.isnull(self.direcionView) then
  769. self.direcionView:stopAllActions()
  770. self.direcionView.ui.Items.ImageView_Dir_Down:setVisible(false)
  771. self.direcionView.ui.Items.ImageView_Dir_Up:setVisible(false)
  772. self.direcionView.ui.Items.ImageView_Dir_Left:setVisible(false)
  773. self.direcionView.ui.Items.ImageView_Dir_Right:setVisible(false)
  774. self.direcionView.ui.Items.Text_Time:setString(string.format("%02d",0))
  775. end
  776. end
  777. function huamajiangRoomView:onGameReconnection()
  778. local function onGameReconnectionCallback(onEnd)
  779. --更新房间基础数据
  780. local roomInfo = app.room.roomInfo;
  781. self:updateRoomBaseData()
  782. if (not isReviewVersion()) and cc.Application:getInstance():getTargetPlatform() ~= 0 then
  783. self:updateAllGpsInfo()
  784. end
  785. -- self:checkGpsDistance(nil,roomInfo:getGameStartCount() == 0)
  786. -- self:checkMyGpsNeedUpdate();
  787. self.toolView:updateButton()
  788. --显示离线状态
  789. for k,v in pairs(roomInfo.memberList) do
  790. local viewId = app.room:getViewIdByUserId(k)
  791. self.playerView:setPlayerOffLineVisible(v.nOnlineStatus ~= MJDefine.PlayerOnlineStatus.Online, viewId)
  792. end
  793. if roomInfo:getGameStartCount() > 0 then
  794. -- 当前局数大于0,处于重连状态
  795. self:handleGameReconnection();
  796. else
  797. -- 游戏未开始,非重连
  798. self:handleGameNormal();
  799. end
  800. if onEnd then
  801. onEnd();
  802. end
  803. end
  804. self:addCallBack(onGameReconnectionCallback);
  805. end
  806. --[[
  807. 重连游戏的逻辑处理
  808. ]]
  809. function huamajiangRoomView:handleGameReconnection()
  810. local roomInfo = app.room.roomInfo;
  811. local myUserId = app.room:getMyUserId();
  812. local memberStatus = {};
  813. local dismissUserId = 0;
  814. local gameStatus = roomInfo:getGameStatus();
  815. -- 当前局数大于0,子游戏重连
  816. if self._fastRequestView then
  817. -- 隐藏快速开局
  818. self._fastRequestView:removeSelf()
  819. self._fastRequestView = nil
  820. end
  821. --隐藏俱乐部
  822. self:hideClub()
  823. self.toolView:setFlowVisible(true);
  824. self.toolView:showTuoGuan(app.room.roomInfo.hosting == 1)
  825. for k,v in pairs(roomInfo.memberList) do
  826. local viewId = app.room:getViewIdByUserId(k)
  827. -- local nOffLineState = v.nOnlineStatus
  828. -- --显示离线
  829. -- self.playerView:setPlayerOffLineVisible(nOffLineState ~= MJDefine.PlayerOnlineStatus.Online,viewId)
  830. --发起解散状态的ID
  831. dismissUserId = (v.nDisbandStatus == 1) and v.nUserId or dismissUserId;
  832. if v.nDisbandStatus ~= 0 then
  833. table.insert(memberStatus,{userId = v.nUserId , status = v.nDisbandStatus})
  834. end
  835. local extInfo = roomInfo.extJson or ""
  836. if type(extInfo)=='table' and extInfo[tostring(v.nUserId)] then
  837. local info = extInfo[tostring(v.nUserId)]
  838. local host = info.hosted or 0--托管状态
  839. local isTuoGuan = host == 1;
  840. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  841. end
  842. end
  843. --显示解散界面
  844. if roomInfo:getIsUserDisbandGame() == 1 and dismissUserId ~= 0 and roomInfo:getIsGameOver() ~= 1 then
  845. local view = require("luaScript.Views.Room.RoomDismissView"):new(dismissUserId, roomInfo.memberList, roomInfo:getDismissStateTime());
  846. -- self:addChild(view,1);
  847. self:addToLayer("popup", view);
  848. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS, memberStatus = memberStatus});
  849. end
  850. --如果一局结束,玩家点了准备,不再显示牌信息
  851. if MJDefine.GameStatus.GAME_STATUS_ROUND_OVER == gameStatus or MJDefine.GameStatus.GAME_STATUS_GAME_OVER == gameStatus then
  852. if roomInfo.memberList[myUserId].nPlayerFlag == 1 then --游戏为停止或开始状态
  853. self:onUserReadyResponse({nUserId = myUserId});
  854. return
  855. end
  856. end
  857. -- 刷新庄家显示
  858. self:updateBanker()
  859. -- 初始化玩家手牌节点
  860. self:initHandCardNodes()
  861. --初始化方位
  862. self.direcionView:initDirection(self.desktopType)
  863. self.direcionView:updateDirection(app.room:getSeatIdByUserId(roomInfo:getNeedOutCardId()));
  864. self.direcionView:updateCardNums(roomInfo:getLeaveCardNum())
  865. --显示用户的牌
  866. for userId,v in pairs(roomInfo.memberList) do
  867. local viewId = app.room:getViewIdByUserId(userId)
  868. if self.playerHandCards[viewId] then
  869. --组合一下牌
  870. local groups={}
  871. for k, v in ipairs(v.operates) do
  872. table.insert(groups, self:getChangeGruopDatas(v));
  873. end
  874. self.playerHandCards[viewId]:createGroupCards(groups);
  875. self.playerHandCards[viewId]:createOutCards(v.outCards);
  876. if table.nums(v.huCards) > 0 and viewId ~= MJDefine.MyViewId then
  877. self.playerHandCards[viewId]:createOpenHandCards(v.handCards);
  878. else
  879. self.playerHandCards[viewId]:createHandCards(v.handCards);
  880. -- self.playerHandCards[viewId]:moveLastCard()
  881. if v.canBaoPai == 1 and viewId ~= MJDefine.MyViewId and v.nSeatId == roomInfo:getBankSeatId() then
  882. -- 庄家报牌的情况下,其他玩家看不到出牌,需补一张手牌
  883. self.playerHandCards[viewId]:createHandCards(0);
  884. self.playerHandCards[viewId]:moveLastCard();
  885. end
  886. end
  887. if v.nPlayerFlag > 1 then
  888. if viewId == MJDefine.MyViewId then
  889. -- self.playerHandCards[viewId]:resetHandCards();
  890. --显示听
  891. if v.nTingStatus==MJDefine.MJTingStatus.Ting then
  892. -- self:setChaTingCardViewVisible(true);
  893. if v.canBaoPai ~= 1 then
  894. self:setButtonTingInfoVisible(true);
  895. end
  896. end
  897. local operates = roomInfo:getOperates();
  898. self.operates = (operates and table.nums(operates)>0) and operates or {};
  899. --local outCardUserId = app.room:getUserIdBySeatId(roomInfo:getNeedOutCardId())
  900. local bIsOutCard = roomInfo:getIsNeedOutCard() > 0 or false
  901. if (not bIsOutCard) and v.nTingStatus == MJDefine.MJTingStatus.Ting then
  902. -- local gameInfo =app.room.roomInfo:getGameRule();
  903. -- self:setButtonTingInfoVisible(gameInfo.tingpai > 0);
  904. end
  905. if v.canBaoPai == 1 then
  906. local lastOpCard = roomInfo:getLastOpCard();
  907. if v.nUserId == roomInfo:getOutCardUserId() and lastOpCard > 0 then
  908. roomInfo:setLastOutViewId(viewId);
  909. self.playerHandCards[viewId]:runOutCardAction(lastOpCard);
  910. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value = lastOpCard,viewId = viewId})
  911. end
  912. self:showBaoJiao();
  913. end
  914. if roomInfo:getGameRuleByKey("piaomode") == 1 then
  915. -- 只有三人、四人才会有飘,做人数限制是因为快速开局不确定人数,可以选择飘
  916. __ = v.canPiao <= 0 and self:showPiao(); -- 可以飘玩家显示飘
  917. end
  918. if table.nums(v.huCards) > 0 then
  919. -- 已经胡牌的玩家,不能操作手牌
  920. self.playerHandCards[viewId]:lockHandCard();
  921. local specRule = roomInfo:getGameRuleByKey("specRule") or 0;
  922. if getNumBand(specRule, 0x08) > 0 then
  923. self.playerHandCards[viewId]:lockHandCard(true);
  924. --ljx 添加重连回来 如果胡牌且勾选了自动胡 不显示过按钮
  925. app.room.roomInfo.passGuo = true;
  926. end
  927. end
  928. if v.nTingStatus==MJDefine.MJTingStatus.Ting or table.nums(v.huCards) > 0 or v.isBaoPai ~= 0 then
  929. -- 听牌、报叫、胡牌情况下,显示听牌按钮
  930. -- 此时需重新请求一下听牌数据,否则显示为空
  931. self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting)
  932. self.isTing = true;
  933. self:setButtonTingInfoVisible(true);
  934. end
  935. end
  936. --已爆牌玩家不能出牌
  937. if v.isBaoPai ~= 0 then
  938. if v.isBaoPai == 1 then-- 报叫
  939. self.playerView:playBaoAnim(viewId)
  940. end
  941. if v.nUserId == myUserId then --自己爆牌
  942. self.playerHandCards[viewId]:lockHandCard()
  943. end
  944. end
  945. local isHu = table.nums(v.huCards) > 0;
  946. self.playerView:showHu(viewId, isHu);
  947. --显示飘状态
  948. self.playerView:showPiao(viewId,tonumber(v.isPiao) == 1)
  949. end
  950. if roomInfo:getNeedOutCardId() == userId then
  951. local lastOpCard = roomInfo:getLastOpCard();
  952. if userId == myUserId and lastOpCard ~= 0 then
  953. self.playerHandCards[viewId]:removeHandCard(lastOpCard);
  954. self.playerHandCards[viewId]:resetHandCards();
  955. self.playerHandCards[viewId]:createHandCards(lastOpCard);
  956. end
  957. self.playerHandCards[viewId]:setOutCardEnable(true);
  958. end
  959. -- 刷新胡牌
  960. self.playerHandCards[viewId]:onGetHuCard(v.huCards, true);
  961. end
  962. local reserve = v.reserve;
  963. local opList = json.decode(reserve);
  964. local resopnse = {};
  965. resopnse.nUserId = v.nUserId;
  966. if opList and table.nums(opList) > 0 then
  967. resopnse.opType = opList.subOpt;
  968. self:onWaitOperate({response = resopnse})
  969. end
  970. end
  971. --显示出牌角标
  972. local lastOutCardViewId = app.room:getViewIdByUserId(roomInfo:getOutCardUserId());
  973. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = roomInfo:getLastOpCard(), viewId = lastOutCardViewId});
  974. --等待换牌 设置换牌显示
  975. if gameStatus == MJDefine.GameStatus.GAME_STATUS_WAIT_SWAP_CARDS then
  976. self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent()
  977. self:showSwapCard(true,10)
  978. self.swapCard.Items.Button_sure:setEnabled(false)
  979. for i, player in pairs(roomInfo.swapCardList) do
  980. local viewId = app.room:getViewIdByUserId(player.nUserId)
  981. if player.nUserId == myUserId then
  982. if player.isSwapCard == 1 and self.swapCard and self.swapCard.Items.ImageView_bg then--操作过换牌
  983. self.swapCard.Items.ImageView_bg:setVisible(false)
  984. end
  985. else
  986. self:setSwapCardSucc(player.isSwapCard == 1,viewId)
  987. end
  988. if player.isSwapCard == 1 then
  989. self.playerHandCards[viewId]:createSwapCards({0,0,0})
  990. end
  991. end
  992. end
  993. --设置可以出牌的人
  994. -- local outCardViewId = app.room:getViewIdBySeatId(roomInfo.outCardSeatId)
  995. -- if outCardViewId then
  996. -- if (outCardViewId~=MJDefine.MyViewId and roomInfo.lastOpCard==0) or (outCardViewId == MJDefine.MyViewId or roomInfo.isNeedOutCard) then
  997. -- self.playerHandCards[outCardViewId]:setOutCardEnable(true)
  998. -- end
  999. -- end
  1000. --显示听标示
  1001. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing});
  1002. --如果有操作显示操作按钮
  1003. self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo:getOperates(), roomInfo:getLastOpCard());
  1004. --显示结算界面
  1005. if gameStatus == MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or gameStatus == MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  1006. -- 摊开手牌
  1007. self:showOpenCard()
  1008. -- 显示小局结算
  1009. self:showXiaoJuView();
  1010. end
  1011. self:setBtnSitDownVisible(false)
  1012. end
  1013. --[[
  1014. 游戏未开始时的逻辑处理
  1015. ]]
  1016. function huamajiangRoomView:handleGameNormal()
  1017. local roomInfo = app.room.roomInfo;
  1018. local gameStatus = roomInfo:getGameStatus();
  1019. local gameInfo = roomInfo:getGameRule();
  1020. local myUserId = app.room:getMyUserId();
  1021. if gameStatus and gameStatus < MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START then
  1022. --self.toolView:enableHosting(false)
  1023. local quickStartInfo = roomInfo:getQuickStartInfo();
  1024. if quickStartInfo then
  1025. if quickStartInfo.tablefaststate == 1 or quickStartInfo.tablefaststate == true then
  1026. local tmpInfo = {}
  1027. for uid,status in pairs(quickStartInfo.list) do
  1028. table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status})
  1029. end
  1030. local response = {}
  1031. response.pList = tmpInfo
  1032. response.timeOut = roomInfo:getQuickStartInfo().time
  1033. self:onBroadcastFaststart({response=response})
  1034. else
  1035. --self.toolView:showFastStart(true)
  1036. end
  1037. else
  1038. if self._fastRequestView then
  1039. self._fastRequestView:removeSelf()
  1040. self._fastRequestView = nil
  1041. end
  1042. --self.toolView:showFastStart(true)
  1043. end
  1044. elseif gameStatus == MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or gameStatus == MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  1045. local mySelf = roomInfo.memberList[myUserId];
  1046. if mySelf.nPlayerFlag ~= 1 then
  1047. --显示哪些玩家胡牌
  1048. for i,player in pairs(roomInfo.memberList) do
  1049. local viewId = app.room:getViewIdByUserId(player.nUserId)
  1050. --已爆牌玩家
  1051. if player.isBaoPai ~= 0 then
  1052. self.playerView:playBaoAnim(viewId)
  1053. end
  1054. end
  1055. end
  1056. elseif gameStatus == MJDefine.GameStatus.GAME_STATUS_WAIT_PIAO then
  1057. self:stopDirection()
  1058. for i, player in pairs(roomInfo.memberList) do
  1059. local viewId = app.room:getViewIdByUserId(player.nUserId)
  1060. if myUserId == player.nUserId then
  1061. if tonumber(player.canPiao) == 1 then -- 操作过飘了
  1062. self.playerView:showPiao(viewId,tonumber(player.isPiao) == 1)
  1063. else
  1064. if gameInfo.piaomode == 1 then--可以飘 还没有飘 显示飘按钮
  1065. self:showPiao()
  1066. end
  1067. end
  1068. else
  1069. self.playerView:showPiao(viewId,tonumber(player.isPiao) == 1)
  1070. end
  1071. if tonumber(player.isPiao) == 1 then
  1072. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1073. if effect then
  1074. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  1075. effect:setLocalZOrder(1000)
  1076. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1077. end
  1078. end
  1079. end
  1080. end
  1081. end
  1082. function huamajiangRoomView:getChangeGruopDatas(g)
  1083. local opType = g.opType
  1084. local showType = MJDefine.MJOperateToGroupType[g.opType]
  1085. local opCard = g.opCard
  1086. local cardNum = g.cardNum
  1087. local fromViewId = nil
  1088. local targetSeatId = g.targetSeatId--操作位置座位号
  1089. local fromUserId = g.opUserId or g.fromUserId --触发操作玩家
  1090. local fromViewId1 = app.room:getViewIdByUserId(fromUserId)
  1091. if fromUserId > 0 and targetSeatId then
  1092. fromViewId = app.room:transPos(targetSeatId, app.room:getSeatIdByUserId(fromUserId))
  1093. --判断是否是对面玩家,对面玩家的话要做一次翻转
  1094. local opViewId = app.room:getViewIdBySeatId(targetSeatId)
  1095. if opViewId == 2 then --对面
  1096. if fromViewId == 1 then
  1097. fromViewId = 3
  1098. elseif fromViewId == 3 then
  1099. fromViewId = 1
  1100. end
  1101. end
  1102. --三人玩只有上下家
  1103. if app.room:getMaxPlayerCount() == 3 and fromViewId == 2 then fromViewId = 3 end
  1104. if app.room:getMaxPlayerCount() == 2 and fromViewId ~= 0 then
  1105. fromViewId = showType == MJDefine.MJGroupType.Peng and 2 or 4;
  1106. end
  1107. end
  1108. --组合一下牌
  1109. local group={
  1110. opType = opType,
  1111. showType = showType,
  1112. values = {},
  1113. opCard = opCard,
  1114. cardNum = cardNum,
  1115. fromViewId = fromViewId,
  1116. fromViewId1 = fromViewId1,--真正的来源viewID
  1117. }
  1118. if MJDefine.MJGroupType.Chi==showType then
  1119. elseif MJDefine.MJGroupType.Peng==showType then
  1120. group.values={opCard,opCard,opCard}
  1121. else
  1122. group.values={opCard,opCard,opCard,opCard}
  1123. end
  1124. return group
  1125. end
  1126. -- 小局结算
  1127. function huamajiangRoomView:onGameXiaoJuResponse(data)
  1128. local function runGameXiaoJuResponse(onEnd)
  1129. if not tolua.isnull(self.firstTingTipsView) then
  1130. self.firstTingTipsView:killSelf()
  1131. self.firstTingTipsView = nil
  1132. end
  1133. -- 取消操作按钮
  1134. if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
  1135. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  1136. end
  1137. local roomInfo = app.room.roomInfo
  1138. if not tolua.isnull(self.direcionView) then
  1139. self.direcionView:stopAllActions()
  1140. end
  1141. self.operates = {}
  1142. self:setTingCardVisible(false);
  1143. app.room:resetTings()
  1144. app.room:cleanTingStatus()
  1145. --如果是解散直接return
  1146. --[[if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1147. if onEnd then
  1148. onEnd()
  1149. end
  1150. return
  1151. end --]]
  1152. --所有胡牌的人 考虑抢杠胡的问题
  1153. --[[local viewIds={}
  1154. local failViewId=0
  1155. for k,v in pairs(roomInfo.memberList) do
  1156. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1157. if v.result>0 then
  1158. table.insert(viewIds,viewId)
  1159. --处理掉huCard, 不加入手牌
  1160. --播放音效
  1161. if viewId==MJDefine.MyViewId then
  1162. --MJSound.PlayWinGame()
  1163. end
  1164. if v.result==MJDefine.MJGameHuType.HU_DIANPAO then
  1165. failViewId = app.room:getViewIdBySeatId(v.dpSeatId)
  1166. end
  1167. end
  1168. end]]
  1169. self:showOpenCard()
  1170. --被抢杠的人回退补杠
  1171. -- if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_NORMAL then
  1172. -- self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard)
  1173. -- end
  1174. local function callback()
  1175. local roomInfo = app.room.roomInfo
  1176. local memberList = roomInfo.memberList;
  1177. local hasHandcards = true;
  1178. for k, v in pairs(memberList) do
  1179. if v.handCards and #v.handCards == 0 then
  1180. hasHandcards = false;
  1181. break;
  1182. end
  1183. end
  1184. if not hasHandcards then
  1185. -- 还没发牌就结束游戏,直接返回大厅
  1186. app.room.roomInfo.needJieSuanInfo = 1;
  1187. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
  1188. return ;
  1189. end
  1190. self:showXiaoJuView()
  1191. if onEnd then
  1192. onEnd()
  1193. end
  1194. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  1195. end
  1196. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  1197. local effect=MJAnimationCompnent.CreateLiuJuEffect(callback)
  1198. self.ui.Items.Layout_Player:addChild(effect)
  1199. effect:setLocalZOrder(1000)
  1200. MJSound.PlayHuangZhuang()
  1201. else
  1202. local delayTime = 1.5;
  1203. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1204. delayTime = 0;
  1205. end
  1206. runDelay(delayTime, function ()
  1207. callback()
  1208. end)
  1209. end
  1210. end
  1211. self:addCallBack(runGameXiaoJuResponse);
  1212. end
  1213. -- 显示小局结算
  1214. function huamajiangRoomView:showXiaoJuView()
  1215. if not tolua.isnull(self.direcionView) then
  1216. self.direcionView:stopAllActions()
  1217. end
  1218. self:setTingCardVisible(false);
  1219. if self.xiaojuView then
  1220. self.xiaojuView:removeFromParent()
  1221. end
  1222. local roomInfo = app.room.roomInfo
  1223. local memberList = roomInfo.memberList;
  1224. for k, v in pairs(memberList) do
  1225. local viewId = app.room:getViewIdByUserId(v.nUserId);
  1226. local huCards = v.huCards;
  1227. if self.playerHandCards[viewId] then
  1228. self.playerHandCards[viewId]:onGetHuCard(huCards, true);
  1229. end
  1230. --刷新玩家分数
  1231. local nodes = self.playerView.allNodes[viewId]
  1232. nodes.score:setText(tostring(v.nTotalMoney))
  1233. end
  1234. self.xiaojuView = MJRoomXiaoJuView:new(self.desktopType)
  1235. self:addToLayer("popup", self.xiaojuView);
  1236. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1237. self.xiaojuView:onClickChaPai()
  1238. end
  1239. app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_XIAOJU_VIEW_SHOWED});
  1240. end
  1241. function huamajiangRoomView:onEventBtnShowFlowViewClicked (event)
  1242. logD("huamajiangRoomView:onButtonFlowClicked");
  1243. local data = event.response;
  1244. if not data then
  1245. local roomInfo = app.room.roomInfo;
  1246. data = {};
  1247. local scoreInfo = roomInfo:getScoreInfo();
  1248. local luoboCards = roomInfo:getLuoBoCards();
  1249. luoboCards = roomInfo:getLuoBoCardsSummary(luoboCards)
  1250. local scoreData = {};
  1251. for k, v in ipairs(scoreInfo) do
  1252. table.insert(scoreData, json.decode(v));
  1253. end
  1254. data.detail = scoreData
  1255. data.luoboCards = luoboCards;
  1256. end
  1257. local flowView = MJFramework.MJImport("mj_huamajiang.luaScript.Views.Components.huamajiangFlowView"):new(data, self.desktopType);
  1258. if data.isReplay then
  1259. self:addChild(flowView);
  1260. else
  1261. self:addToLayer("popup", flowView);
  1262. end
  1263. end
  1264. --- huamajiangRoomView:setChaTingCardViewVisible 显示查听的牌,花麻将弃用
  1265. function huamajiangRoomView:setChaTingCardViewVisible(bVisible,tingCards)
  1266. end
  1267. --- huamajiangRoomView:setTingCardViewVisible 显示听牌框,花麻将弃用
  1268. function huamajiangRoomView:setTingCardViewVisible(bVisible,tingCards)
  1269. end
  1270. function huamajiangRoomView:onTingCardStatus()
  1271. local myUserId=app.user.loginInfo.uid;
  1272. local memberList=app.room.roomInfo.memberList;
  1273. local player = memberList[myUserId];
  1274. if not player then
  1275. return ;
  1276. end
  1277. local nTingStatus = player.nTingStatus
  1278. if nTingStatus == MJDefine.MJTingStatus.Ting then
  1279. print("---------onTingCardStatus-----------1 "..myUserId)
  1280. if player.isBaoPai == 1 then
  1281. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1282. end
  1283. self.isTing = true;
  1284. self:setButtonTingInfoVisible(true);
  1285. else
  1286. print("---------onTingCardStatus-----------0 "..myUserId)
  1287. self:setButtonTingInfoVisible(false);
  1288. end
  1289. end
  1290. function huamajiangRoomView:onTingCardResult(data)
  1291. print("---------听牌结果-------------")
  1292. local tingCards = data.response.tingCards or {};
  1293. self.isTing = table.nums(tingCards) > 0;
  1294. self:setButtonTingInfoVisible(self.isTing);
  1295. self._tingCardView:setData(tingCards);
  1296. end
  1297. function huamajiangRoomView:showTing(evet)
  1298. local roomInfo=app.room.roomInfo;
  1299. local selectCard = evet.card;
  1300. if not selectCard or evet.card <= 0 then
  1301. return;
  1302. end
  1303. local curTingCards = roomInfo:getTingCardsByCard(selectCard);
  1304. if not self._tingCardView then
  1305. return ;
  1306. end
  1307. self._tingCardView:setData(curTingCards);
  1308. self.isTing = table.nums(curTingCards) > 0;
  1309. if self.isTing and (not self:isMySelfHu()) then
  1310. self:setTingCardVisible(true);
  1311. else
  1312. self:setTingCardVisible(false);
  1313. end
  1314. end
  1315. function huamajiangRoomView:isMySelfHu()
  1316. local myUserId = app.room:getMyUserId();
  1317. local player = app.room.roomInfo.memberList[myUserId];
  1318. if not player then
  1319. return false;
  1320. end
  1321. local huCards = player.huCards or {};
  1322. return table.nums(huCards) > 0;
  1323. end
  1324. function huamajiangRoomView:setButtonTingInfoVisible (isVisible)
  1325. if self.btnTing then
  1326. self.btnTing:setVisible(isVisible);
  1327. end
  1328. end
  1329. function huamajiangRoomView:setTingCardVisible (isVisible)
  1330. if not self._tingCardView then
  1331. return ;
  1332. end
  1333. self._tingCardView:setVisible(isVisible);
  1334. end
  1335. function huamajiangRoomView:pushTing()
  1336. local function runPushTing(onEnd)
  1337. local myUserId = app.room:getMyUserId();
  1338. local player = app.room.roomInfo.memberList[myUserId]
  1339. local huCards = player.huCards;
  1340. if self.playerHandCards[MJDefine.MyViewId] then
  1341. if not (table.nums(huCards) > 0 or player.isBaoPai > 0) then
  1342. -- 已经胡牌、报叫的玩家,不显示听牌箭头
  1343. self.playerHandCards[MJDefine.MyViewId]:pushTing()
  1344. end
  1345. end
  1346. if onEnd then
  1347. onEnd()
  1348. end
  1349. end
  1350. self:addCallBack(runPushTing);
  1351. end
  1352. function huamajiangRoomView:onHuResponse(data)
  1353. local function runHuResponse(onEnd)
  1354. local response = data.response
  1355. --是否一炮多响
  1356. local daPaoHaoShuang = response.huRenShu > 1
  1357. local huPaiIndex = response.huIndex
  1358. local function callback()
  1359. self:playHuAni(response)
  1360. if onEnd then
  1361. onEnd()
  1362. end
  1363. end
  1364. --删除等待操作的显示
  1365. if self.waitOperates and #self.waitOperates>0 then
  1366. for k,v in pairs(self.waitOperates) do
  1367. v:removeFromParent()
  1368. end
  1369. self.waitOperates={}
  1370. end
  1371. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1372. local userInfo=app.room:getUserInfoByViewId(viewId)
  1373. local roomInfo = app.room.roomInfo;
  1374. local isNeedRemoveCard = false
  1375. local isPlayHuEffect = false;
  1376. local huInfos = {};
  1377. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1378. isPlayHuEffect = true;
  1379. local huData = {};
  1380. huData.huType = response.huType;
  1381. huData.viewId = viewId;
  1382. huData.userInfo = app.room:getUserInfoByViewId(viewId);
  1383. table.insert(huInfos, huData);
  1384. else
  1385. local ext = roomInfo.memberList[response.nUserId].ext or {};
  1386. local huIndex = roomInfo.memberList[response.nUserId].huIndex;
  1387. if response.isReplay then
  1388. local seat = app.room:getSeatIdByUserId(response.nUserId);
  1389. ext.seat = string.format("%s;", seat);
  1390. huIndex = 1;
  1391. end
  1392. local huSeats = string.split(ext.seat, ";");
  1393. if huSeats and huIndex then
  1394. if (#huSeats - 1) == huIndex then -- 因为最后一个是空格,所以要减一
  1395. isNeedRemoveCard = true
  1396. isPlayHuEffect = true;
  1397. for k, v in ipairs(huSeats) do
  1398. if string.len(v) > 0 then
  1399. local seat = tonumber(v);
  1400. local huData = {};
  1401. huData.huType = MJDefine.MJGameHuType.HU_DIANPAO;
  1402. huData.viewId = app.room:getViewIdBySeatId(seat);
  1403. huData.userInfo = app.room:getUserInfoByViewId(huData.viewId);
  1404. table.insert(huInfos, huData);
  1405. end
  1406. end
  1407. end
  1408. end
  1409. end
  1410. if isPlayHuEffect then
  1411. for k, v in ipairs(huInfos) do
  1412. --先播放胡牌动画和音效,再显示胡牌顺序
  1413. local effect = MJAnimationCompnent.CreateHuEffect(v.huType)
  1414. if v.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1415. MJSound.PlayOperateSound(v.userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU)
  1416. else
  1417. MJSound.PlayOperateSound(v.userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU)
  1418. end
  1419. self.ui.Items.Layout_Effect:addChild(effect)
  1420. effect:setTag(HU_EFFECT_TAG)
  1421. effect:setLocalZOrder(1000)
  1422. effect:setPosition(self.playerHandCards[v.viewId]:getAnimationPostion())
  1423. end
  1424. self:showOperateScore(response.optScore);
  1425. --放炮动画
  1426. if response.huType ~= MJDefine.MJGameHuType.HU_ZIMO then
  1427. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1428. local effect=MJAnimationCompnent.CreateDianPaoEffect()
  1429. self.ui.Items.Layout_Effect:addChild(effect)
  1430. effect:setLocalZOrder(1000)
  1431. effect:setPosition(self.playerHandCards[failViewId]:getAnimationPostion())
  1432. end
  1433. end
  1434. local huCards = roomInfo.memberList[response.nUserId].huCards;
  1435. local huCard = response.huCard;
  1436. if response.huType==MJDefine.MJGameHuType.HU_DIANPAO then
  1437. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1438. --点炮胡或抢杠胡,胡牌类型都是发 点炮胡
  1439. if response.isQiangGng > 0 then
  1440. -- logD("isQiangGng huCard:"..huCard)
  1441. --抢杠胡
  1442. -- self.playerHandCards[viewId]:onGetCard(nil,huCard)
  1443. self.playerHandCards[viewId]:onGetHuCard({huCard},nil,{yipaoduoxiang = daPaoHaoShuang,huPaiIndex = huPaiIndex});
  1444. --被抢杠的人回退补杠
  1445. if daPaoHaoShuang then
  1446. if huPaiIndex == 1 then
  1447. self.playerHandCards[failViewId]:retoreBuGang(huCard.huCard,1)
  1448. end
  1449. else
  1450. self.playerHandCards[failViewId]:retoreBuGang(huCard.huCard,1)
  1451. end
  1452. -- self.playerHandCards[failViewId]:removeHandCardByNum(huCard, 1);
  1453. self.playerHandCards[failViewId]:resetHandCards();
  1454. -- 自动胡情况下,抢杠会自动出牌,此处需设置被抢杠玩家为上次出牌玩家
  1455. -- 否则会出现多牌情况
  1456. local gameInfo = roomInfo:getGameRule();
  1457. local zidonghu = getNumBand(gameInfo.specRule, 0x08) or 0;
  1458. if zidonghu > 0 then
  1459. roomInfo:setLastOutViewId(failViewId);
  1460. end
  1461. elseif response.isGspHu and response.isGspHu > 0 then--点杠炮事手上已经有杠的牌 不需要再加一张胡的牌
  1462. --将胡的牌收走
  1463. if not self.playerHandCards[viewId]:removeLastHandCard() then
  1464. if isNeedRemoveCard then
  1465. self.playerHandCards[failViewId]:removeOutCard(huCard.huCard);
  1466. end
  1467. end
  1468. self.playerHandCards[viewId]:onGetHuCard({huCard});
  1469. else
  1470. -- self.playerHandCards[viewId]:onGetCard(nil,response.huCard)
  1471. self.playerHandCards[viewId]:onGetHuCard({huCard});
  1472. --将胡的牌收走
  1473. if isNeedRemoveCard then
  1474. self.playerHandCards[failViewId]:removeOutCard(huCard.huCard);
  1475. end
  1476. end
  1477. if failViewId==MJDefine.MyViewId and roomInfo:getLastOutViewId() == MJDefine.MyViewId then --修改点炮的人连续二次出牌 不删除牌
  1478. roomInfo:setLastOutViewId(nil);
  1479. end
  1480. --此处仅做保留,没有实际意义
  1481. elseif response.huType==MJDefine.MJGameHuType.HU_QIANGGANG then
  1482. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1483. if response.redRealCard > 0 then
  1484. --抢杠胡时,胡牌的人将胡的牌加入手中
  1485. -- self.playerHandCards[viewId]:onGetCard(nil,response.redRealCard)
  1486. self.playerHandCards[viewId]:onGetHuCard({huCard});
  1487. --被抢杠的人回退补杠
  1488. self.playerHandCards[failViewId]:retoreBuGang(response.redRealCard,1)
  1489. end
  1490. end
  1491. if response.nUserId == app.room:getMyUserId() then
  1492. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1493. -- 自摸时, 去掉服务端下发的胡的那张牌 add->ljx
  1494. local arg = {
  1495. {card = huCard.huCard}
  1496. }
  1497. self.playerHandCards[viewId]:removeHandCard(arg)
  1498. self.playerHandCards[viewId]:resetHandCards()
  1499. self.playerHandCards[viewId]:onGetHuCard({huCard});
  1500. end
  1501. self.playerHandCards[viewId]:setOutCardEnable(false)
  1502. self:setTingCardVisible(false);
  1503. self.playerHandCards[viewId]:setTing(false)
  1504. self.playerHandCards[viewId]:lockHandCard();
  1505. local specRule = roomInfo:getGameRuleByKey("specRule") or 0;
  1506. if getNumBand(specRule, 0x08) > 0 then
  1507. app.room.roomInfo.passGuo = true;
  1508. self.playerHandCards[viewId]:lockHandCard(true);
  1509. end
  1510. -- 胡牌之后,显示听牌按钮,并拉取新的数据
  1511. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1512. self:setButtonTingInfoVisible(true);
  1513. else
  1514. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1515. -- 自摸且回放时, 去掉服务端下发的胡的那张牌 或者去掉最后一张牌 add->ljx
  1516. if response.isReplay then
  1517. local arg = {
  1518. {card = huCard.huCard}
  1519. }
  1520. self.playerHandCards[viewId]:removeHandCard(arg)
  1521. self.playerHandCards[viewId]:resetHandCards()
  1522. else
  1523. self.playerHandCards[viewId]:removeLastHandCard();
  1524. end
  1525. local huCard = huCards[#huCards];
  1526. local tmpCard = {
  1527. huCard = huCard.huCard;
  1528. huType = huCard.huType;
  1529. dpSeatId = huCard.dpSeatId;
  1530. };
  1531. if not response.isReplay then
  1532. tmpCard.huCard = 0;
  1533. end
  1534. self.playerHandCards[viewId]:onGetHuCard({tmpCard});
  1535. end
  1536. -- 其他人胡了倒牌
  1537. local handCards = {}
  1538. for k,v in pairs(self.playerHandCards[viewId]:getHandCardNodes() or {}) do
  1539. table.insert(handCards,{card = v.value or v:getValue()})
  1540. end
  1541. -- if response.huType==MJDefine.MJGameHuType.HU_ZIMO then --如果是自摸胡 把最后一张替换为胡的牌
  1542. -- handCards[#handCards] = {card = response.huCard}
  1543. -- end
  1544. self.playerHandCards[viewId]:removeAllHandCards()
  1545. self.playerHandCards[viewId]:createOpenHandCards(handCards)
  1546. -- self.playerHandCards[viewId]:moveLastOpenCard()
  1547. -- self.playerHandCards[viewId]:removeLastHandCard();
  1548. end
  1549. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  1550. self.playerView:showHu(viewId, true);
  1551. callback();
  1552. end
  1553. self:addCallBack(runHuResponse);
  1554. end
  1555. function huamajiangRoomView:showOperateScore( optScore )
  1556. if not optScore then
  1557. return ;
  1558. end
  1559. for k, v in ipairs(optScore or {}) do
  1560. v.viewId = app.room:getViewIdByUserId(v.uid);
  1561. end
  1562. self._scoreAnim = MJFramework.MJImport("mj_huamajiang.luaScript.Views.Animation.huamajiangScoreAnimation"):new();
  1563. self._scoreAnim:play(optScore, function ()
  1564. self.playerView:refreshPlayerScore(optScore)
  1565. end);
  1566. self:addToLayer("anim", self._scoreAnim);
  1567. end
  1568. function huamajiangRoomView:playHuAni(response)
  1569. -- 花麻将不需要播放胡牌顺序
  1570. -- 需要可以从自贡麻将同步
  1571. end
  1572. function huamajiangRoomView:onQiangDuanOperates(data)
  1573. local function runOnQiangDuanOperates(onEnd)
  1574. logD("huamajiangRoomView:runOnQiangDuanOperates")
  1575. local response = data.response
  1576. if response.operates and self.playerHandCards[MJDefine.MyViewId] then
  1577. self.playerHandCards[MJDefine.MyViewId]:showOperate(response.operates)
  1578. end
  1579. if onEnd then
  1580. onEnd()
  1581. end
  1582. end
  1583. logD("huamajiangRoomView:onQiangDuanOperates")
  1584. self:addCallBack(runOnQiangDuanOperates)
  1585. end
  1586. --游戏消息
  1587. function huamajiangRoomView:bindExtendMessage()
  1588. self:bindEvent(app.room , MJDefine.MJEvent.OutCardTings, handler(self , self.pushTing));
  1589. self:bindEvent(app.room , MJDefine.MJEvent.HuResponse, handler(self , self.onHuResponse))
  1590. self:bindEvent(app.room , MJDefine.MJEvent.BaoPaiResponse, handler(self , self.onBaoPai))
  1591. self:bindEvent(app.room , MJDefine.MJEvent.BankerBaoPai, handler(self , self.onBankerBaoPai))
  1592. self:bindEvent(app.room , MJDefine.MJEvent.SendGuo, handler(self , self.onSendGuo))
  1593. self:bindEvent(app.room , MJDefine.MJEvent.QiangDuanOperates, handler(self , self.onQiangDuanOperates))
  1594. self:bindEvent(app , MJDefine.MJEvent.ChangeLanguage , handler(self , self.doSound))
  1595. self:bindEvent(app.room , MJDefine.MJEvent.StartPiao, handler(self , self.onStartPiao))
  1596. self:bindEvent(app.room , MJDefine.MJEvent.PiaoResponse, handler(self , self.onPiaoResponse))
  1597. self:bindEvent(app.room , MJDefine.MJEvent.FanLuoBoResponse, handler(self , self.onFanLuoBoResponse))
  1598. --更换桌布
  1599. self:bindEvent(app, MJDefine.MJEvent.ChangeTableBg , handler(self , self.changeGameBg));
  1600. self:bindEvent(app.room, MJDefine.MJEvent.EVENT_BTN_SHOW_FLOW_VIEW_CLICKED, handler(self, self.onEventBtnShowFlowViewClicked));
  1601. self:bindEvent(app , MJDefine.MJEvent.ChangeChatEnable , handler(self , self.onChangeChatEnable))
  1602. self:bindEvent(app, "applicationWillEnterForeground", handler(self, self.onApplicationWillEnterForeground ))
  1603. self:bindEvent(app, "applicationDidEnterBackground", handler(self, self.onApplicationDidEnterBackground ))
  1604. self:bindEvent(app, MJDefine.MJEvent.ChangeViewType, handler(self, self.onEventChangeViewType ))
  1605. -- 托管
  1606. self:bindEvent(app.room , MJDefine.MJEvent.HostingRequest, handler(self, self.onHostingRequest))
  1607. --换三张,服务器会通过0x8206通知换牌
  1608. self:bindEvent(app.room , MJDefine.MJEvent.NoticeSwapCard,handler(self,self.onNoticeSwapCardResponse))
  1609. --换三张失败
  1610. self:bindEvent(app.room , MJDefine.MJEvent.SwapCardErr,handler(self,self.onChangeCardFail))
  1611. --换三张成功
  1612. self:bindEvent(app.room , MJDefine.MJEvent.SwapCardSucc,handler(self,self.onChangeCardSucc))
  1613. --换三张成功后的信息
  1614. self:bindEvent(app.room , MJDefine.MJEvent.SwapCardSuccInfo,handler(self,self.onChangeCardInfo))
  1615. --检测是否符合换三张规则
  1616. self:bindEvent(app.room , MJDefine.MJEvent.CheckIsInSwapRule,handler(self , self.onCheckIsInSwapRule))
  1617. --内容和0x8106保持统一 广播桌子上所有玩家庄家起手操作
  1618. self:bindEvent(app.room , MJDefine.MJEvent.AfterDingQue,handler(self , self.onAfterDingQue))
  1619. end
  1620. function huamajiangRoomView:clean()
  1621. self.playerView:init()
  1622. -- --默认状态
  1623. self:defaultState()
  1624. app.room:resetRoomInfo()
  1625. self:setBtnSitDownVisible(false)
  1626. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  1627. --
  1628. self._gameoverview = nil
  1629. end
  1630. function huamajiangRoomView:updateReady()
  1631. local roomInfo = app.room.roomInfo;
  1632. local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  1633. local gameStartCount = roomInfo:getGameStartCount();
  1634. if gameStartCount > 0 then
  1635. self.toolView.ui.Items.Button_Leave:setEnabled(false)
  1636. self:setBtnSitDownVisible(false)
  1637. else
  1638. self.toolView.ui.Items.Button_Leave:setEnabled(true)
  1639. end
  1640. if gameStartCount == 0 and roomInfo:getRoomOwnedUid() ~= nUserId then
  1641. self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
  1642. else
  1643. self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
  1644. end
  1645. self:checkCanDismiss()
  1646. end
  1647. --- huamajiangRoomView:onGameStartResponse 游戏开始
  1648. function huamajiangRoomView:onGameStartResponse()
  1649. huamajiangRoomView.super.onGameStartResponse(self)
  1650. self._gameoverview = nil
  1651. self:changeGameBg();
  1652. self.toolView:setFlowVisible(true);
  1653. self:playGameStartAnim();
  1654. end
  1655. --- huamajiangRoomView:playGameStartAnim 播放整起动画
  1656. function huamajiangRoomView:playGameStartAnim ()
  1657. if self.gameStartAnim then
  1658. self.gameStartAnim = nil;
  1659. end
  1660. -- 整起音效
  1661. local userInfo=app.room:getUserInfoByViewId(MJDefine.MyViewId);
  1662. MJSound.PlayGameStartSound(userInfo.sex)
  1663. local visibleSize = cc.Director:getInstance():getVisibleSize();
  1664. local GameStartAnim = import("mj_huamajiang.luaScript.Views.Animation.huamajiangGameStartAnimation");
  1665. self.gameStartAnim = GameStartAnim:new();
  1666. self.gameStartAnim:play(nil);
  1667. self:addToLayer("anim", self.gameStartAnim);
  1668. end
  1669. -- 大局结算
  1670. function huamajiangRoomView:onGameDaJuResponse(data)
  1671. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  1672. if self._gameoverview then
  1673. return
  1674. end
  1675. runDelay(0.3, function ()
  1676. if app.room.roomInfo.needJieSuanInfo == 1 then--显示总结算
  1677. self:showGameOverResult(data.response)
  1678. else
  1679. --[[local roomInfo=app.room.roomInfo
  1680. --如果是解散直接跳转总结算
  1681. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1682. self:showGameOverResult(data.response)
  1683. end --]]
  1684. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE})
  1685. end
  1686. end)
  1687. end
  1688. -- 大局结算
  1689. function huamajiangRoomView:showGameOverResult(data)
  1690. if self._gameoverview ~= nil then
  1691. return
  1692. end
  1693. if not tolua.isnull(self.direcionView) then
  1694. self.direcionView:stopAllActions()
  1695. end
  1696. self:resetGame()
  1697. local view=MJRoomDaJuView:new(data)
  1698. view:setAnchorPoint(cc.p(0.5, 0.5))
  1699. app:showWaitDialog(view)
  1700. self._gameoverview = view
  1701. app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_DAJU_VIEW_SHOWED});
  1702. self:showGameOverAward()
  1703. end
  1704. function huamajiangRoomView:onOtherLogoutResponse(data)
  1705. if (not data or not data.nUserId or not data.nSeatShowId) then
  1706. return
  1707. end
  1708. local function test(onEnd)
  1709. self.playerView:updatePlayerInfo(data.nSeatShowId)
  1710. self:onUserReadyResponse()
  1711. --更新GPS
  1712. -- self:updateAllGpsInfo()
  1713. -- self:checkGpsDistance()
  1714. -- 是否显示邀请好友
  1715. self.toolView:updateButton()
  1716. if self._fastRequestView then
  1717. self._fastRequestView:removeSelf()
  1718. self._fastRequestView = nil
  1719. end
  1720. logE("88888-onOtherLogoutResponse onEnd")
  1721. if onEnd then
  1722. onEnd()
  1723. end
  1724. end
  1725. self:addCallBack(test)
  1726. end
  1727. function huamajiangRoomView:resetGame()
  1728. huamajiangRoomView.super.resetGame(self)
  1729. app.room.roomInfo:setLastOutViewId(nil);
  1730. self.ui.Items.Layout_Effect:removeAllChildren()
  1731. self.ui.Items.Layout_Effect_luobo_Lable:removeAllChildren()
  1732. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  1733. self.playerView:clearBao()
  1734. self.playerView:clearAllPiao()
  1735. self.playerView:clearHu();
  1736. self.isTing = false;
  1737. if self._tingCardView then
  1738. self:setTingCardVisible(false);
  1739. end
  1740. end
  1741. function huamajiangRoomView:showPiao()
  1742. self:stopDirection()
  1743. local roomInfo=app.room.roomInfo
  1744. local gameInfo= roomInfo:getGameRule();
  1745. if not gameInfo.piaomode or tonumber(gameInfo.piaomode)==0 then return end
  1746. self:hidePiao()
  1747. local ui=loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_piao.ui")
  1748. self:addToLayer("game", ui);
  1749. self.piaoView = ui
  1750. ui.Items.Button_BuPiao:registerClick(function ()
  1751. playBtnEffect()
  1752. self:hidePiao()
  1753. local request = MJMessage.PiaoRequest:new()
  1754. request.isPiao = 0
  1755. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
  1756. end)
  1757. ui.Items.Button_Piao:registerClick(function ()
  1758. playBtnEffect()
  1759. self:hidePiao()
  1760. local request = MJMessage.PiaoRequest:new()
  1761. request.isPiao = 1
  1762. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
  1763. end)
  1764. end
  1765. function huamajiangRoomView:hidePiao()
  1766. if self.piaoView then
  1767. self.piaoView:removeFromParent()
  1768. self.piaoView = nil
  1769. end
  1770. end
  1771. --显示飘操作按钮
  1772. function huamajiangRoomView:onStartPiao(response)
  1773. local function runPiao(onEnd)
  1774. logD("huamajiangRoomView:onStartPiao")
  1775. self:showPiao()
  1776. if onEnd then
  1777. onEnd()
  1778. end
  1779. end
  1780. logD("huamajiangRoomView:runPiao")
  1781. self:addCallBack(runPiao)
  1782. end
  1783. --飘结果
  1784. function huamajiangRoomView:onPiaoResponse(response)
  1785. local function runonPiaoResponse(onEnd)
  1786. logD("huamajiangRoomView:runonPiaoResponse")
  1787. local data = response.response
  1788. local userId = data.nUserId--操作的玩家
  1789. local myUserId = app.room:getMyUserId()
  1790. if myUserId == userId then
  1791. self:hidePiao()
  1792. end
  1793. local playersPiaostate = data.playerPiaoState--所有玩家的飘状态
  1794. if playersPiaostate then
  1795. for i,v in pairs(playersPiaostate) do
  1796. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1797. local userInfo=app.room:getUserInfoByViewId(viewId)
  1798. self.playerView:showPiao(viewId,v.piaostate==1)
  1799. if v.piaostate==1 and userId == v.nUserId then
  1800. --飘音效
  1801. MJSound.PlayPiaoSound(userInfo.sex)
  1802. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1803. if effect then
  1804. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  1805. effect:setLocalZOrder(1000)
  1806. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1807. end
  1808. end
  1809. end
  1810. else
  1811. local viewId = app.room:getViewIdByUserId(userId)
  1812. self.playerView:showPiao(viewId,data.piaostate==1)
  1813. if data.piaostate and data.piaostate == 1 then
  1814. --飘音效
  1815. local userInfo=app.room:getUserInfoByViewId(viewId)
  1816. MJSound.PlayPiaoSound(userInfo.sex)
  1817. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1818. if effect then
  1819. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  1820. effect:setLocalZOrder(1000)
  1821. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1822. end
  1823. end
  1824. end
  1825. if onEnd then
  1826. onEnd()
  1827. end
  1828. end
  1829. logD("huamajiangRoomView:runonPiaoResponse--------")
  1830. self:addCallBack(runonPiaoResponse)
  1831. end
  1832. function huamajiangRoomView:showBaoJiao()
  1833. self:hideBaoJiao()
  1834. local ui=loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_baojiao.ui")
  1835. self:addToLayer("game", ui, 5);
  1836. self._baojiaoView=ui
  1837. ui.Items.Button_Bao:registerClick(function ()
  1838. playBtnEffect()
  1839. self:hideBaoJiao()
  1840. local request = MJMessage.BaoPaiRequest:new()
  1841. request.isBaoPai = 1
  1842. logD(request.isBaoPai,"发送爆:1")
  1843. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  1844. end)
  1845. ui.Items.Button_guo:registerClick(function ()
  1846. playBtnEffect()
  1847. self:hideBaoJiao()
  1848. local request = MJMessage.BaoPaiRequest:new()
  1849. request.isBaoPai = 0
  1850. logD(request.isBaoPai,"发送爆:0")
  1851. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  1852. end)
  1853. end
  1854. function huamajiangRoomView:hideBaoJiao()
  1855. if self._baojiaoView then
  1856. self._baojiaoView:removeFromParent()
  1857. self._baojiaoView=nil
  1858. end
  1859. end
  1860. function huamajiangRoomView:onBtnTingInfoClicked( )
  1861. playBtnEffect()
  1862. if self._tingCardView:isVisible() then
  1863. self:setTingCardVisible(false);
  1864. else
  1865. self:setTingCardVisible(true);
  1866. end
  1867. end
  1868. function huamajiangRoomView:onFanLuoBoResponse (data)
  1869. local onFanLuoBoCallback = function (onEnd)
  1870. self.playerHandCards[MJDefine.MyViewId]:refreshLuoBoCards()
  1871. if not self.isShowFanLuoBo then
  1872. -- 游戏中,不显示翻牌
  1873. if onEnd then
  1874. onEnd();
  1875. end
  1876. return ;
  1877. end
  1878. self.isShowFanLuoBo = false;
  1879. logD("huamajiangRoomView:onFanLuoBoResponse");
  1880. MJSound.PlayLuoBoSound();
  1881. local luoboCards = app.room.roomInfo:getLuoBoCards();
  1882. local luoboCount = table.nums(luoboCards);
  1883. if luoboCount <= 0 then
  1884. return ;
  1885. end
  1886. if self._luoboView then
  1887. self._luoboView:removeFromParent();
  1888. self._luoboView = nil;
  1889. end
  1890. -- local showCards = {};
  1891. -- if luoboCount <= 4 then
  1892. -- showCards = luoboCards;
  1893. -- else
  1894. -- local lastCard = luoboCards[luoboCount]
  1895. -- table.insert(showCards, lastCard);
  1896. -- end
  1897. local showCards = {};
  1898. for i = 1, luoboCount do
  1899. if luoboCards[i] then
  1900. table.insert(showCards, luoboCards[i]);
  1901. end
  1902. end
  1903. self._luoboView = MJFramework.MJImport("mj_huamajiang.luaScript.Views.Components.huamajiangFanLuoBoView"):new(self.desktopType);
  1904. self._luoboView:setCards(showCards);
  1905. self:addToLayer("anim", self._luoboView);
  1906. if onEnd then
  1907. onEnd();
  1908. end
  1909. end
  1910. self:addCallBack(onFanLuoBoCallback);
  1911. end
  1912. -- 等待操作消息
  1913. function huamajiangRoomView:onWaitOperate(data)
  1914. if true then
  1915. -- 花麻将不需要显示“我要碰”、“我要杠”等操作
  1916. return ;
  1917. end
  1918. huamajiangRoomView.super.onWaitOperate(self, data);
  1919. --等待操作的UID
  1920. local nUserId = data.response.nUserId
  1921. -- 有操作,则不能操作手牌
  1922. local viewId = app.room:getViewIdByUserId(nUserId);
  1923. if viewId == MJDefine.MyViewId and data.response and data.response.opType > 0 then
  1924. self.playerHandCards[viewId]:setOutCardEnable(false);
  1925. end
  1926. end
  1927. function huamajiangRoomView:onApplicationWillEnterForeground ()
  1928. end
  1929. function huamajiangRoomView:onApplicationDidEnterBackground( )
  1930. end
  1931. function huamajiangRoomView:onEventChangeViewType(data)
  1932. MJDefine.MJConfig = MJDefine.loadMJConfig()
  1933. self:changeGameBg(true)
  1934. self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
  1935. end
  1936. ---
  1937. -- 托管通知
  1938. -- @param data
  1939. -- @return
  1940. --
  1941. function huamajiangRoomView:onHostingRequest( data )
  1942. local response = data.response
  1943. if response.nUserId == app.user.loginInfo.uid then
  1944. if response.status == 1 then --托管状态
  1945. self.toolView:showTuoGuan(true)
  1946. elseif response.status == 0 then--取消托管状态
  1947. self.toolView:showTuoGuan(false)
  1948. end
  1949. end
  1950. local isTuoGuan = response.status == 1;
  1951. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1952. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  1953. end
  1954. --设置换牌确定按钮可点击性
  1955. function huamajiangRoomView:onCheckIsInSwapRule(data)
  1956. if not data then return end
  1957. if not self.swapCard then return end
  1958. self.swapCard.Items.Button_sure:setEnabled(data.canCommit)
  1959. end
  1960. --显示换三张
  1961. function huamajiangRoomView:showSwapCard(isOpered,time)--是否已经操作过
  1962. self:stopDirection()
  1963. local roomInfo=app.room.roomInfo
  1964. local gameInfo=json.decode(roomInfo.strGameInfo)
  1965. if not gameInfo.specRule or (not (getNumBand(gameInfo.specRule, 0x1000)>0) and not (getNumBand(gameInfo.specRule, 0x80000)>0)) then
  1966. return
  1967. end
  1968. isOpered = isOpered or false
  1969. self:hideSwapCard()
  1970. local ui=loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_swap_card.ui")
  1971. self.ui.Items.Layout_Player:addChild(ui)
  1972. self.swapCard=ui
  1973. self.swapCard.Items.ImageView_bg:setVisible(isOpered)
  1974. for i=1,4 do--先隐藏全部
  1975. if self.swapCard.Items["Layout_swapCard_"..i] then
  1976. self.swapCard.Items["Layout_swapCard_"..i]:setVisible(false)
  1977. end
  1978. self:setSwapCardSucc(false,i)
  1979. end
  1980. for k,v in pairs(app.room.roomInfo.memberList) do--根据人数显示
  1981. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1982. if self.playerHandCards[viewId] then
  1983. if self.swapCard.Items["Layout_swapCard_"..viewId] then
  1984. self.swapCard.Items["Layout_swapCard_"..viewId]:setVisible(true)
  1985. end
  1986. else
  1987. if self.swapCard.Items["Layout_swapCard_"..viewId] then
  1988. self.swapCard.Items["Layout_swapCard_"..viewId]:setVisible(false)
  1989. end
  1990. end
  1991. end
  1992. --确定换牌按钮
  1993. ui.Items.Button_sure:registerClick(function ()
  1994. playBtnEffect()
  1995. self.swapCard.Items.ImageView_bg:setVisible(false)
  1996. --请求换牌
  1997. local cards = self.playerHandCards[MJDefine.MyViewId]:getSelectedCards()
  1998. app.room:requestSwapCards(cards)
  1999. --[[local request = MJMessage.PiaoRequest:new()
  2000. request.isPiao = 0
  2001. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)--]]
  2002. end)
  2003. local swapcolourcard = getNumBand(gameInfo.specRule, 0x80000)
  2004. local Text_tip1 = swapcolourcard > 0 and "选择以下三张 底牌" or "选择以下三张 底牌"
  2005. local Text_tip2 = swapcolourcard > 0 and "任意花色" or "同花色"
  2006. self.swapCard.Items.Text_tip1:setText(Text_tip1)
  2007. self.swapCard.Items.Text_tip2:setText(Text_tip2)
  2008. self.swapCard.Items.Button_sure:setText("确认("..time..")")
  2009. if self.SwapTime then
  2010. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.SwapTime)
  2011. end
  2012. self.SwapTime = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function ()
  2013. time = time - 1
  2014. if time < 0 then
  2015. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.SwapTime)
  2016. return
  2017. end
  2018. self.swapCard.Items.Button_sure:setText("确认("..time..")")
  2019. end,1.0,false)
  2020. end
  2021. --隐藏换三张
  2022. function huamajiangRoomView:hideSwapCard()
  2023. if self.swapCard then
  2024. if self.SwapTime then
  2025. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.SwapTime)
  2026. end
  2027. self.swapCard:removeFromParent()
  2028. self.swapCard=nil
  2029. end
  2030. end
  2031. --换三张,服务器会通过0x8206通知换牌
  2032. function huamajiangRoomView:onNoticeSwapCardResponse(response)
  2033. local function runNoticeSwapCard(onEnd)
  2034. logD("huamajiangRoomView:onNoticeSwapCardResponse")
  2035. local data = response.response
  2036. self:showSwapCard(true,data.time)
  2037. self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent()
  2038. --弹出推荐牌
  2039. self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  2040. self.playerHandCards[MJDefine.MyViewId]:selectCardsByCards(data.swapCards)
  2041. self.swapCard.Items.Button_sure:setEnabled(true)
  2042. if onEnd then
  2043. onEnd()
  2044. end
  2045. end
  2046. logD("huamajiangRoomView:runNoticeSwapCard")
  2047. self:addCallBack(runNoticeSwapCard)
  2048. end
  2049. --换三张失败
  2050. function huamajiangRoomView:onChangeCardFail(response)
  2051. local function runChangeCardFail(onEnd)
  2052. logD("huamajiangRoomView:onChangeCardFail")
  2053. self:hideSwapCard()
  2054. local data = response.response
  2055. if data.time > 0 then
  2056. self:showSwapCard(true,data.time)
  2057. self.swapCard.Items.Button_sure:setEnabled(false)
  2058. end
  2059. self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  2060. if onEnd then
  2061. onEnd()
  2062. end
  2063. end
  2064. logD("huamajiangRoomView:runChangeCardFail")
  2065. self:addCallBack(runChangeCardFail)
  2066. end
  2067. --换三张成功
  2068. function huamajiangRoomView:onChangeCardSucc(response)
  2069. local function runChangeCardSucc(onEnd)
  2070. logD("huamajiangRoomView:onChangeCardSucc换三张成功1")
  2071. local data = response.response
  2072. local userId = data.nUserId--操作的玩家
  2073. local viewId = app.room:getViewIdByUserId(userId)
  2074. local swapCards = data.swapCards--换出去的牌
  2075. if viewId == MJDefine.MyViewId then
  2076. if self.swapCard and self.swapCard.Items.ImageView_bg then
  2077. self.swapCard.Items.ImageView_bg:setVisible(false)
  2078. end
  2079. local tmpCards = {}
  2080. for i=1,3 do
  2081. table.insert(tmpCards,{card = swapCards[i].card})
  2082. end
  2083. self.playerHandCards[MJDefine.MyViewId]:removeHandCard(tmpCards)
  2084. self.playerHandCards[viewId]:resetHandCards()
  2085. else
  2086. self:setSwapCardSucc(true,viewId)
  2087. local tmpCards = {}
  2088. for i=1,3 do
  2089. table.insert(tmpCards,{card = 0})
  2090. end
  2091. self.playerHandCards[viewId]:removeHandCard(tmpCards)
  2092. self.playerHandCards[viewId]:resetHandCards()
  2093. end
  2094. self.playerHandCards[viewId]:createSwapCards({0,0,0})
  2095. if onEnd then
  2096. onEnd()
  2097. end
  2098. end
  2099. logD("huamajiangRoomView:runChangeCardSucc--------")
  2100. self:addCallBack(runChangeCardSucc)
  2101. end
  2102. --换三张成功后的信息
  2103. function huamajiangRoomView:onChangeCardInfo(response)
  2104. local function runChangeCardInfo(onEnd)
  2105. logD("huamajiangRoomView:onChangeCardInfo")
  2106. self:hideSwapCard()
  2107. local data = response.response
  2108. self:showSwapDirection(data.swapType)
  2109. for k,v in pairs(data.swapCards) do
  2110. for i=1,4 do
  2111. if i == MJDefine.MyViewId and self.playerHandCards[MJDefine.MyViewId] then
  2112. self.playerHandCards[MJDefine.MyViewId]:onGetCard(nil,tonumber(v.card),true)
  2113. elseif self.playerHandCards[i] then
  2114. self.playerHandCards[i]:onGetCard(nil,0,true)
  2115. end
  2116. end
  2117. end
  2118. self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  2119. --删去桌面的显示的三张换牌
  2120. for i=1,4 do
  2121. if self.playerHandCards[i] then
  2122. self.playerHandCards[i]:deleteSwapCards()
  2123. end
  2124. end
  2125. self.playerHandCards[MJDefine.MyViewId]:removeTouchEventOnly()
  2126. for i,v in pairs(data.swapCards) do
  2127. local handCards = self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes() or {}
  2128. for j,mjCard in pairs(handCards) do
  2129. if mjCard:getValue() == tonumber(v.card) and mjCard:getSelected() ~= MJDefine.MJStatus.Select then
  2130. --local mjCard = self.playerHandCards[MJDefine.MyViewId]:getMjByValue(tonumber(v.card))
  2131. --if mjCard and mjCard:getSelected() ~= MJDefine.MJStatus.Select then
  2132. mjCard:setSelected(MJDefine.MJStatus.Select)
  2133. mjCard:recordPostion()
  2134. local initPos = mjCard:getPosition()
  2135. local toPos = cc.p(initPos.x, initPos.y + 25)
  2136. mjCard:setPosition(toPos)
  2137. mjCard:runDeSelectAnimationWithTime(1.0)
  2138. mjCard:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function()
  2139. mjCard:setSelected(MJDefine.MJStatus.Normal)
  2140. end)))
  2141. break
  2142. end
  2143. --end
  2144. end
  2145. end
  2146. --[[self:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function()
  2147. self.playerHandCards[MJDefine.MyViewId]:initTouchEvent()
  2148. end)))--]]
  2149. if onEnd then
  2150. onEnd()
  2151. end
  2152. end
  2153. logD("huamajiangRoomView:runChangeCardInfo--------")
  2154. self:addCallBack(runChangeCardInfo)
  2155. end
  2156. --设置换牌成功 isSwaped:true显示有勾的,false显示换牌中
  2157. function huamajiangRoomView:setSwapCardSucc(isSwaped,viewId)
  2158. isSwaped = isSwaped or false
  2159. if not self.swapCard or tolua.isnull(self.swapCard) then
  2160. return
  2161. end
  2162. if self.swapCard.Items["ImageView_swaping_"..viewId] then
  2163. self.swapCard.Items["ImageView_swaping_"..viewId]:setVisible(not isSwaped)
  2164. end
  2165. if self.swapCard.Items["ImageView_swaped_"..viewId] then
  2166. self.swapCard.Items["ImageView_swaped_"..viewId]:setVisible(false)--isSwaped 不显示选牌中了
  2167. end
  2168. end
  2169. --换牌方式 1顺时针 2对家换牌 3逆时针
  2170. function huamajiangRoomView:showSwapDirection(dir)
  2171. if not dir then return end
  2172. self:hideSwapDirection()
  2173. local ui=loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_swap_direction.ui")
  2174. self.ui.Items.Layout_Player:addChild(ui)
  2175. self.swapDirection=ui
  2176. self.swapDirection.Items.Layout_ShunShiZhen:setVisible(dir == 1)
  2177. self.swapDirection.Items.Layout_NiShiZhen:setVisible(dir == 3)
  2178. self.swapDirection.Items.Layout_DuiJia:setVisible(dir == 2)
  2179. self.swapDirection.Items.ImageView_s:playClip("shunshizhen")
  2180. self.swapDirection.Items.ImageView_n:playClip("nishizhen")
  2181. self.swapDirection.Items.Layout_DuiJia:playClip("duijia")
  2182. self.swapDirection:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
  2183. self:hideSwapDirection()
  2184. end)))
  2185. end
  2186. function huamajiangRoomView:hideSwapDirection()
  2187. if self.swapDirection then
  2188. self.swapDirection:removeFromParent()
  2189. self.swapDirection = nil
  2190. end
  2191. end
  2192. function huamajiangRoomView:onAfterDingQue(data)
  2193. local function runOnAfterDingQue(onEnd)
  2194. logE("huamajiangRoomView onAfterDingQue 没定缺就是换牌流程完毕后:"..table.tostring(data.response))
  2195. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  2196. local card= data.response.card
  2197. local operates=data.response.operates
  2198. local nSeatId=data.response.nSeatId
  2199. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  2200. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true)
  2201. if viewId == MJDefine.MyViewId then
  2202. --self.ui.Items.Button_Ting_Info:setVisible(false)
  2203. self:setButtonTingInfoVisible(false)
  2204. if operates and table.nums(operates)>0 then
  2205. self.operates = operates
  2206. local isCanHu = false
  2207. for k,v in pairs(operates.Datas) do
  2208. if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) then
  2209. isCanHu = true
  2210. break
  2211. end
  2212. end
  2213. if isCanHu == true then
  2214. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(false)
  2215. else
  2216. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  2217. end
  2218. else
  2219. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  2220. self.operates = {}
  2221. end
  2222. if self.playerHandCards[MJDefine.MyViewId] then
  2223. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  2224. end
  2225. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  2226. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  2227. end
  2228. self:updateGameNums()
  2229. self.direcionView:updateDirection(nSeatId)
  2230. self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
  2231. self.playerHandCards[MJDefine.MyViewId]:initTouchEvent()
  2232. if onEnd then
  2233. onEnd()
  2234. end
  2235. end
  2236. self:addCallBack(runOnAfterDingQue)
  2237. end
  2238. return huamajiangRoomView