local ChLDaer_Base   ={}
local DEF_POKER_SCALE =1
local DEF_PAI_W = 85
local DEF_PAI_H = 90
local DEF_MOVE_Y  =400
local DEF_PIANYI_Y =50
local config = baseLoadLua('LzDaer/LzDaer_Public/LzDaer_Public_Scripts/Lzde_Config')
function ChLDaer_M_CreScene(  )	
	Pt_EventMgr:clean()
	-- 创建场景
	ChLDaer_Base:CreScene()
end

function ChLDaer_Base:CreScene(  )
	self.m_Scene = sys.runScene()
	tips.ClearAllLayer()
	-- 获取自己的信息
	self.m_MyInfo = Pt_GetPlayerInfo()
	self.m_isVideoState=Pt_M_GetIsVideoFun()
	-- local voice = Pt_GetSoundInfo()
	-- CCLOG("voice ==",voice)
	sys.playMusic(LzDaer_publicaudioRes.music.game_bg)
	-- if voice == 0 then
	-- 	CCLOG("voice 没有")
	-- 	sys.setMusicVolume(0)
	-- end

	local function onEnter( )
		tips.ClearAllLayer()
		SetIsCanMaxWin(true)
		sys.SetWinToCurrPos()
		Pt_loadGame_PublicRes()
		self:Init()
		self:CreateUI()

		if(pt_getNeedFadeGame ~= nil and pt_getNeedFadeGame() == false)then
            pt_setNeedFadeGame(true)
        else
            xui.FadeIn(self.m_Scene)
        end

		if self.m_isVideoState  ==false then
		   self:RegisterEventListen() -- 注册监听
		   CCLOG("register is over")
		end
		self:GoOnInfo()  -- 取消消息阻塞
	end

	local function onExit( )
		-- 卸载自己的资源
		LzDaer_unload_M_Res()
		LzDaer_unloadPublicRes()
		Pt_unloadGame_PublicRes()
		self:CallBackFun()
		self:Init()
		LzDaer_EventMgr:clean()
		self:UnRegisterEventListen()
	end
	local function onResize( )
		if sys.platform == "windows" then
			sys.ReSize()
			ReSizeUI()
		end
	end
	local function onNodeEvent(event)
		if "enter" == event then
			onEnter()
		elseif "exit" == event then
			onExit()
		elseif "resize" == event then
			onResize()
		end
	end
	self.m_Scene:registerScriptHandler(onNodeEvent)
end

-- 消息阻塞
function ChLDaer_Base:StopInfo()
	CCLOG("消息阻塞")
	if self.m_isVideoState ==false then
	   sys.LockMsg()
	end
end

-- 消息继续
function ChLDaer_Base:GoOnInfo()
	CCLOG("消息继续")
	sys.UnlockMsg()
end
---初始化
function ChLDaer_Base:Init(  )
	self.DEF_M_POKER_X= 96
	self.DEF_M_POKER_Y = 80
	self.DEF_POKER_COUNT  =19
	self.DEF_POKER_START_Y =376
    self.DEF_POKER_BEGIN_Y =30
	self.DEF_FAPAI_POS    ={
							[1] = {x = sys.center.x,y = 10},
							[2] = {x = sys.width - 10,y = sys.center.y},
							[3] = {x =  10,y = sys.center.y},
						}
	self.DEF_ANI_POS    ={
							[1] = {x = sys.center.x,y = 200},
							[2] = {x = sys.width - 300,y = sys.center.y+140},
							[3] = {x =  300,y = sys.center.y+140},
						}
    self.DEF_CHUPAI_POS={
							[1]={x=sys.center.x-50,y=sys.center.y-20},
							[2]={x=sys.center.x+240,y=sys.center.y+20},
							[3]={x=sys.center.x-340,y=sys.center.y+20},
						}
	self.m_ResiduePaiNum  =0
	self.m_Events_Key         = "LzDaer_Game"             -- 注册事件key
	self.m_BaseNode           = nil                       -- 基础节点
	self.m_PokerNode          = nil                       -- 牌节点
	self.da_pokerNode         = nil
	self.shou_pokernode       = nil
	self.mopai_node           = nil
	self.m_otherPaiNode       = nil
   
	self.head_node             = nil                         --头像节点
	self.act_node              = nil
	self.m_ResiduePaiSp        = nil
	self.m_juCountLable        = nil
	self.m_huValuebg           =nil
    self.m_tuoshuLabel         =nil
    self.m_chuPaitips          =nil
	self.m_RoomInfo     = {}
	self.m_ShouPaiClassTb = {}
	self.m_PaiDuiTB     = {}
	self.m_MyShouPaiTB  = {}
	self.m_MyShowTB     = {}
	self.m_fanPaiClass  = {}
	self.m_KanShowSpTB    = {}
	self.m_KanPaiTB             = {{},{},{}}
	self.m_DaChuPaiTB      = {{},{},{},{}}

	self.m_KanNodeTB    = {}
    self.m_PutoutShowSpTB    = {}
	self.m_DaChuPaiTB          = {{},{},{}}
	self.m_PutoutNodeTB    = {}
	self.m_RoomState    =0
	self.m_MySeat       =1
	self.m_ZhuangZuoWei =1

	self.m_GameState    =0
	self.m_canClick     =false
	self.m_isCanChuPai  =false

	self.m_BaoJiaoTb    ={0,0,0}
	self.m_CanMovePai   =false
    ----video
	self.m_VideoTimeNode  =nil
	self.hf_node          =nil
    self.m_SendChuValue   =0
    self.m_DelPaiPos       ={x=sys.center.x,y=sys.center.y}
    if self.m_isVideoState then DEF_PIANYI_Y=0 end
    self.m_baiAni        =false
    self.m_isFapai       =true
end
function ChLDaer_Base:CallBackFun(  )
	
	if self.m_isVideoState  then
        self:DelTimeHunFang()
        self:VideoInit()
	end
	M_public_CleanUpAllDATA()
	LzDaer_M_CleanUpBigBalanceUi()
	LzDaer_M_CallOPerateClean()
	LzDaer_M_CleanAllResultData()
	LzDaer_M_CleanAllTouxiangData()
end
--清除数据
function ChLDaer_Base:cleanGameData(  )
	CCLOG("cleanGameData   1")
	for k,v in pairs(self.m_PaiDuiTB ) do
		if v~=nil then 
			v:removeFromParent(true)
		end
	end

	self.da_pokerNode:removeAllChildren(true)
	self.shou_pokernode:removeAllChildren(true)
	self.mopai_node:removeAllChildren(true)
    self.hu_pokerNode:removeAllChildren(true)
    self.m_ShouPaiClassTb = {}
	self.m_PaiDuiTB     = {}
	self.m_MyShouPaiTB  = {}
	self.m_MyShowTB     = {}
	self.m_fanPaiClass  = {}
	self.m_KanShowSpTB       = {}
	self.m_KanPaiTB             = {{},{},{}}
	self.m_KanNodeTB         = {}
    self.m_PutoutShowSpTB    = {}
	self.m_DaChuPaiTB          = {{},{},{}}
	self.m_PutoutNodeTB      = {}
	self.m_BaoJiaoTb         ={0,0,0}

	
	--self.m_GameState    =emDaErCN_GameState_FaPai
	self.m_canClick     =false
	self.m_isCanChuPai  =false
	self.m_CanMovePai   =true
	self.m_chuPaitips=nil
	CCLOG("cleanGameData2")
	if self.m_isVideoState then 
        self.m_ResiduePaiNum  =80
	else
	    self.m_ResiduePaiNum  =0
	    self.m_ZhuangZuoWei =1
	end

	self:UpdateResiduePai()

    self.m_SendChuValue=0
    self.m_ChuPaiClass=nil
    self.m_baiAni        =false

    LzDaer_M_CloseJisuanUI()
    self.m_isFapai       =true
end
function Daer_ChangeDesk()
    local deskRes = string.format('LzDaer/LzDaer_Res/LzDaer_MobileRes/PicRes/SingleRes/lzde_bj_%d.jpg',config:loadDesk())
    UIHelper:loadTexture(ChLDaer_Base.deskSkin,deskRes,UIHelper.TextureType._Local)
    local screenSize = CCDirector:getInstance():getWinSize()
    if(screenSize.width / screenSize.height > 1334 / 750)then
        ChLDaer_Base.deskSkin:setScaleX((screenSize.width / screenSize.height) / (1334 / 750))
    end
end
--创建ui
function ChLDaer_Base:CreateUI( )
	self.m_BaseNode=xui.addNode( self.m_Scene )
	self.m_BaseNode:setName("basenode")
	CCLOG("CreateUI")
	--创建背景
	--local Bg = xui.addSingleResSprite(self.m_BaseNode, "lzde_bj_"..tostring(Daer_P_GetBgNum())..".jpg", sys.center.x, sys.center.y,nil,nil,nil,true)

    local deskRes = string.format('LzDaer/LzDaer_Res/LzDaer_MobileRes/PicRes/SingleRes/lzde_bj_%d.jpg',config:loadDesk())
    self.deskSkin = UIHelper:createImageView(self.m_BaseNode,deskRes,cc.p(sys.center.x,sys.center.y - 30),nil,nil,UIHelper.TextureType._Local)

    local screenSize = CCDirector:getInstance():getWinSize()
    if(screenSize.width / screenSize.height > 1334 / 750)then
        self.deskSkin:setScaleX((screenSize.width / screenSize.height) / (1334 / 750))
    end
	local namebg = xui.addSprite(self.m_BaseNode,"Lzdr_clde_mj",sys.center.x, sys.center.y+100)
    local sizelable = 24

    local l = cc.Layer:create()
    self.m_BaseNode:addChild( l )
    if self.m_isVideoState  ==false then
       self:TouchListener( l )
       self:CrehuShu()
    end
    self.m_otherPaiNode =xui.addNode( self.m_BaseNode )
	--手牌
	self.da_pokerNode  =xui.addNode( self.m_BaseNode )
	self.shou_pokernode =xui.addNode( self.m_BaseNode )
	self.mopai_node=xui.addNode( self.m_BaseNode )
    self.head_node =xui.addNode( self.m_BaseNode )
    self.hu_pokerNode =xui.addNode( self.m_BaseNode)
    self.act_node =xui.addNode(self.m_BaseNode)
    self.m_fapainode=xui.addNode(self.m_BaseNode)
    
	self:CreReadyMean()
	self:SetReadyMeanVisible(false,false)
	
    self.m_moveLingSp =xui.addSprite(self.m_BaseNode ,"lzde_mj_cccx",sys.center.x,DEF_MOVE_Y)
    self:MoveSpTipsShow(false)

    self.hf_node=xui.addNode( self.m_Scene )
    self.hf_node:setLocalZOrder(100)
    self.m_VideoTimeNode=xui.addNode(self.m_Scene)
    -- 公共按钮
    self.M_GameBtn = M_public_CreMenu(function()
        self:UnRegisterEventListen()
    end)
    if self.M_GameBtn.setbtn then
        self.M_GameBtn.setbtn.SetMyBtnVisible(false)
    end
    Daer_P_CreSetUI( self.m_Scene,self.M_GameBtn)
    --重写规则
    if  self.M_GameBtn.guizetn  then
        self.M_GameBtn.guizetn.callback=function (  )
           Lzde_M_PushGuiZeCB()
        end
         self.M_GameBtn.guizetn.SetMyBtnTouchEnableState(true)
    end
    --添加口令
    local startX ,startY= sys.center.x-260,sys.height-30
    local creNode = cc.Node:create()
    local title = xui.addLabel(creNode,"房号:",cc.c3b(143,237,205),sizelable,startX-5,startY,sys.ap.leftCenter)
    self.m_KoulingSp  =xui.addLabel(creNode,"0",cc.c3b( 253,231,110 ),sizelable,startX+title:getContentSize().width,startY,sys.ap.leftCenter)

    local labelSpbg=xui.addSpr9(creNode,"lzde_kl_sp9",170,35,startX-70+title:getContentSize().width,startY+17,sys.ap.topLeft)
    labelSpbg:setLocalZOrder(-2)
    self.m_BaseNode:addChild(creNode)


    local startX = sys.center.x-40
    local creNode = cc.Node:create()
    local title = xui.addLabel(creNode,"局数:",cc.c3b( 253,231,110 ),sizelable,startX,startY,sys.ap.leftCenter)
    self.m_juCountLable  =xui.addLabel(creNode,"0",cc.c3b( 253,231,110 ),sizelable,startX+5+title:getContentSize().width,startY,sys.ap.leftCenter)

    local labelSpbg=xui.addSpr9(creNode,"lzde_kl_sp9",140,35,startX-70+title:getContentSize().width,startY+17,sys.ap.topLeft)
    labelSpbg:setLocalZOrder(-2)
    self.m_BaseNode:addChild(creNode)

    local startX = sys.center.x+200
    local creNode = cc.Node:create()
    local pokersp=xui.addSprite(creNode,"lzde_pknumbg",startX-20,startY)

    self.m_ResiduePaiSp  =xui.addLabel(creNode,"0",cc.c3b(255,255,255),sizelable,startX+25,startY)
    local labelSpbg=xui.addSpr9(creNode,"lzde_kl_sp9",50,35,startX,startY+15,sys.ap.topLeft)
    labelSpbg:setLocalZOrder(-2)
    self.m_BaseNode:addChild(creNode)

    --游戏回调头像信息
    self.M_GameBtn.getPlayerHeadTb=LzDaer_M_GetTouXiangLayer
    -- 公告
    if  self.m_isVideoState ==false then 
        CreWorldGonggaoUI( self.cg_node )
    end
    if self.m_isVideoState ==true then
       self:VideoInit()
       self.m_VideoInfo=sys.copyTab(Pt_M_GetVideoInfoFun())
       self:SetReadyMeanVisible( false, false )
       self:cleanGameData()
       
       --回放按钮
       self:CreHuiFangUIfun()
       --回放头像
        local code = Pt_M_GetCodeDate()
        self:SetKouLingFun(code.playerdata.deskcode)
       -- self.m_juCountLable:setVisible(false)
        if self.m_VideoInfo.t then
            --shengLabel:setString("第 "..self.m_VideoInfo.t.." 局")
            --self:UpdateJushuFun(self.m_VideoInfo.t)
            local videoStr =self.m_VideoInfo.t.."/"..tostring(Pt_GetLimit_MaxJuNum())
            self.m_juCountLable:setString(videoStr)
        end
        if code.playerdata.datetime then
            local TimeSp = xui.addSpr9(self.m_BaseNode,"lzde_xxqp_sj",300,35,sys.center.x, sys.height-80)
            local TimeLabel = xui.addLabel(self.m_BaseNode, code.playerdata.datetime, sys.colors.white,26, sys.center.x, sys.height-80)
        end
    end
   if 1  then return end

   local  WeiXinYaoQingBtn=MyBtnClass:new("lzde_btn_yqhy_zc","lzde_btn_yqhy_dj","lzde_btn_yqhy_zc",function ( )

		--self:SC_DAER_FAPAI()
		self:SC_DAER_MOPAI()
		--LzDaer_M_CreateBigBlanceUI(self.m_Scene)
	end)
	WeiXinYaoQingBtn.btnLy:setPosition(-100,sys.center.y+100)
	self.m_BaseNode:addChild(WeiXinYaoQingBtn.btnLy,10)

  -- self:StopInfo()
end

--设置口令
function ChLDaer_Base:SetKouLingFun( deskcode )
    if self.m_KoulingSp then
        self.m_KoulingSp:setString(deskcode) 
    end
end
--移动出牌提示
function ChLDaer_Base:MoveSpTipsShow(isShow )
    if ChLDaer_Base.m_moveLingSp  then
       ChLDaer_Base.m_moveLingSp:setVisible(isShow)
    end
end
--跟新局数
function ChLDaer_Base:UpdateJushuFun( jushValue )
	if self.m_juCountLable  then 
		local  nMaxJuNum =Pt_GetLimit_MaxJuNum()
		if (jushValue==nil) then jushValue = nMaxJuNum end
		local shengyu = nMaxJuNum-jushValue
        local setStr=tostring(shengyu).."/"..nMaxJuNum
		self.m_juCountLable:setString(setStr)
	end
end
--跟新牌数
function ChLDaer_Base:UpdateResiduePai( jushValue )
	CCLOG("UpdateResiduePai",self.m_ResiduePaiNum)
	if self.m_ResiduePaiSp  then 
		self.m_ResiduePaiSp:setString(self.m_ResiduePaiNum)
	end
end
--更新hu数
function ChLDaer_Base:CrehuShu(  )
	self.m_huValuebg = xui.addSprite(self.m_BaseNode,"lzde_tuo_bg",160,130)
	local nameLable =  xui.addLabel(self.m_huValuebg,"胡\n数",cc.c3b(145, 235,202 ),24,self.m_huValuebg:getContentSize().width/2,75 )
	--self.m_huValuebg:setPosition(200-self.m_huValuebg:getContentSize().width/2,self.m_huValuebg:getContentSize().height/2)
    self.m_tuoshuLabel = xui.addLabel(self.m_huValuebg,"0",cc.c3b( 253,231,110 ),24,self.m_huValuebg:getContentSize().width/2, 20)
end
function  ChLDaer_Base:UpdateHuValue( huValue)
	if self.m_tuoshuLabel then
       self.m_tuoshuLabel:setString(tostring(huValue))
	end
end
--设置发牌的第一人
function ChLDaer_Base:SetToFirst( firstzuowei )
	local zj_zw = {}
	local tb = {1,2,3}
	local m
	for k,v in pairs(tb) do
		if v == firstzuowei then
			m = k
			break
		end     
	end
	for i=m,sys.getTBCount( tb ) do
		table.insert(zj_zw,tb[i])
	end
	for i=1,m-1 do
		table.insert(zj_zw,tb[i])
	end
	return zj_zw
end

--监听
function ChLDaer_Base:RegisterEventListen(  )
	-- 新加入玩家 通知在座的人
	Pt_EventMgr:register( Pt_Events.SC_ROOM_PLAYER_ENTER, self.m_Events_Key, function( key, s )
		self:SC_ROOM_PLAYER_ENTER( key, s )
	end )
	-- 通知刚加入的人 房间信息
	Pt_EventMgr:register( Pt_Events.SC_ROOM_INFO, self.m_Events_Key, function( key, s )
		self:SC_ROOM_INFO( key, s )
	end )
	-- 设置房间状态
	Pt_EventMgr:register( Pt_Events.SC_ROOM_SET_STATE, self.m_Events_Key, function( key, s )
		self:SC_ROOM_SET_STATE( key, s )
	end )
	-- 设置玩家状态
	Pt_EventMgr:register( Pt_Events.XSC_SET_PREPARE, self.m_Events_Key, function( key, s )
		self:XSC_SET_PREPARE( key, s )
	end )
	-- 设置玩家状态
	Pt_EventMgr:register( Pt_Events.SC_ROOM_SET_PLAYER_STATE, self.m_Events_Key, function( key, s )
		self:SC_ROOM_SET_PLAYER_STATE( key, s )
	end )
	-- 玩家离开房间,广播
	Pt_EventMgr:register( Pt_Events.SC_ROOM_PLAYER_QUIT, self.m_Events_Key, function( key, s )
		self:SC_ROOM_PLAYER_QUIT( key, s )
	end )
	-- 房间数据 重连
	Pt_EventMgr:register( Pt_Events.XC_ROOM_INFO, self.m_Events_Key, function( key, s )
		self:XC_ROOM_INFO( key, s )
	end )
	-- 聊天
	Pt_EventMgr:register( Pt_Events.SC_ROOM_CHAT, self.m_Events_Key, function( key, s )
		self:SC_ROOM_CHAT( key, s )
	end )
	-- 游戏中断线重连
	Pt_EventMgr:register( Pt_Events.RECONNECT_INFO, self.m_Events_Key, function( key, s )
		self:RECONNECT_INFO( key, s )
	end )
	-- 重新请求房间数据
	Pt_EventMgr:register( Pt_Events.SC_REQUEST_ROOM, self.m_Events_Key, function( key, s )
		self:SC_REQUEST_ROOM( key, s )
	end )
	-- 广播剩余局数
	Pt_EventMgr:register( Pt_Events.XC_BROADCAST_LAST_TURN, self.m_Events_Key, function( key, s )
		self:XC_BROADCAST_LAST_TURN( key, s )
	end )
    -- 单局结算
    Pt_EventMgr:register( Pt_Events.XC_JIESUAN, self.m_Events_Key, function( key, s )
        self:XC_JIESUAN( key, s )
    end )
    -- 大结算
    Pt_EventMgr:register( Pt_Events.XC_JIESUAN_ALL, self.m_Events_Key, function( key, s )
        self:XC_JIESUAN_ALL( key, s )
    end )
	--------------------------------------------game xc----------------------------------------
	--进入房间
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_ENTER,self.m_Events_Key,function ( key,s )
		self:SC_DAER_ENTER(key,s)
	end)
	--发牌
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_FAPAI,self.m_Events_Key,function ( key,s )
		self:SC_DAER_FAPAI(key,s)
	end)
	--游戏状态改变
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_GAME_STATE,self.m_Events_Key,function ( key,s )
		self:SC_DAER_GAME_STATE(key,s)
	end)
	--翻一张牌
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_FANPAI,self.m_Events_Key,function ( key,s )
		self:SC_DAER_FANPAI(key,s)
	end)
	--摸一张牌
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_MOPAI,self.m_Events_Key,function ( key,s )
		self:SC_DAER_MOPAI(key,s)
	end)
	--当前操作位置
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_NOW_OP_SEAT,self.m_Events_Key,function ( key,s )
		self:SC_DAER_NOW_OP_SEAT(key,s)
	end)
   --通知玩家进行的操作
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_CAN_OPERATE,self.m_Events_Key,function ( key,s )
		self:SC_DAER_CAN_OPERATE(key,s)
	end)
	--通知玩家可以进行保叫
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_CAN_BAOJIAO,self.m_Events_Key,function ( key,s )
		self:SC_DAER_CAN_BAOJIAO(key,s)
	end)
	--保叫结果
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_BAOJIAO,self.m_Events_Key,function ( key,s )
		self:SC_DAER_BAOJIAO(key,s)
	end)
	--通知客户端可以进行拢牌
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_CAN_LONG,self.m_Events_Key,function ( key,s )
		self:SC_DAER_CAN_LONG(key,s)
	end)
	--通知拢牌消息
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_LONG,self.m_Events_Key,function ( key,s )
		self:SC_DAER_LONG(key,s)
	end)
	--吃的结果
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_CHI,self.m_Events_Key,function ( key,s )
		self:SC_DAER_CHI(key,s)
	end)
		--招的结果
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_ZHAO,self.m_Events_Key,function ( key,s )
		self:SC_DAER_ZHAO(key,s)
	end)
		--碰的结果
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_PENG,self.m_Events_Key,function ( key,s )
		self:SC_DAER_PENG(key,s)
	end)
		--胡的结果
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_HU,self.m_Events_Key,function ( key,s )
		self:SC_DAER_HU(key,s)
	end)
    --优先级相关
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_CANCEL_OP,self.m_Events_Key,function ( key,s )
		self:SC_DAER_CANCEL_OP(key,s)
	end)
	--通知客户端出牌
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_NOTICE_CHUPAI,self.m_Events_Key,function ( key,s )
		self:SC_DAER_NOTICE_CHUPAI(key,s)
	end)
    --出
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_CHUPAI,self.m_Events_Key,function ( key,s )
		self:SC_DAER_CHUPAI(key,s)
	end)

	--手牌进入弃牌堆
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_PAIDUI,self.m_Events_Key,function ( key,s )
		self:SC_DAER_PAIDUI(key,s)
	end)

	--是否有操作
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_HAVE_OP,self.m_Events_Key,function ( key,s )
		self:SC_DAER_HAVE_OP(key,s)
	end)

	--胡数
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_HU_NUM,self.m_Events_Key,function ( key,s )
		self:SC_DAER_HU_NUM(key,s)
	end)

	--某人放弃操作
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_QI,self.m_Events_Key,function ( key,s )
		self:SC_DAER_QI(key,s)
	end)
	--某人放弃操作
	LzDaer_EventMgr:register(LzDaer_Events.SC_DAER_SYNC_SP,self.m_Events_Key,function ( key,s )
		self:SC_DAER_SYNC_SP(key,s)
	end)
end
--取消监听
function ChLDaer_Base:UnRegisterEventListen(  )
	Pt_EventMgr:unregisterByKey( self.m_Events_Key )
	LzDaer_EventMgr:unregisterByKey( self.m_Events_Key )
end
-- 新加入玩家 通知在座的人
function ChLDaer_Base:SC_ROOM_PLAYER_ENTER( key, s )
	LzDaer_M_AddTouXiang(s) --添加麻将玩家头像UI
end
-- 通知刚加入的人 房间信息
function ChLDaer_Base:SC_ROOM_INFO( key, s )
	SHOW(s)
	CCLOG("SC_ROOM_INFO----1")
	Pt_EventMgr:fire(Pt_Events.CC_ROOM_SET_STATE,{["roomstate"] = s.roomstate}) --设置公共区房间状态
	tips.removeMaskTips()
	self.m_RoomInfo =s
	--self:UpdateJushuFun(s.deskparam.turn)
	self:UpdateJushuFun(nil)
    self:SetKouLingFun(s.deskcode)
    -- CCLOG("self.m_MyInfo[Def_Player_PlayerId]",self.m_MyInfo[Def_Player_PlayerId],"self.m_MySeat",self.m_MySeat)
    -- for k,v in pairs(s["playerlist"]) do
    -- 	CCLOG("playerseat----id",v.playerid,"seat",v.seat)
    -- end
	for k,v in pairs(s["playerlist"]) do
		-- CCLOG("show-------",k)
		-- SHOW(v)
		if v[Def_Player_PlayerId] == self.m_MyInfo[Def_Player_PlayerId] then
			self.m_MySeat = v["seat"]
			CCLOG("self.MyZuoWeiPos: ",self.m_MySeat,"m_MySeat",ChLDaer_Base.m_MySeat)
		end
	end
	self.m_RoomState = s["roomstate"]
	--清除所有头像
	LzDaer_M_CloseTouXiang()
	-- 创建玩家头像
	LzDaer_M_CreTouXiang( self.head_node, s )
	self:SetReadyMeanVisible(false,false)
	CCLOG("SC_ROOM_INFO----2---0")
	for k,v in pairs(s["playerlist"]) do
	    if v["playerstate"] == emPlayerState_Prepare then
			LzDaer_M_UpdateReadyState(v["seat"], 1)
		elseif v["playerstate"]== emPlayerState_UnPrepare then
			LzDaer_M_UpdateReadyState(v["seat"], 2)
		elseif  v["playerstate"]== emPlayerState_Leave then
			LzDaer_M_LeaveLine(v["seat"], true)
		end
	end
	 CCLOG("SC_ROOM_INFO----2")
	if self.m_RoomState == emRoomState_Game then    --游戏中
		 self:SetReadyMeanVisible(false,false)
	elseif self.m_RoomState == emRoomState_Wait or  self.m_RoomState == emRoomState_JSWait then    --创建准备按钮
		CCLOG("SC_ROOM_INFO----3")
		self:SetReadyMeanVisible(true,true)
	else
		self:SetReadyMeanVisible(false,false)
	end
	Pt_M_CreJisTips(s)
	CCLOG("SC_ROOM_INFO----4")
end

-- 设置房间状态
function ChLDaer_Base:SC_ROOM_SET_STATE( key, s )
   CCLOG("设置房间状态----1")
   self.m_RoomState=s.roomstate
   if self.m_RoomState == emRoomState_Wait then
		Pt_M_SetGoOutCondition( false )
		self:SetReadyMeanVisible(true,true)
		CCLOG("设置房间状态----2")
	elseif self.m_RoomState == emRoomState_Game then
		 self:SetReadyMeanVisible(false,false)
		 CCLOG("设置房间状态----3")
	elseif self.m_RoomState == emRoomState_JSWait then
		local isJiesuan = LzDaer_M_IsCreUI()
		CCLOG("设置房间状态----3",isJiesuan)
		if isJiesuan==false then
			self:SetReadyMeanVisible(true,true)
		end
	elseif self.m_RoomState == emRoomState_Creating then
		CCLOG("设置房间状态----4")
		self:SetReadyMeanVisible(false,false)
	else
		self:SetReadyMeanVisible(false,false)
	end
	Pt_EventMgr:fire(Pt_Events.CC_ROOM_SET_STATE,{["roomstate"] = s.roomstate}) --设置公共区房间状态
end

---小局中间的准备
function ChLDaer_Base:XSC_SET_PREPARE( key,s )
	CCLOG("小局中间的准备")
	local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
	for k,v in pairs(m_TouXiangLayerTB) do
		if v.playerinfo[Def_Player_PlayerId] == s[Def_Player_PlayerId] then
			if s["prepare"] == emPlayerState_Prepare then
				LzDaer_M_UpdateReadyState(s.seat, 1, self.My_ZuoWei_TB)
			end
		end
	end
	if self.m_MyInfo[Def_Player_PlayerId]== s[Def_Player_PlayerId] and s["prepare"] == emPlayerState_Prepare then
		self:cleanGameData()
		for i=1,DEF_PLAYER_NUM do
			LzDaer_M_UpdatePaiNum(i,-10,false)
		end
	end
end
-- 设置玩家状态
function ChLDaer_Base:SC_ROOM_SET_PLAYER_STATE( key, s )
	CCLOG("设置玩家状态----1")
	local playerseat = 0
	local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
	for k,v in pairs(m_TouXiangLayerTB  ) do
		if  v.playerinfo and v.playerinfo[Def_Player_PlayerId] == s[Def_Player_PlayerId] then
			playerseat = v.zuowei
			break
		end
	end
	if s["playerstate"] == emPlayerState_Prepare then
		LzDaer_M_UpdateReadyState(playerseat, 1)
		if self.m_MySeat == playerseat then
			self:cleanGameData()
		end
		CCLOG("设置玩家状态----2")
		LzDaer_M_LeaveLine(playerseat, false)
	elseif s["playerstate"] == emPlayerState_UnPrepare then
		LzDaer_M_UpdateReadyState(playerseat, 2)
		CCLOG("设置玩家状态----3")
		LzDaer_M_LeaveLine(playerseat, false)
	elseif s["playerstate"] == emPlayerState_Leave then
	   LzDaer_M_LeaveLine(playerseat, true)
	   CCLOG("设置玩家状态----4")
	elseif s["playerstate"] == emPlayerState_ZanLi then
		LzDaer_M_LeaveLine(playerseat, true)
	else
		LzDaer_M_LeaveLine(playerseat, false)
	end
end

-- 玩家离开房间,广播
function ChLDaer_Base:SC_ROOM_PLAYER_QUIT( key, s )
	-- 处理玩家座位头像
	local playerseat = 0
	local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
	for k,v in pairs(m_TouXiangLayerTB) do
		if v.playerinfo[Def_Player_PlayerId] == s[Def_Player_PlayerId] then
			playerseat = v.zuowei
			break
		end
	end
	CCLOG("SC_ROOM_PLAYER_QUIT---1")
	LzDaer_M_SubTouXiang(playerseat)
end
-- 判断是否是观看者 然后做相应重连
function ChLDaer_Base:XC_ROOM_INFO( key, s )
	CCLOG("重连-----1")
	--self:StopInfo()
	self.m_GameState=s.state
	if s.emTurnState  then
	   self.m_emTurnState=s.emTurnState
	end
	local ishaveReady = false
	if s.tablePlayerPrepare  then
		if self.m_emTurnState ==emTurnState_Wait  then
			CCLOG("在游戏准备")
			for k,v in pairs(s.tablePlayerPrepare ) do
				if v.seat  then
					if v.prepare  ==0 then

					else
						LzDaer_M_UpdateReadyState(v["seat"], 1)
						if v["seat"]  ==self.m_MySeat then
							 ishaveReady=true
						 end
					end
				end
			end
		else
			CCLOG("在游戏中")
		end
	end
	self:cleanGameData()
	 CCLOG("重连-----11")
	if  s.nLastTurnNum  then
		CCLOG("xc 剩余局数",s.nLastTurnNum)
		self:UpdateJushuFun(s.nLastTurnNum)
	end
    CCLOG("重连-----111")
	if ishaveReady  then CCLOG("ishaveReady is true") self:GoOnInfo() return end
	CCLOG("重连-----2")
	self.m_CanMovePai=false
    self.m_ResiduePaiNum=s.leftpai
    self:UpdateResiduePai()
    CCLOG("重连-----4")
	CCLOG("self.m_GameState",self.m_GameState)
	local daseat = LzDaer_M_GetPointZuoWei(s.seat)+1
	for k,v in pairs(s.playerdata) do
		CCLOG("重连-----5--",k)
		local temp_zw =LzDaer_M_GetPointZuoWei(k)+1
		if temp_zw ==1 then 
			self.m_MyShouPaiTB=v.shoupai
			CCLOG("发自己的牌1",self.m_MyShouPaiTB)
            
            if v.hu_num  and v.hu_num>0 then
           	   self:UpdateHuValue(v.hu_num)
            end
            CCLOG("发自己的牌1")
        else
        	-- for i=1,#v.shoupai do
        	-- 	LzDaer_M_CreateOneSp(k)
        	-- end	
		end
	    LzDaer_M_UpdatePaiNum(k,#v.shoupai,true)
	    if v.peng  then 
	    	for k1,v1 in pairs(v.peng) do
	    		table.insert(self.m_KanPaiTB[k],{["kan"]={v1,v1,v1,["ty"]="peng"}})
	    	end
	    end
	    if v.long  then 
	    	for k1,v1 in pairs(v.long) do
	    		table.insert(self.m_KanPaiTB[k],{["kan"]={v1,v1,v1,["ty"]="long"}})
	    	end
	    end
	    if v.zhao  then 
	    	for k1,v1 in pairs(v.zhao) do
	    		table.insert(self.m_KanPaiTB[k],{["kan"]={v1,v1,v1,["ty"]="zhao"}})
	    	end
	    end
	    if v.chi  then 
	    	for k1,v1 in pairs(v.chi) do 
	    		CCLOG("断线吃--")
	    		table.insert(self.m_KanPaiTB[k],{["kan"]={v1.o1,v1.o2,v1.pai,["ty"]="chi"}})
	    	end
	    end
	    if v.fei  then 
           self.m_DaChuPaiTB[k]=v.fei
	    end
        if v.baohu  and v.baohu==1 then
            LzDaer_M_CreBaojiaoSp(k,1)
            self.m_BaoJiaoTb[k]=1
        end
        if v.isbaobai and v.isbaobai==1 then
            self.m_baiAni  =true
            if k==self.m_MySeat then
	        LzDaerAniamtions.BaoBaiAni(self.act_node,self.DEF_ANI_POS[temp_zw].x,self.DEF_ANI_POS[temp_zw].y,function (  ) 
	           --self:GoOnInfo()
	        end)
	        end
        end
	end
	--CCLOG("self.m_KanPaiTB")
    --SHOW(self.m_KanPaiTB)
    for i=1,3 do
    	self:UpdateKan(i)
    	self:UpdateChuPai(i)	
    end
    if sys.getTBCount(self.m_MyShouPaiTB)>0 then
       DEF_PIANYI_Y =50
    end
	self:ZhanKaiMyShouPai()
	if s.currpai  and s.currpai>0 then
	    self:CHuYiZhangFun(s.seat,s.currpai,nil,nil,true)
        self.m_FanPaiSeat=s.seat
	end
    if s.zhuang  then
    	self.m_ZhuangZuoWei =s.zhuang
		local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
	    if m_TouXiangLayerTB[self.m_ZhuangZuoWei].ZhuangSp then 
	       m_TouXiangLayerTB[self.m_ZhuangZuoWei].ZhuangSp:setVisible(true)
	    end
    end
	self:GoOnInfo()
end

-- 聊天
function ChLDaer_Base:SC_ROOM_CHAT( key, s )
	CCLOG("SC_ROOM_CHAT")
	if self.m_isVideoState then return end
	local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
	for k,v in pairs(m_TouXiangLayerTB) do
		if v.playerinfo[Def_Player_PlayerId] == s[Def_Player_PlayerId] then
			local temp_zw =LzDaer_M_GetPointZuoWei(k)+1
			local off_y = 0
			if s["str"] then
				v:ShowTalkPop(s["str"],nil,nil,nil,nil,nil,-90)
				PT_AddOneMsgex(v.playerinfo[Def_Player_NickName],nil,s["str"])
			end 
			if s["kuaijieID"] then
				local label = Pt_PlayKuaiJieLaioTianSound(s["kuaijieID"],v.xingbie)
				v:ShowTalkPop(label,nil,nil,nil,nil,nil,-90)
				PT_AddOneMsgex(v.playerinfo[Def_Player_NickName],nil,label)
			end 
			if s["resID"] then
				if temp_zw==2 then 
				   off_y=-20
				end
				local resname,rescount = PT_PublicGetBiaoQingRes(s["resID"])
				v:ShowTalkPop("",nil,nil,resname,rescount,nil,-145+off_y)
				PT_AddOneMsgex(v.playerinfo[Def_Player_NickName],s["resID"],nil)
			end 
			if s["headBiaoQing"]  then
				CCLOG("头像表情",k)
				if s["sendseat"] then
					local sendTosea=s["sendseat"]
					if m_TouXiangLayerTB[sendTosea]  then
						CCLOG("头像表情",sendTosea)
						local sendPos={}
						sendPos.x,sendPos.y =m_TouXiangLayerTB[sendTosea]:getPosition()
						--SHOW(sendPos)
						v:PlayHeadBiaoQing(s["headBiaoQing"],sendPos)
					end
				end
			end
		end
	end
end
-- 游戏中断线重连
function ChLDaer_Base:RECONNECT_INFO( key, s )
	self:StopInfo()
	self:cleanGameData()
	CreMidScene(SCENE_GAME, 100, true)
end
--重新请求房间数据
function ChLDaer_Base:SC_REQUEST_ROOM( key, s )
	if self.m_BaseNode then 
	   self.m_BaseNode:stopAllActions()
	end
	LzDaer_M_CloseResultUI()
end

--局数
function ChLDaer_Base:XC_BROADCAST_LAST_TURN( key,s )
	if  s.lastturn  then
		self:UpdateJushuFun(s.lastturn)
	end
end
--创建准备按钮

function ChLDaer_Base:CreReadyMean()
	self.m_WeiXinYaoQingBtn=MyBtnClass:new("lzde_btn_yqhy_zc","lzde_btn_yqhy_dj","lzde_btn_yqhy_zc",function ( )
		Pt_M_WeiXinYaoQingFriend()
	end)
	self.m_WeiXinYaoQingBtn.btnLy:setPosition(sys.center.x-267-35,sys.center.y-100)
	self.m_BaseNode:addChild(self.m_WeiXinYaoQingBtn.btnLy,10)

	self.m_JieSuanRoomBtn=MyBtnClass:new("lzde_btn_jsfj_zc","lzde_btn_jsfj_dj","lzde_btn_jsfj_zc",function (  )
		Pt_M_PushbackFun()
	end)
	self.m_JieSuanRoomBtn.btnLy:setPosition(sys.center.x+65 ,sys.center.y-100)
	self.m_BaseNode:addChild(self.m_JieSuanRoomBtn.btnLy,10)

	if(sys.isSupportEnableApp())then
        self.m_CoptyFangJianBtn=MyBtnClass:new("lzde_btn_fzfjh_zc","lzde_btn_fzfjh_dj","lzde_btn_fzfjh_zc",function ( )
            Pt_M_PushCallRoomNumFun()
        end)
        self.m_CoptyFangJianBtn.btnLy:setPosition(sys.center.x-120,sys.center.y-170)
        self.m_BaseNode:addChild(self.m_CoptyFangJianBtn.btnLy,10)
    end
end
function ChLDaer_Base:SetReadyMeanVisible( zb_visible,qxzb_visible )
	--CCLOG("准备按钮状态",zb_visible,"取消准备状态",qxzb_visible)
	if  CHECK_VER_FLAG_CONTROL ~=nil  then
        if self.m_WeiXinYaoQingBtn  then
            self.m_WeiXinYaoQingBtn.SetMyBtnVisible(false)
        end
        if self.m_JieSuanRoomBtn then
            self.m_JieSuanRoomBtn.SetMyBtnVisible(false)
        end
        if self.m_CoptyFangJianBtn then
            self.m_CoptyFangJianBtn.SetMyBtnVisible(false)
        end
        return
    end
    if self.m_WeiXinYaoQingBtn  then
        self.m_WeiXinYaoQingBtn.SetMyBtnVisible(zb_visible)
    end
    if self.m_JieSuanRoomBtn then
        self.m_JieSuanRoomBtn.SetMyBtnVisible(qxzb_visible)
    end
    if self.m_CoptyFangJianBtn then
        self.m_CoptyFangJianBtn.SetMyBtnVisible(qxzb_visible)
    end
    if Pt_M_GetMyselfIsFangZhu() then
       if(sys.isSupportEnableApp())then
            if self.m_WeiXinYaoQingBtn  then
                self.m_WeiXinYaoQingBtn.btnLy:setPosition(sys.center.x-217-235,sys.center.y-100)
            end
            if self.m_CoptyFangJianBtn  then
                self.m_CoptyFangJianBtn.btnLy:setPosition(sys.center.x-120 ,sys.center.y-100)
            end
            if self.m_JieSuanRoomBtn  then
                self.m_JieSuanRoomBtn.btnLy:setPosition(sys.center.x+215 ,sys.center.y-100)
            end
        else
            if self.m_WeiXinYaoQingBtn  then
                 self.m_WeiXinYaoQingBtn.btnLy:setPosition(sys.center.x-267-35,sys.center.y-100)
            end
            if self.m_JieSuanRoomBtn  then
                self.m_JieSuanRoomBtn.btnLy:setPosition(sys.center.x+65 ,sys.center.y-100)
            end
        end
    else
        if (sys.isSupportEnableApp())then
            if self.m_WeiXinYaoQingBtn  then
                self.m_WeiXinYaoQingBtn.btnLy:setPosition(sys.center.x-267-55,sys.center.y-100)
            end
            if self.m_CoptyFangJianBtn  then
                self.m_CoptyFangJianBtn.btnLy:setPosition(sys.center.x+65 ,sys.center.y-100)
            end
            if self.m_JieSuanRoomBtn  then
                self.m_JieSuanRoomBtn.SetMyBtnVisible(false)
            end
        else
            if self.m_WeiXinYaoQingBtn  then
                self.m_WeiXinYaoQingBtn.btnLy:setPosition(sys.center.x-120,sys.center.y-100)
            end
            if self.m_JieSuanRoomBtn  then
                self.m_JieSuanRoomBtn.SetMyBtnVisible(false)
            end
        end
    end
	CCLOG("SetReadyMeanVisible")
end
--小结算
function ChLDaer_Base:XC_JIESUAN(key,s)
	SHOW(s)
	CCLOG("XC_JIESUAN-----1")
	self:StopInfo()
	LzDaer_M_DelAllTime()
    LzDaer_M_DelOperateUI()
    local ishu =false 
    local zuowei = 1
    local time = 2
    local hutype = 0
    local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
    for k,v in pairs(s.jiesuan.plr_data) do
    	if v~=nil then 
            if v.ishu and v.ishu ==1 then
                zuowei=k
                ishu=true
                hutype=v.hu_type or 0
            end
    	end
    end
    self.m_CanMovePai=true
    if ishu and hutype~=4  then
    	CCLOG("XC_JIESUAN-----2",hutype)
    	if hutype==1 then
           LzDaer_Public_PlaySound("zimo",m_TouXiangLayerTB[zuowei].xingbie)
        else
            LzDaer_Public_PlaySound("hu",m_TouXiangLayerTB[zuowei].xingbie)
        end
        if self.m_baiAni  ==false then
		   	local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
		    LzDaerAniamtions.HuAni(self.act_node,self.DEF_ANI_POS[operate].x,self.DEF_ANI_POS[operate].y,function (  )
		    	-- LzDaer_M_HuSp(zuowei)
		     --   	LzDaer_M_CreResultUI(self.m_BaseNode,self.m_Scene,s)
		     --   	self:GoOnInfo()
		    end)
		    time=1.2
		else
			time=0.01
	    end
	else
		CCLOG("XC_JIESUAN-----3")
        LzDaerAniamtions.LiuJuAni(self.act_node,"lzde_liuju",sys.center.x,sys.center.y)
        time = 2.5
	end
	local array={}
	array[1]=cc.DelayTime:create(time)
	array[2]=cc.CallFunc:create(function ( ... )
		LzDaer_M_HuSp(zuowei)
       	LzDaer_M_CreResultUI(self.m_BaseNode,self.m_Scene,s)
       	self:GoOnInfo()
	end)
	self.m_BaseNode:runAction(cc.Sequence:create(array))
    self.m_baiAni        =false
end
--进入房间
function ChLDaer_Base:XC_JIESUAN_ALL(key,s)
	SHOW(s)
	CCLOG("XC_JIESUAN_ALL")
    self:SetReadyMeanVisible( true, true )
    Pt_M_GameJieSanTips()
    Pt_M_ShowBackBtn(true)
    LzDaer_M_DelAllTime()
    LzDaer_M_DelOperateUI()
	LzDaer_M_CreateBigBlanceUI(self.m_Scene,s)
end
--进入房间
function ChLDaer_Base:SC_DAER_ENTER(key,s)
	SHOW(s)
	CCLOG("SC_DAER_ENTER")
end
--发牌
function ChLDaer_Base:SC_DAER_FAPAI(key,s)
	SHOW(s)
	self:StopInfo()
	self.m_canClick=false
	self.m_CanMovePai =true
	self.m_isFapai       =false
	self.m_ZhuangZuoWei =s.zhuang
	local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
    if m_TouXiangLayerTB[self.m_ZhuangZuoWei].ZhuangSp then 
       m_TouXiangLayerTB[self.m_ZhuangZuoWei].ZhuangSp:setVisible(true)
    end
    CCLOG("庄家----",self.m_ZhuangZuoWei)
    self.m_MyShouPaiTB=s.shoupai
    self.m_LastZuowei =s.lastzuo or 0
    local fapaiCount=20
    local firstTB = self:SetToFirst( self.m_ZhuangZuoWei)
    local tim = 0.1
    DEF_PIANYI_Y=0
	for i=1,fapaiCount do
        for j=1,DEF_PLAYER_NUM do
        	local zuowei=firstTB[j]
        	local isCanfa = false
        	if DEF_PLAYER_NUM ==3 then
                isCanfa=true
        	else
        		isCanfa=true
                if zuowei ==self.m_LastZuowei  then
                    if i>2 then
                       isCanfa=false
                    end
                end
        	end
        	if zuowei and isCanfa then
                tim = tim + 0.03
                local array ={}
                array[1] = cc.DelayTime:create(tim)
			    array[2] = cc.CallFunc:create(function (  )

				    if self.m_isVideoState ==false then
                        local daer_value = s.shoupai[i] or 0
					    self:FaOnePai(firstTB[j],daer_value,i)
					else
						local zuowei=firstTB[j]
						self:FaOnePai(zuowei,self.m_videoShoPaiTb[zuowei][i],i)
					end
					self.m_ResiduePaiNum = self.m_ResiduePaiNum - 1
					if self.m_ResiduePaiNum < 0 then
						self.m_ResiduePaiNum = 0
					end
					self:UpdateResiduePai()
				end)
				if i == fapaiCount and j == DEF_PLAYER_NUM then
				    array[3] = cc.DelayTime:create(0.03)
					array[4] = cc.CallFunc:create(function (  )
						self.m_ResiduePaiNum = self.m_ResiduePaiNum - 1
						if self.m_ResiduePaiNum < 0 then
							self.m_ResiduePaiNum = 0
						end
						if self.m_isVideoState then 
							self.m_ResiduePaiNum = 20
			            end
						self:UpdateResiduePai()
						self:FaPaiEnd()
					end)
				end
				self.m_BaseNode:runAction(cc.Sequence:create(array))
        	end
        end
	end

end
--发完牌
function ChLDaer_Base:FaPaiEnd( )
    CCLOG("FaPaiEnd   1")
	local array = {}
	array[1] = cc.DelayTime:create(1)
	array[2] = cc.CallFunc:create(function (  )
	   self.m_CanMovePai=false
	   if self.m_isVideoState ==true then
            self.m_videoStepIndex=self.m_videoStepIndex+1
            self.m_VideoActiom=true
	         DEF_PIANYI_Y=0
	    else
	        DEF_PIANYI_Y=50
	    end
	   self:ZhanKaiMyShouPai()
       self.m_isFapai       =true
       self:GoOnInfo()
	end)
	self.m_BaseNode:runAction(cc.Sequence:create(array))
	if self.m_LastZuowei ~=self.m_MySeat  and DEF_PLAYER_NUM~=4 then
	   self:ShouLongMyShouPai()
	end
    for i=1,DEF_PLAYER_NUM do
    	if i~=self.m_MySeat then
    		local PaiCount=20
            if self.m_isVideoState then
                self:CreOtherPoker(i,PaiCount,false)
            else
                LzDaer_M_UpdatePaiNum(i,PaiCount,true)
            end
    	end
    end
	CCLOG("FaPaiEnd   3")
end

--发一张牌
function ChLDaer_Base:FaOnePai( zuowei,value,count)    
	CCLOG("发一张牌------2") 
	local time = 0.1
    CCLOG("发一张牌",zuowei,value,count)
    local  mycPos=LzDaer_M_GetPointZuoWei(zuowei)+1
    LzDaer_Public_ActionSound("fapai")
	local changpaiSp = xui.addSprite(self.m_fapainode,"lzde_pai_beixiao",sys.center.x-33,sys.center.y+100,nil)
	changpaiSp:setScale(0.1)
	CCLOG("mycPos",mycPos)
	local array ={}
	array[1] = cc.Spawn:create(cc.MoveTo:create(time,{x=self.DEF_FAPAI_POS[mycPos].x,y=self.DEF_FAPAI_POS[mycPos].y}),cc.FadeOut:create(time),cc.ScaleTo:create(time,2))
	array[2] = cc.CallFunc:create(function (  )
		changpaiSp:removeFromParent(true)
	end)
	changpaiSp:runAction(cc.Sequence:create(array))
	if zuowei == self.m_MySeat then
		if count/3 > sys.getTBCount(self.m_MyShowTB) then
			self.m_MyShowTB[sys.getTBCount(self.m_MyShowTB)+1] = {}
		end
		table.insert(self.m_MyShowTB[sys.getTBCount(self.m_MyShowTB)],{["daer_value"]=value,["m_used"]=false})
		self:TrimGangfapai("fapai")
	else
        if self.m_isVideoState  then
            self:CreOtherPoker(zuowei,count)
        else
		    LzDaer_M_UpdatePaiNum(zuowei,count,false)
        end
	end
end
--组合发牌
function ChLDaer_Base:TrimGangfapai(optye)
    if self.shou_pokernode then
	   self.shou_pokernode:removeAllChildren(true)
	end
	self.m_ShouPaiClassTb={}
	local paitbCount = #self.m_MyShowTB
	for k1,v1 in pairs(self.m_MyShowTB) do
		self.m_ShouPaiClassTb[k1]={}
		for k2,v2 in pairs(v1) do
			local off_x = self:getPoker(paitbCount,k1)
			local off_y = (k2-1)*self.DEF_M_POKER_Y +DEF_PIANYI_Y
			local  pokerClass=DaerPokerClass:Create(self.shou_pokernode,v2.daer_value,"myshou",self.m_canClick)
			pokerClass.m_player:setPosition(off_x,off_y)
			pokerClass.m_player:setLocalZOrder(20-k2)
			pokerClass.m_offx=off_x
			pokerClass.m_offy=off_y
			pokerClass.m_zoerod=20-k2
			pokerClass.weizhi_x  =k1
			pokerClass.weizhi_y  =k2
			table.insert(self.m_ShouPaiClassTb[k1],pokerClass)
		end
	end
	if not optye then
	    self:ChangeSortPoker(false)
	end
end
--出一张 摸一张
function ChLDaer_Base:ChangeSortPoker( isCanAni)
	CCLOG("ChangeSortPoker1",isCanAni)
	self.hu_pokerNode:removeAllChildren(true)
	self.m_HuValueTb    ={}
	local paitbCount =#self.m_ShouPaiClassTb
	for k1,v1 in pairs(self.m_ShouPaiClassTb) do
		local off_x = self:getPoker(paitbCount,k1)
		for k2,v2 in pairs(v1) do
			if  type(v2) =="table" and v2.m_player  then
			    local off_y =(k2-1)*self.DEF_M_POKER_Y+DEF_PIANYI_Y
			    v2.m_player:setLocalZOrder(20-k2)
				v2.m_offx=off_x
				v2.m_offy=off_y
				v2.m_zoerod=20-k2
				v2.weizhi_x  =k1
				v2.weizhi_y  =k2
				---v2.m_player:stopAllActions()
			    if  isCanAni then
			    	v2.m_player:setPositionX(off_x)
			    	self.m_CanMovePai=true
			    	local array = {}
			    	array[1]=cc.MoveTo:create(0.2,{x=off_x,y=off_y})
			    	array[2]=cc.CallFunc:create(function (  )
			    		self.m_CanMovePai =false
			    	end)
                    v2.m_player:runAction(cc.Sequence:create(array))
			    else
                    self.m_CanMovePai =false
                    v2.m_player:setPosition(off_x,off_y)
                end
                if v2.frantSp then
                   v2.frantSp:setOpacity(255)
                end
                local haveCount=self:HaveSameCount(v2.daer_value)
                if haveCount>=3 then 
                   v2.frantSp:setColor(sys.creColor3(125,125,125))
                end
			end
		end
		if self.m_isVideoState ==false then 
			local hu_num = LzDaer_M_FindPreHuValue(v1)
			self.m_HuValueTb[k1] =xui.addSprite(self.hu_pokerNode,"lzde_qw_hubg_1",off_x+43,25)
	        local niunumber=cc.Label:createWithCharMap("lzde_qw_hunum.png",24, 27,  string.byte("0"))
	        niunumber:setPosition(20,self.m_HuValueTb[k1]:getContentSize().height/2)
	        self.m_HuValueTb[k1]:addChild(niunumber ) 
	        niunumber:setString(hu_num) 
	        local hu_sp = xui.addSprite(self.m_HuValueTb[k1],"lzde_qw_hu",60,self.m_HuValueTb[k1]:getContentSize().height/2)
	    end
	end
end
--检测牌点击
function ChLDaer_Base:TouchListener( l )
    local moveDis = 10
    -- MOUSE事件
    local curSelect = nil -- 当前选中
    local curMoveSelct   =nil
    local touchXY= {x=0,y=0}
    --local creKey = {x=0,y=0}
    local function onTouchBegan(touch, event)
        curSelect = nil
        curMoveSelct =nil
        touchXY= {x=0,y=0}
        --creKey = {x=0,y=0}
        local location = touch:getLocation()
        local absPos = cc.p( location.x, location.y )
        if not self.m_isFapai      then  CCLOG("self.m_isFapai") return end
        if self.m_CanMovePai  then  CCLOG("TouchListener is true")  return end
        local flag = false
        if self:Chek_HaveMove() then
    		for k1,v1 in pairs(self.m_ShouPaiClassTb or {}) do
    			if type(v1) =="table" then
    				for k2,v2 in pairs(v1) do
    					if v2 ~=nil and v2.m_player then
    		                local rect = v2.m_player:getBoundingBox()
    		                if cc.rectContainsPoint( rect, absPos ) then
                                curSelect=v2
                                v2.m_isMove=true
                                touchXY=absPos
                                -- creKey.x=k1 
                                -- creKey.y=k2
                                CCLOG("curSelect----1")
                                break
    		                end
    					end
    				end
    		    end
    		end
        else
            CCLOG("有牌在移动")
        end
		return true
    end
    local function onTouchMove(touch, event)
        local location = touch:getLocation()
        local absPos = cc.p( location.x, location.y )
        -- if creKey.x>0 and creKey.y >0 then
        --     if  self.m_ShouPaiClassTb[creKey.x]  and type( self.m_ShouPaiClassTb[creKey.x])then
        --         local seleckPai = self.m_ShouPaiClassTb[creKey.x][creKey.y]
        --         if seleckPai and type(seleckPai) =="table" then
        --             curSelect=seleckPai
        --             CCLOG("CCLOGseleckPai")
        --         else
        --             curSelect=nil
        --             CCLOG("没有这张牌1111")
        --         end
        --     else
        --         curSelect=nil
        --         --CCLOG("没有这张牌222")
        --     end
        -- end
        curSelect=self:Chech_PokerFun(curSelect)
        if curSelect and type(curSelect)=="table" and curSelect.m_player  then
           -- CCLOG("onTouchMovecurSelect")
            --SHOW(curSelect)
            local rect = curSelect.m_player:getBoundingBox()
            if rect and ( (math.abs(touchXY.x-absPos.x)>moveDis) or (math.abs(touchXY.y-absPos.y)>moveDis) ) then
                --CCLOG("onTouchMovecurSelect------")
                self:SetBackColor()
                curMoveSelct=curSelect
                curMoveSelct.frantSp:setOpacity(200)
                local isCanChuPai =self:CallCanChuPai()
                if curMoveSelct.m_player  then
	                if absPos.y> DEF_MOVE_Y-DEF_PAI_H and isCanChuPai then
	                    self:MoveSpTipsShow(true)
	                end
	                curMoveSelct.m_player:setLocalZOrder(30)
	                curMoveSelct.m_player:setPosition(absPos)
                end
                return true
            end
        else
            curMoveSelct =nil
        end
        return true
    end
    local function onTouchEnd(touch, event)
        local location = touch:getLocation()
        local absPos = cc.p( location.x, location.y )
        self:MoveSpTipsShow(false)
        local isRun = false
         curSelect=self:Chech_PokerFun(curSelect)
        if curSelect and type(curSelect) =="table" then
           curSelect.m_isMove=false
        end
        if curMoveSelct  and type(curMoveSelct)=="table" and curMoveSelct.m_player then
            --CCLOG("onTouchEndonTouchEndonTouchEnd")
			curMoveSelct.m_isMove=false
            --SHOW(curMoveSelct)
			curMoveSelct.frantSp:setOpacity(255)
			local height_Y = curMoveSelct.m_player:getPositionY()
			--CCLOG("height_Y",height_Y,curMoveSelct.m_offy)
			local isCanChuPai =self:CallCanChuPai()
			if isCanChuPai then
				if height_Y >DEF_MOVE_Y then
	               local isChu = self:MoveChuPai(curMoveSelct)
	               if isChu then CCLOG("移动出牌成功")  return end
				end
	        end
        	local iscn = self:MoveInsertFun(curMoveSelct)
        	if not iscn then
	            curMoveSelct.m_player:setLocalZOrder( curMoveSelct.m_zoerod)
	        	curMoveSelct.m_player:setPosition(curMoveSelct.m_offx,curMoveSelct.m_offy)
	        	self:CleanPokerTbFun()
	        	self:ChangeSortPoker(true)
	        end
            return
        end
        for k1,v1 in pairs(self.m_ShouPaiClassTb) do
        	for k2,v2 in pairs(v1) do
        		local rect = v2.m_player:getBoundingBox()
                v2.m_isMove=false
        		if cc.rectContainsPoint( rect, absPos ) then
					if v2.m_isNeedChu ==false then
                        v2:SetChangColor(true)
                        v2.m_isNeedChu=true
					else
                        local isCanChuPai =self:CallCanChuPai()
                        if isCanChuPai then
    						local isChu = self:MoveChuPai(v2)
    						if not isChu  then
    	                        v2:SetChangColor(false)
    	                        v2.m_isNeedChu=false
    	                    end
                        end
					end
        		else
                    v2:SetChangColor(false)
	                v2.m_isNeedChu=false
        		end
        	end
        end
        self:CleanPokerTbFun()
        self:ChangeSortPoker()
        for k1,v1 in pairs(self.m_ShouPaiClassTb) do
            for k2,v2 in pairs(v1) do
                if v2.m_player then
                   v2.m_isMove=false
                    if v2.frantSp then
                        --v2.frantSp:setOpacity(255)
                    end
                end
            end
        end
    end
    local listener = cc.EventListenerTouchOneByOne:create()
    listener:setSwallowTouches(false)  --允许消息向下流转
    listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
    listener:registerScriptHandler(onTouchMove,cc.Handler.EVENT_TOUCH_MOVED )
    listener:registerScriptHandler(onTouchEnd,cc.Handler.EVENT_TOUCH_ENDED )
    local eventDispatcher = l:getEventDispatcher()
    eventDispatcher:addEventListenerWithSceneGraphPriority(listener, l)
end
--是否还有这张牌
function ChLDaer_Base:Chech_PokerFun( m_curSelect )
	local  m_select = nil
    --CCLOG("Chech_PokerFun--2")
    if type(m_curSelect)=="table" and m_curSelect.weizhi_x and m_curSelect.weizhi_x>0 and m_curSelect.weizhi_y and m_curSelect.weizhi_y>0 then
        local seleckPai = self.m_ShouPaiClassTb[m_curSelect.weizhi_x][m_curSelect.weizhi_y]
        if seleckPai and type(seleckPai) =="table" then
           m_select=seleckPai
          -- CCLOG("Chech_PokerFun--1")
        end        
    end 
    return m_select
end
function ChLDaer_Base:Chek_HaveMove(  )
    local isHaveMove = true
    for k1,v1 in pairs(self.m_ShouPaiClassTb or {}) do
        if type(v1) =="table" then
            for k2,v2 in pairs(v1) do
                if v2 ~=nil and v2.m_player  and v2.m_isMove ==true then
                   isHaveMove=false
                   break
                end
            end
        end
    end
    CCLOG("isHaveMove",isHaveMove)
    return isHaveMove
end
function ChLDaer_Base:CallCanChuPai(  )
	local isCan =false
	if self.m_GameState ==emDaErCN_GameState_Gaming and self.m_isCanChuPai==true then 
		isCan =true
    end
    return isCan
end
--有相同牌shu
function ChLDaer_Base:HaveSameCount( daer_value )
    local count  =0
    for k1,v1 in pairs(self.m_ShouPaiClassTb) do
        if type(v1) =="table" then
            for k2,v2 in pairs(v1) do
               if  v2.daer_value and  v2.daer_value ==daer_value then
                    count=count+1
               end
            end
        end
    end
    return count
end
--移动chupai
function ChLDaer_Base:MoveChuPai( chupaiTb )
	local isChu = false
	 CCLOG("MoveChuPai----0")
	if not chupaiTb  then return isChu end
	local isMoveCanChuPai =self:CallCanChuPai()
	if not isMoveCanChuPai  then return isChu end
    local haveCount=self:HaveSameCount(chupaiTb.daer_value)
    if haveCount>=3 then
       tips.creUpTimeTips("不能拆牌!")
       return isChu
    end
    if chupaiTb.m_isNotChu  then
       tips.creUpTimeTips("上吐下泻,不能打出该张!")
       return isChu
    end
    if chupaiTb.m_player then
       local offx,offy = chupaiTb.m_offx,chupaiTb.m_offy
       local weizhi_x = chupaiTb.weizhi_x
       local weizhi_y = chupaiTb.weizhi_y
       local delPai = nil
       for k1,v1 in pairs(self.m_ShouPaiClassTb or {}) do
            local del = false
       	    if k1==weizhi_x then
	            if type(v1) =="table" then
	                for k2,v2 in pairs(v1) do
	                 	if k2==weizhi_y then
                           delPai=table.remove(v1,k2)
                           del =true
                           break
	                 	end
	                end
	           	end
	        end
            if del then break end
       end
       if delPai and delPai.m_player then
            self.m_DelPaiPos.x=delPai.m_player:getPositionX()
            self.m_DelPaiPos.y=delPai.m_player:getPositionY()
            delPai.m_player:removeFromParent(true)
            isChu=true
            self:CleanPokerTbFun()
            self:ChangeSortPoker(true)
            local info = {}
            info.value=delPai.daer_value
            CS_DAER_CHUPAI(info)
            self.m_SendChuValue=delPai.daer_value
            self.m_isCanChuPai=false
       end
    end
    return isChu
end
--移动chupai
function ChLDaer_Base:MoveChuPai( chupaiTb )
	local isChu = false
	 CCLOG("MoveChuPai----0")
	if not chupaiTb  then return isChu end
	local isMoveCanChuPai =self:CallCanChuPai()
	if not isMoveCanChuPai  then return isChu end
    local haveCount=self:HaveSameCount(chupaiTb.daer_value)
    if haveCount>=3 then
       tips.creUpTimeTips("不能拆牌!")
       return isChu
    end
    if chupaiTb.m_isNotChu  then
       tips.creUpTimeTips("上吐下泻,不能打出该张!")
       return isChu
    end
    if chupaiTb.m_player then
       local offx,offy = chupaiTb.m_offx,chupaiTb.m_offy
       local weizhi_x = chupaiTb.weizhi_x
       local weizhi_y = chupaiTb.weizhi_y
       local delPai = nil
       for k1,v1 in pairs(self.m_ShouPaiClassTb or {}) do
            local del = false
       	    if k1==weizhi_x then
	            if type(v1) =="table" then
	                for k2,v2 in pairs(v1) do
	                 	if k2==weizhi_y then
                           delPai=table.remove(v1,k2)
                           del =true
                           break
	                 	end
	                end
	           	end
	        end
            if del then break end
       end
       if delPai and delPai.m_player then
            self.m_DelPaiPos.x=delPai.m_player:getPositionX()
            self.m_DelPaiPos.y=delPai.m_player:getPositionY()
            delPai.m_player:removeFromParent(true)
            isChu=true
            self:CleanPokerTbFun()
            self:ChangeSortPoker(true)
            local info = {}
            info.value=delPai.daer_value
            CS_DAER_CHUPAI(info)
            self.m_SendChuValue=delPai.daer_value
            self.m_isCanChuPai=false
           -- self:SaveShouPaiInfo()
       end
    end
    return isChu
end
--能否沱牌
function ChLDaer_Base:isCanMove( keyIndex, daer_value )
    local isCan =false
    local count = 0
    for k,v in pairs(self.m_ShouPaiClassTb) do
   	    if k==keyIndex then
            for k1,v1 in pairs(v) do
          	    if v1.daer_value ==daer_value then
          	   	    count =count+1
          	   	end
            end
   	    end
    end
    if count>=3 then isCan =true end
    return isCan
end
--移动拖牌
function ChLDaer_Base:MoveInsertFun( chonsePai)
	CCLOG("MoveInsertFun")
	local isSort = false
	local weizhi_x = nil
	local weizhi_y = nil
	local chonsePaiPos = {}
	local m_maxX = 0
	local m_minX = 0
	local m_isMaxY = false
	local delPai =  nil
	local shouPaiCount1=0
    if self:isCanMove(chonsePai.weizhi_x,chonsePai.daer_value ) then CCLOG("大于3张相同") return isSort end
	for k1,v1 in pairs(self.m_ShouPaiClassTb) do
		for k1,v2 in pairs(v1) do
			if v2 ~=nil then
                shouPaiCount1=shouPaiCount1+1
			end
		end
	end
	chonsePaiPos.x= chonsePai.m_player:getPositionX()
	chonsePaiPos.y= chonsePai.m_player:getPositionY()
	local changValue = chonsePai.daer_value
	--SHOW(chonsePaiPos)
	m_minX=self.m_ShouPaiClassTb[1][1].m_offx
	m_maxX=self.m_ShouPaiClassTb[#self.m_ShouPaiClassTb][1].m_offx+DEF_PAI_W

	if chonsePaiPos.x<=m_minX or  chonsePaiPos.x>=m_maxX then
        if #self.m_ShouPaiClassTb>=10 then  CCLOG("#self.m_ShouPaiClassTb]>=10") return  isSort end
		for k1,v1 in pairs( self.m_ShouPaiClassTb) do
			for k2,v2 in pairs(v1) do
				if k1==chonsePai.weizhi_x  and chonsePai.weizhi_y==k2 then
				   delPai=table.remove(v1,k2)
				end
			end
		end
		for k,v in pairs( self.m_ShouPaiClassTb) do
			if #v==0 then
			   CCLOG("selfdel")
			   table.remove(self.m_ShouPaiClassTb,k)
			end
		end
        if chonsePaiPos.x<=m_minX then
        	CCLOG("左边")
            table.insert(self.m_ShouPaiClassTb,1,{chonsePai})
        else
        	CCLOG("右边边")
            table.insert(self.m_ShouPaiClassTb,{chonsePai})
        end
    	self.m_isAction=true
		self:ChangeSortPoker(true)
		isSort=true
	else
		CCLOG("中间")
		local m_isMaxY = false
        for k1,v1 in pairs(self.m_ShouPaiClassTb) do
			for k2,v2 in pairs(v1) do
				local shuallCount = #v1
				if shuallCount <4 and not self:isCanMove(k1,v2.daer_value ) then
					if k1==chonsePai.weizhi_x and k2 ==chonsePai.weizhi_y   then
						CCLOG("自己的牌")
					else
						local rect =v2.m_player:getBoundingBox()
						if  k2==shuallCount then
                            rect.height=sys.height
						end
						if cc.rectContainsPoint( rect, chonsePaiPos ) then
						    weizhi_x=k1
						    weizhi_y=k2
						    if chonsePaiPos.y>= rect.y+DEF_PAI_H then
                               m_isMaxY=true
						    end
						    CCLOG("weizhi_x1",weizhi_x,"weizhi_y",weizhi_y,m_isMaxY)
						    break
						end
					end
				end
				if k1 ==chonsePai.weizhi_x and k2 ~=chonsePai.weizhi_y  then
                 	local rect =v2.m_player:getBoundingBox()
					if  k2==shuallCount then
                        rect.height=sys.height
					end
					if cc.rectContainsPoint( rect, chonsePaiPos ) then
					   weizhi_x=k1
					   weizhi_y=k2
					   if chonsePaiPos.y>= rect.y+DEF_PAI_H then
                          m_isMaxY=true
					   end
					   CCLOG("weizhi_x",weizhi_x,"weizhi_y",weizhi_y,m_isMaxY)
					   break
					end
				end
				--end
			end
		end
		if weizhi_x  and  weizhi_y then
            for k1,v1 in pairs( self.m_ShouPaiClassTb) do
				for k2,v2 in pairs(v1) do
					if k1==chonsePai.weizhi_x  and chonsePai.weizhi_y==k2 then
					   delPai= table.remove(v1,k2)
					end
				end
			end
			for k1,v1 in pairs( self.m_ShouPaiClassTb) do
				for k2,v2 in pairs(v1) do
				    if k1==weizhi_x then
						local keyindex=weizhi_y
						CCLOG("插入",keyindex,m_isMaxY)
						if m_isMaxY and weizhi_y==2 then
							table.insert(v1,chonsePai)
						else
							table.insert(v1,keyindex,chonsePai)
						end
						break
				    end
				end
			end
			for k,v in pairs( self.m_ShouPaiClassTb) do
				if #v==0 then
				   CCLOG("selfdel")
				   table.remove(self.m_ShouPaiClassTb,k)
				end
			end
			self.m_isAction=true
			self:ChangeSortPoker(true)
			isSort=true
		end
	end
	local shouPaiCount2 = 0
	for k1,v1 in pairs(self.m_ShouPaiClassTb) do
		for k1,v2 in pairs(v1) do
			if v2 ~=nil then
                shouPaiCount2=shouPaiCount2+1
			end
		end
	end
	if shouPaiCount1~=shouPaiCount2 then
	   CCLOG("移动出错")
	   self:CheckSerCount()
    end
	return isSort
end
--回复拍颜色
function ChLDaer_Base:SetBackColor(  )
	for k1,v1 in pairs(self.m_ShouPaiClassTb or {}) do
		if type(v1) =="table" then
			for k2,v2 in pairs(v1) do
				if v2 ~=nil and v2.m_player then
	                v2:SetChangColor(false)
	                v2.m_isNeedChu=false
	                local haveCount=self:HaveSameCount(v2.daer_value)
	                if haveCount>=3 then 
	                   v2.frantSp:setColor(sys.creColor3(125,125,125))
	                end
				end
			end
	    end
	end
end

--出一张pai
function ChLDaer_Base:CHuYiZhangFun( zuowei,daer_value,px,py ,isMove,cb)
	local chupaiPosTb = {
	  {x=sys.center.x-DEF_PAI_W/2,y=100,ex=sys.center.x+DEF_PAI_W+DEF_PAI_H/2+5,ey=sys.center.y+DEF_PAI_H,d=-90},
	  {x=sys.width-160,y=sys.height-220,ex=sys.center.x+210,ey=sys.center.y,d=0},
	  --{x=sys.center.x-DEF_PAI_W/2,y=sys.height-90,ex=sys.center.x-DEF_PAI_W/2,ey= sys.center.y+20,d=90},
	  {x=40,y=sys.center.y+50,ex=sys.center.x-340,ey=sys.center.y,d=0},
    }
    --SHOW(chupaiPosTb)
    local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
    local offx,offy = chupaiPosTb[operate].x ,chupaiPosTb[operate].y
    if px then offx=px end
    if py then offy=py end
    if self.m_ChuPaiClass then
       self.m_ChuPaiClass.m_player:removeFromParent(true)
       self.m_ChuPaiClass=nil
    end
    CCLOG("CHuYiZhangFun",offx,offy,operate)
    local shouType="shou"
    if zuowei ==self.m_LastZuowei then
        shouType="bei"
        if self.m_isVideoState then
            shouType="shou"
        end
    end
    if daer_value and daer_value==0 then shouType="bei" end
    CCLOG("shouType",shouType)
    self.m_ChuPaiClass=DaerPokerClass:Create(self.mopai_node,daer_value,shouType,false)
    self.m_ChuPaiClass.m_player:setPosition(offx,offy)
    if not isMove then
        self:StopInfo()
	    local time = 0.15
	    local array={}
	    if operate ==1 then
	        array[1]=cc.Spawn:create(cc.RotateBy:create(time,chupaiPosTb[operate].d),cc.MoveTo:create(time,{x=chupaiPosTb[operate].ex,y=chupaiPosTb[operate].ey}))
	    else
	    	self.m_ChuPaiClass.m_player:setScale(0.2)
	    	array[1]=cc.Spawn:create(cc.ScaleTo:create(time,1),cc.RotateBy:create(time,chupaiPosTb[operate].d),cc.MoveTo:create(time,{x=chupaiPosTb[operate].ex,y=chupaiPosTb[operate].ey}))
	    end
	    array[2]=cc.CallFunc:create(function ( ... )
	    	--self:GoOnInfo()
            if cb then cb() end
	    end)
	    self.m_ChuPaiClass.m_player:runAction(cc.Sequence:create(array))
	    self.m_ChuPaiClass.frantSp:runAction(cc.Sequence:create({cc.FadeIn:create(time)}))
        local array = {}
        array[1]=cc.DelayTime:create(0.4)
        array[2]=cc.CallFunc:create(function ( ... )
            self:GoOnInfo()
        end)
        self.m_BaseNode:runAction(cc.Sequence:create(array))
	else
		self.m_ChuPaiClass.m_player:setRotation(chupaiPosTb[operate].d)
        CCLOG("CHuYiZhangFun---1")
		self.m_ChuPaiClass.m_player:setPosition(chupaiPosTb[operate].ex,chupaiPosTb[operate].ey)
    end
end
--收拢牌
function ChLDaer_Base:ShouLongMyShouPai(  )
	CCLOG("ShouLongMyShouPai")
    for k1,v1 in pairs(self.m_ShouPaiClassTb) do
		if type(v1)=="table" then
			for k2,v2 in pairs(v1) do
				if v2.m_player then
					local array = {}
					array[1] = cc.DelayTime:create(0.2)
					array[2] = cc.MoveTo:create(0.5,{x = sys.center.x-DEF_PAI_W/2,y = (k2-1)*self.DEF_M_POKER_Y+DEF_PIANYI_Y})
					v2.m_player:runAction(cc.Sequence:create(array))
				end
			end
		end
	end
end
--展开首牌
function ChLDaer_Base:ZhanKaiMyShouPai(  )
	CCLOG("展开首牌")
	self.m_canClick=true
	self.m_MyShowTB={}
	if self.m_isVideoState then
		self.m_MyShouPaiTB={}
		self.m_MyShouPaiTB= sys.copyTab(self.m_videoShoPaiTb[self.m_MySeat])
	end
	SHOW(self.m_MyShouPaiTB)
	self.m_MyShouPaiTB=LzDaer_M_ZuhePokerTb(self.m_MyShouPaiTB)
	self.m_MyShowTB=LzDaer_M_inSortPokerTB( self.m_MyShouPaiTB)
	self:TrimGangfapai()
end
--游戏状态改变
function ChLDaer_Base:SC_DAER_GAME_STATE(key,s)
	SHOW(s)
	CCLOG("SC_DAER_GAME_STATE")
	self.m_GameState=s.state  
	if self.m_GameState  ==emDaErCN_GameState_FaPai  then 
        CCLOG("发牌中")
        LzDaer_M_DelDingHeadReadSp()
        self:SetReadyMeanVisible(false,false)
	end
	if self.m_GameState  ==emDaErCN_GameState_Long  then 
       CCLOG("龙牌")
	end
	if self.m_GameState  ==emDaErCN_GameState_BaoJiao  then 
       CCLOG("报叫")
	end
	if self.m_GameState  ==emDaErCN_GameState_Gaming  then 
       CCLOG("有戏中")
	end
end

--翻一张牌
function ChLDaer_Base:SC_DAER_FANPAI(key,s)
	SHOW(s)
	 CCLOG("SC_DAER_FANPAI---2")
    LzDaer_M_DelAllTime()
    self:StopInfo()
    local zuowei =s.seat or self.m_MySeat
    self.m_FanPaiSeat   =zuowei
    if zuowei ==self.m_MySeat then
        self.m_isCanChuPai=false
        self:DelTipsChuPai(false)
    end
    local changValue =s.pai  or 0

    self:CHuYiZhangFun(zuowei,changValue,self.m_DelPaiPos.x,self.m_DelPaiPos.y,nil,function (  )
       -- self:MoPai4Ren(zuowei,changValue)
    end)
    self.m_ResiduePaiNum = s.leftpai
    self:UpdateResiduePai()
    self.m_DelPaiPos       ={x=sys.center.x,y=sys.center.y}
    local time =s.timer  or 0
    if time ==0 then  time=30 else time=math.ceil(time/1000) end
    LzDaer_M_CreTimeUI(zuowei,time)

    local headTb = LzDaer_M_GetTouXiangLayer()
    LzDaer_Public_ActionSound("poker",headTb[zuowei].xingbie,changValue,0,headTb[zuowei].voice)
end

--  摸牌action
function ChLDaer_Base:FanYiPai( zuowei,changValue,typ,cb)
	self:DelFanPaiFun()
	CCLOG("FanYiPai",zuowei,changValue,typ)
	local function crefanpai(  )
		self.m_fanPaiClass = DaerPokerClass:Create(self.mopai_node,changValue,"bei")
		self.m_fanPaiClass.m_player:setPosition(sys.center.x-self.m_fanPaiClass.m_player:getContentSize().width/2,sys.center.y)
		-- 测试代码
		local RotateAngle = 0
		local daseat= LzDaer_M_GetPointZuoWei(zuowei)+1
		if daseat == 1 then
			RotateAngle = 0
		end 
		if daseat == 2 then
			RotateAngle = -60
		end
		if daseat == 3 then
			RotateAngle = 60
		end
		CCLOG("crefanpai---1")
		local time = 0.1
		local array = {}
		array[1] = cc.Spawn:create(cc.MoveTo:create(time,{x = self.DEF_CHUPAI_POS[daseat].x,y = self.DEF_CHUPAI_POS[daseat].y}),cc.RotateBy:create(time/2,RotateAngle))
		array[2] = cc.Spawn:create(cc.OrbitCamera:create(time, 0.1, 0, 0, 90, -90, 0),cc.ScaleTo:create(time,1.2),cc.MoveBy:create(time,{x = 0,y = -10}))
		array[3] = cc.CallFunc:create(function (  )
			if typ ~= "mopai" then
			   self.m_fanPaiClass:UpDatefrantSp(changValue)
			else
			 	if  changValue ==0 then
                    self.m_fanPaiClass.frantSp:setSpriteFrame("daer_pai_bei")
			 	else
			        --self.m_fanPaiClass.frantSp:setSpriteFrame("lzde_cp")
			         self.m_fanPaiClass:UpDatefrantSp(changValue)
			    end
		     end
			self.m_fanPaiClass.m_player:setRotation(0)
		end)
		array[4] = cc.Spawn:create(cc.OrbitCamera:create(time/2, 0.1, 0, 90+180, 90, -90, 0),cc.ScaleTo:create(time/2,DEF_POKER_SCALE),cc.MoveBy:create(time,{x = 0,y = -10}))
		array[5] = cc.DelayTime:create(0.4)
		array[6] = cc.CallFunc:create(function (  )
			if typ == "mopai" then --此时为摸牌
				local arrani = {}
				local movetime = 0.1
				local headpos = LzDaer_M_GetTouXiangPOS(zuowei)
				arrani[1] = cc.DelayTime:create(0.2)
				arrani[2] =  cc.Spawn:create(cc.MoveTo:create(movetime,{x = headpos.x,y = headpos.y}),cc.ScaleTo:create(movetime,0.2))
				arrani[3] = cc.CallFunc:create(function (  )
					CCLOG("此时为摸牌---1")
					self:DelFanPaiFun(zuowei)
					CCLOG("此时为摸牌---2")
					if cb then
						CCLOG("此时为摸牌---3")
						cb()
					end 
					self:GoOnInfo()
				end)
				self.m_fanPaiClass.m_player:runAction(cc.Sequence:create(arrani))
			else
				self:GoOnInfo()
			end 
		end)
		self.m_fanPaiClass.m_player:runAction(cc.Sequence:create(array))
		CCLOG("创建展示牌成功")    
	end
	if self.m_fanPaiClass.m_player  then 
		self:Action_UpPaiFadeOut(zuowei,crefanpai)
	else
		crefanpai()
	end
end
-- 删除番的牌
function ChLDaer_Base:DelFanPaiFun(zuowei  )
	if self.m_fanPaiClass.m_player  then
	   self.m_fanPaiClass.m_player:removeFromParent(true)
	   self.m_fanPaiClass={}
	   CCLOG("self.m_fanPaiClassisnil")
	end
end
function ChLDaer_Base:Action_UpPaiFadeOut(zuowei, cb )
	if self.m_fanPaiClass.m_player  == nil then
		return
	end 
	CCLOG("翻牌消失函数")
	local array = {}
	array[1] = cc.Spawn:create(cc.FadeOut:create(0.2),cc.MoveBy:create(0.2,{x = 0,y = -100}))
	array[2] = cc.CallFunc:create(function (  )
			CCLOG("m_CurrUpPaiSp 执行动作 Action_UpPaiFadeOut 完毕 ")
			self:DelFanPaiFun()
			if cb then
				cb()
			end
	end)
	CCLOG("m_CurrUpPaiSp 执行动作 Action_UpPaiFadeOut ")
	self.m_fanPaiClass.m_player:runAction(cc.Sequence:create(array))
end

--摸一张牌
function ChLDaer_Base:SC_DAER_MOPAI(key,s)
	SHOW(s)
	CCLOG("SC_DAER_MOPAI---1")
	self:StopInfo()
	LzDaer_Public_ActionSound("qipai")
	local zuowei =s.seat or self.m_MySeat
	local changValue =s.value  or 0

	if zuowei==self.m_MySeat  then
		CCLOG("SC_DAER_MOPAI自己")
		self.m_isFapai      =false
		self:MoYiPai(zuowei,changValue,function (  )
			self:GoOnInfo()
			self.m_isFapai      =true
		end)
	else
		self:FanYiPai(zuowei,changValue,"mopai",function (  )
			LzDaer_M_UpdatePaiNum(zuowei,s.spnum or 0,true)
			self:GoOnInfo()

		end)
   end
	self.m_ResiduePaiNum = s.leftpai
	self:UpdateResiduePai()
	CCLOG("SC_DAER_MOPAI---2")
end
--找到插入牌位置
function ChLDaer_Base:FindChaRuPos( changValue )
	local weizhi_x,weizhi_y=0,0
	local isFind  =false
	local charu3  =false
    --找到组队的
	for k1,v1 in pairs(self.m_ShouPaiClassTb) do
     	for k2,v2 in pairs(v1) do
     		local vCount = sys.getTBCount(v1)
     		if vCount>=3 then
     			-- if v2.daer_value ==changValue then
        --            CCLOG("插如大于三")
        --             charu3=true
        --             weizhi_x=k1
	       --          weizhi_y=k2
        --         end
     		else
	     		if v2.daer_value ==changValue then
	                weizhi_x=k1
	                weizhi_y=k2
	                isFind=true
	     		end
	     	end
     	end
    end
    if charu3 and isFind ==false then
       -- weizhi_x=weizhi_x
        if weizhi_x<=0 then weizhi_x=1  end
        for k1,v1 in pairs(self.m_ShouPaiClassTb) do
        	local vCount = sys.getTBCount(v1)
        	if vCount<3 then
	            if k1==weizhi_x  then
	               weizhi_y=sys.getTBCount(v1)
	               isFind=true
	               break
	            end
	        end
	    end
	end
    if isFind ==false then 
	    --找到挨着的
	    local findValue =changValue
	    if changValue%10 ==1 then findValue=changValue+1 end
	    if changValue%10 ==0 then findValue=changValue-1 end
	    CCLOG("changValue",changValue)
		for k1,v1 in pairs(self.m_ShouPaiClassTb) do
	     	for k2,v2 in pairs(v1) do
	     		local vCount = sys.getTBCount(v1)
        	    if vCount<3 then
		     		if (v2.daer_value ==findValue+1) or (v2.daer_value ==findValue-1)  then
		                weizhi_x=k1
		                weizhi_y=k2
		                isFind=true
		                break
		     		end
		     	end
	     	end
	    end
	    if isFind ==false then
	       for k1,v1 in pairs(self.m_ShouPaiClassTb) do
		     	for k2,v2 in pairs(v1) do
		     	    local vCount = sys.getTBCount(v1)
        	        if vCount<3 then
			     		if sys.getTBCount(v1)==1 then 
			                weizhi_x=k1
			                weizhi_y=k2
			                isFind=true
			                break
			     		end
			     	end
		     	end
		    end
	    end
	end

	CCLOG("FindChaRuPos",weizhi_x,weizhi_y)
	return weizhi_x,weizhi_y
end
-- 翻牌 摸牌action
function ChLDaer_Base:MoYiPai( zuowei,changValue,cb)
    CCLOG("MoYiPai---")
    self:DelFanPaiFun()
    CCLOG("MoYiPai---0")
    local pokerScal =1
    if self.m_isVideoState  then
        pokerScal=0.8
    end
	local  m_fanPaiClass = DaerPokerClass:Create(self.shou_pokernode,changValue,"bei",true)
	m_fanPaiClass.m_player:setPosition(sys.center.x-m_fanPaiClass.m_player:getContentSize().width/2,sys.center.y)
    m_fanPaiClass.m_player:setLocalZOrder(100)

    m_fanPaiClass.m_player:setScale(0.8)
	-- 测试代码
	local RotateAngle = 0
	local Pos = {x = 0,y = 0}
	local daseat= LzDaer_M_GetPointZuoWei(zuowei)+1
	if daseat == 1 then
		RotateAngle = 0
	end 
	if daseat == 2 then
		RotateAngle = -60
	end
	if daseat == 3 then
		RotateAngle = 60
	end
	CCLOG("MoYiPai---1")
	local time = 0.1
	local array = {}
	array[1] = cc.Spawn:create(cc.MoveTo:create(time,{x = self.DEF_CHUPAI_POS[daseat].x,y = self.DEF_CHUPAI_POS[daseat].y}),cc.RotateBy:create(time/2,RotateAngle))
	array[2] = cc.Spawn:create(cc.OrbitCamera:create(time, 0.1, 0, 0, 90, -90, 0),cc.ScaleTo:create(time,0.8),cc.MoveBy:create(time,{x = 0,y = -10}))
	array[3] = cc.CallFunc:create(function (  )
		m_fanPaiClass:UpDatefrantSp(changValue)
		m_fanPaiClass.m_player:setRotation(0)
	end)
	array[4] = cc.Spawn:create(cc.OrbitCamera:create(time/2, 0.1, 0, 90+180, 90, -90, 0),cc.ScaleTo:create(time/2,pokerScal),cc.MoveBy:create(time,{x = 0,y = -10}))
	array[5] = cc.DelayTime:create(0.3)
	array[6] = cc.CallFunc:create(function (  )
		m_fanPaiClass:UpDatefrantSp(changValue,daseat)
		m_fanPaiClass.m_CanClicke=true
		CCLOG("MoYiPai---2")
		m_fanPaiClass.m_player:setScale(1)
		--m_fanPaiClass.m_player:setContentSize({width=86,height=90})
		m_fanPaiClass.m_player:setPosition(0,0)
		CCLOG("MoYiPai---3")
		if self.m_isVideoState then
             self:ChangeSortPoker(false)
		else
		    self:ChangeSortPoker(true)
		end
		if cb then cb() end
		CCLOG("MoYiPai---4")
	end)
	array[7] = cc.DelayTime:create(0.2)
	array[8] = cc.CallFunc:create(function (  )
		self:GoOnInfo()
	end)
	m_fanPaiClass.m_player:runAction(cc.Sequence:create(array))
	self:CleanPokerTbFun()
    local weizhi_x,weizhi_y=self:FindChaRuPos(changValue)
	if weizhi_x ==0 and weizhi_y ==0 then
	    CCLOG("创建展示牌成功-----1")
	    self.m_ShouPaiClassTb[#self.m_ShouPaiClassTb+1]={}
	    SHOW( self.m_ShouPaiClassTb)
	    table.insert( self.m_ShouPaiClassTb[#self.m_ShouPaiClassTb],m_fanPaiClass)
	else
		CCLOG("创建展示牌成功-----2")
        for k1,v1 in pairs(self.m_ShouPaiClassTb) do
	        if k1 ==weizhi_x then
               table.insert(v1,weizhi_y,m_fanPaiClass)
	        end
	    end
	    CCLOG("创建展示牌成功-----3")
	end
	CCLOG("创建展示牌成功") 
end
--得到手牌
function ChLDaer_Base:GetPlarShouPai(  )
	local shouPaiTb={}
	for k1,v1 in pairs( self.m_MyShowTB) do
		for k2,v2 in pairs(v1) do
			if v2.daer_value  then 
			   table.insert(shouPaiTb,v2.daer_value)
			end
		end
	end
	return  shouPaiTb
end
--当前操作位置
function ChLDaer_Base:SC_DAER_NOW_OP_SEAT(key,s)
	SHOW(s)
	CCLOG("SC_DAER_NOW_OP_SEAT")
end
--通知玩家进行的操作
function ChLDaer_Base:SC_DAER_CAN_OPERATE(key,s)
	SHOW(s)
	CCLOG("SC_DAER_CAN_OPERATE")
    LzDaer_M_CreOperateUi(self.m_Scene,s)
end
--通知玩家可以进行保叫
function ChLDaer_Base:SC_DAER_CAN_BAOJIAO(key,s)
	SHOW(s)
	CCLOG("SC_DAER_CAN_BAOJIAO")
	--s={}
	s.guo=1
	---s.bao=1
    LzDaer_M_CreOperateUi(self.m_Scene,s)

end
--保叫结果
function ChLDaer_Base:SC_DAER_BAOJIAO(key,s)
	SHOW(s)
	CCLOG("SC_DAER_BAOJIAO")
	local zuowei=s.seat
	local baohu = s.baohu  or 0
	local baobai =s.baobai or 0
    if baohu==0  and baobai==0  then  return end
    self.m_BaoJiaoTb[zuowei]=1
    CCLOG("SC_DAER_BAOJIAO111")
    self:StopInfo()
	local headTb = LzDaer_M_GetTouXiangLayer()
	
	local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
    if  baobai==1  then
        self.m_baiAni  =true
        LzDaerAniamtions.BaoBaiAni(self.act_node,self.DEF_ANI_POS[operate].x,self.DEF_ANI_POS[operate].y,function (  ) 
           self:GoOnInfo()
        end)
        LzDaer_Public_PlaySound("baile",headTb[zuowei].xingbie)
    elseif  baohu==1  then
	    LzDaerAniamtions.BaoAni(self.act_node,self.DEF_ANI_POS[operate].x,self.DEF_ANI_POS[operate].y,function (  ) 
           LzDaer_M_CreBaojiaoSp(zuowei,1)
           self:GoOnInfo()
	    end)
	    LzDaer_Public_PlaySound("baole",headTb[zuowei].xingbie)
	end
end
--通知客户端可以进行拢牌
function ChLDaer_Base:SC_DAER_CAN_LONG(key,s)
	SHOW(s)
	CCLOG("SC_DAER_CAN_LONG")
end
--通知拢牌消息
function ChLDaer_Base:SC_DAER_LONG(key,s)
	SHOW(s)
	CCLOG("SC_DAER_LONG")
    self:Operate_UI("long",s)
end
--吃的结果
function ChLDaer_Base:SC_DAER_CHI(key,s)
	SHOW(s)
	CCLOG("SC_DAER_CHI")
	self:Operate_UI("chi",s)
end
--招的结果
function ChLDaer_Base:SC_DAER_ZHAO(key,s)
	SHOW(s)
	CCLOG("SC_DAER_ZHAO")
	self:Operate_UI("zhao",s)
end
--碰的结果
function ChLDaer_Base:SC_DAER_PENG(key,s)
	SHOW(s)
	CCLOG("SC_DAER_PENG")

	self:Operate_UI("peng",s)
end
--胡的结果
function ChLDaer_Base:SC_DAER_HU(key,s)
	SHOW(s)	CCLOG("SC_DAER_HU")
	CCLOG("SC_DAER_HU")
	--self:Operate_UI("hu",s)
end
--优先级相关
function ChLDaer_Base:SC_DAER_CANCEL_OP(key,s)
	SHOW(s)
	CCLOG("SC_DAER_CANCEL_OP")
end
--是否有操作
function ChLDaer_Base:SC_DAER_HAVE_OP(key,s)
	SHOW(s)
	CCLOG("SC_DAER_HAVE_OP")
	LzDaer_M_DelAllTime()
	--local zuowei = s.seat
	CCLOG("SC_DAER_HAVE_OP--1")
	local time = s.timeleft or 0
	LzDaer_M_DelAllTime()
	for k,v in pairs(s.haveop or {}) do
		if v==1 then
		   LzDaer_M_CreTimeUI(k,time)
		end
	end
	CCLOG("SC_DAER_HAVE_OP2")
end
--通知客户端出牌
function ChLDaer_Base:SC_DAER_NOTICE_CHUPAI(key,s)
	SHOW(s)
	CCLOG("SC_DAER_NOTICE_CHUPAI")
	local zuowei = s.seat
	local time = s.timeleft or 0
	LzDaer_M_DelAllTime()
	LzDaer_M_DelOperateUI()
	--LzDaer_M_CreTimeUI(zuowei,time)
	if zuowei ==self.m_MySeat then 
       self.m_isCanChuPai =true
       self:CreTipsChuPai()
    else
       self.m_isCanChuPai=false
	end
end
--胡数
function ChLDaer_Base:SC_DAER_HU_NUM( key,s )
	CCLOG("SC_DAER_HU_NUM")
	SHOW(s)
	local huNum = s.hu_num
    self:UpdateHuValue(huNum)
end

--某人放弃操作
function ChLDaer_Base:SC_DAER_QI( key,s )
	CCLOG("SC_DAER_QI")
	SHOW(s)
    local zuowei=s.seat
    LzDaer_M_DelOneTimeFun(zuowei)

    local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
    if m_TouXiangLayerTB[zuowei] then 
        m_TouXiangLayerTB[zuowei]:ShowTalkPop("过",nil,20,nil,nil,true,-90)
        LzDaer_Public_ActionSound("guopai")
    end
end
--出牌提示
function ChLDaer_Base:CreTipsChuPai(  )
    self.m_chuPaitips =xui.addSprite(self.mopai_node,"lzde_qcp",sys.center.x,sys.center.y+40)
end
function ChLDaer_Base:DelTipsChuPai(  )
	if self.m_chuPaitips then
		self.m_chuPaitips:removeFromParent(true)
		self.m_chuPaitips=nil
	end
end
--出牌 等待
function ChLDaer_Base:WaiTeChuPai( s )
	LzDaer_M_DelAllTime()
	LzDaer_M_DelOperateUI()
	local zuowei=s.seat
	local delPai = nil
	local changValue = s.value
	local headTb = LzDaer_M_GetTouXiangLayer()
    LzDaer_Public_PlaySound("poker",headTb[zuowei].xingbie,changValue)
	if zuowei ==self.m_MySeat then
	    self:DelTipsChuPai()
	    self.m_isCanChuPai=false
        for k1,v1 in pairs(self.m_ShouPaiClassTb) do
         	for k2,v2 in pairs(v1) do
         		if v2.m_isOutChuPai ==true then 
                   CCLOG("k1,k2",k1,k2)
                   delPai=table.remove(v1,k2)
         		end
         	end
        end
        if delPai  and delPai.m_player then
        	CCLOG("出牌成功")
            self.m_fanPaiClass=delPai
            self:CleanPokerTbFun()
            self:ChangeSortPoker(true)
        else
        	CCLOG("出牌失败")
        	self:CheckSerCount()
        end 
	else
       self:ChuYiPai(zuowei,changValue)
	end
	LzDaer_M_DelOneSp(zuowei)
end
--出牌
function ChLDaer_Base:SC_DAER_CHUPAI(key,s)
	SHOW(s)
	CCLOG("SC_DAER_CHUPAI")
    SHOW(s)
	local zuowei =s.seat or self.m_MySeat
	local bTuoguan= s.tuoguan  or 0
	local changValue =s.value  or 0
    LzDaer_M_DelAllTime()
    local time =s.timer  or 0
    if time ==0 then  time=30 else time=math.ceil(time/1000) end
    LzDaer_M_CreTimeUI(zuowei,time)
    if zuowei ==self.m_MySeat then
        self.m_isCanChuPai=false
        self:DelTipsChuPai(false)
        self.m_NotChuValue={}
        if bTuoguan and bTuoguan==1 then
        	CCLOG("bTuoguan----1",self.m_SendChuValue)
            Eqs_M_DelOperateUI()
            if self.m_SendChuValue ==0 then
    	        for k1,v1 in pairs(self.m_ShouPaiClassTb or {}) do
    	        	local isdel = false
    	            if type(v1) =="table" then
    	                for k2,v2 in pairs(v1) do
    	                    if v2 ~=nil and v2.daer_value ==changValue then
    	                        self.m_DelPaiPos.x=v2.m_player:getPositionX()
    	                        self.m_DelPaiPos.y=v2.m_player:getPositionY()
    	                        v2.m_player:removeFromParent(true)
    	                        table.remove(v1,k2)
    	                        isdel=true
    	                        CCLOG("bTuoguan----2")
    	                        break
    	                    end
    	                end
    	            end
    	            if isdel then break end
    	        end
                self:CleanPokerTbFun()
                self:ChangeSortPoker(true)
    	        CCLOG("bTuoguan----3")
            end
        end
        if self.m_SendChuValue~=changValue then
           CS_DAER_SYNC_SP()
        end
         self.m_SendChuValue=0
        for k1,v1 in pairs(self.m_ShouPaiClassTb or {}) do
            if type(v1) =="table" then
                for k2,v2 in pairs(v1) do
                    if v2 ~=nil and v2.m_player then
                        v2.m_isNotChu=false
                        v2.m_player:setVisible(true)
                        v2:SetChangColor(false)
                        local haveCount=self:HaveSameCount(v2.daer_value)
                        if haveCount>=3 then 
                           v2.frantSp:setColor(sys.creColor3(125,125,125))
                        end
                    end
                end
            end
        end
    end
    if bTuoguan and bTuoguan==1 then 
        
    end
    self:CHuYiZhangFun(zuowei,changValue,self.m_DelPaiPos.x,self.m_DelPaiPos.y)
    self.m_DelPaiPos       ={x=sys.center.x,y=sys.center.y}
    LzDaer_M_UpdatePaiNum(zuowei,s.spnum or 0 ,true)

    local headTb = LzDaer_M_GetTouXiangLayer()
    LzDaer_Public_PlaySound("poker",headTb[zuowei].xingbie,changValue,0,headTb[zuowei].voice)
end
--出一张牌
function ChLDaer_Base:ChuYiPai( zuowei,changValue )
	CCLOG("出一张牌")
	local daseat = LzDaer_M_GetPointZuoWei(zuowei)+1
	local function crefanpai(  )
		local headpos = LzDaer_M_GetTouXiangLayer(zuowei)
		CCLOG("出一张牌 3 ")
		self.m_fanPaiClass = DaerPokerClass:Create(self.mopai_node,changValue,"shou")
		--self.m_fanPaiClass.m_player:setScale(DEF_POKER_SCALE)
		self.m_fanPaiClass.m_player:setPosition(headpos.x,headpos.y)
		local movetime = 0.25
		CCLOG("出一张牌 4 ")
		local array = {}
		CCLOG("出一张牌 5 ")
		array[1] =cc.Spawn:create(cc.ScaleTo:create(movetime/2,DEF_POKER_SCALE),cc.MoveTo:create(movetime,{x = self.DEF_CHUPAI_POS[daseat].x,y = self.DEF_CHUPAI_POS[daseat].y}))
		array[2] = cc.DelayTime:create(0.5)
		array[3] = cc.CallFunc:create(function (  )
			--self:GoOnInfo()
			CCLOG("出一张牌 7 ")
		end)
		CCLOG("出一张牌 6 ")
		self.m_fanPaiClass.m_player:runAction(cc.Sequence:create(array))
    end
    if self.m_fanPaiClass.m_player  then
        CCLOG("出一张牌 2 ") 
		self:Action_UpPaiFadeOut(zuowei,crefanpai)
	else
		CCLOG("出一张牌 1 ")
		crefanpai()
	end
end
---踢出#v==0 
function ChLDaer_Base:CleanPokerTbFun(  )
	for i=1,10 do
		for k,v in pairs(self.m_ShouPaiClassTb) do
	   	    if sys.getTBCount(v) ==0 then
	            table.remove(self.m_ShouPaiClassTb,k)
	   	    end
	    end
	end
	
end
---操作
function ChLDaer_Base:Operate_UI( opType,s )
	local zuowei =s.seat
	local dekPaicount = 1
	local delCount =0
	local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
    local delPaiValue =0
    self:StopInfo()
    if operate==1 then 
    	self:CleanPokerTbFun()
	    self:ChangeSortPoker(false)
	    self.m_CanMovePai   =true
	end
    local talkLab=""
    local headTb = LzDaer_M_GetTouXiangLayer()
    LzDaer_Public_PlaySound(opType,headTb[zuowei].xingbie)
    resetHeartTimeOutCnt()
	if opType =="long" then
		local changValue =s.long
	    delPaiValue=changValue
        CCLOG("拢牌",operate,changValue)
        talkLab="拢"
        LzDaerAniamtions.LongAni(self.act_node,self.DEF_ANI_POS[operate].x,self.DEF_ANI_POS[operate].y,function (  )
			self:GoOnInfo()
			self.m_CanMovePai   =false
        end)
   	   if operate ==1 then
   	   	   for i=1,4 do 
	       	   for k1,v1 in pairs(self.m_ShouPaiClassTb) do
	       	   	   for k2,v2 in pairs(v1) do
	       	   	   	    if v2.daer_value ==changValue  then
	       	   	   	   	     CCLOG("拢牌---del")
	       	   	   	   	    if v2.m_player then 
	       	   	   	   	    	delCount=delCount+1
	       	   	   	   	  	    v2.m_player:removeFromParent(true)
	       	   	   	   	  	    table.remove(v1,k2)
	       	   	   	   	    end   
	       	   	   	    end
	       	   	    end
	       	    end
	       	end
	    else
	    	if self.m_isVideoState  then
	    		for i=1,4 do 
                    for k1,v1 in pairs(self.m_OtherPokerTb[zuowei] or {}) do
                		if v1.m_player  and v1.daer_value ==changValue then
                			v1.m_player:removeFromParent(true)
                            table.remove(self.m_OtherPokerTb[zuowei],k1)
                            CCLOG("video-----dellong")
                            break
                		end
                	end
                end
        	end
        end
   	    table.insert(self.m_KanPaiTB[zuowei],{["kan"]={changValue,changValue,changValue,["ty"]="long"}})
        dekPaicount=4
        if delCount~=4  and operate ==1 and self.m_isVideoState ==false  then
       	    CCLOG("delCount",delCount)
       	    SHOW(self.m_ShouPaiClassTb)
		    tips.creUpTimeTips("请求同步手牌")
		    CS_DAER_SYNC_SP()
	    end 
	end
    if opType=="zhao"   then
        CCLOG("招牌")
        talkLab="招"
        LzDaerAniamtions.ZhaoAni(self.act_node,self.DEF_ANI_POS[operate].x,self.DEF_ANI_POS[operate].y,function (  )
       	  self:GoOnInfo()
       	  self.m_CanMovePai   =false
        end)
        local changValue =s.value
        delPaiValue=changValue
        dekPaicount=3
        if operate ==1 then
        	for i=1,dekPaicount do
		        for k1,v1 in pairs(self.m_ShouPaiClassTb) do
		   	   	    for k2,v2 in pairs(v1) do
		   	   	   	    if v2.daer_value ==changValue  then
		   	   	   	    	CCLOG("招牌--del")
	   	   	   	    	   	if v2.m_player then 
	   	   	   	    	   		delCount=delCount+1
	       	   	   	   	  	    v2.m_player:removeFromParent(true)
	       	   	   	   	  	    table.remove(v1,k2)
	       	   	   	   	    end
		   	   	   	    end
		   	   	    end
		   	    end 
		   	end
		   	if delCount~=3 and self.m_isVideoState ==false then
				CCLOG("delCount",delCount)
				SHOW(self.m_ShouPaiClassTb)
				tips.creUpTimeTips("请求同步手牌")
				CS_DAER_SYNC_SP()
	        end
	    else
	    	if self.m_isVideoState  then
	    		for i=1,dekPaicount do
                    for k1,v1 in pairs(self.m_OtherPokerTb[zuowei] or {}) do
                		if v1.m_player  and v1.daer_value ==changValue then
                			v1.m_player:removeFromParent(true)
                            table.remove(self.m_OtherPokerTb[zuowei],k1)
                             CCLOG("video-----zhao")
                            break
                		end
                	end
	        	end
	        end
	   	end
   	    table.insert(self.m_KanPaiTB[zuowei],{["kan"]={changValue,changValue,changValue,["ty"]="zhao"}})
   	   
    end
    if opType=="peng"   then
        CCLOG("碰牌")
        talkLab="碰"
        LzDaerAniamtions.PengAni(self.act_node,self.DEF_ANI_POS[operate].x,self.DEF_ANI_POS[operate].y,function (  )
       	  self:GoOnInfo()
       	  self.m_CanMovePai   =false
       end)
        local changValue =s.value
        delPaiValue=changValue
        dekPaicount=2
        CCLOG("碰牌--------",changValue)
        --SHOW(self.m_ShouPaiClassTb)
        if operate ==1 then
        	for i=1,dekPaicount do
        		for k1,v1 in pairs(self.m_ShouPaiClassTb) do
		   	   	    for k2,v2 in pairs(v1) do
		   	   	   	    if v2.daer_value ==changValue  then
	   	   	   	    	    if v2.m_player then 
	   	   	   	    	    	CCLOG("碰牌--del")
	   	   	   	    	    	delCount=delCount+1
	       	   	   	   	  	    v2.m_player:removeFromParent(true)
	       	   	   	   	  	    table.remove(v1,k2)
	       	   	   	   	    end
		   	   	   	    end
		   	   	    end
		   	    end 
        	end 
        	if delCount~=2 and self.m_isVideoState ==false then
				CCLOG("delCount",delCount)
				SHOW(self.m_ShouPaiClassTb)
				tips.creUpTimeTips("请求同步手牌")
				CS_DAER_SYNC_SP()
	        end 
	    else
	        if self.m_isVideoState  then
	    		for i=1,dekPaicount do
                    for k1,v1 in pairs(self.m_OtherPokerTb[zuowei] or {}) do
                		if v1.m_player  and v1.daer_value ==changValue then
                			v1.m_player:removeFromParent(true)
                            table.remove(self.m_OtherPokerTb[zuowei],k1)
                             CCLOG("video-----peng")
                            break
                		end
                	end
	        	end
	        end   
	        
	   	end
   	    table.insert(self.m_KanPaiTB[zuowei],{["kan"]={changValue,changValue,changValue,["ty"]="peng"}}) 
    end
    if opType=="chi"   then
       CCLOG("吃牌")
       talkLab="吃"
       LzDaerAniamtions.ChiAni(self.act_node,self.DEF_ANI_POS[operate].x,self.DEF_ANI_POS[operate].y,function (  )
       	  self:GoOnInfo()
       	  self.m_CanMovePai   =false
       end)
       if s.chi  then
          	delPaiValue=s.chi.pai
            local delTb = {s.chi.o1,s.chi.o2}
		    table.insert(self.m_KanPaiTB[zuowei],{["kan"]={s.chi.o1,s.chi.o2,s.chi.pai,["ty"]="chi"}})
		    dekPaicount=2
		    if operate ==1 then
	            for k,changValue in pairs(delTb) do
	            	local flag = false
	            	for k1,v1 in pairs(self.m_ShouPaiClassTb) do
			   	   	    for k2,v2 in pairs(v1) do
			   	   	   	    if v2.daer_value ==changValue  then	
		   	   	   	    	    if v2.m_player then
		   	   	   	    	        delCount=delCount+1 
		   	   	   	    	        CCLOG("吃牌--del")
		       	   	   	   	  	    v2.m_player:removeFromParent(true)
		       	   	   	   	  	    table.remove(v1,k2)
		       	   	   	   	  	    flag=true
		       	   	   	   	  	    break
		       	   	   	   	    end
			   	   	   	    end
			   	   	    end
			   	   	    if flag then break end
			   	    end 
	            end
	        else
	        	if self.m_isVideoState  then
                    for k,changValue in pairs(delTb) do
                    	for k1,v1 in pairs(self.m_OtherPokerTb[zuowei] or {}) do
                    		if v1.m_player  and v1.daer_value ==changValue then
                    			v1.m_player:removeFromParent(true)
                                table.remove(self.m_OtherPokerTb[zuowei],k1)
                                 CCLOG("video-----chi")
                                break
                    		end
                    	end
                    end
	        	end
            end
            if s.bi then 
               delTb={}
               table.insert(delTb,s.bi.o1)
               table.insert(delTb,s.bi.o2)
               table.insert(delTb,s.bi.pai)
               table.insert(self.m_KanPaiTB[zuowei],{["kan"]={s.bi.o1,s.bi.o2,s.bi.pai,["ty"]="bi"}})
              -- self:CleanPokerTbFun()
               dekPaicount=5
               talkLab="吃和比"
               if operate ==1 then
		            for k,changValue in pairs(delTb) do
		            	local flag = false
		            	for k1,v1 in pairs(self.m_ShouPaiClassTb) do
				   	   	    for k2,v2 in pairs(v1) do
				   	   	   	    if v2.daer_value ==changValue  then
				   	   	   	    	
			   	   	   	    	    if v2.m_player then 
			   	   	   	    	    	CCLOG("bi--del")
			   	   	   	    	    	delCount=delCount+1 
			       	   	   	   	  	    v2.m_player:removeFromParent(true)
			       	   	   	   	  	    table.remove(v1,k2)
			       	   	   	   	  	    flag=true
		       	   	   	   	  	         break
			       	   	   	   	    end
				   	   	   	    end
				   	   	    end
				   	   	    if flag then break end
				   	    end 
		            end
		        else
		        	if self.m_isVideoState  then
	                    for k,changValue in pairs(delTb) do
	                    	for k1,v1 in pairs(self.m_OtherPokerTb[zuowei] or {}) do
	                    		if v1.m_player  and v1.daer_value ==changValue then
									v1.m_player:removeFromParent(true)
									table.remove(self.m_OtherPokerTb[zuowei],k1)
									CCLOG("video-----bi")
	                                break
	                    		end
	                    	end
	                    end
		        	end
	            end
            end
           -- SHOW(delTb)  
            if operate ==1 and self.m_isVideoState ==false  then
	            if delCount==2 or delCount==5  then
	            else
	               CCLOG("delCount",delCount)
	               --SHOW(self.m_ShouPaiClassTb)
			       tips.creUpTimeTips("请求同步手牌")
			       CS_DAER_SYNC_SP()
		        end 
		    end 
        end
    end
    local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
    if m_TouXiangLayerTB[zuowei] then 
       m_TouXiangLayerTB[zuowei]:ShowTalkPop(talkLab,nil,20,nil,nil,true,-90)
    end
	if  self.m_isVideoState ==false  then
		if operate ==1 then
		    self:CleanPokerTbFun()
		    self:ChangeSortPoker(true) 
		end
		LzDaer_M_UpdatePaiNum(zuowei,s.spnum or 0 ,true)	
	else

		LzDaer_M_DelAllTime()
		self:DelayTimeFun(function (  )
			
		end,0.2)
        self:Video_SortPai(zuowei)
	end
	self:MovePaiToDui(zuowei,delPaiValue,"caozuo")
	self:UpdateKan(zuowei)
	CCLOG("Operate_UI is end")
end
function LzDaer_M_SetMoveState(isMove  )
	 ChLDaer_Base.m_CanMovePai =isMove
end
--检查手牌与服务器
function ChLDaer_Base:CheckSerCount(  )
	CCLOG("检查手牌与服务器")
	local shouCiunt = 0
	for k1,v1 in pairs(self.m_ShouPaiClassTb) do
		for k2,v2 in pairs(v1) do
			if v2 ~=nil then
                shouCiunt=shouCiunt+1
			end
		end
	end
	CCLOG("shouCiunt",shouCiunt)
	if shouCiunt%3~=2 then
	   SHOW(self.m_fanPaiClass)
       tips.creUpTimeTips("请求同步手牌")
       CS_DAER_SYNC_SP()
	end
end
function ChLDaer_Base:SC_DAER_SYNC_SP( key,s )
   SHOW(s)
   CCLOG("SC_DAER_SYNC_SP")
  -- if 1 then self:GoOnInfo()   return end
   self.m_MyShouPaiTB=s.shoupai
   self.m_KanPaiTB[self.m_MySeat]={}
   if s.hu_num  and s.hu_num>0 then
   	 self:UpdateHuValue(s.hu_num)
   end
    if s.peng  then 
    	for k1,v1 in pairs(s.peng) do
    		table.insert(self.m_KanPaiTB[self.m_MySeat],{["kan"]={v1,v1,v1,["ty"]="peng"}})
    	end
    end
    if s.long  then 
    	for k1,v1 in pairs(s.long) do
    		table.insert(self.m_KanPaiTB[self.m_MySeat],{["kan"]={v1,v1,v1,["ty"]="long"}})
    	end
    end
    if s.zhao  then 
    	for k1,v1 in pairs(s.zhao) do
    		table.insert(self.m_KanPaiTB[self.m_MySeat],{["kan"]={v1,v1,v1,["ty"]="zhao"}})
    	end
    end
    if s.chi  then 
    	for k1,v1 in pairs(s.chi) do 
    		SHOW(v1)
    		table.insert(self.m_KanPaiTB[self.m_MySeat],{["kan"]={v1.o1,v1.o2,v1.pai,["ty"]="chi"}})
    	end
    end
    if s.fei  then 
       self.m_DaChuPaiTB[self.m_MySeat]=s.fei
    end
	CCLOG("self.m_KanPaiTB")
    SHOW(self.m_KanPaiTB)
	self:UpdateKan(self.m_MySeat)
	self:UpdateChuPai(self.m_MySeat)	
	self:ZhanKaiMyShouPai()
end
--更新坎
function ChLDaer_Base:UpdateKan( zuowei )
    local  m_KanPaiTB = self.m_KanPaiTB[zuowei] or {}
    CCLOG("更新坎----2",zuowei)
    local  offx,offy,jianju_x,jianju_y = LzDaer_M_PengPaiPos(zuowei)
     CCLOG("更新坎----2222222", offx,offy,jianju_x,jianju_y)
     SHOW(m_KanPaiTB)
    local tag = zuowei*10
    for k1,kan in pairs(m_KanPaiTB or {}) do
    	SHOW(kan.kan)
    	 CCLOG("更新坎----3",zuowei)
		if kan.kan then
            local chicount = 0
            for k2,v in pairs( kan.kan or {}) do
            	 CCLOG("更新坎----4",v)
            	if type(v) =="number"  then
                    local chupai = DaerPokerClass:Create(self.da_pokerNode,v,"da")
		            chupai.m_player:setPosition(offx-jianju_x*k1,offy+jianju_y*k2)
		            chupai.m_player:setLocalZOrder(20-k2)
		            m_KanPaiTB[k1]["kan"][k2]=chupai
                    chicount=chicount+1
            	end
                if type(v) == "string" then
                    local resname = nil
                    if v=="long" then
                       resname="lzde_long"
                    elseif v=="zhao" then
                        resname="lzde_zhao"
                    end
                    if resname then
                        local caozuosp = self.da_pokerNode:getChildByTag(k1+tag)
                        if caozuosp then self.da_pokerNode:removeChildByTag(k1+tag)  end
                        caozuosp=xui.addSprite(self.da_pokerNode,resname,offx-jianju_x*k1+18,offy+jianju_y*1,nil,125)
                        caozuosp:setTag(k1+tag)
                        caozuosp:setScale(0.8)
                    end
                end
            end
		end
    end
end

--手牌进入弃牌堆
function ChLDaer_Base:SC_DAER_PAIDUI(key,s )
	CCLOG("SC_DAER_PAIDUI")
	SHOW(s)
 	self:StopInfo()
	local zuowei = s.seat
	local changValue = s.value
    self:MovePaiToDui(zuowei,changValue,"qi")
    self.m_FanPaiSeat   =0
    local array = {}
    array[1]=cc.DelayTime:create(0.3)
    array[2]=cc.CallFunc:create(function (  )
    	self:GoOnInfo()
    end)
    self.m_BaseNode:runAction(cc.Sequence:create(array))
end

--出牌移动到打牌堆
function ChLDaer_Base:MovePaiToDui( zuowei,daer_value,ty,pengTb)
	if not  self.m_ChuPaiClass then
        CCLOG("MovePaiToDui 创建")
       self:CHuYiZhangFun(zuowei,daer_value,nil,nil,true)
	end
	local  offx,offy,jianju_x,jianju_y =0,0,0,0
	local startX,startY =0,0
    if ty=="qi" then
        offx,offy,jianju_x,jianju_y = LzDaer_M_DaPaiPos(zuowei)
        local  m_DaChuPaiTB = self.m_DaChuPaiTB[zuowei] or {}
        local a =#m_DaChuPaiTB%2
   	    if a==0 then a=2 end
   	    local b = math.ceil(#m_DaChuPaiTB/2)
        startX = offx-jianju_x*b
        startY = offy-jianju_y*a
    else
        offx,offy,jianju_x,jianju_y = LzDaer_M_PengPaiPos(zuowei)
        local  m_DaChuPaiTB = self.m_KanPaiTB[zuowei] or {}
        startX = offx-jianju_x*(#m_DaChuPaiTB)
        startY = offy-jianju_y*2
    end
    self.m_ChuPaiClass.frantSp:setOpacity(200)
    local time=0.1
    self.m_ChuPaiClass.frantSp:runAction(cc.Sequence:create({cc.FadeOut:create(0.15)}))
    if ty=="qi" then
       table.insert(self.m_DaChuPaiTB[zuowei],daer_value)
       self:UpdateChuPai(zuowei)
    end
    local array = {}
    array[1]=cc.Spawn:create(cc.ScaleTo:create(time,0.1),cc.RotateTo:create(0.15,0),cc.FadeOut:create(0.1),cc.MoveTo:create(time,{x=startX,y=startY}))
    array[2]=cc.CallFunc:create(function(  )
        if self.m_ChuPaiClass.m_player then
        	self.m_ChuPaiClass.m_player:removeFromParent(true)
        	self.m_ChuPaiClass=nil
        end
    	-- if ty=="qi" then    
    	-- end
    end)
    self.m_ChuPaiClass.m_player:runAction(cc.Sequence:create(array))
end
--打牌起始位置
function LzDaer_M_DaPaiPos(zuowei )
	local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
    local offx,offy = sys.width-40,90
	local jianju_x,jianju_y = 33,37
	local zhangshu = 6
    if operate ==2 then
        offx,offy = sys.width-80,sys.center.y-30
    end
    -- if operate ==3 then
    --     offx,offy = sys.center.x-240,sys.height-20
    --     jianju_x=-37
    -- end
    if operate ==3 then
        offx,offy = -10,sys.center.y-20-50
        jianju_x=-33
    end
    return  offx,offy,jianju_x,jianju_y
end
--碰牌起始位置
function LzDaer_M_PengPaiPos(zuowei )
	local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
	local offx,offy =160,90-2*37
	local jianju_x,jianju_y = -33,37
	local zhangshu = 6
    if operate ==2 then
        offx,offy = sys.width-80,sys.center.y-30-37+20
        jianju_x=33
    end
    -- if operate ==3 then
    --     offx,offy = sys.center.x-240+7*37,sys.height-80-3*jianju_y
    --     jianju_x=-37
    -- end
    if operate ==3 then
        offx,offy = -10,sys.center.y-37-50
        jianju_x=-33
    end
    return  offx,offy,jianju_x,jianju_y
end

--得到打出pai
function ChLDaer_Base:UpdateChuPai( zuowei )
	local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
    local  m_DaChuPaiTB = self.m_DaChuPaiTB[zuowei] or {}
    local  offx,offy,jianju_x,jianju_y = LzDaer_M_DaPaiPos(zuowei)
	for k,v in pairs(m_DaChuPaiTB or {}) do
   	    local a =k%2
   	    if a==0 then a=2 end
   	    local b = math.ceil(k/2)
		if type(v)=="number"  then
        	local chupai = DaerPokerClass:Create(self.da_pokerNode,v,"da")
            chupai.m_player:setPosition(offx-jianju_x*b,offy-jianju_y*a)
            m_DaChuPaiTB[k]=chupai
        else

		end
	end
end
--得到打出pai
function ChLDaer_Base:Action_OutfuiPai(cPos, cb )
	if self.m_fanPaiClass.m_player  == nil then
		return
	end 
	CCLOG("翻牌消失函数")
	local operate = LzDaer_M_GetPointZuoWei(cPos)+1
    local movePosTb={
      [1]={x = sys.center.x-150,y = sys.center.y-40},
      [2]={x = sys.center.x+150,y = sys.center.y+155},
      [3]={x = sys.center.x-240,y = sys.center.y+155},
    }
	
	local array = {}
	-- array[1] = cc.FadeOut:create(0.2)
	array[1] = cc.Spawn:create(cc.ScaleTo:create(0.2,0.01),cc.FadeOut:create(0.2),cc.MoveTo:create(0.2,{x = movePosTb[operate].x,y = movePosTb[operate].y}))
	array[2] = cc.CallFunc:create(function (  )
			CCLOG("m_CurrUpPaiSp 执行动作 Action_OutfuiPai 完毕 ")
			self:DelFanPaiFun()
			if cb then
				cb()
			end
	end)
	CCLOG("m_CurrUpPaiSp 执行动作 Action_OutfuiPai ")
	self.m_fanPaiClass.m_player:runAction(cc.Sequence:create(array))
end
--到处那张牌
function ChLDaer_Base:Action_OutPaiToZhuoMian( zuowei,cb )
	if self.m_PutoutShowSpTB[zuowei]  then 
		local taget = self.m_PutoutShowSpTB[zuowei][#self.m_PutoutShowSpTB[zuowei]]
		if taget.m_player  then 
			local posy = taget.m_player:getPositionY()
			taget.m_player:setPositionY(posy+50)
			local array = {}
			array[1] = cc.MoveBy:create(0.2,{x = 0,y = -50})
			array[2] = cc.CallFunc:create(function (  )
				if cb then
					cb()
				end
			end)
			taget.m_player:runAction(cc.Sequence:create(array))
		end
	end
end
--牌起始位置
function ChLDaer_Base:getPokerBeginX(tableCount )
	local beginx=sys.center.x
	local offx = 0
	if self.m_KanPaiTB[self.m_MySeat]  then
		local kanCount = sys.getTBCount(self.m_KanPaiTB[self.m_MySeat])
		local paiHang =#self.m_ShouPaiClassTb
		if tableCount <8 then
			offx=-DEF_PAI_W/2
			if tableCount%2==0 then
				offx=-DEF_PAI_W/2
			end
		end
	end
	if tableCount%2~=0 then
		beginx=sys.center.x-DEF_PAI_W/2*(tableCount)-DEF_PAI_W/2
	else
		beginx=sys.center.x-DEF_PAI_W/2*(tableCount)-DEF_PAI_W
	end
	return beginx
end
--得到牌位置
function ChLDaer_Base:getPoker( tableCount,index )
	local beginx = self:getPokerBeginX(tableCount)
	return  beginx+DEF_PAI_W*index

end


--得到指定座位与我的相对座位之差
function LzDaer_M_GetPointZuoWei( zuowei )
	CCLOG("ChLDaer_Base.m_MySeat",ChLDaer_Base.m_MySeat)
	local zw = zuowei - ChLDaer_Base.m_MySeat
	if zw < 0 then
		zw = zw + 3
	end 
	CCLOG("zw",zw)

	return zw
end
--自己
function LzDaer_M_GetMyZuoWei(  )
	CCLOG("ChLDaer_Base.m_MySeat",ChLDaer_Base.m_MySeat)
	return ChLDaer_Base.m_MySeat
end

function LzDaer_M_PushReadyBntCallFun(  )
	for i=1,3 do
		LzDaer_M_DelAllDuiSp(i)
	end
	ChLDaer_Base:UpdateHuValue(0)
end

---回放UI
function ChLDaer_Base:CreHuiFangUIfun(  )
    local StopBtn =nil
    local PlayerBtn=nil
    local Layer=cc.Layer:create()
    self.hf_node:addChild( Layer )
    --遮罩
    local mask=xui.creMaskLy( Layer)

    local startY =sys.center.y-200


    local  function PlayerBtnCall( state )
        CCLOG("PlayerBtnCall",state)
        if state ==2 then
            if StopBtn then
                StopBtn.SetMyBtnVisible(true)
            end
            if PlayerBtn then
                PlayerBtn.SetMyBtnVisible(false)
            end
        else
            if StopBtn then
                StopBtn.SetMyBtnVisible(false)
            end
            if PlayerBtn then
                PlayerBtn.SetMyBtnVisible(true)
            end
        end
    end
        --后退
    local houtuiBtn = MyBtnClass:new("lzde_houtui_zc","lzde_houtui_dj","lzde_houtui_zc",function ( ... )
      
        self.m_ClikeCount=self.m_ClikeCount- self.m_VideoKHCount
        CCLOG("Push 后退",self.m_ClikeCount)
        --if self.m_ClikeCount>=self.MaxSetpCount then
           self.m_VideoActiom=true
           PlayerBtnCall(2)
           self:PausePlayer()
       -- end
    end)
    Layer:addChild(houtuiBtn.btnLy)
    houtuiBtn.btnLy:setPosition(sys.center.x-270,startY)
    --重播
    local rePlayerBtn = MyBtnClass:new("lzde_replay_zc","lzde_replay_dj","lzde_replay_zc",function ( ... )
        self.m_videoStepIndex=1
        self.m_VideoActiom=true
        PlayerBtnCall(2)
        CCLOG("重播")
        self:cleanVideoUI()
        if self.m_VideoInfo.gamedata.baohu  then
	        for k,v in pairs(self.m_VideoInfo.gamedata.baohu ) do
	        	if v==1 then
	                LzDaer_M_CreBaojiaoSp(k,v)
	            end
	        end
	    end
    end)
    Layer:addChild(rePlayerBtn.btnLy)
    rePlayerBtn.btnLy:setPosition(sys.center.x-455,startY)
    PlayerBtn = MyBtnClass:new("lzde_play_zc","lzde_play_dj","lzde_play_zc",function ( ... )
        PlayerBtnCall(2)      
        self:PausePlayer()

    end)
    Layer:addChild(PlayerBtn.btnLy)
    --播放
    PlayerBtn.btnLy:setPosition(sys.center.x-90,startY-30)
    PlayerBtn.SetMyBtnVisible(false)

    --停止
    StopBtn = MyBtnClass:new("lzde_zanting_zc","lzde_zanting_dj","lzde_zanting_zc",function ( ... )
        PlayerBtnCall(1) 
        self:PauseStop()
    end)
    Layer:addChild(StopBtn.btnLy)
    StopBtn.btnLy:setPosition(sys.center.x-90,startY-30)
    --快进
    local  KuaijinBtn = MyBtnClass:new("lzde_kuaijin_zc","lzde_kuaijin_dj","lzde_kuaijin_zc",function (  )
        self.m_ClikeCount=self.m_ClikeCount+self.m_VideoKHCount
        --self.m_VideoActiom=true   
        CCLOG("快进",self.m_videoStepIndex)
        PlayerBtnCall(2)
        self:PausePlayer()
    end)
    Layer:addChild(KuaijinBtn.btnLy)
    KuaijinBtn.btnLy:setPosition(sys.center.x+145,startY)

    --返回
    local  fanHuiBtn = MyBtnClass:new("lzde_fanhui_zc","lzde_fanhui_dj","lzde_fanhui_zc",function (  )
        Pt_M_PushbackFun()
    end)
    Layer:addChild(fanHuiBtn.btnLy)
    fanHuiBtn.btnLy:setPosition(sys.center.x+145+190,startY)

   
    self:SetMaxStepFun(  )
    --创建头像
    self:CreHuiFangHead()
    --监听
    self:HunFangListener()

    local balanceTB = {}
    if self.m_VideoInfo.js and self.m_VideoInfo.js  then 
        balanceTB.jiesuan=self.m_VideoInfo.js
    end
    CCLOG("CreHuiFangUIfun")
    SHOW(self.m_playerInfo)
    balanceTB.player=self.m_playerInfo
    self.m_VideoJieSuanBtn=MyBtnClass:new("lzde_js_xq_zc","lzde_js_xq_dj","lzde_js_xq_zc",function ( ... )
        LzDaer_M_CreResultUI(self.m_BaseNode,self.m_Scene,balanceTB)
        self.m_VideoJieSuanBtn.SetMyBtnVisible(false)
    end)
    Layer:addChild(self.m_VideoJieSuanBtn.btnLy,12)
    self.m_VideoJieSuanBtn.btnLy:setPosition(sys.center.x-105,sys.center.y)
   	self.m_VideoJieSuanBtn.SetMyBtnVisible(false)
end
--暂停
function  ChLDaer_Base:PauseStop()
    CCLOG("Push 暂停")
    self.pauseActions =   CCDirector:getInstance():getActionManager():pauseAllRunningActions()
end
--播放
function  ChLDaer_Base:PausePlayer()
    CCLOG("Push 播放")
    if  self.pauseActions ~= nil then
        CCDirector:getInstance():getActionManager():resumeTargets(self.pauseActions)
        self.pauseActions=nil
    end
end

---回放init
function ChLDaer_Base:VideoInit(  )
   CCLOG("会放 VideoInit")
   self.m_VideoInfo={}
  -- self.m_VideoTimeNode         =nil
   self.m_videoStepIndex        =1             --步骤
   self.MaxSetpCount            =1             --最大步骤
   self.m_videoShoPaiTb         ={}
   self.m_VideoListenerTime     =0.1
   self.m_ClikeCount            =0
   self.m_VideoKHCount          =2            --快进步骤
   self.m_playerInfo            ={}
   self.m_VideoActiom           =true         --是否会掉
   self.pauseActions            =nil          --暂停
   self.m_OtherPokerNodeTb      ={}
   self.m_OtherPokerTb          ={{},{},{}}
   self.m_Cliper                ={}
end
--时间
function ChLDaer_Base:DelayTimeFun(callCb,time)
    local array={}
    array[1]=CCDelayTime:create(time or 1)
    array[2]=CCCallFunc:create(function (  )
        if callCb then
            callCb()
        end
      end)
    self.m_VideoTimeNode:runAction(CCSequence:create(array))
end
--回放放回
function ChLDaer_Base:GoBallFun(  )
    CCLOG("回放放回")
    self:DelTimeHunFang()
    self:GoOnInfo()
end
--设置最大步骤
function ChLDaer_Base:SetMaxStepFun(  )
    self.MaxSetpCount=sys.getTBCount(self.m_VideoInfo.gamedata.op)+1
    CCLOG("设置最大步骤",self.MaxSetpCount)
    self.m_ZhuangZuoWei = 1
    if self.m_VideoInfo.gamedata.zhuang  then
       self.m_ZhuangZuoWei=self.m_VideoInfo.gamedata.zhuang
    end
    for k,v in pairs(self.m_VideoInfo.gamedata.card) do
         self.m_videoShoPaiTb[k] =v
    end
end

---每部数据
function ChLDaer_Base:FindPerStepDate( )
    local m_OperteTb ={}
    local m_OperteDateTb={}
    if self.m_videoStepIndex>1 then
        local keyIndex = self.m_videoStepIndex-1
        m_OperteTb = self.m_VideoInfo.gamedata.op
        m_OperteDateTb=self:GetOperteDate(m_OperteTb,keyIndex)
    end
    return  m_OperteDateTb
end
--得到操纵数据
function ChLDaer_Base:GetOperteDate( data,index )
	CCLOG("GetOperteDate","index",index)
    local InitShouTb = {}
    InitShouTb.shoupaiTb={}
    for i=1,3 do
        InitShouTb.shoupaiTb[i]=sys.copyTab(self.m_VideoInfo.gamedata.card[i])
    end
    InitShouTb.Operate={}
    if data[index]  then
       InitShouTb.Operate=data[index]
    end
    InitShouTb.kantb ={{},{},{}}
    InitShouTb.feitb ={{},{},{}}
    InitShouTb.leftpai=20
    InitShouTb.chuTb ={}
    for k,v in pairs(data) do
    	if v.o and k<=index then
    		local zuowei =v.s
    		local operateSeat = LzDaer_M_GetPointZuoWei(zuowei)+1
            if v.o==emDaErCNHisOp_FanPai then
               InitShouTb.leftpai=InitShouTb.leftpai-1
                InitShouTb.chuTb.value=v.v
                InitShouTb.chuTb.seat=zuowei
            end
            if v.o== emDaErCNHisOp_MoPai  then
               InitShouTb.leftpai=InitShouTb.leftpai-1
               local changValue=v.v
               table.insert(InitShouTb.shoupaiTb[zuowei],changValue)
               CCLOG("摸牌action")
            end
            if v.o ==emDaErCNHisOp_ChiPai  then
            	--吃
                if v.v1 then
                    for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
                  	    if v.v1 ==v1 then
                  	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
                  	    	break
                  	    end
                    end
                end
                if v.v2 then
                    for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
                  	    if v.v2 ==v1 then
                  	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
                  	    	break
                  	    end
                    end
                end
                table.insert(InitShouTb.kantb[zuowei],{["kan"]={v.v1,v.v2,v.v,["ty"]="chi"}})
                --比
                if v.c1 and v.c1>0 then
                    for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
                  	    if v.c1==v1 then
                  	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
                  	    	break
                  	    end
                    end
                    for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
                  	    if v.c2 ==v1 then
                  	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
                  	    	break
                  	    end
                    end
                    for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
                  	    if v.v ==v1 then
                  	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
                  	    	break
                  	    end
                    end
                    table.insert(InitShouTb.kantb[zuowei],{["kan"]={v.c1,v.c2,v.v,["ty"]="chi"}})
                end
            end
            if v.o ==emDaErCNHisOp_LongPai  then
            	local long=v.v
            	for i=1,4 do
            		for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
                  	    if v1 ==long then
                  	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
                  	    	CCLOG("longlonglonglonglong")
                  	    end
                    end
            	end
            	table.insert(InitShouTb.kantb[zuowei],{["kan"]={long,long,long,["ty"]="long"}})
            end
            if v.o ==emDaErCNHisOp_ZhaoPai  then
            	for i=1,3 do
            		for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
                  	    if v.v ==v1 then
                  	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
                  	    end
                    end
            	end
            	table.insert(InitShouTb.kantb[zuowei],{["kan"]={v.v,v.v,v.v,["ty"]="zhao"}})
            end
            if v.o ==emDaErCNHisOp_PengPai  then
            	for i=1,2 do
            		for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
                  	    if v.v ==v1 then
                  	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
                  	    end
                    end
            	end
            	table.insert(InitShouTb.kantb[zuowei],{["kan"]={v.v,v.v,v.v,["ty"]="peng"}})
            end
            if v.o ==emDaErCNHisOp_ChuPai  then
        		for k1,v1 in pairs(InitShouTb.shoupaiTb[zuowei]) do
              	    if v.v ==v1 then
              	    	table.remove(InitShouTb.shoupaiTb[zuowei],k1)
              	    	break
              	    end
                end
                InitShouTb.chuTb.value=v.v
                InitShouTb.chuTb.seat=zuowei
            end
            if v.o ==emDaErCNHisOp_Qi  then
                table.insert(InitShouTb.feitb[zuowei],v.v)
            end
   	    end
    end
    return  InitShouTb
end
--删定时器
function ChLDaer_Base:DelTimeHunFang(  )
    if self.m_hunFangTime then
        CCDirector:getInstance():getScheduler():unscheduleScriptEntry( self.m_hunFangTime )
        self.m_hunFangTime = nil
    end
end
--回放监听 
function ChLDaer_Base:HunFangListener(  )
    self:DelTimeHunFang()
    local update = function()
       self:PlayIngPerStep()
    end
    self.m_hunFangTime=CCDirector:getInstance():getScheduler():scheduleScriptFunc(update, self.m_VideoListenerTime,false)
end
---清理界面
function ChLDaer_Base:cleanVideoUI(  )
	self:DelFanPaiFun()
	self.m_fapainode:removeAllChildren()
	self.m_VideoTimeNode:stopAllActions()
    self.m_BaseNode:stopAllActions()
    self.m_otherPaiNode:stopAllActions()
    self.shou_pokernode:stopAllActions()
    self.act_node:stopAllActions()
    self.act_node:removeAllChildren(true)
	self:Video_UpdateCoin(false)
	self.m_VideoJieSuanBtn.SetMyBtnVisible(false)
    self:cleanGameData()
    self.m_otherPaiNode:removeAllChildren(true)
    self.m_OtherPokerNodeTb      ={}
    self.m_OtherPokerTb          ={{},{},{}}
    self.m_videoShoPaiTb         = {}
    self.m_Cliper                ={}
    LzDaer_M_CloseResultUI()
    self:Video_UpdateCoin(false)
end
--播放每一步
function ChLDaer_Base:PlayIngPerStep(  )
    --CCLOG("PlayIngPerStep",self.m_videoStepIndex,self.m_VideoActiom)
    if  self.m_VideoActiom ==false  then  CCLOG("self.m_VideoActiom is false") return end
    --初始化
    local m_isKuaiOrTui = false
    --CCLOG("self.m_ClikeCount",self.m_ClikeCount)
    self.m_videoStepIndex=self.m_ClikeCount+self.m_videoStepIndex
    if self.m_videoStepIndex<1 then self.m_videoStepIndex=1 end
    if self.m_videoStepIndex>self.MaxSetpCount   then  
        if self.m_ClikeCount ~=0 then       
            self.m_videoStepIndex=self.MaxSetpCount 
        else
        	self.m_VideoJieSuanBtn.SetMyBtnVisible(true)
            self:Video_UpdateCoin(true)
            self.m_VideoActiom =false
            self:VideoLiuJuFun()
            CCLOG("播完了",self.m_videoStepIndex)
            return  
        end
    end
    self:GoOnInfo()
    if self.m_ClikeCount ~=0 then 
    	m_isKuaiOrTui=true
        self:cleanVideoUI()
        self.m_ClikeCount =0
    end
    --发牌
    if self.m_videoStepIndex==1 then
    	self.m_VideoActiom =false
	    for k,v in pairs(self.m_VideoInfo.gamedata.card) do
	        self.m_videoShoPaiTb[k] =sys.copyTab(v)
	    end
    	self:Video_FaPai()
    end
    if self.m_videoStepIndex>1 then
        self:PlayerOperateFun(m_isKuaiOrTui)
    end  
end
--回放创建touxiang
function ChLDaer_Base:CreHuiFangHead( )
    if  self.m_VideoInfo.pl  then
        for k,v in pairs(self.m_VideoInfo.pl) do
            if v.id and self.m_MyInfo.playerid ==v.id then
                self.m_MySeat = v.st
                CCLOG("CreHuiFangHead ",self.MyZuoWeiPos)
            end
        end
        local sc_info = {}
        sc_info.playerlist={}
        for k,v in pairs(self.m_VideoInfo.pl ) do
            if v.st  then
                local info = {}
                info.seat=v.st
                info.coin=v.c
                info.nickname=v.nk
                info.sex= v.sx  or 0
                info.playerid=v.id
                info.clientip =v.ip
                info.headurl =v.hd
                info.areaid  =Pt_GetMyCurAreaIdx()
                table.insert(sc_info.playerlist,info)
            end
        end
        self.m_playerInfo=sc_info.playerlist
        LzDaer_M_CreTouXiang( self.head_node, sc_info )
        local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
	    if m_TouXiangLayerTB[self.m_ZhuangZuoWei].ZhuangSp then 
	       m_TouXiangLayerTB[self.m_ZhuangZuoWei].ZhuangSp:setVisible(true)
	    end
    end
    if self.m_VideoInfo.gamedata.baohu  then
        for k,v in pairs(self.m_VideoInfo.gamedata.baohu ) do
        	if v==1 then
                LzDaer_M_CreBaojiaoSp(k,v)
            end
        end
    end
end
--回放发牌
function ChLDaer_Base:Video_FaPai(  )
    local s ={}
    s.zhuang=self.m_ZhuangZuoWei or self.m_MySeat
    self:SC_DAER_FAPAI("nil",s)
end
--video 闯将其他手牌
function ChLDaer_Base:CreOtherPoker( zuowei,count )
	    if   self.m_OtherPokerNodeTb[zuowei]  then
    	 self.m_OtherPokerNodeTb[zuowei]:removeFromParent(true)
    	 self.m_OtherPokerNodeTb[zuowei]=nil
    	 self.m_OtherPokerTb[zuowei]={}
    end
    self.m_OtherPokerNodeTb[zuowei]=cc.Node:create()
    self.m_otherPaiNode:addChild( self.m_OtherPokerNodeTb[zuowei])
    local operateSeat = LzDaer_M_GetPointZuoWei(zuowei)+1
    local pokerCount =  20
    local pokerTb ={}
    local startY = sys.center.y
    local startX = sys.center.x
    local jianjuY = 30
    local jianju_x = 50
    local jianju_y = -50
    if operateSeat ==2 then
        pokerTb=self.m_videoShoPaiTb[zuowei]
        startX=sys.width-245
        startY=sys.center.y+250
        jianju_x=-50
    end
    if operateSeat ==3 then
        pokerTb=self.m_videoShoPaiTb[zuowei]
        startX=200
        startY=sys.center.y+250
    end
    table.sort(pokerTb,function ( a,b )
    	return a<b
    end)
    local paicount = 0
    local a=0
    for k,v in pairs(pokerTb) do
        paicount=paicount+1
        local b = paicount%3
        if b==0 then b=3 end
        local changpai =  DaerPokerClass:Create( self.m_OtherPokerNodeTb[zuowei],v,"da",false)
		changpai.m_player:setAnchorPoint(sys.ap.centerBottom)
		changpai.m_player:setPosition(startX+jianju_x*a,startY+jianju_y*b)
		changpai.m_player:setScale(1.5)
        table.insert( self.m_OtherPokerTb[zuowei],changpai)
        if paicount%3 ==0 then a=a+1 end
		if count==k then break end
    end
end
--操作
function ChLDaer_Base:PlayerOperateFun( m_isKuaiOrTui )
	CCLOG("是否快进",m_isKuaiOrTui)
    local m_OperteTb= self:FindPerStepDate()
    self.m_VideoActiom=false
    if m_isKuaiOrTui then
        self.m_videoShoPaiTb=sys.copyTab(m_OperteTb.shoupaiTb)
        self.m_MyShouPaiTB=sys.copyTab(m_OperteTb.shoupaiTb[self.m_MySeat])
        self.m_KanPaiTB=sys.copyTab(m_OperteTb.kantb)
        self.m_DaChuPaiTB=sys.copyTab(m_OperteTb.feitb)
        self:ZhanKaiMyShouPai()
        local chuTb = m_OperteTb.chuTb
        if chuTb and chuTb.value then
           self:CHuYiZhangFun(chuTb.seat,chuTb.value,nil,nil,true)
        end
        for i=1,3 do
        	if i~=self.m_MySeat then
        		self:CreOtherPoker(i,21)
        	end
        	self:UpdateKan(i)
        	self:UpdateChuPai(i)
        end
		self.m_ResiduePaiNum =m_OperteTb.leftpai
		self:UpdateResiduePai()
        self.m_videoStepIndex=self.m_videoStepIndex+1
        self.m_VideoActiom=true
        if self.m_VideoInfo.gamedata.baohu  then
	        for k,v in pairs(self.m_VideoInfo.gamedata.baohu ) do
	        	if v==1 then
	                LzDaer_M_CreBaojiaoSp(k,v)
	            end
	        end
	    end
        --SHOW(m_OperteTb)
        return 
    end
    
    if m_OperteTb.Operate.o==emDaErCNHisOp_FanPai then
        CCLOG("video -----翻公用牌")
        SHOW(m_OperteTb)
        self:Video_Fan(m_OperteTb.Operate)
    elseif m_OperteTb.Operate.o==emDaErCNHisOp_MoPai then
	    CCLOG("video -----玩家摸牌")
	    SHOW(m_OperteTb)
	    self:Video_Mopai(m_OperteTb.Operate,m_OperteTb.shoupaiTb)
	elseif m_OperteTb.Operate.o==emDaErCNHisOp_ChiPai then
	    CCLOG("video -----吃牌")
	    self:Video_CHI(m_OperteTb.Operate)
	elseif m_OperteTb.Operate.o==emDaErCNHisOp_LongPai then
	    CCLOG("video -----拢牌")
	      self:Video_Long(m_OperteTb.Operate)
	elseif m_OperteTb.Operate.o==emDaErCNHisOp_ZhaoPai then
		CCLOG("video -----招牌")
	    self:Video_Zhao(m_OperteTb.Operate)
	elseif m_OperteTb.Operate.o==emDaErCNHisOp_PengPai then
		CCLOG("video -----碰牌")
	    self:Video_Peng(m_OperteTb.Operate)
	elseif m_OperteTb.Operate.o==emDaErCNHisOp_ChuPai then
		CCLOG("video -----出牌")
		self:Video_Chu(m_OperteTb.Operate)
	elseif m_OperteTb.Operate.o==emDaErCNHisOp_Hu then
	    CCLOG("video -----胡牌")
	    self:Video_Hu(m_OperteTb.Operate)
    elseif m_OperteTb.Operate.o==emDaErCNHisOp_Qi then
	    CCLOG("video -----弃牌")
	    self:Video_Qi(m_OperteTb.Operate)
	else
		CCLOG("video------没有操作")
    end
end
--摸牌
function ChLDaer_Base:Video_Mopai( OperteTb,shoupaiTb)
	SHOW(OperteTb)
	CCLOG("Video_Mopai")
	local zuowei =OperteTb.s
	local changValue = OperteTb.v
	DEF_PIANYI_Y=0
	local daseat = LzDaer_M_GetPointZuoWei(zuowei)+1
	if zuowei ==self.m_MySeat then
	    self:MoYiPai(zuowei,changValue,function (  )
	    	self.m_videoStepIndex=self.m_videoStepIndex+1
            self.m_VideoActiom=true
	    end)
	else
        self:FanYiPai(zuowei,changValue,"mopai",function (  )
        	--table.insert(self.m_videoShoPaiTb[zuowei],changValue)
        	self.m_videoShoPaiTb[zuowei]=shoupaiTb[zuowei] or {}
        	self:CreOtherPoker(zuowei,33)
            self.m_videoStepIndex=self.m_videoStepIndex+1
            self.m_VideoActiom=true
        end)
	end
	self.m_ResiduePaiNum =self.m_ResiduePaiNum -1
	self:UpdateResiduePai()
end
function ChLDaer_Base:Video_Chu( OperteTb)
	CCLOG("Video_Chu---1")
	local zuowei = OperteTb.s
	local changValue = OperteTb.v
	local delPai =nil
	local daseat = LzDaer_M_GetPointZuoWei(zuowei)+1
	if daseat==1 then
		CCLOG("Video_Chu---2")
		--SHOW(self.m_ShouPaiClassTb)
        for k1,v1 in pairs(self.m_ShouPaiClassTb) do
        	local flag =false
   	   	    for k2,v2 in pairs(v1) do
   	   	   	    if v2.daer_value ==changValue  then
   	   	   	   	    if v2.m_player then  	  	    
   	   	   	   	  	    delPai= table.remove(v1,k2)
   	   	   	   	  	    flag =true

   	   	   	   	  	    break
   	   	   	   	    end   
   	   	   	    end
   	   	    end
   	   	    if flag then break end
   	    end
	else
		CCLOG("Video_Chu---3")
        for k,v in pairs(self.m_OtherPokerTb[zuowei] or {}) do
        	if v.m_player and  v.daer_value ==changValue then
                delPai= table.remove(self.m_OtherPokerTb[zuowei],k)
                break
        	end
        end
	end
	SHOW(delPai)
	CCLOG("Video_Chu---4")
	if delPai and delPai.m_player then
		CCLOG("Video_Chu---5")
		local headTb = LzDaer_M_GetTouXiangLayer()
        LzDaer_Public_PlaySound("poker",headTb[zuowei].xingbie,changValue,0,headTb[zuowei].voice)
		self.m_DelPaiPos.x=delPai.m_player:getPositionX()
        self.m_DelPaiPos.y=delPai.m_player:getPositionY()
        delPai.m_player:removeFromParent(true)
        self:CHuYiZhangFun(zuowei,changValue, self.m_DelPaiPos.x, self.m_DelPaiPos.y)
        self:Video_SortPai(zuowei)
	   self:DelayTimeFun(function (  )
            self.m_videoStepIndex=self.m_videoStepIndex+1
            self.m_VideoActiom=true

        end,1)
	end
	
end
---重新整理牌
function ChLDaer_Base:Video_SortPai( zuowei )
	CCLOG("Video_SortPai",zuowei)
	local operateSeat = LzDaer_M_GetPointZuoWei(zuowei)+1
    local startY = sys.center.y
    local startX = sys.center.x
    local jianjuY = 30
    local jianju_x = 50
    local jianju_y = -50
    if operateSeat ==2 then
        pokerTb=self.m_videoShoPaiTb[zuowei]
        startX=sys.width-245
        startY=sys.center.y+250
        jianju_x=-50
    end
    -- if operateSeat ==3 then
    --     pokerTb=self.m_videoShoPaiTb[zuowei]
    --     startY=sys.center.y+250
    -- end
    if operateSeat ==3 then
        pokerTb=self.m_videoShoPaiTb[zuowei]
        startX=200
        startY=sys.center.y+250
    end
    if operateSeat ==1 then
        self:CleanPokerTbFun()
        self:ChangeSortPoker(true)
    else
        local paicount = 0
        local a=0
        for k,v in pairs(self.m_OtherPokerTb[zuowei] or {}) do
            if v.m_player  then
               paicount=paicount+1
               local b = paicount%3
               if b==0 then b=3 end
               local array = {}
               array[1]=cc.MoveTo:create(0.1,{x=startX+jianju_x*a,y=startY+jianju_y*b})
               v.m_player:runAction(cc.Sequence:create(array))
               if paicount%3 ==0 then a=a+1 end
            end
        end
    end
	CCLOG("Video_SortPai is end")
end
function ChLDaer_Base:Video_Fan( OperteTb )
	local s = {}
	s.seat=OperteTb.s
	s.pai =OperteTb.v 
	s.leftpai=self.m_ResiduePaiNum -1
	SHOW(OperteTb)
	self:SC_DAER_FANPAI("nil",s)
	self:DelayTimeFun(function (  )
		self.m_videoStepIndex=self.m_videoStepIndex+1
        self.m_VideoActiom=true
	end,1.5)
end
function ChLDaer_Base:Video_CHI(OperteTb )
	local s = {}
	s.seat=OperteTb.s
	s.chi={}
	s.chi.o1=OperteTb.v1  
	s.chi.o2=OperteTb.v2 
	s.chi.pai=OperteTb.v 
	if  OperteTb.c1 and OperteTb.c1>0 then
       s.bi={}
       s.bi.o1=OperteTb.c1  
	   s.bi.o2=OperteTb.c2 
	   s.bi.pai=OperteTb.v 
	end
	self:Operate_UI("chi",s)

	self:DelayTimeFun(function (  )
		self.m_videoStepIndex=self.m_videoStepIndex+1
        self.m_VideoActiom=true
	end,1.5)
end
function ChLDaer_Base:Video_Long( OperteTb )
	local s = {}
	s.seat=OperteTb.s
	s.long=OperteTb.v
	--s.long[1]=OperteTb.v 
	SHOW(s)
	self:Operate_UI("long",s)

	self:DelayTimeFun(function (  )
		self.m_videoStepIndex=self.m_videoStepIndex+1
        self.m_VideoActiom=true
	end,1.5)
end
function ChLDaer_Base:Video_Zhao( OperteTb )
	local s = {}
	s.seat=OperteTb.s
	s.value =OperteTb.v 
	self:Operate_UI("zhao",s)
	self:DelayTimeFun(function (  )
		self.m_videoStepIndex=self.m_videoStepIndex+1
        self.m_VideoActiom=true
	end,1.5)
end
function ChLDaer_Base:Video_Peng( OperteTb )
	local s = {}
	s.seat=OperteTb.s
	s.value =OperteTb.v 
	self:Operate_UI("peng",s)
	self:DelayTimeFun(function (  )
		self.m_videoStepIndex=self.m_videoStepIndex+1
        self.m_VideoActiom=true
	end,1.5)
end

function ChLDaer_Base:Video_Qi( OperteTb )
	local s = {}
	s.seat=OperteTb.s
	s.value =OperteTb.v 
	self:SC_DAER_PAIDUI("nil",s)
    self:DelayTimeFun(function (  )
		self.m_videoStepIndex=self.m_videoStepIndex+1
        self.m_VideoActiom=true
	end,1.5)
end
--video 胡
function ChLDaer_Base:Video_Hu( OperteTb)
	CCLOG("Video_HuVideo_HuVideo_HuVideo_Hu")
	local zuowei = OperteTb.s
	local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
	local hutype =OperteTb.h  or 0
    local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()
    if hutype~=4 then
    	if hutype==1 then
           LzDaer_Public_PlaySound("zimo",m_TouXiangLayerTB[zuowei].xingbie)
        else
            LzDaer_Public_PlaySound("hu",m_TouXiangLayerTB[zuowei].xingbie)
        end
    end
   	local operate = LzDaer_M_GetPointZuoWei(zuowei)+1
   	if hutype<=3 then 
		LzDaerAniamtions.HuAni(self.act_node,self.DEF_ANI_POS[operate].x,self.DEF_ANI_POS[operate].y,function (  )
		end)
	else
        LzDaerAniamtions.LiuJuAni(self.act_node,"lzde_liuju",sys.center.x,sys.center.y)
	end
	self.m_VideoJieSuanBtn.SetMyBtnVisible(true)
	self:Video_UpdateCoin(true)
end
--video 金币
function ChLDaer_Base:Video_UpdateCoin(isShow)
    local m_TouXiangLayerTB = LzDaer_M_GetTouXiangLayer()  or {}
    for k,v in pairs(self.m_VideoInfo.pl) do
        if v.st then 
            if m_TouXiangLayerTB[v.st]  then 
                if isShow then
                    if v.ce then 
                        m_TouXiangLayerTB[v.st]:UpDateJiaQian(v.c+v.ce)
                    else
                        m_TouXiangLayerTB[v.st]:UpDateJiaQian(v.c)
                    end
                else
                   m_TouXiangLayerTB[v.st]:UpDateJiaQian(v.c)
                end
            end
        end
    end
end
---判断是否三人有叫流局
function ChLDaer_Base:VideoLiuJuFun(  )
	local balanceTB = {}
    if self.m_VideoInfo.js and self.m_VideoInfo.js.gameover  then 
        balanceTB=self.m_VideoInfo.js.gameover  or {}
    end
    if sys.getTBCount(balanceTB) ==0 then
        LzDaerAniamtions.LiuJuAni(self.act_node,"lzde_liuju",sys.center.x,sys.center.y)
        --self:Video_UpdateCoin(true)
    end
end