您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1199 行
38 KiB

  1. local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  2. local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
  3. local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound")
  4. local ZPMessage = ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage")
  5. local ZPRoomOperationView = class("ZPRoomOperationView", cc.UIView)
  6. function ZPRoomOperationView:ctor()
  7. ZPRoomOperationView.super.ctor(self);
  8. self.lieShuMax = 15
  9. self.hangShuMax = 4
  10. end
  11. function ZPRoomOperationView:loadUI()
  12. local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_operation.ui");
  13. self.ui = ui;
  14. self:addChild(ui);
  15. end
  16. function ZPRoomOperationView:getEatCardVisible()
  17. return self.ui.Items.Layout_Eat:isVisible()
  18. end
  19. function ZPRoomOperationView:setEatBtnEnabledTrue()
  20. return self.ui.Items.Button_1:setEnabled(true)
  21. end
  22. function ZPRoomOperationView:onEnter()
  23. ZPRoomOperationView.super.onEnter(self)
  24. self:loadUI()
  25. self.eatViewSrcSize = self.ui.Items.ImageView_EatPanelBg:getContentSize()
  26. self.eatBiViewSrcSize = self.ui.Items.ImageView_EatPanelBg_Bi:getContentSize()
  27. self.eatSanBiViewSrcSize = self.ui.Items.ImageView_EatPanelBg_SanBi:getContentSize()
  28. --ui排序:吃碰胡过
  29. self.ui.Items.Button_1:registerClick(nil,function ()
  30. local function chi()
  31. local code = self.operationLocalCode
  32. self:touchEatOneCardCallBack(false)
  33. end
  34. local isHu = self:getIsHaveHuOp()
  35. if isHu == true then
  36. local content = string.format("确定放弃胡牌吗?")
  37. local okCallBack = function ()
  38. chi()
  39. end
  40. local cancelCallBack = function ()
  41. end
  42. showConfirmDialog(content,okCallBack,cancelCallBack)
  43. else
  44. chi()
  45. end
  46. end)
  47. self.ui.Items.Button_2:registerClick(function ()
  48. local function peng()
  49. local operateCode = {}
  50. operateCode[1] = ZPDef.OpCode.OP_PENG
  51. self:sendOperationCode(operateCode)
  52. --直接隐藏界面
  53. self:setOperatorPanelView(false)
  54. end
  55. local isHu = self:getIsHaveHuOp()
  56. if isHu == true then
  57. local content = string.format("确定放弃胡牌吗?")
  58. local okCallBack = function ()
  59. peng()
  60. end
  61. local cancelCallBack = function ()
  62. end
  63. showConfirmDialog(content,okCallBack,cancelCallBack)
  64. else
  65. peng()
  66. end
  67. end)
  68. --self:hidePengBtn()
  69. self.ui.Items.Button_3:registerClick(function ()
  70. if app.room:isLittleFamily() then return end
  71. local isHu = self:getIsHaveHuOp()
  72. if isHu == true then
  73. local content = string.format("确定放弃胡牌吗?")
  74. local okCallBack = function ()
  75. self:onClickGuo()
  76. end
  77. local cancelCallBack = function ()
  78. end
  79. showConfirmDialog(content,okCallBack,cancelCallBack)
  80. else
  81. self:onClickGuo()
  82. end
  83. end)
  84. self.ui.Items.Button_4:registerClick(function ()
  85. local operateCode = {}
  86. operateCode[1] = ZPDef.OpCode.OP_HU
  87. self:sendOperationCode(operateCode)
  88. self:setOperatorPanelView(false)
  89. end)
  90. --不爆牌
  91. self.ui.Items.Button_6:registerClick(function ()
  92. if app.room:isLittleFamily() then return end
  93. local request = ZPMessage.BaoPai:new()
  94. request.optType = 0
  95. logE("ZPRoomOperationView:baopai"..table.tostring(request))
  96. self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
  97. logE("ZPRoomOperationView baopai response = ", table.tostring(response))
  98. end)
  99. self:showBaoPaiOpView(false)
  100. end)
  101. --爆牌
  102. self.ui.Items.Button_5:registerClick(function ()
  103. if app.room:isLittleFamily() then return end
  104. local request = ZPMessage.BaoPai:new()
  105. request.optType = 1
  106. logE("ZPRoomOperationView:baopai"..table.tostring(request))
  107. self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
  108. logE("ZPRoomOperationView baopai response = ", table.tostring(response))
  109. end)
  110. self:showBaoPaiOpView(false)
  111. end)
  112. self:hideSelf()
  113. end
  114. --获取是否有胡操作
  115. function ZPRoomOperationView:getIsHaveHuOp()
  116. if not self.operationLocalCode then return false end
  117. local beginList = {}
  118. beginList = ZPFuc.getZPOperationType(self.operationLocalCode,true)
  119. local isHu = false
  120. for k,opType in pairs(beginList) do
  121. if opType == ZPDef.OpType.OP_TYPE_HU then
  122. isHu = true
  123. break
  124. end
  125. end
  126. return isHu
  127. end
  128. --泸州大贰自动碰,所以隐藏碰按钮
  129. function ZPRoomOperationView:hidePengBtn()
  130. self.ui.Items.Layout_2:setVisible(false)
  131. self.ui.Items.ImageView:setScale(0.7,1,1)
  132. local posx = self.ui.Items.ImageView:getPositionX()
  133. self.ui.Items.ImageView:setPositionX(posx+60)
  134. end
  135. function ZPRoomOperationView:showOpeation(mainOpCode,viewId,card)
  136. if app.room:isLittleFamily() then return end
  137. --操作码
  138. self.operationLocalCode = mainOpCode
  139. logE("RoomView:showOpeation(mainOpCode) 1:"..mainOpCode)
  140. --操作类型
  141. local beginList = {}
  142. beginList = ZPFuc.getZPOperationType(mainOpCode,true)--,self.playerZhao[1] > 0
  143. logE("RoomView:showOpeation isCheckMustOperation before (beginList)1 :"..table.tostring(beginList))
  144. --胡牌优先规则
  145. local isHu = false
  146. for k,opType in pairs(beginList) do
  147. if opType == ZPDef.OpType.OP_TYPE_HU then
  148. isHu = true
  149. break
  150. end
  151. end
  152. --发送操作
  153. if not isHu then
  154. --自动操作判断
  155. for k,opType in ipairs(beginList) do
  156. if opType == ZPDef.OpType.OP_TYPE_MINGWEI then
  157. local operateCode = {}
  158. operateCode[1] = ZPDef.OpCode.OP_MING_SHAO
  159. self:sendOperationCode(operateCode)
  160. --直接隐藏界面
  161. self:setOperatorPanelView(false)
  162. return
  163. elseif opType == ZPDef.OpType.OP_TYPE_ANWEI then
  164. local operateCode = {}
  165. operateCode[1] = ZPDef.OpCode.OP_AN_SHAO
  166. self:sendOperationCode(operateCode)
  167. --直接隐藏界面
  168. self:setOperatorPanelView(false)
  169. return
  170. elseif opType == ZPDef.OpType.OP_TYPE_PAO then
  171. local operateCode = {}
  172. operateCode[1] = ZPDef.OpCode.OP_PAO
  173. self:sendOperationCode(operateCode)
  174. --直接隐藏界面
  175. self:setOperatorPanelView(false)
  176. return
  177. elseif opType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
  178. local operateCode = {}
  179. operateCode[1] = ZPDef.OpCode.OP_PAO
  180. self:sendOperationCode(operateCode)
  181. --直接隐藏界面
  182. self:setOperatorPanelView(false)
  183. return
  184. elseif opType == ZPDef.OpType.OP_TYPE_TI then
  185. local operateCode = {}
  186. operateCode[1] = ZPDef.OpCode.OP_TI
  187. self:sendOperationCode(operateCode)
  188. --直接隐藏界面
  189. self:setOperatorPanelView(false)
  190. return
  191. elseif opType == ZPDef.OpType.OP_TYPE_PENG then
  192. local operateCode = {}
  193. operateCode[1] = ZPDef.OpCode.OP_PENG
  194. self:sendOperationCode(operateCode)
  195. --直接隐藏界面
  196. self:setOperatorPanelView(false)
  197. return
  198. end
  199. end
  200. else
  201. --[[local operateCode = {}
  202. operateCode[1] = ZPDef.OpCode.OP_HU
  203. self:sendOperationCode(operateCode)
  204. return--]]
  205. --self:setHuPanelView(true,beginList)
  206. --return
  207. end
  208. --如果没有胡,扫,提,跑,等自动操作,则显示吃碰过操作
  209. self:setOperatorPanelView(true,beginList)
  210. end
  211. --隐藏行为操作层
  212. function ZPRoomOperationView:setOperatorPanelView(bVisible,operations)
  213. self:setVisible(bVisible)
  214. self.ui.Items.Layout_operatorPanel:setVisible(bVisible)
  215. --置灰所有 ui排序:吃碰过
  216. for i = 1 ,6 do
  217. local name = string.format("Button_%d",i)
  218. if self.ui.Items[name] then
  219. self.ui.Items[name]:setVisible(false)
  220. end
  221. end
  222. local index = 1
  223. local guoPosx = self.ui.Items.Layout_3:getPositionX()
  224. --显示操作序列
  225. if operations then
  226. for k,v in pairs(operations) do
  227. local name = string.format("Button_%d",v)
  228. local layout = string.format("Layout_%d",v)
  229. if self.ui.Items[name] then
  230. self.ui.Items[name]:setEnabled(true)
  231. self.ui.Items[name]:setVisible(true)
  232. if v ~= 3 then
  233. self.ui.Items[layout]:setPositionX(guoPosx - index*181)
  234. index = index + 1
  235. end
  236. end
  237. end
  238. end
  239. end
  240. --显示爆牌操作
  241. function ZPRoomOperationView:showBaoPaiOpView(isshow)
  242. if app.room:isLittleFamily() then return end
  243. self:setVisible(isshow)
  244. if true == isshow then
  245. local operations = {[1] = 5,[2] = 6}
  246. self:setOperatorPanelView(isshow,operations)
  247. else
  248. self:setOperatorPanelView(false)
  249. end
  250. end
  251. --隐藏自身
  252. function ZPRoomOperationView:hideSelf()
  253. self.ui.Items.Layout_operatorPanel:setVisible(false)
  254. self.ui.Items.Layout_Eat:setVisible(false)
  255. end
  256. function ZPRoomOperationView:sendOperationCode(operationCode)
  257. if app.room:isLittleFamily() then return end
  258. if type(operationCode) ~= "table" then return end
  259. local request = ZPMessage.GameSendOpCodeResponse:new()
  260. --发送操作码
  261. for k,v in ipairs(operationCode) do
  262. request.operateCode[k] = v
  263. end
  264. --request.opCardNum = table.nums(operationCode)
  265. request.opCard = self.outCard or 0
  266. logE("sendOperationCode:"..table.tostring(request))
  267. self.ui:sendMsg(app.room, "sendOperationCode", request, function(status, response)
  268. logE("RoomView sendOperationCode() response = ", table.tostring(response))
  269. end)
  270. app:dispatchEvent({name = "onClickOpBtn"});
  271. end
  272. function ZPRoomOperationView:onClickGuo()
  273. --算法保留,现在是强制胡牌,如果是非强制胡牌的规则,这里就起作用了
  274. --操作类型
  275. local beginList = {}
  276. beginList = ZPFuc.getZPOperationType(self.operationLocalCode,true)--,self.playerZhao[1] > 0
  277. local isHu = false
  278. for k,opType in pairs(beginList) do
  279. if opType == ZPDef.OpType.OP_TYPE_HU then
  280. isHu = true
  281. break
  282. end
  283. end
  284. if isHu and not self.isTianHu then
  285. self.isTianHu = false
  286. for k,opType in pairs(beginList) do
  287. if opType ~= ZPDef.OpType.OP_TYPE_HU then
  288. if opType == ZPDef.OpType.OP_TYPE_MINGWEI then
  289. local operateCode = {}
  290. operateCode[1] = ZPDef.OpCode.OP_MING_SHAO
  291. self:sendOperationCode(operateCode)
  292. --直接隐藏界面
  293. self:setOperatorPanelView(false)
  294. return
  295. elseif opType == ZPDef.OpType.OP_TYPE_ANWEI then
  296. local operateCode = {}
  297. operateCode[1] = ZPDef.OpCode.OP_AN_SHAO
  298. self:sendOperationCode(operateCode)
  299. --直接隐藏界面
  300. self:setOperatorPanelView(false)
  301. return
  302. elseif opType == ZPDef.OpType.OP_TYPE_PAO then
  303. local operateCode = {}
  304. operateCode[1] = ZPDef.OpCode.OP_PAO
  305. self:sendOperationCode(operateCode)
  306. --直接隐藏界面
  307. self:setOperatorPanelView(false)
  308. return
  309. elseif opType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
  310. local operateCode = {}
  311. operateCode[1] = ZPDef.OpCode.OP_PAO
  312. self:sendOperationCode(operateCode)
  313. --直接隐藏界面
  314. self:setOperatorPanelView(false)
  315. return
  316. elseif opType == ZPDef.OpType.OP_TYPE_TI then
  317. local operateCode = {}
  318. operateCode[1] = ZPDef.OpCode.OP_TI
  319. self:sendOperationCode(operateCode)
  320. --直接隐藏界面
  321. self:setOperatorPanelView(false)
  322. return
  323. elseif opType == ZPDef.OpType.OP_TYPE_CANCEL then
  324. local operateCode = {}
  325. operateCode[1] = ZPDef.OpCode.OP_CANCEL
  326. self:sendOperationCode(operateCode)
  327. --直接隐藏界面
  328. self:setOperatorPanelView(false)
  329. --如果有吃的界面则隐藏
  330. self:setEatCardView(false)
  331. local nUserID = app.room:getUserIdByViewId(1)
  332. elseif opType == ZPDef.OpType.OP_TYPE_PENG then
  333. local operateCode = {}
  334. operateCode[1] = ZPDef.OpCode.OP_PENG
  335. self:sendOperationCode(operateCode)
  336. --直接隐藏界面
  337. self:setOperatorPanelView(false)
  338. return
  339. end
  340. end
  341. end
  342. else
  343. local operateCode = {}
  344. operateCode[1] = ZPDef.OpCode.OP_CANCEL
  345. self:sendOperationCode(operateCode)
  346. --直接隐藏界面
  347. self:setOperatorPanelView(false)
  348. --如果有吃的界面则隐藏
  349. self:setEatCardView(false)
  350. local nUserID = app.room:getUserIdByViewId(1)
  351. --playVoiceOperation(ZPDef.OpType.OP_TYPE_CANCEL,nUserID)
  352. end
  353. end
  354. --隐藏吃牌界面
  355. function ZPRoomOperationView:setEatCardView(bVisible)
  356. self.ui.Items.Layout_Eat:setVisible(bVisible)
  357. self.ui.Items.ImageView_EatPanelBg:removeAllChildren()
  358. end
  359. --隐藏比牌界面
  360. function ZPRoomOperationView:setEatCardBiView(bVisible)
  361. self.ui.Items.ImageView_EatPanelBg_Bi:setSize(self.eatBiViewSrcSize)
  362. self.ui.Items.ImageView_EatPanelBg_Bi:setVisible(bVisible)
  363. self.ui.Items.ImageView_EatPanelBg_Bi:removeAllChildren()
  364. --动态设置坐标
  365. local offX = self.ui.Items.ImageView_EatPanelBg:getPositionX()
  366. local offWidth = self.ui.Items.ImageView_EatPanelBg:getSize().width/2
  367. local biPosX = offX - offWidth - 50
  368. self.ui.Items.ImageView_EatPanelBg_Bi:setPositionX(biPosX)
  369. end
  370. --隐藏比牌界面
  371. function ZPRoomOperationView:setEatCardSanBiView(bVisible)
  372. self.ui.Items.ImageView_EatPanelBg_SanBi:setSize(self.eatBiViewSrcSize)
  373. self.ui.Items.ImageView_EatPanelBg_SanBi:setVisible(bVisible)
  374. self.ui.Items.ImageView_EatPanelBg_SanBi:removeAllChildren()
  375. --动态设置坐标
  376. local offX = self.ui.Items.ImageView_EatPanelBg_Bi:getPositionX()
  377. local offWidth = self.ui.Items.ImageView_EatPanelBg_Bi:getSize().width
  378. local biPosX = offX - offWidth
  379. self.ui.Items.ImageView_EatPanelBg_SanBi:setPositionX(biPosX)
  380. end
  381. function ZPRoomOperationView:setAllEatView(bVisible)
  382. self:setEatCardView(bVisible)
  383. self:setEatCardBiView(bVisible)
  384. self:setEatCardSanBiView(bVisible)
  385. end
  386. --吃牌点击
  387. function ZPRoomOperationView:touchEatOneCardCallBack()
  388. --选了不能回选
  389. self.ui.Items.Button_1:setEnabled(false)
  390. --显示吃牌的节点
  391. self:setEatCardView(true)
  392. self:setEatCardBiView(false)
  393. self:setEatCardSanBiView(false)
  394. --最终显示的第一组列表
  395. local list = {}
  396. local listCode = {}
  397. local index = 1
  398. --服务器发来的操作码
  399. local mType = self.operationLocalCode
  400. --服务器发来的吃牌
  401. local card = self.outCard
  402. --左吃顺子
  403. local ret1 = bit32.band(mType,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
  404. --中吃顺子
  405. local ret2 = bit32.band(mType,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
  406. --右吃顺子
  407. local ret3 = bit32.band(mType,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
  408. --吃同色搭子(壹壹一,吃牌为一)
  409. local ret4 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
  410. --大小搭吃
  411. local ret5 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
  412. --二七十
  413. local ret6 = bit32.band(mType,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  414. --判断是否有吃牌组合
  415. if ret1 > 0 then
  416. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
  417. listCode[index] = ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI
  418. index = index + 1
  419. end
  420. if ret2 > 0 then
  421. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
  422. listCode[index] = ZPDef.OpCode.OP_CHI_MID_SHUN_ZI
  423. index = index + 1
  424. end
  425. if ret3 > 0 then
  426. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
  427. listCode[index] = ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI
  428. index = index + 1
  429. end
  430. if ret4 > 0 then
  431. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
  432. listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME
  433. index = index + 1
  434. end
  435. if ret5 > 0 then
  436. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
  437. listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX
  438. index = index + 1
  439. end
  440. if ret6 > 0 then
  441. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  442. listCode[index] = ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN
  443. index = index + 1
  444. end
  445. logE("onEatCardCallBack list before rank data:"..table.tostring(list))
  446. logE("onEatCardCallBack listCode before rank data:"..table.tostring(listCode))
  447. --油数优先排前面
  448. list,listCode = self:RankChiPai(list,listCode)
  449. logE("onEatCardCallBack list after rank data:"..table.tostring(list))
  450. logE("onEatCardCallBack listCode after rank data:"..table.tostring(listCode))
  451. --初始化UI
  452. self.ui.Items.ImageView_EatPanelBg:removeAllChildren()
  453. self.ui.Items.ImageView_EatPanelBg:setSize(self.eatViewSrcSize)
  454. --九宫格拉伸
  455. local num = table.nums(list)
  456. if num == 2 then
  457. num = 2
  458. elseif num == 3 then
  459. num = 3
  460. elseif num == 4 then
  461. num = 4
  462. elseif num == 5 then
  463. num = 5
  464. elseif num == 6 then
  465. num = 6
  466. end
  467. self.ui.Items.ImageView_EatPanelBg:setSize(cc.size(self.eatViewSrcSize.width * num ,self.eatViewSrcSize.height))
  468. --播放动画
  469. local centerPos = cc.p(self.ui.Items.ImageView_EatPanelBg:getContentSize().width/2,
  470. self.ui.Items.ImageView_EatPanelBg:getContentSize().height/2 - 2)
  471. local seq = cc.Sequence:create(cc.ScaleTo:create(0.2,1,1,1),cc.CallFunc:create(function ()
  472. --playBoxEat()
  473. end))
  474. self.ui.Items.ImageView_EatPanelBg:setScale(0,1,1)
  475. self.ui.Items.ImageView_EatPanelBg:runAction(seq)
  476. local countPosIndex = 0
  477. local intrval = 42
  478. --坐标
  479. local eatPosList = {}
  480. eatPosList[1] = {cc.p(centerPos.x,centerPos.y)}
  481. eatPosList[2] = {cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y)}
  482. eatPosList[3] = {cc.p(centerPos.x - intrval*2,centerPos.y),cc.p(centerPos.x,centerPos.y),cc.p(centerPos.x + intrval*2,centerPos.y)}
  483. eatPosList[4] = {cc.p(centerPos.x - intrval * 3,centerPos.y),
  484. cc.p(centerPos.x - intrval,centerPos.y),
  485. cc.p(centerPos.x + intrval,centerPos.y),
  486. cc.p(centerPos.x + intrval * 3,centerPos.y)}
  487. eatPosList[5] = {cc.p(centerPos.x - intrval * 4,centerPos.y),
  488. cc.p(centerPos.x - intrval*2,centerPos.y),
  489. cc.p(centerPos.x,centerPos.y),
  490. cc.p(centerPos.x + intrval*2,centerPos.y),
  491. cc.p(centerPos.x +intrval*4,centerPos.y)}
  492. eatPosList[6] = {cc.p(centerPos.x - intrval * 5,centerPos.y),cc.p(centerPos.x - intrval * 3,centerPos.y),
  493. cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y),
  494. cc.p(centerPos.x + intrval * 3,centerPos.y),cc.p(centerPos.x + intrval * 5,centerPos.y)}
  495. --绘图
  496. local uiList = {}
  497. local max = table.nums(list)
  498. for k,v in ipairs(list) do
  499. local eatCardUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_eat_card.ui")
  500. self.ui.Items.ImageView_EatPanelBg:addChild(eatCardUI)
  501. uiList[k] = eatCardUI
  502. eatCardUI:setPosition(eatPosList[max][k])
  503. eatCardUI.Items.ImageView_Select:setVisible(false)
  504. for i = 1, 3 do
  505. local cardShow = v[i]
  506. local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE)
  507. local eatCardName = string.format("card_%d",i)
  508. logE("创建吃牌单个:.."..fileName)
  509. eatCardUI.Items[eatCardName]:loadTextureFromPlist(fileName)
  510. --eatCardUI.Items[eatCardName]:setTouchEnabled(true)
  511. if eatCardUI.Items[eatCardName]:isTouchEnabled() then
  512. logE("吃牌设置触摸成功")
  513. end
  514. end
  515. eatCardUI.Items.ImageView_bg:registerClick(function()
  516. self:setEatCardBiView(false)
  517. self:setEatCardSanBiView(false)
  518. for k,v in ipairs(uiList) do
  519. v.Items.ImageView_Select:setVisible(false)
  520. end
  521. eatCardUI.Items.ImageView_Select:setVisible(true)
  522. logE(listCode[k])
  523. self:touchEatTwoCardCallBack(listCode[k],v)
  524. end)
  525. end
  526. end
  527. --点击吃牌组合牌一回调
  528. function ZPRoomOperationView:touchEatTwoCardCallBack(operateCode,weaveCardList)
  529. logE("touchEatTwoCardCallBack cur touch card data : "..table.tostring(weaveCardList))
  530. logE("touchEatTwoCardCallBack cur touch card ZPDef.OpCode : "..operateCode)
  531. local weaveCardListCopy = DeepCopy(weaveCardList)
  532. local card = self.outCard
  533. --删除吃或摸的那个牌
  534. for i = 3,1,-1 do
  535. if weaveCardListCopy[i] == card then
  536. table.remove(weaveCardListCopy,i)
  537. break
  538. end
  539. end
  540. logE("touchEatTwoCardCallBack leave card:"..table.tostring(weaveCardListCopy))
  541. --1.手牌减去吃的第一个组合牌
  542. local handCardValueLocalTemp = DeepCopy(self.handCardValueLocal)
  543. logE("touchEatTwoCardCallBack handCardValueLocal eat card:"..table.tostring(self.handCardValueLocal))
  544. local isEnd = false
  545. local i = 1
  546. local indexChi = 0
  547. while weaveCardListCopy[i] do
  548. if indexChi > 3 then
  549. showTooltip("吃牌数据异常")
  550. --self.toolView:onClickLog()
  551. return
  552. end
  553. for col = self.lieShuMax,1,-1 do --列数
  554. for row = self.hangShuMax,1,-1 do --行数
  555. if weaveCardListCopy[i] == handCardValueLocalTemp[col][row] then --判断值是否相等
  556. table.remove(handCardValueLocalTemp[col],row)
  557. i = i + 1
  558. isEnd = true
  559. break
  560. end
  561. end
  562. if isEnd then
  563. isEnd = false
  564. break
  565. end
  566. end
  567. indexChi = indexChi + 1
  568. end
  569. --2.继续算吃的组合显示,如果没有组合就向服务器发消息
  570. local cardSecondList,listCode,listSize = self:getEatLeaveWeave(handCardValueLocalTemp)
  571. logE("touchEatTwoCardCallBack cardSecondList:"..table.tostring(cardSecondList))
  572. logE("touchEatTwoCardCallBack listCode:"..table.tostring(listCode))
  573. if listSize == 0 then
  574. --正常吃牌或者吃包子
  575. --告诉服务器我的operateCode
  576. local opList = {}
  577. opList[1] = operateCode
  578. self:sendOperationCode(opList)
  579. else
  580. --UI 初始化
  581. self:setEatCardBiView(true)
  582. --九宫格拉伸
  583. local num = table.nums(cardSecondList)
  584. if num == 2 then
  585. num = 2
  586. elseif num == 3 then
  587. num = 3
  588. elseif num == 4 then
  589. num = 4
  590. elseif num == 5 then
  591. num = 5
  592. elseif num == 6 then
  593. num = 6
  594. end
  595. self.ui.Items.ImageView_EatPanelBg_Bi:setSize(cc.size(self.eatViewSrcSize.width * num ,self.eatViewSrcSize.height))
  596. --辅助计算
  597. local centerPos = cc.p(self.ui.Items.ImageView_EatPanelBg_Bi:getContentSize().width/2,
  598. self.ui.Items.ImageView_EatPanelBg_Bi:getContentSize().height/2 -2)
  599. local intrval = 42
  600. --坐标
  601. local eatPosList = {}
  602. eatPosList[1] = {cc.p(centerPos.x,centerPos.y)}
  603. eatPosList[2] = {cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y)}
  604. eatPosList[3] = {cc.p(centerPos.x - intrval*2,centerPos.y),cc.p(centerPos.x,centerPos.y),cc.p(centerPos.x + intrval*2,centerPos.y)}
  605. eatPosList[4] = {cc.p(centerPos.x - intrval * 3,centerPos.y),
  606. cc.p(centerPos.x - intrval,centerPos.y),
  607. cc.p(centerPos.x + intrval,centerPos.y),
  608. cc.p(centerPos.x + intrval * 3,centerPos.y)}
  609. eatPosList[5] = {cc.p(centerPos.x - intrval * 4,centerPos.y),
  610. cc.p(centerPos.x - intrval*2,centerPos.y),
  611. cc.p(centerPos.x,centerPos.y),
  612. cc.p(centerPos.x + intrval*2,centerPos.y),
  613. cc.p(centerPos.x +intrval*4,centerPos.y)}
  614. eatPosList[6] = {cc.p(centerPos.x - intrval * 5,centerPos.y),cc.p(centerPos.x - intrval * 3,centerPos.y),
  615. cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y),
  616. cc.p(centerPos.x + intrval * 3,centerPos.y),cc.p(centerPos.x + intrval * 5,centerPos.y)}
  617. --绘图
  618. local uiList = {}
  619. for k,v in ipairs(cardSecondList) do
  620. local eatCardUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_eat_card.ui")
  621. self.ui.Items.ImageView_EatPanelBg_Bi:addChild(eatCardUI)
  622. eatCardUI:setPosition(eatPosList[#cardSecondList][k])
  623. eatCardUI.Items.ImageView_Select:setVisible(false)
  624. uiList[k] = eatCardUI
  625. for i = 1, 3 do
  626. local cardShow = v[i]
  627. local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE)
  628. local eatCardName = string.format("card_%d",i)
  629. eatCardUI.Items[eatCardName]:loadTextureFromPlist(fileName)
  630. --eatCardUI.Items[eatCardName]:setTouchEnabled(true)
  631. end
  632. eatCardUI.Items.ImageView_bg:registerClick(function()
  633. for k,v in ipairs(uiList) do
  634. v.Items.ImageView_Select:setVisible(false)
  635. end
  636. eatCardUI.Items.ImageView_Select:setVisible(true)
  637. logE(listCode[k])
  638. logE(v)
  639. self:touchEatSanCardCallBack(operateCode,weaveCardList,listCode[k],v)
  640. end)
  641. end
  642. end
  643. end
  644. --点击吃牌组合牌一回调
  645. function ZPRoomOperationView:touchEatSanCardCallBack(operateCode1,weaveCardList1,operateCode2,weaveCardList2)
  646. local weaveCardListCopy = DeepCopy(weaveCardList1)
  647. local weaveCardListCopy2 = DeepCopy(weaveCardList2)
  648. local card = self.outCard
  649. --删掉第一组牌
  650. --删除吃或摸的那个牌
  651. for i = 3,1,-1 do
  652. if weaveCardListCopy[i] == card then
  653. table.remove(weaveCardListCopy,i)
  654. break
  655. end
  656. end
  657. logE("touchEatSanCardCallBack leave card:"..table.tostring(weaveCardListCopy))
  658. --手牌减去吃的牌,继续算吃的组合显示,如果没有组合就向服务器发消息
  659. --1.手牌减去吃的牌
  660. local handCardValueLocalTemp = DeepCopy(self.handCardValueLocal)
  661. --logE("touchEatTwoCardCallBack handCardValueLocal eat card:"..table.tostring(self.handCardValueLocal))
  662. local isEnd = false
  663. local i = 1
  664. while weaveCardListCopy[i] do
  665. for col = self.lieShuMax,1,-1 do --列数
  666. for row = self.hangShuMax,1,-1 do --行数
  667. if weaveCardListCopy[i] == handCardValueLocalTemp[col][row] then --判断值是否相等
  668. table.remove(handCardValueLocalTemp[col],row)
  669. i = i + 1
  670. isEnd = true
  671. break
  672. end
  673. end
  674. if isEnd then
  675. isEnd = false
  676. break
  677. end
  678. end
  679. end
  680. --删除第二组牌
  681. isEnd = false
  682. i = 1
  683. while weaveCardListCopy2[i] do
  684. for col = self.lieShuMax,1,-1 do --列数
  685. for row = self.hangShuMax,1,-1 do --行数
  686. if weaveCardListCopy2[i] == handCardValueLocalTemp[col][row] then --判断值是否相等
  687. table.remove(handCardValueLocalTemp[col],row)
  688. i = i + 1
  689. isEnd = true
  690. break
  691. end
  692. end
  693. if isEnd then
  694. isEnd = false
  695. break
  696. end
  697. end
  698. end
  699. --剩下第三组
  700. --2.继续算吃的组合显示,如果没有组合就向服务器发消息
  701. local cardThirdList,listCode,listSize = self:getEatLeaveWeave(handCardValueLocalTemp)
  702. if listSize == 0 then
  703. --正常吃牌或者吃包子
  704. --告诉服务器我的operateCode
  705. local opList = {}
  706. opList[1] = operateCode1
  707. opList[2] = operateCode2
  708. self:sendOperationCode(opList)
  709. else
  710. --UI 初始化
  711. self:setEatCardSanBiView(true)
  712. --九宫格拉伸
  713. local num = table.nums(cardThirdList)
  714. if num == 2 then
  715. num = 1.7
  716. elseif num == 3 then
  717. num = 2.1
  718. elseif num == 4 then
  719. num = 2.5
  720. elseif num == 5 then
  721. num = 2.9
  722. elseif num == 6 then
  723. num = 3.3
  724. end
  725. self.ui.Items.ImageView_EatPanelBg_SanBi:setSize(cc.size(self.eatSanBiViewSrcSize.width * num ,self.eatSanBiViewSrcSize.height))
  726. --辅助计算
  727. local centerPos = cc.p(self.ui.Items.ImageView_EatPanelBg_SanBi:getContentSize().width/2,
  728. self.ui.Items.ImageView_EatPanelBg_SanBi:getContentSize().height/2 -2)
  729. local intrval = 42
  730. --坐标
  731. local eatPosList = {}
  732. eatPosList[1] = {cc.p(centerPos.x,centerPos.y)}
  733. eatPosList[2] = {cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y)}
  734. eatPosList[3] = {cc.p(centerPos.x - intrval*2,centerPos.y),cc.p(centerPos.x,centerPos.y),cc.p(centerPos.x + intrval*2,centerPos.y)}
  735. eatPosList[4] = {cc.p(centerPos.x - intrval * 3,centerPos.y),
  736. cc.p(centerPos.x - intrval,centerPos.y),
  737. cc.p(centerPos.x + intrval,centerPos.y),
  738. cc.p(centerPos.x + intrval * 3,centerPos.y)}
  739. eatPosList[5] = {cc.p(centerPos.x - intrval * 4,centerPos.y),
  740. cc.p(centerPos.x - intrval*2,centerPos.y),
  741. cc.p(centerPos.x,centerPos.y),
  742. cc.p(centerPos.x + intrval*2,centerPos.y),
  743. cc.p(centerPos.x +intrval*4,centerPos.y)}
  744. eatPosList[6] = {cc.p(centerPos.x - intrval * 5,centerPos.y),cc.p(centerPos.x - intrval * 3,centerPos.y),
  745. cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y),
  746. cc.p(centerPos.x + intrval * 3,centerPos.y),cc.p(centerPos.x + intrval * 5,centerPos.y)}
  747. --绘图
  748. local uiList = {}
  749. for k,v in ipairs(cardThirdList) do
  750. local eatCardUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_eat_card.ui")
  751. self.ui.Items.ImageView_EatPanelBg_SanBi:addChild(eatCardUI)
  752. eatCardUI:setPosition(eatPosList[#cardThirdList][k])
  753. eatCardUI.Items.ImageView_Select:setVisible(false)
  754. uiList[k] = eatCardUI
  755. for i = 1, 3 do
  756. local cardShow = v[i]
  757. local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE)
  758. local eatCardName = string.format("card_%d",i)
  759. eatCardUI.Items[eatCardName]:loadTextureFromPlist(fileName)
  760. --eatCardUI.Items[eatCardName]:setTouchEnabled(true)
  761. end
  762. eatCardUI.Items.ImageView_bg:registerClick(function()
  763. for k,v in ipairs(uiList) do
  764. v.Items.ImageView_Select:setVisible(false)
  765. end
  766. eatCardUI.Items.ImageView_Select:setVisible(true)
  767. logE(listCode[k])
  768. logE(v)
  769. local opList = {}
  770. opList[1] = operateCode1
  771. opList[2] = operateCode2
  772. opList[3] = listCode[k]
  773. self:sendOperationCode(opList)
  774. end)
  775. end
  776. end
  777. end
  778. --判断能否吃牌
  779. --[[
  780. operateCode:吃牌操作码
  781. list : 吃牌组合,key为操作码,value为三张牌组合
  782. index :list的有效大小
  783. ]]
  784. function ZPRoomOperationView:getEatLeaveWeave(handCardValueLocalTemp)
  785. --最终显示的第一组列表
  786. local list = {}
  787. local listCode = {}
  788. local index = 1
  789. --服务器发来的操作码
  790. local mType = self.operationLocalCode
  791. --服务器发来的吃牌
  792. local card = self.outCard
  793. --左吃顺子
  794. local ret1 = bit32.band(mType,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
  795. --中吃顺子
  796. local ret2 = bit32.band(mType,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
  797. --右吃顺子
  798. local ret3 = bit32.band(mType,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
  799. --吃同色搭子(壹壹一,吃牌为一)
  800. local ret4 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
  801. --大小搭吃
  802. local ret5 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
  803. --二七十
  804. local ret6 = bit32.band(mType,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  805. --判断是否有吃牌组合
  806. if ret1 > 0 then
  807. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
  808. listCode[index] = ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI
  809. index = index + 1
  810. end
  811. if ret2 > 0 then
  812. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
  813. listCode[index] = ZPDef.OpCode.OP_CHI_MID_SHUN_ZI
  814. index = index + 1
  815. end
  816. if ret3 > 0 then
  817. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
  818. listCode[index] = ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI
  819. index = index + 1
  820. end
  821. if ret4 > 0 then
  822. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
  823. listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME
  824. index = index + 1
  825. end
  826. if ret5 > 0 then
  827. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
  828. listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX
  829. index = index + 1
  830. end
  831. if ret6 > 0 then
  832. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  833. listCode[index] = ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN
  834. index = index + 1
  835. end
  836. logE("所有吃的组合:"..table.tostring(list))
  837. logE("下一步剔除二比吃后不可以三比的组合牌")
  838. local erBiList = {}
  839. local erBiListCode = {}
  840. for k,v in pairs(list) do
  841. local isReal = self:eatCardLogic(list[k],handCardValueLocalTemp)
  842. if isReal then
  843. table.insert(erBiList,list[k])
  844. table.insert(erBiListCode,listCode[k])
  845. end
  846. end
  847. local listSize = table.nums(erBiList)
  848. if listSize > 0 then
  849. erBiList,erBiListCode = self:RankChiPai(erBiList,erBiListCode)
  850. end
  851. local listSize = table.nums(erBiList)
  852. return erBiList,erBiListCode,listSize
  853. end
  854. --判断能否吃牌
  855. --[[
  856. weaveCard:要吃的那组牌
  857. handCardValueLocalTemp:剩下的手牌(已经假定删掉吃过的牌)
  858. ]]
  859. function ZPRoomOperationView:eatCardLogic(weaveCard,handCardValueLocalTemp)
  860. --[[ OP_CHI_LEFT_SHUN_ZI = 0x0001, //左吃_顺子, 如吃牌为大壹,则表示为吃大壹贰叁
  861. OP_CHI_MID_SHUN_ZI = 0x0002, //中吃_顺子,如吃牌为大贰,则表示为吃大壹贰叁
  862. OP_CHI_RIGHT_SHUN_ZI= 0x0004,//右吃_顺子,如吃牌为大叁,则表示为吃大壹贰叁
  863. OP_CHI_DA_ZI_BY_SAME= 0x0008, //吃_同色搭子,如两张大壹,吃牌为小一
  864. OP_CHI_DA_ZI_BY_MIX = 0x0010, //吃_混色搭子,如一张大壹一张小一,吃牌为大壹或小一
  865. OP_CHI_TWO_SEVEN_TEN= 0x0020, //吃_二七十 --]]
  866. --吃牌操作码
  867. local function getChiPaiNum(cardData,card)
  868. local list = {}
  869. local listCode = {}
  870. local index = 1
  871. local tt = self:ChangeDataToVector(cardData)
  872. --扑克多少张,从1-20,key分别代表小写到大写的1-10,value代表有多少张数
  873. local m_cbCardIndex = ZPFuc.switchToCardIndex(tt)
  874. --牌的下标序号(rang:1-20)从小写1-10,大写依次返回11-20
  875. local cbCurrentIndex = ZPFuc.switchToIndex(card);
  876. if m_cbCardIndex[cbCurrentIndex] == 0 then
  877. --二比
  878. index = index + 1
  879. return list,listCode,index
  880. end
  881. --判断左吃_顺子
  882. if cbCurrentIndex <= 18 and cbCurrentIndex ~= 9 and cbCurrentIndex ~= 10
  883. and m_cbCardIndex[cbCurrentIndex] >= 1 and m_cbCardIndex[cbCurrentIndex + 1] >= 1 and m_cbCardIndex[cbCurrentIndex + 2] >= 1 then
  884. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
  885. listCode[index] = ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI
  886. index = index + 1
  887. end
  888. --判断中吃_顺子
  889. if cbCurrentIndex >= 2 and cbCurrentIndex <= 19 and cbCurrentIndex ~= 10 and cbCurrentIndex ~= 11 and m_cbCardIndex[cbCurrentIndex - 1] >= 1
  890. and m_cbCardIndex[cbCurrentIndex] >= 1 and m_cbCardIndex[cbCurrentIndex + 1] >= 1 then
  891. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
  892. listCode[index] = ZPDef.OpCode.OP_CHI_MID_SHUN_ZI
  893. index = index + 1
  894. end
  895. --判断右吃_顺子
  896. if cbCurrentIndex >= 3 and cbCurrentIndex ~= 11 and cbCurrentIndex ~= 12
  897. and m_cbCardIndex[cbCurrentIndex - 2] >= 1 and m_cbCardIndex[cbCurrentIndex - 1] >= 1
  898. and m_cbCardIndex[cbCurrentIndex ] >= 1 then
  899. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
  900. listCode[index] = ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI
  901. index = index + 1
  902. end
  903. --获取该牌对应另一个大写或小写字牌
  904. local cbReverseIndex = (cbCurrentIndex + 10) % 20;
  905. if cbReverseIndex == 0 then
  906. if ZPFuc.getZPCardIsBig(card) then
  907. cbReverseIndex = 10
  908. else
  909. cbReverseIndex = 20
  910. end
  911. end
  912. --判断吃_同色搭子
  913. if (m_cbCardIndex[cbCurrentIndex] >= 1 and m_cbCardIndex[cbReverseIndex] >= 2) then
  914. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
  915. listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME
  916. index = index + 1
  917. end
  918. --判断吃_同色搭子
  919. if (m_cbCardIndex[cbCurrentIndex] >= 2 and m_cbCardIndex[cbReverseIndex] >= 1) then
  920. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
  921. listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX
  922. index = index + 1
  923. end
  924. --2,7,10
  925. if ZPFuc.getZPIsErQiShi(card) then
  926. if not ZPFuc.getZPCardIsBig(card) then
  927. if m_cbCardIndex[2] >= 1 and m_cbCardIndex[7] >= 1 and m_cbCardIndex[10] >= 1 then
  928. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  929. listCode[index] = ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN
  930. index = index + 1
  931. end
  932. else
  933. if m_cbCardIndex[12] >= 1 and m_cbCardIndex[17] >= 1 and m_cbCardIndex[20] >= 1 then
  934. list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  935. listCode[index] = ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN
  936. index = index + 1
  937. end
  938. end
  939. end
  940. return list,listCode,index
  941. end
  942. local function doDelCard(cardList,cardData)
  943. --1.手牌减去吃的牌
  944. local handCardTemp = DeepCopy(cardData)
  945. local delCard = DeepCopy(cardList)
  946. local isEnd = false
  947. local i = 1
  948. local indexChi = 0
  949. while delCard[i] do
  950. if indexChi > 3 then
  951. showTooltip("吃牌数据异常")
  952. --self.toolView:onClickLog()
  953. return
  954. end
  955. for col = self.lieShuMax,1,-1 do --列数
  956. for row = self.hangShuMax,1,-1 do --行数
  957. if delCard[i] == handCardTemp[col][row] then --判断值是否相等
  958. table.remove(handCardTemp[col],row)
  959. i = i + 1
  960. isEnd = true
  961. break
  962. end
  963. end
  964. if isEnd then
  965. isEnd = false
  966. break
  967. end
  968. end
  969. indexChi = indexChi + 1
  970. end
  971. logE("doDelCard handCardTemp eat card delete:"..table.tostring(handCardTemp))
  972. return handCardTemp
  973. end
  974. --服务器发来的吃牌
  975. local opCard = self.outCard
  976. local tt = self:ChangeDataToVector(handCardValueLocalTemp)
  977. --扑克多少张,从1-20,key分别代表小写到大写的1-10,value代表有多少张数
  978. local m_cbCardIndex = ZPFuc.switchToCardIndex(tt)
  979. --牌的下标序号(rang:1-20)从小写1-10,大写依次返回11-20
  980. local cbCurrentIndex = ZPFuc.switchToIndex(opCard);
  981. --手里有多少张一样
  982. local leaveCardCount = m_cbCardIndex[cbCurrentIndex]
  983. if leaveCardCount == 0 then
  984. --这个情况表示第一次吃完牌后,剩下的牌没有再能组合
  985. return false
  986. elseif leaveCardCount == 1 then
  987. --二比
  988. local list,listCode,index = getChiPaiNum(handCardValueLocalTemp,opCard)
  989. for k,v in ipairs(list) do
  990. if list[k][1] == weaveCard[1] and list[k][2] == weaveCard[2] and list[k][3] == weaveCard[3] then
  991. return true
  992. end
  993. end
  994. return false
  995. elseif leaveCardCount == 2 then
  996. --三比
  997. local list,listCode,index = getChiPaiNum(handCardValueLocalTemp,opCard)
  998. for k,v in ipairs(list) do
  999. if list[k][1] == weaveCard[1] and list[k][2] == weaveCard[2] and list[k][3] == weaveCard[3] then
  1000. local handTemp = doDelCard(weaveCard,handCardValueLocalTemp)
  1001. local listSan,listCodeSan,indexSan = getChiPaiNum(handTemp,opCard)
  1002. if indexSan > 1 then
  1003. return true
  1004. end
  1005. end
  1006. end
  1007. return false
  1008. else
  1009. showTooltip("比牌逻辑错误")
  1010. print("不存在4比的情况")
  1011. end
  1012. end
  1013. --多维数组转 一维数组
  1014. function ZPRoomOperationView:ChangeDataToVector(data)
  1015. local tt = {}
  1016. for i = 1, self.lieShuMax do
  1017. for j = 1, self.hangShuMax do
  1018. if data[i][j] then
  1019. table.insert(tt,data[i][j])
  1020. end
  1021. end
  1022. end
  1023. return tt
  1024. end
  1025. --[[
  1026. 吃牌优化:优先显示油数的组合
  1027. ]]
  1028. function ZPRoomOperationView:RankChiPai(weaveCardList,listCode)
  1029. --结果
  1030. local result1 = {}
  1031. local result2 = {}
  1032. local listCode1 = {}
  1033. local listCode2 = {}
  1034. --查找油数的组合保存,非油数的保存
  1035. for k,list in ipairs(weaveCardList) do
  1036. if
  1037. list[1] == 2 and list[2] == 7 and list[3] == 10 or
  1038. list[1] == 7 and list[2] == 2 and list[3] == 10 or
  1039. list[1] == 10 and list[2] == 2 and list[3] == 7 or
  1040. list[1] == 1 and list[2] == 2 and list[3] == 3 or
  1041. list[1] == 2 and list[2] == 1 and list[3] == 3 or
  1042. list[1] == 3 and list[2] == 1 and list[3] == 2 or
  1043. list[1] == 18 and list[2] == 23 and list[3] == 26 or
  1044. list[1] == 23 and list[2] == 18 and list[3] == 26 or
  1045. list[1] == 26 and list[2] == 18 and list[3] == 23 or
  1046. list[1] == 17 and list[2] == 18 and list[3] == 19 or
  1047. list[1] == 18 and list[2] == 17 and list[3] == 19 or
  1048. list[1] == 19 and list[2] == 17 and list[3] == 18 then
  1049. table.insert(result1,list)
  1050. table.insert(listCode1,listCode[k])
  1051. else
  1052. table.insert(result2,list)
  1053. table.insert(listCode2,listCode[k])
  1054. end
  1055. end
  1056. --非油数的插入到油数后面
  1057. for k,v in ipairs(result2) do
  1058. table.insert(result1,v)
  1059. table.insert(listCode1,listCode2[k])
  1060. end
  1061. --返回
  1062. return result1,listCode1
  1063. end
  1064. --游戏场景传一些参数过来 出的牌,手牌数据
  1065. function ZPRoomOperationView:setSameParame(outCard,handCardList)
  1066. self.outCard = outCard
  1067. self.handCardValueLocal = handCardList
  1068. end
  1069. return ZPRoomOperationView;