|
- local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
- local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
- local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound")
- local ZPMessage = ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage")
-
- local ZPRoomOperationView = class("ZPRoomOperationView", cc.UIView)
-
- function ZPRoomOperationView:ctor()
- ZPRoomOperationView.super.ctor(self);
-
- self.lieShuMax = 15
- self.hangShuMax = 4
- end
-
- function ZPRoomOperationView:loadUI()
- local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_operation.ui");
- self.ui = ui;
- self:addChild(ui);
- end
-
- function ZPRoomOperationView:getEatCardVisible()
- return self.ui.Items.Layout_Eat:isVisible()
- end
-
- function ZPRoomOperationView:setEatBtnEnabledTrue()
- return self.ui.Items.Button_1:setEnabled(true)
- end
-
- function ZPRoomOperationView:onEnter()
- ZPRoomOperationView.super.onEnter(self)
- self:loadUI()
-
- self.eatViewSrcSize = self.ui.Items.ImageView_EatPanelBg:getContentSize()
- self.eatBiViewSrcSize = self.ui.Items.ImageView_EatPanelBg_Bi:getContentSize()
- self.eatSanBiViewSrcSize = self.ui.Items.ImageView_EatPanelBg_SanBi:getContentSize()
-
- --ui排序:吃碰胡过
- self.ui.Items.Button_1:registerClick(nil,function ()
- local function chi()
- local code = self.operationLocalCode
- self:touchEatOneCardCallBack(false)
- end
- local isHu = self:getIsHaveHuOp()
- if isHu == true then
- local content = string.format("确定放弃胡牌吗?")
- local okCallBack = function ()
- chi()
- end
- local cancelCallBack = function ()
-
- end
- showConfirmDialog(content,okCallBack,cancelCallBack)
- else
- chi()
- end
- end)
-
- self.ui.Items.Button_2:registerClick(function ()
- local function peng()
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_PENG
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- end
- local isHu = self:getIsHaveHuOp()
- if isHu == true then
- local content = string.format("确定放弃胡牌吗?")
- local okCallBack = function ()
- peng()
- end
- local cancelCallBack = function ()
-
- end
- showConfirmDialog(content,okCallBack,cancelCallBack)
- else
- peng()
- end
- end)
- --self:hidePengBtn()
-
- self.ui.Items.Button_3:registerClick(function ()
- if app.room:isLittleFamily() then return end
- local isHu = self:getIsHaveHuOp()
- if isHu == true then
- local content = string.format("确定放弃胡牌吗?")
- local okCallBack = function ()
- self:onClickGuo()
- end
- local cancelCallBack = function ()
-
- end
- showConfirmDialog(content,okCallBack,cancelCallBack)
- else
- self:onClickGuo()
- end
- end)
-
- self.ui.Items.Button_4:registerClick(function ()
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_HU
- self:sendOperationCode(operateCode)
- self:setOperatorPanelView(false)
- end)
-
- --不爆牌
- self.ui.Items.Button_6:registerClick(function ()
- if app.room:isLittleFamily() then return end
- local request = ZPMessage.BaoPai:new()
- request.optType = 0
- logE("ZPRoomOperationView:baopai"..table.tostring(request))
- self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
- logE("ZPRoomOperationView baopai response = ", table.tostring(response))
- end)
- self:showBaoPaiOpView(false)
- end)
-
- --爆牌
- self.ui.Items.Button_5:registerClick(function ()
- if app.room:isLittleFamily() then return end
- local request = ZPMessage.BaoPai:new()
- request.optType = 1
- logE("ZPRoomOperationView:baopai"..table.tostring(request))
- self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
- logE("ZPRoomOperationView baopai response = ", table.tostring(response))
- end)
- self:showBaoPaiOpView(false)
- end)
-
- self:hideSelf()
- end
-
- --获取是否有胡操作
- function ZPRoomOperationView:getIsHaveHuOp()
- if not self.operationLocalCode then return false end
- local beginList = {}
- beginList = ZPFuc.getZPOperationType(self.operationLocalCode,true)
- local isHu = false
- for k,opType in pairs(beginList) do
- if opType == ZPDef.OpType.OP_TYPE_HU then
- isHu = true
- break
- end
- end
- return isHu
- end
-
- --泸州大贰自动碰,所以隐藏碰按钮
- function ZPRoomOperationView:hidePengBtn()
- self.ui.Items.Layout_2:setVisible(false)
- self.ui.Items.ImageView:setScale(0.7,1,1)
- local posx = self.ui.Items.ImageView:getPositionX()
- self.ui.Items.ImageView:setPositionX(posx+60)
- end
-
- function ZPRoomOperationView:showOpeation(mainOpCode,viewId,card)
- if app.room:isLittleFamily() then return end
- --操作码
- self.operationLocalCode = mainOpCode
- logE("RoomView:showOpeation(mainOpCode) 1:"..mainOpCode)
- --操作类型
- local beginList = {}
-
- beginList = ZPFuc.getZPOperationType(mainOpCode,true)--,self.playerZhao[1] > 0
- logE("RoomView:showOpeation isCheckMustOperation before (beginList)1 :"..table.tostring(beginList))
-
- --胡牌优先规则
- local isHu = false
- for k,opType in pairs(beginList) do
- if opType == ZPDef.OpType.OP_TYPE_HU then
- isHu = true
- break
- end
- end
-
- --发送操作
- if not isHu then
- --自动操作判断
- for k,opType in ipairs(beginList) do
- if opType == ZPDef.OpType.OP_TYPE_MINGWEI then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_MING_SHAO
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_ANWEI then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_AN_SHAO
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_PAO then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_PAO
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_PAO
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_TI then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_TI
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_PENG then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_PENG
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- end
- end
- else
- --[[local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_HU
- self:sendOperationCode(operateCode)
- return--]]
- --self:setHuPanelView(true,beginList)
- --return
- end
-
- --如果没有胡,扫,提,跑,等自动操作,则显示吃碰过操作
- self:setOperatorPanelView(true,beginList)
- end
-
- --隐藏行为操作层
- function ZPRoomOperationView:setOperatorPanelView(bVisible,operations)
- self:setVisible(bVisible)
- self.ui.Items.Layout_operatorPanel:setVisible(bVisible)
-
- --置灰所有 ui排序:吃碰过
- for i = 1 ,6 do
- local name = string.format("Button_%d",i)
- if self.ui.Items[name] then
- self.ui.Items[name]:setVisible(false)
- end
- end
-
- local index = 1
- local guoPosx = self.ui.Items.Layout_3:getPositionX()
- --显示操作序列
- if operations then
- for k,v in pairs(operations) do
- local name = string.format("Button_%d",v)
- local layout = string.format("Layout_%d",v)
- if self.ui.Items[name] then
- self.ui.Items[name]:setEnabled(true)
- self.ui.Items[name]:setVisible(true)
- if v ~= 3 then
- self.ui.Items[layout]:setPositionX(guoPosx - index*181)
- index = index + 1
- end
- end
- end
- end
- end
-
- --显示爆牌操作
- function ZPRoomOperationView:showBaoPaiOpView(isshow)
- if app.room:isLittleFamily() then return end
- self:setVisible(isshow)
- if true == isshow then
- local operations = {[1] = 5,[2] = 6}
- self:setOperatorPanelView(isshow,operations)
- else
- self:setOperatorPanelView(false)
- end
- end
-
- --隐藏自身
- function ZPRoomOperationView:hideSelf()
- self.ui.Items.Layout_operatorPanel:setVisible(false)
- self.ui.Items.Layout_Eat:setVisible(false)
- end
-
- function ZPRoomOperationView:sendOperationCode(operationCode)
- if app.room:isLittleFamily() then return end
- if type(operationCode) ~= "table" then return end
- local request = ZPMessage.GameSendOpCodeResponse:new()
- --发送操作码
- for k,v in ipairs(operationCode) do
- request.operateCode[k] = v
- end
- --request.opCardNum = table.nums(operationCode)
- request.opCard = self.outCard or 0
- logE("sendOperationCode:"..table.tostring(request))
- self.ui:sendMsg(app.room, "sendOperationCode", request, function(status, response)
- logE("RoomView sendOperationCode() response = ", table.tostring(response))
- end)
- app:dispatchEvent({name = "onClickOpBtn"});
- end
-
- function ZPRoomOperationView:onClickGuo()
- --算法保留,现在是强制胡牌,如果是非强制胡牌的规则,这里就起作用了
- --操作类型
- local beginList = {}
- beginList = ZPFuc.getZPOperationType(self.operationLocalCode,true)--,self.playerZhao[1] > 0
-
- local isHu = false
- for k,opType in pairs(beginList) do
- if opType == ZPDef.OpType.OP_TYPE_HU then
- isHu = true
- break
- end
- end
-
- if isHu and not self.isTianHu then
- self.isTianHu = false
- for k,opType in pairs(beginList) do
- if opType ~= ZPDef.OpType.OP_TYPE_HU then
- if opType == ZPDef.OpType.OP_TYPE_MINGWEI then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_MING_SHAO
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_ANWEI then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_AN_SHAO
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_PAO then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_PAO
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_PAO
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_TI then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_TI
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- elseif opType == ZPDef.OpType.OP_TYPE_CANCEL then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_CANCEL
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- --如果有吃的界面则隐藏
- self:setEatCardView(false)
- local nUserID = app.room:getUserIdByViewId(1)
- elseif opType == ZPDef.OpType.OP_TYPE_PENG then
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_PENG
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- return
- end
- end
- end
- else
- local operateCode = {}
- operateCode[1] = ZPDef.OpCode.OP_CANCEL
- self:sendOperationCode(operateCode)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- --如果有吃的界面则隐藏
- self:setEatCardView(false)
- local nUserID = app.room:getUserIdByViewId(1)
- --playVoiceOperation(ZPDef.OpType.OP_TYPE_CANCEL,nUserID)
- end
- end
-
- --隐藏吃牌界面
- function ZPRoomOperationView:setEatCardView(bVisible)
- self.ui.Items.Layout_Eat:setVisible(bVisible)
- self.ui.Items.ImageView_EatPanelBg:removeAllChildren()
- end
-
- --隐藏比牌界面
- function ZPRoomOperationView:setEatCardBiView(bVisible)
- self.ui.Items.ImageView_EatPanelBg_Bi:setSize(self.eatBiViewSrcSize)
- self.ui.Items.ImageView_EatPanelBg_Bi:setVisible(bVisible)
- self.ui.Items.ImageView_EatPanelBg_Bi:removeAllChildren()
- --动态设置坐标
- local offX = self.ui.Items.ImageView_EatPanelBg:getPositionX()
- local offWidth = self.ui.Items.ImageView_EatPanelBg:getSize().width/2
- local biPosX = offX - offWidth - 50
- self.ui.Items.ImageView_EatPanelBg_Bi:setPositionX(biPosX)
- end
-
- --隐藏比牌界面
- function ZPRoomOperationView:setEatCardSanBiView(bVisible)
- self.ui.Items.ImageView_EatPanelBg_SanBi:setSize(self.eatBiViewSrcSize)
- self.ui.Items.ImageView_EatPanelBg_SanBi:setVisible(bVisible)
- self.ui.Items.ImageView_EatPanelBg_SanBi:removeAllChildren()
- --动态设置坐标
- local offX = self.ui.Items.ImageView_EatPanelBg_Bi:getPositionX()
- local offWidth = self.ui.Items.ImageView_EatPanelBg_Bi:getSize().width
- local biPosX = offX - offWidth
- self.ui.Items.ImageView_EatPanelBg_SanBi:setPositionX(biPosX)
- end
-
- function ZPRoomOperationView:setAllEatView(bVisible)
- self:setEatCardView(bVisible)
- self:setEatCardBiView(bVisible)
- self:setEatCardSanBiView(bVisible)
- end
-
- --吃牌点击
- function ZPRoomOperationView:touchEatOneCardCallBack()
- --选了不能回选
- self.ui.Items.Button_1:setEnabled(false)
- --显示吃牌的节点
- self:setEatCardView(true)
- self:setEatCardBiView(false)
- self:setEatCardSanBiView(false)
- --最终显示的第一组列表
- local list = {}
- local listCode = {}
- local index = 1
- --服务器发来的操作码
- local mType = self.operationLocalCode
- --服务器发来的吃牌
- local card = self.outCard
-
- --左吃顺子
- local ret1 = bit32.band(mType,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
- --中吃顺子
- local ret2 = bit32.band(mType,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
- --右吃顺子
- local ret3 = bit32.band(mType,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
- --吃同色搭子(壹壹一,吃牌为一)
- local ret4 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
- --大小搭吃
- local ret5 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
- --二七十
- local ret6 = bit32.band(mType,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
-
- --判断是否有吃牌组合
- if ret1 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI
- index = index + 1
- end
- if ret2 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_MID_SHUN_ZI
- index = index + 1
- end
- if ret3 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI
- index = index + 1
- end
- if ret4 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
- listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME
- index = index + 1
- end
- if ret5 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
- listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX
- index = index + 1
- end
- if ret6 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
- listCode[index] = ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN
- index = index + 1
- end
-
-
- logE("onEatCardCallBack list before rank data:"..table.tostring(list))
- logE("onEatCardCallBack listCode before rank data:"..table.tostring(listCode))
-
- --油数优先排前面
- list,listCode = self:RankChiPai(list,listCode)
-
- logE("onEatCardCallBack list after rank data:"..table.tostring(list))
- logE("onEatCardCallBack listCode after rank data:"..table.tostring(listCode))
- --初始化UI
- self.ui.Items.ImageView_EatPanelBg:removeAllChildren()
- self.ui.Items.ImageView_EatPanelBg:setSize(self.eatViewSrcSize)
-
- --九宫格拉伸
- local num = table.nums(list)
- if num == 2 then
- num = 2
- elseif num == 3 then
- num = 3
- elseif num == 4 then
- num = 4
- elseif num == 5 then
- num = 5
- elseif num == 6 then
- num = 6
- end
- self.ui.Items.ImageView_EatPanelBg:setSize(cc.size(self.eatViewSrcSize.width * num ,self.eatViewSrcSize.height))
-
- --播放动画
- local centerPos = cc.p(self.ui.Items.ImageView_EatPanelBg:getContentSize().width/2,
- self.ui.Items.ImageView_EatPanelBg:getContentSize().height/2 - 2)
- local seq = cc.Sequence:create(cc.ScaleTo:create(0.2,1,1,1),cc.CallFunc:create(function ()
- --playBoxEat()
- end))
- self.ui.Items.ImageView_EatPanelBg:setScale(0,1,1)
- self.ui.Items.ImageView_EatPanelBg:runAction(seq)
-
-
- local countPosIndex = 0
- local intrval = 42
- --坐标
- local eatPosList = {}
-
- eatPosList[1] = {cc.p(centerPos.x,centerPos.y)}
-
- eatPosList[2] = {cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y)}
-
- eatPosList[3] = {cc.p(centerPos.x - intrval*2,centerPos.y),cc.p(centerPos.x,centerPos.y),cc.p(centerPos.x + intrval*2,centerPos.y)}
-
- eatPosList[4] = {cc.p(centerPos.x - intrval * 3,centerPos.y),
- cc.p(centerPos.x - intrval,centerPos.y),
- cc.p(centerPos.x + intrval,centerPos.y),
- cc.p(centerPos.x + intrval * 3,centerPos.y)}
-
- eatPosList[5] = {cc.p(centerPos.x - intrval * 4,centerPos.y),
- cc.p(centerPos.x - intrval*2,centerPos.y),
- cc.p(centerPos.x,centerPos.y),
- cc.p(centerPos.x + intrval*2,centerPos.y),
- cc.p(centerPos.x +intrval*4,centerPos.y)}
-
- eatPosList[6] = {cc.p(centerPos.x - intrval * 5,centerPos.y),cc.p(centerPos.x - intrval * 3,centerPos.y),
- cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y),
- cc.p(centerPos.x + intrval * 3,centerPos.y),cc.p(centerPos.x + intrval * 5,centerPos.y)}
-
-
-
- --绘图
- local uiList = {}
- local max = table.nums(list)
- for k,v in ipairs(list) do
- local eatCardUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_eat_card.ui")
- self.ui.Items.ImageView_EatPanelBg:addChild(eatCardUI)
- uiList[k] = eatCardUI
- eatCardUI:setPosition(eatPosList[max][k])
- eatCardUI.Items.ImageView_Select:setVisible(false)
- for i = 1, 3 do
- local cardShow = v[i]
- local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE)
- local eatCardName = string.format("card_%d",i)
- logE("创建吃牌单个:.."..fileName)
- eatCardUI.Items[eatCardName]:loadTextureFromPlist(fileName)
- --eatCardUI.Items[eatCardName]:setTouchEnabled(true)
-
- if eatCardUI.Items[eatCardName]:isTouchEnabled() then
- logE("吃牌设置触摸成功")
- end
- end
- eatCardUI.Items.ImageView_bg:registerClick(function()
- self:setEatCardBiView(false)
- self:setEatCardSanBiView(false)
- for k,v in ipairs(uiList) do
- v.Items.ImageView_Select:setVisible(false)
- end
- eatCardUI.Items.ImageView_Select:setVisible(true)
- logE(listCode[k])
- self:touchEatTwoCardCallBack(listCode[k],v)
- end)
- end
- end
- --点击吃牌组合牌一回调
- function ZPRoomOperationView:touchEatTwoCardCallBack(operateCode,weaveCardList)
-
- logE("touchEatTwoCardCallBack cur touch card data : "..table.tostring(weaveCardList))
- logE("touchEatTwoCardCallBack cur touch card ZPDef.OpCode : "..operateCode)
-
- local weaveCardListCopy = DeepCopy(weaveCardList)
-
- local card = self.outCard
-
- --删除吃或摸的那个牌
- for i = 3,1,-1 do
- if weaveCardListCopy[i] == card then
- table.remove(weaveCardListCopy,i)
- break
- end
- end
-
- logE("touchEatTwoCardCallBack leave card:"..table.tostring(weaveCardListCopy))
-
- --1.手牌减去吃的第一个组合牌
- local handCardValueLocalTemp = DeepCopy(self.handCardValueLocal)
- logE("touchEatTwoCardCallBack handCardValueLocal eat card:"..table.tostring(self.handCardValueLocal))
- local isEnd = false
- local i = 1
- local indexChi = 0
- while weaveCardListCopy[i] do
- if indexChi > 3 then
- showTooltip("吃牌数据异常")
- --self.toolView:onClickLog()
- return
- end
-
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if weaveCardListCopy[i] == handCardValueLocalTemp[col][row] then --判断值是否相等
- table.remove(handCardValueLocalTemp[col],row)
- i = i + 1
- isEnd = true
- break
- end
- end
- if isEnd then
- isEnd = false
- break
- end
- end
- indexChi = indexChi + 1
- end
-
- --2.继续算吃的组合显示,如果没有组合就向服务器发消息
- local cardSecondList,listCode,listSize = self:getEatLeaveWeave(handCardValueLocalTemp)
-
- logE("touchEatTwoCardCallBack cardSecondList:"..table.tostring(cardSecondList))
- logE("touchEatTwoCardCallBack listCode:"..table.tostring(listCode))
-
- if listSize == 0 then
- --正常吃牌或者吃包子
- --告诉服务器我的operateCode
- local opList = {}
- opList[1] = operateCode
- self:sendOperationCode(opList)
- else
- --UI 初始化
- self:setEatCardBiView(true)
-
- --九宫格拉伸
- local num = table.nums(cardSecondList)
- if num == 2 then
- num = 2
- elseif num == 3 then
- num = 3
- elseif num == 4 then
- num = 4
- elseif num == 5 then
- num = 5
- elseif num == 6 then
- num = 6
- end
-
- self.ui.Items.ImageView_EatPanelBg_Bi:setSize(cc.size(self.eatViewSrcSize.width * num ,self.eatViewSrcSize.height))
-
- --辅助计算
- local centerPos = cc.p(self.ui.Items.ImageView_EatPanelBg_Bi:getContentSize().width/2,
- self.ui.Items.ImageView_EatPanelBg_Bi:getContentSize().height/2 -2)
-
- local intrval = 42
- --坐标
- local eatPosList = {}
-
- eatPosList[1] = {cc.p(centerPos.x,centerPos.y)}
-
- eatPosList[2] = {cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y)}
-
- eatPosList[3] = {cc.p(centerPos.x - intrval*2,centerPos.y),cc.p(centerPos.x,centerPos.y),cc.p(centerPos.x + intrval*2,centerPos.y)}
-
- eatPosList[4] = {cc.p(centerPos.x - intrval * 3,centerPos.y),
- cc.p(centerPos.x - intrval,centerPos.y),
- cc.p(centerPos.x + intrval,centerPos.y),
- cc.p(centerPos.x + intrval * 3,centerPos.y)}
-
- eatPosList[5] = {cc.p(centerPos.x - intrval * 4,centerPos.y),
- cc.p(centerPos.x - intrval*2,centerPos.y),
- cc.p(centerPos.x,centerPos.y),
- cc.p(centerPos.x + intrval*2,centerPos.y),
- cc.p(centerPos.x +intrval*4,centerPos.y)}
-
- eatPosList[6] = {cc.p(centerPos.x - intrval * 5,centerPos.y),cc.p(centerPos.x - intrval * 3,centerPos.y),
- cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y),
- cc.p(centerPos.x + intrval * 3,centerPos.y),cc.p(centerPos.x + intrval * 5,centerPos.y)}
-
- --绘图
- local uiList = {}
- for k,v in ipairs(cardSecondList) do
- local eatCardUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_eat_card.ui")
- self.ui.Items.ImageView_EatPanelBg_Bi:addChild(eatCardUI)
- eatCardUI:setPosition(eatPosList[#cardSecondList][k])
- eatCardUI.Items.ImageView_Select:setVisible(false)
- uiList[k] = eatCardUI
- for i = 1, 3 do
- local cardShow = v[i]
- local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE)
- local eatCardName = string.format("card_%d",i)
- eatCardUI.Items[eatCardName]:loadTextureFromPlist(fileName)
- --eatCardUI.Items[eatCardName]:setTouchEnabled(true)
-
- end
- eatCardUI.Items.ImageView_bg:registerClick(function()
- for k,v in ipairs(uiList) do
- v.Items.ImageView_Select:setVisible(false)
- end
- eatCardUI.Items.ImageView_Select:setVisible(true)
- logE(listCode[k])
- logE(v)
- self:touchEatSanCardCallBack(operateCode,weaveCardList,listCode[k],v)
- end)
- end
- end
- end
-
-
- --点击吃牌组合牌一回调
- function ZPRoomOperationView:touchEatSanCardCallBack(operateCode1,weaveCardList1,operateCode2,weaveCardList2)
- local weaveCardListCopy = DeepCopy(weaveCardList1)
- local weaveCardListCopy2 = DeepCopy(weaveCardList2)
-
- local card = self.outCard
- --删掉第一组牌
- --删除吃或摸的那个牌
- for i = 3,1,-1 do
- if weaveCardListCopy[i] == card then
- table.remove(weaveCardListCopy,i)
- break
- end
- end
-
- logE("touchEatSanCardCallBack leave card:"..table.tostring(weaveCardListCopy))
-
- --手牌减去吃的牌,继续算吃的组合显示,如果没有组合就向服务器发消息
- --1.手牌减去吃的牌
- local handCardValueLocalTemp = DeepCopy(self.handCardValueLocal)
- --logE("touchEatTwoCardCallBack handCardValueLocal eat card:"..table.tostring(self.handCardValueLocal))
- local isEnd = false
- local i = 1
- while weaveCardListCopy[i] do
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if weaveCardListCopy[i] == handCardValueLocalTemp[col][row] then --判断值是否相等
- table.remove(handCardValueLocalTemp[col],row)
- i = i + 1
- isEnd = true
- break
- end
- end
- if isEnd then
- isEnd = false
- break
- end
- end
- end
-
- --删除第二组牌
- isEnd = false
- i = 1
- while weaveCardListCopy2[i] do
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if weaveCardListCopy2[i] == handCardValueLocalTemp[col][row] then --判断值是否相等
- table.remove(handCardValueLocalTemp[col],row)
- i = i + 1
- isEnd = true
- break
- end
- end
- if isEnd then
- isEnd = false
- break
- end
- end
- end
-
- --剩下第三组
- --2.继续算吃的组合显示,如果没有组合就向服务器发消息
- local cardThirdList,listCode,listSize = self:getEatLeaveWeave(handCardValueLocalTemp)
-
- if listSize == 0 then
- --正常吃牌或者吃包子
- --告诉服务器我的operateCode
- local opList = {}
- opList[1] = operateCode1
- opList[2] = operateCode2
- self:sendOperationCode(opList)
- else
- --UI 初始化
- self:setEatCardSanBiView(true)
-
- --九宫格拉伸
- local num = table.nums(cardThirdList)
- if num == 2 then
- num = 1.7
- elseif num == 3 then
- num = 2.1
- elseif num == 4 then
- num = 2.5
- elseif num == 5 then
- num = 2.9
- elseif num == 6 then
- num = 3.3
- end
-
- self.ui.Items.ImageView_EatPanelBg_SanBi:setSize(cc.size(self.eatSanBiViewSrcSize.width * num ,self.eatSanBiViewSrcSize.height))
-
- --辅助计算
- local centerPos = cc.p(self.ui.Items.ImageView_EatPanelBg_SanBi:getContentSize().width/2,
- self.ui.Items.ImageView_EatPanelBg_SanBi:getContentSize().height/2 -2)
-
- local intrval = 42
- --坐标
- local eatPosList = {}
-
- eatPosList[1] = {cc.p(centerPos.x,centerPos.y)}
-
- eatPosList[2] = {cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y)}
-
- eatPosList[3] = {cc.p(centerPos.x - intrval*2,centerPos.y),cc.p(centerPos.x,centerPos.y),cc.p(centerPos.x + intrval*2,centerPos.y)}
-
- eatPosList[4] = {cc.p(centerPos.x - intrval * 3,centerPos.y),
- cc.p(centerPos.x - intrval,centerPos.y),
- cc.p(centerPos.x + intrval,centerPos.y),
- cc.p(centerPos.x + intrval * 3,centerPos.y)}
-
- eatPosList[5] = {cc.p(centerPos.x - intrval * 4,centerPos.y),
- cc.p(centerPos.x - intrval*2,centerPos.y),
- cc.p(centerPos.x,centerPos.y),
- cc.p(centerPos.x + intrval*2,centerPos.y),
- cc.p(centerPos.x +intrval*4,centerPos.y)}
-
- eatPosList[6] = {cc.p(centerPos.x - intrval * 5,centerPos.y),cc.p(centerPos.x - intrval * 3,centerPos.y),
- cc.p(centerPos.x - intrval,centerPos.y),cc.p(centerPos.x + intrval,centerPos.y),
- cc.p(centerPos.x + intrval * 3,centerPos.y),cc.p(centerPos.x + intrval * 5,centerPos.y)}
-
- --绘图
- local uiList = {}
- for k,v in ipairs(cardThirdList) do
- local eatCardUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_eat_card.ui")
- self.ui.Items.ImageView_EatPanelBg_SanBi:addChild(eatCardUI)
- eatCardUI:setPosition(eatPosList[#cardThirdList][k])
- eatCardUI.Items.ImageView_Select:setVisible(false)
- uiList[k] = eatCardUI
- for i = 1, 3 do
- local cardShow = v[i]
- local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE)
- local eatCardName = string.format("card_%d",i)
- eatCardUI.Items[eatCardName]:loadTextureFromPlist(fileName)
- --eatCardUI.Items[eatCardName]:setTouchEnabled(true)
- end
- eatCardUI.Items.ImageView_bg:registerClick(function()
- for k,v in ipairs(uiList) do
- v.Items.ImageView_Select:setVisible(false)
- end
- eatCardUI.Items.ImageView_Select:setVisible(true)
- logE(listCode[k])
- logE(v)
- local opList = {}
- opList[1] = operateCode1
- opList[2] = operateCode2
- opList[3] = listCode[k]
- self:sendOperationCode(opList)
- end)
- end
- end
- end
-
- --判断能否吃牌
- --[[
- operateCode:吃牌操作码
- list : 吃牌组合,key为操作码,value为三张牌组合
- index :list的有效大小
- ]]
- function ZPRoomOperationView:getEatLeaveWeave(handCardValueLocalTemp)
- --最终显示的第一组列表
- local list = {}
- local listCode = {}
- local index = 1
-
- --服务器发来的操作码
- local mType = self.operationLocalCode
- --服务器发来的吃牌
- local card = self.outCard
-
- --左吃顺子
- local ret1 = bit32.band(mType,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
- --中吃顺子
- local ret2 = bit32.band(mType,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
- --右吃顺子
- local ret3 = bit32.band(mType,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
- --吃同色搭子(壹壹一,吃牌为一)
- local ret4 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
- --大小搭吃
- local ret5 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
- --二七十
- local ret6 = bit32.band(mType,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
-
- --判断是否有吃牌组合
- if ret1 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI
- index = index + 1
- end
- if ret2 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_MID_SHUN_ZI
- index = index + 1
- end
- if ret3 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI
- index = index + 1
- end
- if ret4 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
- listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME
- index = index + 1
- end
- if ret5 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
- listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX
- index = index + 1
- end
- if ret6 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
- listCode[index] = ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN
- index = index + 1
- end
-
- logE("所有吃的组合:"..table.tostring(list))
- logE("下一步剔除二比吃后不可以三比的组合牌")
- local erBiList = {}
- local erBiListCode = {}
-
- for k,v in pairs(list) do
- local isReal = self:eatCardLogic(list[k],handCardValueLocalTemp)
- if isReal then
- table.insert(erBiList,list[k])
- table.insert(erBiListCode,listCode[k])
- end
- end
-
- local listSize = table.nums(erBiList)
-
- if listSize > 0 then
- erBiList,erBiListCode = self:RankChiPai(erBiList,erBiListCode)
- end
-
- local listSize = table.nums(erBiList)
-
- return erBiList,erBiListCode,listSize
- end
-
- --判断能否吃牌
- --[[
- weaveCard:要吃的那组牌
- handCardValueLocalTemp:剩下的手牌(已经假定删掉吃过的牌)
- ]]
- function ZPRoomOperationView:eatCardLogic(weaveCard,handCardValueLocalTemp)
- --[[ OP_CHI_LEFT_SHUN_ZI = 0x0001, //左吃_顺子, 如吃牌为大壹,则表示为吃大壹贰叁
- OP_CHI_MID_SHUN_ZI = 0x0002, //中吃_顺子,如吃牌为大贰,则表示为吃大壹贰叁
- OP_CHI_RIGHT_SHUN_ZI= 0x0004,//右吃_顺子,如吃牌为大叁,则表示为吃大壹贰叁
- OP_CHI_DA_ZI_BY_SAME= 0x0008, //吃_同色搭子,如两张大壹,吃牌为小一
- OP_CHI_DA_ZI_BY_MIX = 0x0010, //吃_混色搭子,如一张大壹一张小一,吃牌为大壹或小一
- OP_CHI_TWO_SEVEN_TEN= 0x0020, //吃_二七十 --]]
- --吃牌操作码
- local function getChiPaiNum(cardData,card)
- local list = {}
- local listCode = {}
- local index = 1
-
- local tt = self:ChangeDataToVector(cardData)
- --扑克多少张,从1-20,key分别代表小写到大写的1-10,value代表有多少张数
- local m_cbCardIndex = ZPFuc.switchToCardIndex(tt)
- --牌的下标序号(rang:1-20)从小写1-10,大写依次返回11-20
- local cbCurrentIndex = ZPFuc.switchToIndex(card);
-
- if m_cbCardIndex[cbCurrentIndex] == 0 then
- --二比
- index = index + 1
- return list,listCode,index
- end
-
- --判断左吃_顺子
- if cbCurrentIndex <= 18 and cbCurrentIndex ~= 9 and cbCurrentIndex ~= 10
- and m_cbCardIndex[cbCurrentIndex] >= 1 and m_cbCardIndex[cbCurrentIndex + 1] >= 1 and m_cbCardIndex[cbCurrentIndex + 2] >= 1 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI
- index = index + 1
- end
-
- --判断中吃_顺子
- if cbCurrentIndex >= 2 and cbCurrentIndex <= 19 and cbCurrentIndex ~= 10 and cbCurrentIndex ~= 11 and m_cbCardIndex[cbCurrentIndex - 1] >= 1
- and m_cbCardIndex[cbCurrentIndex] >= 1 and m_cbCardIndex[cbCurrentIndex + 1] >= 1 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_MID_SHUN_ZI
- index = index + 1
- end
-
- --判断右吃_顺子
- if cbCurrentIndex >= 3 and cbCurrentIndex ~= 11 and cbCurrentIndex ~= 12
- and m_cbCardIndex[cbCurrentIndex - 2] >= 1 and m_cbCardIndex[cbCurrentIndex - 1] >= 1
- and m_cbCardIndex[cbCurrentIndex ] >= 1 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
- listCode[index] = ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI
- index = index + 1
- end
- --获取该牌对应另一个大写或小写字牌
- local cbReverseIndex = (cbCurrentIndex + 10) % 20;
- if cbReverseIndex == 0 then
- if ZPFuc.getZPCardIsBig(card) then
- cbReverseIndex = 10
- else
- cbReverseIndex = 20
- end
- end
-
- --判断吃_同色搭子
- if (m_cbCardIndex[cbCurrentIndex] >= 1 and m_cbCardIndex[cbReverseIndex] >= 2) then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
- listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME
- index = index + 1
- end
-
- --判断吃_同色搭子
- if (m_cbCardIndex[cbCurrentIndex] >= 2 and m_cbCardIndex[cbReverseIndex] >= 1) then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
- listCode[index] = ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX
- index = index + 1
- end
-
- --2,7,10
- if ZPFuc.getZPIsErQiShi(card) then
- if not ZPFuc.getZPCardIsBig(card) then
- if m_cbCardIndex[2] >= 1 and m_cbCardIndex[7] >= 1 and m_cbCardIndex[10] >= 1 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
- listCode[index] = ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN
- index = index + 1
- end
- else
- if m_cbCardIndex[12] >= 1 and m_cbCardIndex[17] >= 1 and m_cbCardIndex[20] >= 1 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
- listCode[index] = ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN
- index = index + 1
- end
- end
- end
-
- return list,listCode,index
- end
-
- local function doDelCard(cardList,cardData)
- --1.手牌减去吃的牌
- local handCardTemp = DeepCopy(cardData)
- local delCard = DeepCopy(cardList)
- local isEnd = false
- local i = 1
- local indexChi = 0
- while delCard[i] do
- if indexChi > 3 then
- showTooltip("吃牌数据异常")
- --self.toolView:onClickLog()
- return
- end
-
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if delCard[i] == handCardTemp[col][row] then --判断值是否相等
- table.remove(handCardTemp[col],row)
- i = i + 1
- isEnd = true
- break
- end
- end
- if isEnd then
- isEnd = false
- break
- end
- end
- indexChi = indexChi + 1
- end
-
- logE("doDelCard handCardTemp eat card delete:"..table.tostring(handCardTemp))
- return handCardTemp
- end
-
- --服务器发来的吃牌
- local opCard = self.outCard
- local tt = self:ChangeDataToVector(handCardValueLocalTemp)
- --扑克多少张,从1-20,key分别代表小写到大写的1-10,value代表有多少张数
- local m_cbCardIndex = ZPFuc.switchToCardIndex(tt)
- --牌的下标序号(rang:1-20)从小写1-10,大写依次返回11-20
- local cbCurrentIndex = ZPFuc.switchToIndex(opCard);
-
- --手里有多少张一样
- local leaveCardCount = m_cbCardIndex[cbCurrentIndex]
-
- if leaveCardCount == 0 then
- --这个情况表示第一次吃完牌后,剩下的牌没有再能组合
- return false
- elseif leaveCardCount == 1 then
- --二比
- local list,listCode,index = getChiPaiNum(handCardValueLocalTemp,opCard)
- for k,v in ipairs(list) do
- if list[k][1] == weaveCard[1] and list[k][2] == weaveCard[2] and list[k][3] == weaveCard[3] then
- return true
- end
- end
- return false
- elseif leaveCardCount == 2 then
- --三比
- local list,listCode,index = getChiPaiNum(handCardValueLocalTemp,opCard)
- for k,v in ipairs(list) do
- if list[k][1] == weaveCard[1] and list[k][2] == weaveCard[2] and list[k][3] == weaveCard[3] then
- local handTemp = doDelCard(weaveCard,handCardValueLocalTemp)
- local listSan,listCodeSan,indexSan = getChiPaiNum(handTemp,opCard)
- if indexSan > 1 then
- return true
- end
- end
- end
- return false
- else
- showTooltip("比牌逻辑错误")
- print("不存在4比的情况")
- end
- end
-
- --多维数组转 一维数组
- function ZPRoomOperationView:ChangeDataToVector(data)
- local tt = {}
- for i = 1, self.lieShuMax do
- for j = 1, self.hangShuMax do
- if data[i][j] then
- table.insert(tt,data[i][j])
- end
- end
- end
- return tt
- end
-
- --[[
- 吃牌优化:优先显示油数的组合
- ]]
- function ZPRoomOperationView:RankChiPai(weaveCardList,listCode)
- --结果
- local result1 = {}
- local result2 = {}
- local listCode1 = {}
- local listCode2 = {}
- --查找油数的组合保存,非油数的保存
- for k,list in ipairs(weaveCardList) do
- if
- list[1] == 2 and list[2] == 7 and list[3] == 10 or
- list[1] == 7 and list[2] == 2 and list[3] == 10 or
- list[1] == 10 and list[2] == 2 and list[3] == 7 or
- list[1] == 1 and list[2] == 2 and list[3] == 3 or
- list[1] == 2 and list[2] == 1 and list[3] == 3 or
- list[1] == 3 and list[2] == 1 and list[3] == 2 or
- list[1] == 18 and list[2] == 23 and list[3] == 26 or
- list[1] == 23 and list[2] == 18 and list[3] == 26 or
- list[1] == 26 and list[2] == 18 and list[3] == 23 or
- list[1] == 17 and list[2] == 18 and list[3] == 19 or
- list[1] == 18 and list[2] == 17 and list[3] == 19 or
- list[1] == 19 and list[2] == 17 and list[3] == 18 then
- table.insert(result1,list)
- table.insert(listCode1,listCode[k])
- else
- table.insert(result2,list)
- table.insert(listCode2,listCode[k])
- end
- end
- --非油数的插入到油数后面
- for k,v in ipairs(result2) do
- table.insert(result1,v)
- table.insert(listCode1,listCode2[k])
- end
- --返回
- return result1,listCode1
- end
-
- --游戏场景传一些参数过来 出的牌,手牌数据
- function ZPRoomOperationView:setSameParame(outCard,handCardList)
- self.outCard = outCard
- self.handCardValueLocal = handCardList
- end
-
- return ZPRoomOperationView;
|