|
- local PKDef = PKFramework.PKImport("pk_base.luaScript.PKDef")
- local PKFuc = PKFramework.PKImport("pk_base.luaScript.PKFunctions")
- local PKSound = PKFramework.PKImport("pk_base.luaScript.PKSound")
- local PKMessage = PKFramework.PKImport("pk_base.luaScript.Protocol.PKMessage")
- local PKRoomPlayerView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomPlayerView")
- local PKRoomToolView = PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomToolView")
- local PKRoomXiaoJuChaPaiView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomXiaoJuChaPaiView")
- local PKRoomXiaoJuView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomXiaoJuView")
- local PKRoomOperationView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomOperationView")
- local PKRoomCard=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomCard")
- local PKRoomCountAllView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomDaJuView")
- local PKRoomSettingView = PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomSettingView")
- local PKAnimationCompnent=PKFramework.PKImport("pk_base.luaScript.Views.Component.PKAnimationCompnent")
- local PKWanFa = PKFramework.ImportWanFa("luaScript.SubGameDefine.PuKe.PKWanFa")
- --local RoomDefined = require("Views.Room.RoomDefined")
-
- local PKRoomView = class("PKRoomView", cc.UIView)
-
- function PKRoomView:ctor()
- PKRoomView.super.ctor(self);
- self.Time = nil
- --牌Layout UI
- self.handCardRoot = {}
- --手牌数组UI
- self.handCardItem = {}
- --牌数据UI
- self.handCardValueLocal = {}
- --扇形最大列数
- self.lieShuMax = 20
- --扇形最大行数
- self.hangShuMax = 1
- --是否出牌
- self.bOutCard = false
- --组合牌之间的间隔
- self.cardInterval = 80
- --牌上升高度
- self.cardOffY = 30;
- self:resetShangJiaData();
- --正在执行删除牌操作的时候,保护删除是正常,避免少牌可能性出现
- self.isGodHand = false
- --提示
- self.tipList = {}
- --最后一手牌
- self.lastHandTemp = {};
- --shegn
- self.leftCardNum = {};
-
- --isReconet
- self.isReconet = false
-
- self.isRecord = false
-
- for i = 1,4 do
- self.leftCardNum[i] = 0;
- end
- end
-
- function PKRoomView:loadRoomUI()
- local ui = loadUI("pk_base/res/ui/ui_fangjian/pk_ui_fangjian.ui");
- self.ui = ui;
- self:addChild(ui);
- end
-
- function PKRoomView:onEnter()
- PKRoomView.super.onEnter(self)
-
- self:loadRoomUI();
-
- --加载纹理缓存
- self:loadTextureCache()
- --初始化游戏事件按钮
- self:initGameButton()
- --初始化基础节点
- self:initBaseNode()
- -- 初始化GPS组件
- self:initGpsComponent();
- --默认状态
- self:defaultState()
- --监听事件
- self:bindAllEvent()
-
- self:onGameReconnection()
- --起飞
- self:startGame()
- -- 背景音乐
- self:playBGM()
- end
-
- -- 播放背景音乐
- function PKRoomView:playBGM()
- local cacheMusic = "gameBgMusic"..(PKDef.GameID or app.gameId)
- local defaultValue = tonumber(loadUserInfo(cacheMusic)) or 1
- PKSound.PlayGameBGM(defaultValue)
- end
-
- function PKRoomView:doSound()--1 普通话 2 方言
- local PKLanguageType = "PKLanguageType"..app.gameId
- local languageType = tonumber(loadUserInfo(PKLanguageType)) or PKDef.GameLanguageType.PU_TONG_HUA
- PKSound.setCurLanguage(idx)
- end
-
- function PKRoomView:startGame()
- --起飞
- app.net:onMsgResume()
- end
-
- function PKRoomView:loadTextureCache()
- PKFuc.loadSpriteFromFile("pk_base/res/ui/zy_fangjian/card/pk_card_1.plist")
- end
-
- function PKRoomView:initBaseNode()
- --玩家界面
- self.PlayerView = PKRoomPlayerView:new()
- self.ui.Items.Layout_Player:addChild(self.PlayerView)
-
- --工具界面
- self.toolView = PKRoomToolView:new(self)
- self.ui.Items.Layout_Tool:addChild(self.toolView)
-
- --操作界面
- self.operationView = PKRoomOperationView:new(self)
- self.ui.Items.Layout_OperationView:addChild(self.operationView)
- self.operationView:setPlayerView(self.PlayerView)
-
- local timestr = os.date("%y-%m-%d %H:%M:%S")
- self.ui.Items.Text_systemTime:setText(timestr)
- --定时器
- if not self.Time then
- self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
- local timestr = os.date("%y-%m-%d %H:%M:%S")
- self.ui.Items.Text_systemTime:setText(timestr)
- end,1.0,false)
- end
-
- self.outCardList = {}
- for i = 1, PKDef.GameMaxPlayer do
- local weaveCardName = string.format("Layout_outCard_%d",i)
- self.outCardList[i] = self.ui.Items[weaveCardName]
- end
-
- --隐藏出牌复制节点
- self.ui.Items.Layout_CardItem:setVisible(false)
- end
-
- function PKRoomView:onExit()
- PKRoomView.super.onExit(self)
- --关闭定时器
- if self.Time then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
- end
-
- app.room:dispatchEvent({name = "onGameOverResponse"});
-
- stopBGMusic()
- end
-
- function PKRoomView:initGameButton()
- self.ui.Items.Layout_Touch:registerClick(function ()
- if not self.toolView.ui.Items.Button_Menu:isBright() then
- self.toolView:onClickMenu()
- end
- self:BanlanceAllCard()
- end)
- end
-
- function PKRoomView:defaultState()
- --队列初始化
- self.callbackQueue = {}
- self.callbackRunning = false
- if self.PlayerView then
- self.PlayerView:setOffLine(false)
- self.PlayerView:setPlayerVisible(false)
- end
- self:resetGameData()
- --第一局清理托管标志,后面每局开始不清理(不然会出现没有取消托管,托管标志不显示bug)
- self.PlayerView:setTuoGuanFlagVisible(false)
- end
-
- function PKRoomView:resetGameData()
- logD("===========重置游戏数据===============")
- self.handCardRoot = {}
- self.handCardItem = {}
- self.handCardValueLocal = {}
- app.room.roomInfo.isShowDismiss = false
- self.isFristOutCard = true
- self.isReconet = false
- self:setWaitBgVisible(false)
- self:setWetChatVisible(false)
- self:setBtnSitDownVisible(false)
- self:setBtnClubInviteVisible(false)
- self:setLiangPaiVisible(false)
- if self.PlayerView then
- self.PlayerView:setReadyStateVisible()
- self.PlayerView:setBankerVisible()
- self.PlayerView:setOperatorTipVisible()
- self.PlayerView:setAllClockVisible()
- self.PlayerView:hideLeftCard()
- self.PlayerView:hideAllPopText()
- self.PlayerView:setOffLine()
- self.PlayerView:setOwnerVisible()
- self.PlayerView:setOffLineBg()
- self.PlayerView:setFriendFlagVisible()
- self.PlayerView:setBaoPaiFlagVisible()
- self.PlayerView:setRankingFlagVisible()
- for i = 1, PKDef.GameMaxPlayer do
- self.PlayerView:showBaoJingAni(i,true)
- end
- end
-
- self.operationView:hideSelf(true)
-
- --操作码
- self.isGameOver = false
- self.isGodHand = false
- --发牌器
- self.fapaiqiLeftCard = nil
- --移除所有的牌局
- self.ui.Items.LayoutMain_4:removeAllChildren()
-
- for i = 1, PKDef.GameMaxPlayer do
- local weaveCardName = string.format("Layout_outCard_%d",i)
- self.ui.Items[weaveCardName]:removeAllChildren()
- end
-
- if self.xiaojuView then
- self.xiaojuView:removeFromParent()
- self.xiaojuView = nil
- end
-
- if self.chaPaiView and (not tolua.isnull(self.chaPaiView)) then
- self.chaPaiView:removeFromParent()
- self.chaPaiView = nil
- end
-
- self.weaveCardList = {}
- self.tiShiCount = 1;
-
- --停止一些动画
- self.ui:stopAllActions()
-
- --重置包牌数据
- for k,v in pairs(app.room.roomInfo.memberList) do
- local memberInfo = app.room.roomInfo.memberList[v.nUserId]
- if memberInfo then
- memberInfo.baoPai = nil
- end
- end
- end
-
-
-
- --更新房间基础数据
- function PKRoomView:updateRoomBaseData()
- --初始化背景
- local PKgameBgPicture = "gameBgPicture"..(PKDef.GameID or app.gameId)
- local idx2 = tonumber(loadUserInfo(PKgameBgPicture)) or 4
- self:setTableImg(idx2)
-
- local roomInfo = app.room.roomInfo;
-
- -- 房间号
- self.ui.Items.Text_roomNum:setText(tostring(roomInfo.nShowTableId));
-
- --局数
- self:updateGameNums()
-
- self:showOwner()
-
- self:onUserReadyResponse()
-
- for i = 1,PKDef.GameMaxPlayer do
- self.PlayerView:updatePlayerInfo(i)
- end
-
- self.toolView:showFastStart(true)
-
- -- 是否显示邀请好友
- if app.room.roomInfo.nGameStartCount > 0 then
- self:setWetChatVisible(false)
- self:setBtnClubInviteVisible(false)
- else
- self:setBtnClubInviteVisible(app.room:getCurMaxPlayer() < PKFuc.getCreateRoomPlayerNum())
- self:setWetChatVisible(app.room:getCurMaxPlayer() < PKFuc.getCreateRoomPlayerNum())
- end
- end
-
- function PKRoomView:onGameReconnection()
- --logE("PK当前版本号:"..PKFuc.getPKCurVersion())
- --更新房间基础数据
- self:updateRoomBaseData()
-
- local roomInfo = app.room.roomInfo;
-
- --断线重连
- if roomInfo.nGameStartCount > 0 then
- local function runOnGameReconnection(onEnd)
- local roomInfo = app.room.roomInfo;
- --显示庄家
- self:updateBanker()
- local myUserID = app.room:getMyRecordUserId()
- --解散状态
- local isDismiss = false
- local uid = 0
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local viewId = app.room:getViewIdByUserId(k)
- local nOffLineState = v.nOnlineStatus
- --显示离线
- self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
-
- local viewId = app.room:getViewIdByUserId(k)
- --记录玩家解散状态 0:初始状态, 1:发起解散 2: 同意解散 3:不同意解散
- app.room.dismissInfo[k] = v.disbandStatus;
- --有人发起解散时才显示解散界面
- if v.disbandStatus == 1 then
- isDismiss = true
- uid = k
- end
- if self.toolView.chatView then
- self.toolView.chatView:addPlayer(k)
- end
- end
-
- --有人发起解散时才显示解散界面
- if isDismiss then
- app.room.roomInfo.nDismissStateTime = roomInfo.nDismissStateTime or roomInfo.disBandTimeOut;
- app.room.roomInfo.nDismissToTalTime = roomInfo.nDismissToTalTime;
-
- local view = require("luaScript.Views.Room.RoomDismissView"):new(uid,app.room.roomInfo.memberList,roomInfo.nDismissStateTime)
- view:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(view);
- end
-
- --托管状态恢复
- for k,v in pairs(roomInfo.playerTuoGuanState or {}) do
- local entrustType = v.state;--托管状态 1-托管中 0-未托管
- local nUserID = v.nUserId;
- local viewId = app.room:getViewIdByUserId(nUserID)
- local isTuoGuan = entrustType == 1;
- if viewId == self:getMeViewId() then
- if isTuoGuan then
- self:showTuoGuan(true)
- self.isTuoGuan = true
- else
- self:showTuoGuan(false)
- self.isTuoGuan = false
- end
-
- end
- self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
- end
-
- --如果一局结束,玩家点了准备,不再显示牌信息
- if PKDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == PKDef.USER_STATE.READY
- or PKDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == PKDef.USER_STATE.READY
- then --游戏为停止或开始状态
- self:onUserReadyResponse()
- if onEnd then
- onEnd()
- end
- return
- end
-
- for k,v in pairs(roomInfo.arrayTableInfo or {}) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- local nScore = v.nTotalScore or 0
-
- --玩家分数
- self.PlayerView:setPlayerScore(viewId,nScore)
-
- --恢复手牌
- if v.nUserId == myUserID then
- self:createCard(false,myUserID,nil)
- end
-
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- self.leftCardNum[viewId] = table.nums(v.handCardList)
- --显示剩余牌
- self.PlayerView:setLeftCardNum(viewId,true,self.leftCardNum[viewId])
-
- if self.leftCardNum[viewId] < 3 then
- self:playBaoJingAni(viewId)
- end
- end
-
- if PKDef.ReconnectState.GAME_STATUS_INIT == roomInfo.nStatus then
-
- elseif PKDef.ReconnectState.GAME_STATUS_WAIT_BANKER_START == roomInfo.nStatus then
-
- elseif PKDef.ReconnectState.GAME_STATUS_WAITTING == roomInfo.nStatus then
-
- elseif PKDef.ReconnectState.GAME_STATUS_READALL == roomInfo.nStatus then
-
- elseif PKDef.ReconnectState.GAME_STATUS_CHOOSE_PIAO == roomInfo.nStatus then
-
- elseif PKDef.ReconnectState.GAME_STATUS_SHUFFLE == roomInfo.nStatus then
-
- elseif PKDef.ReconnectState.GAME_STATUS_SENDCARDS == roomInfo.nStatus then
-
- elseif PKDef.ReconnectState.GAME_STATUS_ASK_BAO == roomInfo.nStatus then
- local viewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
- self.PlayerView:showClockVisible(viewId,true,app.room.roomInfo.opTypeTime)
- if viewId == self:getMeViewId() then
- if app.room.roomInfo.opType == 3 then
- self.operationView:setLayoutBaoPaiView(true)
- elseif app.room.roomInfo.opType == 4 then
- self.operationView:setLayoutFanPaoView(true)
- end
- end
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- local state = v.baoPaiType
- if state > 1 then
- self.PlayerView:showOperatorTip(viewId,state,false)
- self.PlayerView:showBaoPaiFlag(viewId,state)
- end
- end
- elseif PKDef.ReconnectState.GAME_STATUS_ASK_CARD == roomInfo.nStatus then
- local viewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
- self.PlayerView:showClockVisible(viewId,true,app.room.roomInfo.opTypeTime)
- self.operationView:setCallCardView(true,app.room.roomInfo.noCards)
- elseif PKDef.ReconnectState.GAME_STATUS_PLAYING == roomInfo.nStatus then
- self.isFristOutCard = false
- local lastUserId = roomInfo.GetOpUid;
- local cardType = roomInfo.cardType;
- local cardList = app.room:getCardList(roomInfo.cardList);
- self:resetShangJiaData()
- self.shangJiaData.cardList = cardList
- self.shangJiaData.cardType = cardType;
- self.shangJiaData.nUserId = lastUserId;
- --恢复上家手牌
- if self.shangJiaData.nUserId > 0 then
- local shangjiaViewId = app.room:getViewIdByUserId(self.shangJiaData.nUserId);
- self:createOutCard(shangjiaViewId, cardList, roomInfo.cardType, true,cardList,nil);
- end
-
- local viewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
- self.PlayerView:showClockVisible(viewId,true,app.room.roomInfo.opTypeTime)
- if viewId == self:getMeViewId() then
- self.operationView:setOperatorPanelView(true,app.room.roomInfo.curOpType)
- self:initTipData()
- end
- if app.room.roomInfo.cAskCard > 0 then
- self.operationView:setCallCardView(true,app.room.roomInfo.noCards,app.room.roomInfo.cAskCard,true)
- if app.room.roomInfo.bFriendAppear == 0 then
- self:showFriendFlag()
- else
- self:showMengYouFlag(false)
- end
- end
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- local IsPlaying = v.IsPlaying
- local baoPaiType = v.baoPaiType
- if IsPlaying == 0 then
- if viewId == self:getMeViewId() then
- self.ui.Items.Layout_Wait:setVisible(true)
- end
- elseif baoPaiType == 1 then
- self.PlayerView:showBaoPaiFlag(viewId,baoPaiType)
- end
- if v.ranking > 0 then
- self.PlayerView:showRanking(viewId,v.ranking)
- self.PlayerView:showBaoJingAni(viewId,true)
- end
- end
- elseif PKDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus then
- self.isReconet = true
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local memberInfo = app.room.roomInfo.memberList[v.nUserId]
- if memberInfo then
- memberInfo.baoPai = v.baoPaiType
- end
- end
- self:setBtnSitDownVisible(false)
- elseif PKDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then
- self.isReconet = true
- self:setBtnSitDownVisible(false)
- end
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - self:addCallBack(runOnGameReconnection)" )
- self:addCallBack(runOnGameReconnection)
- else
- --未开局正常坐下这里会进来
- for k,v in pairs(roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(k)
- local nOffLineState = v.nOnlineStatus or 1
- --显示离线
- self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
- if self.toolView.chatView then
- self.toolView.chatView:addPlayer(k)
- end
- end
-
- --未开局重连坐下
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local viewId = app.room:getViewIdByUserId(k)
- local nOffLineState = v.nOnlineStatus
- --显示离线
- self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
- end
-
- if table.nums(roomInfo.arrayTableInfo) <=0 then
- if self.toolView.chatView then
- self.toolView.chatView:addPlayer(app.room:getUserIdByViewId(self:getMeViewId()))
- end
- end
-
- --游戏未开始
- local fastStartUserId = 0
- --显示离线状态
- if roomInfo.fastStartPlayerInfos then
- for k,v in pairs(roomInfo.fastStartPlayerInfos) do
- --发起快速开始ID
- if v.optType == PKDef.SPEED_START_GAME.START_OPT_TYPE_REQ then
- fastStartUserId = v.uid
- end
- end
- --显示快速开始界面
- if roomInfo.bUserFastStartGame == 1 and fastStartUserId ~= 0 then
- if self.startView then
- self.startView:removeFromParent()
- end
- local function callback()
- self.startView = nil
- end
-
- local responseEx = {}
- responseEx.nleftStartGameTimeout = roomInfo.nFastStartTimeOut
- responseEx.playerList = roomInfo.fastStartPlayerInfos
-
- self.startView = import("pk_base.luaScript.Views.Room.PKRoomStartWaitView"):new(responseEx, callback);
- self.startView:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(self.startView);
- end
- end
- end
- end
-
-
- --隐藏微信按钮
- function PKRoomView:setWetChatVisible(bVisible)
- self.toolView.ui.Items.Layout_Invite:setVisible(bVisible)
- if isReviewVersion() then
- self.toolView.ui.Items.Layout_Invite:setVisible(false)
- end
- self.toolView.ui.Items.Layout_Btn:requestDoLayout()
- self.toolView.ui.Items.Layout_Btn:doLayout()
-
- end
-
- --隐藏准备按钮
- function PKRoomView:setBtnSitDownVisible(bVisible)
- self.toolView.ui.Items.Layout_Ready:setVisible(bVisible)
- self.toolView.ui.Items.Layout_Btn:requestDoLayout()
- self.toolView.ui.Items.Layout_Btn:doLayout()
- end
-
- function PKRoomView:setBtnClubInviteVisible(bVisible)
- self.toolView.ui.Items.Layout_ClubInvite:setVisible(false);
-
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- self.toolView.ui.Items.Layout_ClubInvite:setVisible(bVisible);
- end
-
- --[[if app.club_php.isArena and app.club_php.isArena == 2 then
- self.toolView.ui.Items.Layout_ClubInvite:setVisible(false);
- end--]]
-
- self.toolView.ui.Items.Layout_Btn:requestDoLayout()
- self.toolView.ui.Items.Layout_Btn:doLayout()
- end
-
-
- function PKRoomView:bindAllEvent()
- --[[
- 消息分类管理
- ]]
- --用户状态(包括准备,其他玩家进入或者离开通知,离线等)
- self:bindUserStatedMessage()
-
- --私人场消息(包括解散等)
- self:bindPrivateMessage()
-
- --游戏消息
- self:bindGameMessage()
-
- --游戏场景消息
- self:bindGameSceneMessage()
-
- --绑定更换桌布事件
- self:bindEvent(app , PKDef.PKEvent.OnChangeTable , handler(self , self.onChangeTable));
- end
-
- function PKRoomView:onChangeTable(data)
- local idx = data.idx
- self:setTableImg(idx)
- end
-
-
- function PKRoomView:setTableImg(idx)
- local name = string.format("pk_base/res/ui/zy_fangjian/bg/pk_common_bg_%d.jpg",idx)
- --桌布
- self.ui.Items.ImageView_bg:loadTexture(name)
- local cacheGameBgPic = "gameBgPicture"..(PKDef.GameID or app.gameId)
- saveUserInfo(cacheGameBgPic,idx)
-
- --改变水印
- self:changeLogo(idx)
- end
-
- function PKRoomView:changeLogo(idx)
- --[[ local name = nil
- local config = getSubGameConfig(29)
- -- if idx == 6 then
- -- name = "pk_base/res/ui/zy_fangjian/pk_roomtitle_2.png"
- -- if config.gameDataConfig and config.gameDataConfig.logo2 then
- -- name = config.gameDataConfig.logo2
- -- end
- -- else
- name = "pk_base/res/ui/zy_fangjian/pk_roomtitle_1.png"
- if config.gameDataConfig and config.gameDataConfig.logo1 then
- name = config.gameDataConfig.logo1
- end
- -- end
-
- --桌布
- self.ui.Items.ImageView_Logo:loadTexture(name)--]]
- self:initLogo()
- end
-
-
- function PKRoomView:initLogo()
- if tolua.isnull(self.ui.Items.ImageView_Logo) then
- return
- end
-
- if not (type(getSubGameRoomLogo) == 'function') then
- self.ui.Items.ImageView_Logo:setVisible(false)
- return
- end
-
- local roomInfo = app.room.roomInfo
- local gameInfo = json.decode(roomInfo.strGameInfo or "")
- local gamerule = tonumber(gameInfo.gamerule or 0)
- roomInfo.gameId = roomInfo.gameId or app.gameId or 0
- local logofile = getSubGameRoomLogo(roomInfo.gameId, gamerule)
- if logofile then
- self.ui.Items.ImageView_Logo:loadTexture(logofile)
- self.ui.Items.ImageView_Logo:setVisible(true);
- else
- self.ui.Items.ImageView_Logo:setVisible(false);
- end
- end
-
- --用户状态消息
- function PKRoomView:bindUserStatedMessage()
- --默认状态
- self:bindEvent(app.room , PKDef.PKEvent.DefaultState , handler(self , self.defaultState));
- -- 玩家准备
- self:bindEvent(app.room , PKDef.PKEvent.OnUserReadyResponse , handler(self , self.onUserReadyResponse));
- -- 其他玩家进入房间
- self:bindEvent(app.room , PKDef.PKEvent.OnOtherSitDownResponse , handler(self , self.onOtherSitDownResponse));
- -- 其他玩家退出房間
- self:bindEvent(app.room , PKDef.PKEvent.OnOtherLogoutResponse , handler(self , self.onOtherLogoutResponse));
- -- 其他玩家掉线
- self:bindEvent(app.room , PKDef.PKEvent.OnOtherDroppedResponse , handler(self , self.onOtherDroppedResponse));
- -- 用户T出
- self:bindEvent(app.room , PKDef.PKEvent.OnUserExitResponseRoom , handler(self , self.onUserExitResponseRoom));
-
- -- 玩家的GPS信息发生变化
- --self:bindEvent(app.room , PKDef.PKEvent.OnServerChangeUserInfo , handler(self , self.onServerChangeUserInfo));
-
- self:bindEvent(app.room, PKDef.PKEvent.BraodcastFastStart , handler(self, self.onBroadcastFaststart));
-
- self:bindEvent(app.room, PKDef.PKEvent.FastStartSucc , handler(self, self.onFastStartSucc));
-
- end
-
- --私人场消息
- function PKRoomView:bindPrivateMessage()
- -- 玩家收到解散房间的请求
- self:bindEvent(app.room , PKDef.PKEvent.OnDismissResponse , handler(self , self.onDismissResponse));
- end
-
- --游戏消息
- function PKRoomView:bindGameMessage()
- -- 游戏开始
- self:bindEvent(app.room , PKDef.PKEvent.OnGameStartResponse , handler(self , self.onGameStartResponse));
- --游戏状态更新
- self:bindEvent(app.room , PKDef.PKEvent.OnGameUpdateStatus , handler(self , self.onGameUpdateStatus));
- --包牌
- self:bindEvent(app.room , PKDef.PKEvent.OnBaoPaiStartBroad , handler(self , self.onBaoPaiStartBroad));
-
- self:bindEvent(app.room , PKDef.PKEvent.OnBaoPaiResponse , handler(self , self.onBaoPaiResponse));
- self:bindEvent(app.room , PKDef.PKEvent.OnGameBankerChange , handler(self , self.onGameBankerChange));
- self:bindEvent(app.room , PKDef.PKEvent.OnPlayerBaoPaiResult , handler(self , self.onPlayerBaoPaiResult));
- self:bindEvent(app.room , PKDef.PKEvent.OnBroadCastNoPlayPlayer , handler(self , self.onBroadCastNoPlayPlayer));
- self:bindEvent(app.room , PKDef.PKEvent.OnBroadCastBankerCallCard , handler(self , self.onBroadCastBankerCallCard));
- self:bindEvent(app.room , PKDef.PKEvent.OnGameBankerSendCallCardResponse , handler(self , self.onGameBankerSendCallCardResponse));
- self:bindEvent(app.room , PKDef.PKEvent.OnFriendAppear , handler(self , self.onFriendAppear));
- self:bindEvent(app.room , PKDef.PKEvent.OnOutCardRanking , handler(self , self.onOutCardRanking));
- -- 开始给桌子上用户发牌
- self:bindEvent(app.room , PKDef.PKEvent.OnGameSendCardResponse , handler(self , self.onGameSendCardResponse));
- -- 出牌通知
- self:bindEvent(app.room , PKDef.PKEvent.OnBroadPlayerOutCard, handler(self , self.onBroadPlayerOutCard));
- -- 出牌错误
- self:bindEvent(app.room , PKDef.PKEvent.OnOutCardError, handler(self , self.onOutCardError));
- -- 出牌成功
- self:bindEvent(app.room , PKDef.PKEvent.OnOutCardSuccess, handler(self , self.onOutCardSuccess));
-
- self:bindEvent(app.room , PKDef.PKEvent.OnGameXiaoJuResponse , handler(self , self.onGameXiaoJuResponse));
- self:bindEvent(app.room , PKDef.PKEvent.OnGameDaJuResponse , handler(self , self.onGameDaJuResponse));
- --托管结果
- self:bindEvent(app.room , "onTuoGuanResponse",handler(self , self.onTuoGuanResponse));
- end
-
- --场景恢复
- function PKRoomView:bindGameSceneMessage()
- local function onEnterRoomSuccess(event)
- if tolua.isnull(self.ui) then
- logE("self.is null")
- return
- end
- self:stopAllActions()
- self:defaultState()
- self:onGameReconnection()
- self:startGame()
- end
- app.hall:addEventListener(PKDef.PKEvent.OnEnterRoomSuccess, onEnterRoomSuccess)
- end
-
- function PKRoomView:onBroadcastFaststart(data)
- local response = data.response
- if self.startView then
- local function callTip(txt)
- showTooltip(txt)
- end
- self.startView:updateState(response, callTip)
- else
- --“有玩家进入房间” 和 “超时未作出选择”,快速开始中断
- if data.response.optType == 5 or data.response.optType == 6 then
- return
- end
- local function callback()
- self.startView = nil
- end
- self.startView = import("pk_base.luaScript.Views.Room.PKRoomStartWaitView"):new(response,callback);
- self.startView:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(self.startView);
- end
- end
-
- function PKRoomView:onFastStartSucc(data)
- if self._fastRequestView then
- self._fastRequestView:removeSelf()
- end
- self.PlayerView:setPlayerVisible(false)
- self:updateRoomBaseData()
- end
-
- --自己的视图ID
- function PKRoomView:getMeViewId()
- return PKDef.MyViewID
- end
-
- function PKRoomView:onGameSendCardResponse()
- local function runGameSendCardResponse(onEnd)
- log("2000000000-PKRoomView - runGameSendCardResponse()")
- --发牌
- self:createCard(true,app.user.loginInfo.uid,onEnd)
- end
- log("2000000000-PKRoomView - addCallBack(runGameSendCardResponse)" )
- self:addCallBack(runGameSendCardResponse);
- end
-
- function PKRoomView:createCard(bShowAnimation,nUserID,onEnd)
- logD("====================RoomView:createCard()===================");
-
- local cardList = app.room.cards[nUserID]
-
- if not cardList or table.nums(cardList) <= 0 then
- --重连当自己没有手牌
- return
- end
-
- local function sortFunc(a,b)
- return tonumber(PKFuc.getCardValue(a)) < tonumber(PKFuc.getCardValue(b))
- end
-
- logD("cardList:",table.tostring(cardList))
- table.sort(cardList,sortFunc)
-
- --重新调整
- local tt = {};
- for i = table.nums(cardList),1,-1 do
- table.insert(tt,cardList[i])
- end
-
- logE("createCard Rank ok :"..table.tostring(tt))
-
- local index = 1
- self.ui.Items.LayoutMain_4:removeAllChildren();
-
- local max = table.nums(tt)
-
- local mSprite = cc.ImageView:createNode();
- mSprite:loadTextureFromPlist("pk_cards_0_1.png")
- self.cardWidth = mSprite:getContentSize().width
-
- --不管有无数据,默认创建10列数据
- for i = 1,4 do
- self.leftCardNum[i] = max
- end
- for i = 1,max do
- local value = tt[i] or 0
- local isShowFlag = nUserID == app.room.roomInfo.nBankerUserId and i == max
- local card = PKRoomCard:new(value,i,isShowFlag)
- local pos = cc.p(self.ui.Items.Layout_StartPos:getPositionX() + (i - max / 2) * (self.cardWidth - self.cardInterval), self.ui.Items.Layout_StartPos:getPositionY());
- card.ui:setPosition(pos)
- self.ui.Items.LayoutMain_4:addChild(card.ui,1)
-
- --数据记录
- self.handCardRoot[i] = card
- self.handCardValueLocal[i] = value
-
- --存储所有的单牌节点Image
- self.handCardItem[index] = card.imgList
- index = index + 1
- end
-
- logD("create card finish self.handCardValueLocal : "..table.tostring(self.handCardValueLocal))
-
- if bShowAnimation then
- self:showGetCardAni(onEnd)
- else
- --注册点击
- self:registerCardTouch()
- --排序
- self:RankCard(true)
-
- if onEnd then
- onEnd()
- end
- end
- end
-
- -- 发牌动画
- function PKRoomView:showGetCardAni(onEnd)
- local screenWidth = getWinSize().width;
- local max = table.nums(self.handCardItem)
- local function secondAction()
- local index2 = 0;
- for j = max,1,-1 do
- local card = self.handCardItem[j];
- local seq2 = cc.Sequence:create(cc.DelayTime:create(0.03 * (max - j)),
- cc.CallFunc:create(function ()
- PKFuc.logCard(card.value);
- local fileName = PKFuc.getPKCardImgByValue(card.value);
- card:loadTextureFromPlist(fileName);
- end), cc.CallFunc:create(function ()
- index2 = index2 + 1;
- if index2 == max then
- logD("only do once!")
- --注册点击
- self:registerCardTouch();
- --排序
- self:RankCard();
- if app.room.roomInfo.playerList then
- for k,v in pairs(app.room.roomInfo.playerList) do
- local nUserID = v.nUserId
- local viewId = app.room:getViewIdByUserId(nUserID)
- --显示剩余牌
- self.PlayerView:setLeftCardNum(viewId,true,self.leftCardNum[viewId])
- end
- end
- if onEnd then
- onEnd();
- end
- end
- end))
- card:getParent():runAction(seq2);
- end
- end
-
- local index = 0;
- for i = 1, max do
- local card = self.handCardItem[i];
- card:getParent():setOpacity(0);
- local srcPos = card:getParent():getPosition();
-
- local fileName = PKFuc.getPKCardImgByValue(0xff);
- card:loadTextureFromPlist(fileName);
- card:getParent():setPositionX(screenWidth + 800);
-
- local time = 0.1;
- local spawn = cc.Spawn:create(cc.FadeIn:create(time), cc.MoveTo:create(time, srcPos));
- local seq = cc.Sequence:create(cc.DelayTime:create(0.1 * i), cc.CallFunc:create(function ()
- PKSound.PlayGetCard()
- end),spawn,cc.CallFunc:create(function ()
- index = index + 1
- if index == max then
- logD("first action only do once!")
- secondAction();
- end
- end));
- card:getParent():runAction(seq);
- end
- end
-
- --牌UI调整
- function PKRoomView:RankCard(isNotShowAni)
- --如果列小于最大列数则需要调整UI
- local showColNum = self:getVisibleCardLayoutNum()
- if showColNum == 0 then
- return
- end
- local tpYouCount = 1
- local handCardRootTemp = {}
- local handCardValueLocalTemp = {}
-
- for k = 1,table.nums(self.handCardValueLocal) do
- if self.handCardValueLocal[k] > 0 then
- local tarPos = cc.p(self.ui.Items.Layout_StartPos:getPositionX() + (tpYouCount - showColNum / 2) * (self.cardWidth - self.cardInterval),
- self.ui.Items.Layout_StartPos:getPositionY());
- if true then
- self.handCardRoot[k].ui:setPosition(tarPos)
- else
- self.handCardRoot[k].ui:runAction(cc.MoveTo:create(0.17, tarPos));
- end
- self.handCardRoot[k].imgList.lieshu = tpYouCount
- handCardValueLocalTemp[tpYouCount] = self.handCardValueLocal[k]
- handCardRootTemp[tpYouCount] = self.handCardRoot[k]
- self.handCardRoot[k].flag:setVisible(false)
- tpYouCount = tpYouCount + 1;
- end
- end
- self.handCardValueLocal = handCardValueLocalTemp;
- self.handCardRoot = handCardRootTemp;
- local idx = table.nums(self.handCardRoot)
- self.handCardRoot[idx].flag:setVisible(app.room.roomInfo.nBankerUserId == app.room:getMyRecordUserId())
- end
-
- --整理牌
- function PKRoomView:neatenCard(isNotShowAni)
- self:RankCard(isNotShowAni)
- end
-
- function PKRoomView:getVisibleCardLayoutNum()
- local index = 0
- for i,v in ipairs(self.handCardValueLocal) do
- if v > 0 then
- index = index + 1
- end
- end
- return index
- end
-
- --获取该列显示了几个
- function PKRoomView:getRowVisibleCount(lieshu)
- local count = 0
- for k = 1, 4 do
- if self.handCardRoot[lieshu].imgList[k] and self.handCardRoot[lieshu].imgList[k]:isVisible() then
- count = count + 1
- end
- end
- return count
- end
-
- function PKRoomView:resetCardState()
- for i = table.nums(self.handCardItem), 1 do
- local mSprite = self.handCardItem[i];
- mSprite.hit = false;
- mSprite:setColor(PKDef.nomalColor);
- end
- end
-
- --注册点击事件
- function PKRoomView:registerCardTouch()
- local function getPosOO()
- local nodeTouch = self.ui.Items.Layout_Touch;
- local posTouch = nodeTouch:getWorldPosition()
- local poaAnchor = nodeTouch:getAnchorPoint()
- local sizeTouch = nodeTouch:getContentSize();
- local posOO = { x = posTouch.x - sizeTouch.width * poaAnchor.x , y = posTouch.y - sizeTouch.height * poaAnchor.y}
-
- return posOO;
- end
-
- --触摸
- local max = table.nums(self.handCardItem)
- for itemK,itemV in ipairs(self.handCardItem) do
- function onTouchBegan(touch)
- self.beginPos = touch:getLocation();
- PKFuc.logCard(itemV.value);
- --当前滑动选中的牌
- self.hitItem = {};
- table.insert(self.hitItem,itemV)
- self:resetCardState()
- itemV:setColor(PKDef.selectColor)
- itemV.hit = true;
- logD("88888888-=============onTouchBegan================")
- end
-
- function onTouchMove(touch)
- local touchPos = touch:getLocation();
- local dis = touchPos.x - self.beginPos.x;
- local towardRight
- if dis > 0 then
- towardRight = true
- else
- towardRight = false
- end
-
- if math.abs(touchPos.x - self.beginPos.x) < 5 then
- logD("小于5过滤");
- return
- end
- local touchPos = touch:getLocation()
- for i = max, 1, -1 do
- local mSprite = self.handCardItem[i]
- local posNode = mSprite:getParent():convertToNodeSpace(touchPos)
- local width = self.cardInterval
- local height = mSprite:getContentSize().height
- local x = mSprite:getPositionX()
- local y = mSprite:getPositionY()
- local mRect = cc.Rectangle:new(x,y,width,height)
- local cardWorldPos = mSprite:getParent():convertToWorldSpace(mSprite:getPosition())
- --是否朝右
- local isRight = cardWorldPos.x < touchPos.x
- ---如果是朝左,去掉间隔再比较
- if not towardRight then
- isRight = cardWorldPos.x < touchPos.x - width
- end
-
- if mSprite.value == 0 or (mSprite.hit and (isRight == towardRight)) then
- --牌是选中&&滑动的朝向和touchpos.x在牌的左右方向一样,则不计算,也就说,这个牌一直在选中范围里面的,过滤!
- else
- if mRect:contains(posNode.x,posNode.y) and not mSprite.hit then
- if mSprite.value == 0 then
- showTooltip("move 不合法")
- end
- mSprite.hit = true;
- mSprite:setColor(PKDef.selectColor)
- table.insert(self.hitItem,mSprite)
- PKFuc.logCard(mSprite.value)
- break;
- else
- mSprite.hit = false;
- mSprite:setColor(PKDef.nomalColor)
- for idx = 1,table.nums(self.hitItem) do
- if self.hitItem[idx].value == mSprite.value then
- table.remove(self.hitItem,idx)
- break;
- end
- end
- end
- end
- end
- end
-
- function onTouchEnd(touch)
- if not itemV.value then
- return;
- end
- logD("88888888-=============onTouchEnd================")
- logD("self.hitItem.length :", table.nums(self.hitItem));
- self:BanlanceCard();
- end
-
- function onTouchCancel(touch)
- if not itemV.value then
- return
- end
- logD("88888888-=============onTouchCancel================")
- logD("self.hitItem.length :", table.nums(self.hitItem));
- self:BanlanceCard();
- end
-
- itemV:setTouchEnabled(true)
- itemV:registerTouchEvent(onTouchBegan, onTouchMove, onTouchEnd, onTouchCancel)
- end
- end
-
- function PKRoomView:BanlanceCard()
- local tt = {};
- local max = table.nums(self.hitItem)
- for i = 1,max do
- local card = self.hitItem[i];
- local cardValue = card.value;
- table.insert(tt,cardValue)
- PKFuc.logCard(cardValue);
- if card:getPositionY() == self.cardOffY then
- card:setPositionY(0);
- else
- card:setPositionY(self.cardOffY);
- end
- card:setColor(PKDef.nomalColor)
- card.hit = false;
- end
- end
-
- function PKRoomView:sendOutCard()
- local srcList = self:getOutCardList();
- if table.nums(srcList) > 0 then
- local tpLeftIsLai = self:getLeftIsLai(srcList)
- local tpCardInfo = PKFuc.getCardType(srcList)
- --outCardList是多个出牌组合
- local outCardList = PKFuc.getIsCanOutCard(srcList, tpCardInfo, self.shangJiaData)
- if not tpLeftIsLai and outCardList and table.nums(outCardList) > 0 then
- if table.nums(outCardList) > 1 then
- self.operationView:setOperatorPanelView(false)
- self.operationView:setChoiceCardView(true,srcList,outCardList)
- else
- --srcList原始的癞子数据
- --outCardList是癞子转换为具体某个牌的数据
- app.room:requestSendOutCard(1,srcList,outCardList[1])
- local list = {}
- for k,card in ipairs(outCardList[1]) do
- table.insert(list,card)
- end
- --加个排序
- local function sortFunc(a,b)
- return tonumber(PKFuc.getCardValue(a)) < tonumber(PKFuc.getCardValue(b))
- end
-
- table.sort(list,sortFunc)
-
- self:createOutCard(self:getMeViewId(), list, tpCardInfo[1].cardType, false, srcList);
- self.PlayerView:showClockVisible(self:getMeViewId(), false)
- self.operationView:setOperatorPanelView(false)
- end
- else
- showTooltip("你选择的牌不满足规则!请重新选择!");
- end
- else
- showTooltip("请选择牌");
- end
- end
-
- function PKRoomView:sendNoOutCard()
- app.room:requestSendOutCard(0, {},{})
- self.operationView:setOperatorPanelView(false)
- self.PlayerView:showClockVisible(self:getMeViewId(), false)
- self:BanlanceAllCard();
- end
-
- function PKRoomView:onTiShiClick()
- if self.weaveCardList and table.nums(self.weaveCardList) > 0 then
- local function tiShi()
- local weaveList = self.weaveCardList[self.tiShiCount]
- if weaveList then
- self:BanlanceAllCard()
- for j = 1,table.nums(weaveList) do
- local weaveValue = weaveList[j]
- for i = 1, table.nums(self.handCardItem) do
- local sprite = self.handCardItem[i]
- local value = sprite.value;
- if value == weaveValue then
- sprite:setPositionY(self.cardOffY);
- end
- end
- end
- self.tiShiCount = self.tiShiCount + 1;
- else
- self.tiShiCount = 1;
- tiShi();
- end
- end
- tiShi();
- else
- self:sendNoOutCard()
- end
- end
-
- function PKRoomView:createOutCard(viewId, outCardList, cardType, isReconet, srcList, onEnd)
- if viewId == self:getMeViewId() and not isReconet then
- --删除原有的数据
- for j = 1, table.nums(srcList) do
- local card = srcList[j]
- for i = 1, table.nums(self.handCardValueLocal) do
- local value = self.handCardValueLocal[i];
- if value == card then
- self.handCardValueLocal[i] = 0;
- break;
- end
- end
- end
- --UI隐藏
- for j = 1, table.nums(srcList) do
- local card = srcList[j]
- for i = 1, table.nums(self.handCardItem) do
- local cardLocal = self.handCardItem[i]
- if card == cardLocal.value then
- cardLocal:setVisible(false)
- cardLocal:setOpacity(255)
- cardLocal:setPositionY(0);
- cardLocal.value = 0;
- cardLocal.lieshu = nil;
- cardLocal.hit = false;
- break;
- end
- end
- end
- --重新排序
- self:RankCard();
- end
-
- -- 清理所有玩家的牌
- for i = 1, PKDef.GameMaxPlayer do
- self:cleanOutCardByViewId(i)
- end
-
- --清理当前玩家的桌面牌
- local layout = self.outCardList[viewId]
- layout:removeAllChildren()
-
- local nUserId = app.room:getUserIdByViewId(viewId)
- local value;
- --创建牌到屏幕
- if outCardList and table.nums(outCardList) > 0 then
- for i = 1, table.nums(outCardList) do
- local mSprite = self.ui.Items.Layout_CardItem:getCopied()
- mSprite.Items = getUIItems(mSprite)
- local finalFileName = PKFuc.getPKCardImgByValue(outCardList[i])
- mSprite.Items.ImageView_CardItem:loadTextureFromPlist(finalFileName)
- local size = mSprite:getContentSize()
- if app.room.roomInfo.nBankerUserId ~= nUserId then
- mSprite.Items.ImageView_BankerFlag:setVisible(false)
- end
- layout:addChild(mSprite)
- end
-
- layout:requestDoLayout()
- layout:doLayout()
-
- local first = outCardList[1]
- value = PKFuc.getCardValue(first)
- end
- local userInfo = app.room:getUserInfo(nUserId)
- --播放动画
- if cardType and not isReconet then
- if cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SINGLE or cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_DUIZI then
- PKSound.playVoiceCardValue(userInfo.sex,PKFuc.getCardValue(srcList[1]),cardType)
- self.ui:runAction(
- cc.Sequence:create(
- cc.DelayTime:create(0.2),
- cc.CallFunc:create(function ()
- if onEnd then
- onEnd()
- end
- end)
- )
- )
- elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SANZHANG then
- PKAnimationCompnent.playBoomAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
- PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
- elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUNZI then
- PKAnimationCompnent.playShunZiAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
- PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
- elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUANGSHUN then
- PKAnimationCompnent.playBanZiPaoAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
- PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
- elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SANSHUN then
- PKAnimationCompnent.playGunTongAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
- PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
- elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SISHUN then
- PKAnimationCompnent.playGunLongAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
- PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
- elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_BOMB then
- PKAnimationCompnent.playQingDanAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
- PKSound.playVoiceCardValue(userInfo.sex,PKFuc.getCardValue(srcList[1]),cardType)
- elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_TIANPAI then
- PKAnimationCompnent.playTianPaiAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
- PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
- else
- if onEnd then
- onEnd()
- end
- end
- else
- if onEnd then
- onEnd()
- end
- end
- end
-
- function PKRoomView:playTianPaiAnimation(nUserId, callback)
- local viewId = app.room:getViewIdByUserId(nUserId)
- local userInfo = app.room:getUserInfo(nUserId)
- PKAnimationCompnent.playTianPaiAnimation(
- self.ui.Items.Layout_Touch,
- self.outCardList[viewId]:getPosition(),
- viewId,
- function ()
- if callback then
- callback()
- end
- end
- )
- PKSound.playVoiceCardValue(userInfo.sex, 0, PKDef.CARD_TYPE.BANZIPAO_TYPE_TIANPAI)
- end
-
- --播放报警动画
- function PKRoomView:playBaoJingAni(viewId)
- if viewId ~= PKDef.MyViewID then
- self.PlayerView:showBaoJingAni(viewId)
- end
- end
-
- --通知出牌
- function PKRoomView:onBroadPlayerOutCard(data)
- local function runonBroadPlayerOutCard(onEnd)
- local response = data.response
- logD("PKRoomView:runonBroadPlayerOutCard(), response = ", table.tostring(response))
- local nUserId = response.nUserId;
- local opType = response.opType;
-
- self.PlayerView:hideAllPopText()
-
- if self.isFristOutCard then
- self.isFristOutCard = false
- self.PlayerView:setOperatorTipVisible()
- end
-
- local viewId = app.room:getViewIdByUserId(nUserId)
- self.outCardOpType = opType;
- self.weaveCardList = {};
- self.tiShiCount = 1;
-
- self.PlayerView:showClockVisible(viewId,true,PKDef.OpTime.OUTCARD)
-
- --清理桌面牌
- self:cleanOutCardByViewId(viewId);
-
- if viewId == self:getMeViewId() then
- self.operationView:setOperatorPanelView(true,opType)
- -- self:BanlanceAllCard();
- if opType == 2 then
- self:resetShangJiaData()
- --清理桌面牌
- for i = 1, PKDef.GameMaxPlayer do
- self:cleanOutCardByViewId(i);
- end
- end
- self:initTipData()
-
-
-
- --判断是不是最后一手牌
- --local handList = self:getMyHandCardList();
- --[[local cardType = PKFuc.getCardType(handList);
- local bLast = PKFuc.getIsCanOutCard(handList, cardType, self.shangJiaData);
- local isHaveBoom = PKFuc.getIsHaveBoom(handList);
- if bLast and cardType ~= PKDef.CARD_TYPE.LANDLORD_TYPE_NULL and not isHaveBoom then
- logD("-------------------是最后一手牌-----------------------")
- self.ui:runAction(cc.Sequence:create(
- cc.DelayTime:create(0.5),
- cc.CallFunc:create(function ()
- self:letMyHandCardUp()
- self:sendOutCard()
- end)))
- end--]]
- else--如果不是自己出牌,隐藏出牌按钮
- self.operationView:setOperatorPanelView(false)
- end
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonBroadPlayerOutCard)")
- self:addCallBack(runonBroadPlayerOutCard)
- end
-
- function PKRoomView:initTipData()
- if self.operationView.ui.Items.Button_Tip:isVisible() and 0 == table.nums(self.weaveCardList) then
- logD("self.shangJiaData:",table.tostring(self.shangJiaData))
- logD("self.handCardValueLocal:",table.tostring(self.handCardValueLocal))
- self.weaveCardList = PKFuc.getTip(self.handCardValueLocal, self.shangJiaData)
- end
- end
-
- function PKRoomView:letMyHandCardUp()
- local tt = {};
- for i = table.nums(self.handCardItem),1,-1 do
- local mSprite = self.handCardItem[i];
- if mSprite.value then
- mSprite:setPositionY(self.cardOffY);
- mSprite:setOpacity(0);
- end
- end
-
- return tt;
- end
-
- function PKRoomView:getMyHandCardList()
- local tt = {};
- for i = table.nums(self.handCardItem),1,-1 do
- local mSprite = self.handCardItem[i];
- if mSprite.value then
- table.insert(tt,mSprite.value)
- end
- end
-
- return tt;
- end
-
- function PKRoomView:cleanOutCardByViewId(viewId)
- local layout = self.ui.Items["Layout_outCard_"..viewId];
- if layout then
- layout:removeAllChildren();
- end
- end
-
- function PKRoomView:BanlanceAllCard()
- for i = 1,table.nums(self.handCardItem) do
- local card = self.handCardItem[i];
- if card:getPositionY() == self.cardOffY then
- card:setPositionY(0);
- end
- card:setColor(PKDef.nomalColor)
- card.hit = false;
- end
- end
-
- function PKRoomView:getOutCardList()
- local tt = {};
- for i = table.nums(self.handCardItem),1,-1 do
- local mSprite = self.handCardItem[i]
- if mSprite.value and mSprite:getPositionY() == self.cardOffY then
- table.insert(tt,mSprite.value)
- PKFuc.logCard(mSprite.value)
- end
- end
-
- return tt;
- end
-
- function PKRoomView:getLeftIsLai(outCardList)
- local tt = {};
- tt[14] = 0; --14(0xe花牌)
- tt[0] = 0; --计数
-
- --手上的牌
- for i = 1, table.nums(self.handCardRoot) do
- local tpValue = PKFuc.getCardValue(self.handCardRoot[i].imgList.value)
- tt[tpValue] = tt[tpValue] or 0
- tt[tpValue] = tt[tpValue] + 1
- tt[0] = tt[0] + 1
- end
-
- --手上的牌 - 翘起来的牌
- for _i = 1,table.nums(outCardList) do
- local _tpValue = PKFuc.getCardValue(outCardList[_i])
- if 0 ~= tt[_tpValue] then
- tt[_tpValue] = tt[_tpValue] - 1
- tt[0] = tt[0] - 1
- else
- logD("getLeftIsLai error not find handCard : "..tostring(outCardList[_i]))
- end
- end
- --tt为得到为翘起来的牌,14为癞子,如果癞子的数量等于总的数量,证明剩下的全是癞子
- return tt[14] > 0 and tt[14] == tt[0]
- end
-
- --出牌错误
- function PKRoomView:onOutCardError(data)
- local function runOnOutCardError(onEnd)
- logE("PKRoomView:onOutCardError(), response = ", table.tostring(data.response))
- log("2000000000-PKRoomView - runOnOutCardError")
- local errorType = data.response.errorType
- local cards = data.response.cards
- local nUserId = data.response.nUserId
- local viewId = app.room:getViewIdByUserId(nUserId)
- if viewId == self:getMeViewId() then
- showTooltip("你选择的牌不满足规则!请重新选择哦!!!")
- --清楚桌面的牌
- self:cleanOutCardByViewId(viewId);
- self.operationView:setOperatorPanelView(true,self.outCardOpType);
- --视为超时了
- self.PlayerView:showClockVisible(viewId, true, PKDef.OpTime.OUTCARD);
- --
- for k,v in pairs(cards) do
- table.insert(self.handCardValueLocal,v.card)
- end
-
- local card = DeepCopy(self.handCardValueLocal)
-
- self.ui.Items.LayoutMain_4:removeAllChildren();
- self.handCardItem = {}
- self.handCardValueLocal = {}
- self.handCardRoot = {}
- app.room.cards[nUserId] = {}
- app.room.cards[nUserId] = card
- self:createCard(false, nUserId, null);
- end
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runOnOutCardError)")
- self:addCallBack(runOnOutCardError)
- end
-
- --出牌成功
- function PKRoomView:onOutCardSuccess(data)
- logD("PKRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
- local function runOnOutCardSuccess(onEnd)
- log("2000000000-PKRoomView - runOnOutCardSuccess")
- local response = data.response
- --出牌者ID
- local nUserId = response.nUserId
- --操作类型 0 pass 1 出牌
- local opType = response.opType
- --牌型
- local cardsType = response.cardsType
- --剩余手牌数
- local leftNum = response.leftNum
- --原始数据
- local cardList = app.room:getCardList(response.cardList)
- --解析了癞子后的数据
- local cardList2 = app.room:getCardList(response.cardList2)
- local viewId = app.room:getViewIdByUserId(nUserId)
-
- if opType == 0 then
- self.PlayerView:showOperatorTip(viewId,opType,true)
- if onEnd then
- onEnd()
- end
- return
- end
-
- self:resetShangJiaData()
- self.shangJiaData.cardList = cardList2;
- self.shangJiaData.cardType = cardsType;
- self.shangJiaData.nUserId = nUserId;
-
- --显示剩余手牌数
- self.leftCardNum[viewId] = leftNum
- self.PlayerView:setLeftCardNum(viewId,true,self.leftCardNum[viewId])
- local userInfo = app.room:getUserInfo(nUserId)
- if leftNum > 0 and leftNum <= 3 then
- PKSound.PlayLeftNumSound(userInfo.sex,leftNum)
- end
-
- if leftNum <= 3 then
- self:playBaoJingAni(viewId)
- end
-
- if viewId ~= self:getMeViewId() or self.isRecord then
- local tpCardInfo = PKFuc.getCardType(cardList)
- if tpCardInfo[1] and tpCardInfo[1].cardType and tpCardInfo[1].cardType == 0 then
- cardsType = tpCardInfo[1].cardType
- end
- --判断是不是天牌
- self:createOutCard(viewId,cardList2,cardsType,false,cardList,onEnd)
- else
- if self.isTuoGuan then--如果是托管状态需要删除一次手牌
- self:createOutCard(viewId,cardList2,cardsType,false,cardList,nil)
- end
- self.operationView:setOperatorPanelView(false)
- if onEnd then
- onEnd()
- end
- end
- end
- log("2000000000-PKRoomView - addCallBack(runOnOutCardSuccess)")
- self:addCallBack(runOnOutCardSuccess)
- end
-
- --[[
- outCard:出的牌
- ]]
- function PKRoomView:IsTingPaiCard(outCard)
- if outCard then
- local data = self.tingCardLocal[outCard]
- if data then
- --标记只听模式
- self.isNoCardTingPai = true
- else
- self.isNoCardTingPai = false
- end
- self.tingCardLocal = {}
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- local card = self.handCardRoot[col].imgList[row]:getChildren()[1]
- if card then
- self.handCardRoot[col].imgList[row]:getChildren()[1]:setVisible(false)
- end
- end
- end
- end
- end
-
-
- function PKRoomView:addCallBack(callback)
- table.insert(self.callbackQueue, callback)
- logE(" #self.callbackQueue:".. #self.callbackQueue)
- --高延迟情况下,执行快速播放,15条是没有标准,根据实际调整的
- --if #self.callbackQueue >= 15 then
- --cc.Director:getInstance():getScheduler():setTimeScale(5.0)
- --else
- cc.Director:getInstance():getScheduler():setTimeScale(1.0)
- --end
- local function runFunc()
-
- log("2000000000 - runNextFunc() size = ", #self.callbackQueue )
-
- if #self.callbackQueue <= 0 then
- self.callbackRunning = false
- return
- end
-
- --logE("2000000001 - ", debug.traceback())
-
- local func = self.callbackQueue[1]
- table.remove(self.callbackQueue,1)
- self.callbackRunning = true
- func(function()
- self.callbackRunning = false;
- runFunc();
- end)
- end
- log("self.callbackRunning:",self.callbackRunning)
- if not self.callbackRunning then
- runFunc();
- end
- end
-
- -- 其他玩家坐下成功
- function PKRoomView:onOtherSitDownResponse(data)
- if not data or not data.nSeatShowId then
- return
- end
-
- local nSeatShowId = data.nSeatShowId;
- local nUserId = app.room:getUserIdByViewId(nSeatShowId)
- if self.toolView.chatView then
- self.toolView.chatView:addPlayer(nUserId)
- end
-
- self:onUserReadyResponse()
-
- -- 是否显示邀请好友
- self:setWetChatVisible(table.nums(app.room.roomInfo.memberList) < PKFuc.getCreateRoomPlayerNum())
- self:setBtnClubInviteVisible(table.nums(app.room.roomInfo.memberList) < PKFuc.getCreateRoomPlayerNum())
-
- if app.room.roomInfo.nGameStartCount > 0 then
- self:setWetChatVisible(false)
- self:setBtnClubInviteVisible(false)
- end
-
- self.toolView:showFastStart(true)
-
- if self.startView then
- local userInfo = app.room:getUserInfo(nUserId);
- userInfo = type(userInfo) == "string" and json.decode(userInfo) or userInfo
- showTooltip("中途有【" .. getSubStringNickname(userInfo.nickname) .. "】玩家加入,申请开始系统自动关闭!")
- self.startView:cleanup()
- end
- end
-
- function PKRoomView:onOtherLogoutResponse(data)
- local jushu = app.room.roomInfo.nGameStartCount or 0
- if (not data or not data.nUserId or not data.nSeatShowId) or jushu > 0 then
- logD("88888-return onOtherLogoutResponse")
- return
- end
-
- if self.toolView.chatView then
- self.toolView.chatView:delPlayer(data.nUserId)
- end
-
- local function test(onEnd)
- app.room:updateUserSeateShowId()
-
- -- 是否显示邀请好友
- self:setWetChatVisible(app.room:getCurMaxPlayer() < PKFuc.getCreateRoomPlayerNum())
- self:setBtnClubInviteVisible(app.room:getCurMaxPlayer() < PKFuc.getCreateRoomPlayerNum())
-
- if app.room.roomInfo.nGameStartCount > 0 then
- self:setWetChatVisible(false)
- self:setBtnClubInviteVisible(false)
- end
-
- local memberList = app.room.roomInfo.memberList
- memberList[data.nUserId] = nil
- app.room:updateGpsUserInfo(nil,false)
-
- self:onUserReadyResponse()
-
- self.toolView:showFastStart(true)
- if self.startView then
- self.startView:removeFromParent()
- self.startView = nil
- end
- logD("88888-onOtherLogoutResponse onEnd")
- if onEnd then
- onEnd()
- end
- end
- logD("88888-addCallBack onOtherLogoutResponse")
- self:addCallBack(test)
- end
-
- function PKRoomView:updateGameNums()
- -- 更新当前局数
- local roomInfo = app.room.roomInfo
- local curCount = roomInfo.nGameStartCount or 0
- local str = string.format("局数:%d/%d", curCount, roomInfo.nTotalGameNum)
- self.ui.Items.Text_JuShu:setText(str);
- end
-
- -- 游戏开始
- function PKRoomView:onGameStartResponse()
-
- local function runGameStartResponse(onEnd)
- log("2000000000-PKRoomView - runGameStartResponse()" )
-
- --重置玩家数据
- self:resetGameData()
-
- --写入数据
- for k,v in pairs(app.room.roomInfo.memberList) do
- v.nPlayerFlag = PKDef.USER_STATE.PLAYING
- end
-
- --更新玩家状态状态
- self:onUserReadyResponse()
-
- -- 隐藏邀请好友
- self:setWetChatVisible(false)
- self:setBtnClubInviteVisible(false)
- self.toolView:showFastStart(false)
-
- -- 更新局数
- self:updateGameNums()
-
- --更新分数
- for k,v in pairs(app.room.roomInfo.memberList) do
- local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
- self.PlayerView:updatePlayerInfo(nSeatShowId)
- end
-
- app.room.roomInfo.nBankerUserId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankerSeatId)
- --更新庄家
- self:updateBanker()
-
- self:showOwner();
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runGameStartResponse)")
- self:addCallBack(runGameStartResponse);
- end
-
- function PKRoomView:onBaoPaiResponse(data)
- local function runOnBaoPaiResponese(onEnd)
- log("2000000000-PKRoomView - runOnBaoPaiResponese()")
- local response = data.response
- local errType = response.errType
- --1-轮次错误 2-该玩家已经操作过了
-
- if errType == 1 then
- showTooltip("轮次错误")
- elseif errType == 2 then
- showTooltip("该玩家已经操作过了")
- end
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runOnBaoPaiResponese)" )
- self:addCallBack(runOnBaoPaiResponese);
- end
-
- function PKRoomView:onGameUpdateStatus()
- local function runonGameUpdateStatus(onEnd)
- log("2000000000-PKRoomView - runonGameUpdateStatus()" )
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonGameUpdateStatus)" )
- self:addCallBack(runonGameUpdateStatus);
- end
-
- function PKRoomView:onBaoPaiStartBroad(data)
- local function runonBaoPaiStartBroad(onEnd)
- log("2000000000-PKRoomView - runonBaoPaiStartBroad()" )
- local response = data.response;
- local askUid = response.askUid
- local opType = response.opType
- local viewId = app.room:getViewIdByUserId(askUid)
- --显示闹钟
- self.PlayerView:showClockVisible(viewId,true,PKDef.OpTime.BAOPAI)
-
- if opType == 3 then
- if viewId == self:getMeViewId() then
- self.operationView:setLayoutBaoPaiView(true)
- end
- elseif opType == 4 then
- if viewId == self:getMeViewId() then
- self.operationView:setLayoutFanPaoView(true)
- end
- end
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonBaoPaiStartBroad)" )
- self:addCallBack(runonBaoPaiStartBroad);
- end
-
- function PKRoomView:onGameBankerChange()
- local function runonGameBankerChange(onEnd)
- log("2000000000-PKRoomView - runonGameBankerChange()" )
- self:updateBanker()
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonGameBankerChange)" )
- self:addCallBack(runonGameBankerChange);
- end
-
- function PKRoomView:onPlayerBaoPaiResult(data)
- local function runonPlayerBaoPaiResult(onEnd)
- log("2000000000-PKRoomView - runonPlayerBaoPaiResult()" )
- local response = data.response;
- local askUid = response.askUid
- local opType = response.opType
- local viewId = app.room:getViewIdByUserId(askUid)
- self.PlayerView:showOperatorTip(viewId,opType,true)
- self.PlayerView:showBaoPaiFlag(viewId,opType)
- --记录,查牌用
- local memberInfo = app.room.roomInfo.memberList[askUid]
- if memberInfo then
- memberInfo.baoPai = opType
- end
- if app.room:getMyRecordUserId() == askUid then
- self.operationView:setLayoutBaoPaiView(false)
- self.operationView:setLayoutFanPaoView(false)
- end
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonPlayerBaoPaiResult)" )
- self:addCallBack(runonPlayerBaoPaiResult);
- end
-
- function PKRoomView:onBroadCastNoPlayPlayer(data)
- local function runonBroadCastNoPlayPlayer(onEnd)
- log("2000000000-PKRoomView - runonBroadCastNoPlayPlayer()" )
- local response = data.response
- local uid = response.uid
- local viewId = app.room:getViewIdByUserId(uid)
- if viewId == self:getMeViewId() then
- self.ui.Items.Layout_Wait:setVisible(true)
- end
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonBroadCastNoPlayPlayer)" )
- self:addCallBack(runonBroadCastNoPlayPlayer);
- end
-
- function PKRoomView:onBroadCastBankerCallCard(data)
- local function runonBroadCastBankerCallCard(onEnd)
- log("2000000000-PKRoomView - runonBroadCastBankerCallCard()")
- local response = data.response;
- local nBankerUserId = response.nBankerUserId;
- local noCards = response.noCards;
- local viewId = app.room:getViewIdByUserId(nBankerUserId)
- self.PlayerView:setOperatorTipVisible()
- self.PlayerView:showClockVisible(viewId,true,PKDef.OpTime.CALLCARD)
- self.operationView:setCallCardView(true,noCards)
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonBroadCastBankerCallCard)" )
- self:addCallBack(runonBroadCastBankerCallCard);
- end
-
- function PKRoomView:onGameBankerSendCallCardResponse(data)
- local function runonGameBankerSendCallCardResponse(onEnd)
- log("2000000000-PKRoomView - runonGameBankerSendCallCardResponse()" )
- local response = data.response;
- local nBankerUserId = response.nBankerUserId;
- local callCard = response.card;
- app.room.roomInfo.cAskCard = callCard
- local viewId = app.room:getViewIdByUserId(nBankerUserId)
- self.PlayerView:setAllClockVisible()
- self.operationView:setCallCardView(true,nil,callCard)
- self:showFriendFlag()
-
- --音效
- local userInfo = app.room:getUserInfo(nBankerUserId)
- PKSound.PlayJiaoPaiSound(userInfo.sex)
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonGameBankerSendCallCardResponse)" )
- self:addCallBack(runonGameBankerSendCallCardResponse);
- end
-
- function PKRoomView:showFriendFlag()
- local list = self:getMyHandCardList()
- local firendList = {}
- local enemyList = {}
- for k,v in ipairs(list) do
- if v == app.room.roomInfo.cAskCard then
- local nbankerViewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerUserId)
- for k,v in pairs(app.room.roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- if viewId == self:getMeViewId() or viewId == nbankerViewId then
- table.insert(firendList,viewId)
- else
- table.insert(enemyList,viewId)
- end
- end
- self.PlayerView:showFriendFlag(firendList,enemyList)
- break
- end
- end
- end
-
- function PKRoomView:showMengYouFlag(bAni)
- local firendList = {}
- local enemyList = {}
- local nFriendViewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerHelper)
- local nBankerViewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerUserId)
- for k,v in pairs(app.room.roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- if viewId == nBankerViewId or viewId == nFriendViewId then
- table.insert(firendList,viewId)
- else
- table.insert(enemyList,viewId)
- end
- end
- self.PlayerView:showFriendFlag(firendList,enemyList,bAni)
- end
-
-
- function PKRoomView:onFriendAppear()
- local function runonFriendAppear(onEnd)
- log("2000000000-PKRoomView - runonFriendAppear()" )
- self:showMengYouFlag(true)
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonFriendAppear)" )
- self:addCallBack(runonFriendAppear);
- end
-
- function PKRoomView:onOutCardRanking(data)
- local function runonOutCardRanking(onEnd)
- log("2000000000-PKRoomView - runonOutCardRanking()" )
- local response = data.response
- local nUserId = response.uid
- local ranking = response.ranking
- local viewId = app.room:getViewIdByUserId(nUserId)
- if viewId then
- self.PlayerView:showRanking(viewId,tonumber(ranking))
- self.PlayerView:showBaoJingAni(viewId,true)
- end
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runonOutCardRanking)" )
- self:addCallBack(runonOutCardRanking);
- end
-
- function PKRoomView:setLiangPaiVisible(bVisible)
- --self.xiaojuChaPaiView:setVisible(bVisible)
- end
-
- -- 小局结算
- function PKRoomView:onGameXiaoJuResponse(data)
- self.PlayerView:setAllClockVisible()
- self.PlayerView:setAllBaoJingVisible()
-
- local function runGameXiaoJuResponse(onEnd)
-
- local response = data.response
-
- --标记单局结束
- self.isGameOver = true
-
- local roomInfo = app.room.roomInfo
- local myScore = 0
-
- --玩家分数
- for k,v in pairs(roomInfo.playerList) do
- local viewId = app.room:getViewIdByUserId(k)
- local nScore = tonumber(v.nTotalScore)
- local memberInfo = app.room.roomInfo.memberList[k]
- memberInfo.nTotalScore = nScore
- self.PlayerView:setPlayerScore(viewId,nScore)
-
- if viewId == PKDef.MyViewID then
- myScore = nScore
- end
- end
-
- local function showXiaoJu(noShowSound)
- if self.xiaojuView then
- -- 停止背景音乐
- stopBGMusic()
- self.xiaojuView:setVisible(true)
- if not noShowSound then
- if myScore >= 0 then
- PKSound.PlayWinSound()
- else
- PKSound.PlayLoseSound()
- end
- end
- end
- end
-
- local function showChaPai()
- self.chaPaiView = PKRoomXiaoJuChaPaiView:new(showXiaoJu)
- self:addChild(self.chaPaiView)
- end
-
- local function nextCallBackFun()
- self:resetGameData()
- self:playBGM()
- self.ui:sendMsg(app.room, PKDef.PKEvent.CallReadyRequest);
- end
-
- local function showAllJieSuan()
- if self.RoomCountAllViewUI then
- -- 停止背景音乐
- stopBGMusic()
- self.RoomCountAllViewUI:setVisible(true)
- self:showGameOverAward()
- end
- end
-
- self.xiaojuView = PKRoomXiaoJuView:new(nextCallBackFun,showChaPai,showAllJieSuan)
- self:addChild(self.xiaojuView)
- self.xiaojuView:setVisible(false)
-
- --天牌
- if app.room.roomInfo.mSpecialType == 1 then
- local winerInfo = nil
- for k,v in pairs(app.room.roomInfo.playerList) do
- if v.mWinLose == 1 then
- winerInfo = v
- break
- end
- end
- local viewId = app.room:getViewIdByUserId(winerInfo.nUserId)
- self:playTianPaiAnimation(winerInfo.nUserId,function ()
- showXiaoJu()
- end)
- else
- local time = 2
- if self.isReconet then
- time = 0.001
- end
- self.ui:runAction(cc.Sequence:create(cc.DelayTime:create(time),cc.CallFunc:create(function ()
- showXiaoJu()
- end)))
- end
-
- --结束
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runGameXiaoJuResponse)" )
- self:addCallBack(runGameXiaoJuResponse);
- end
-
- -- 大局结算
- function PKRoomView:onGameDaJuResponse(data)
- local function runGameDaJuResponse(onEnd)
- app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
-
- if data.response.stopFlag == 9 then
- app.room.roomInfo.isShowDismiss = true
- end
-
- if app.room.roomInfo.nGameStartCount == app.room.roomInfo.nTotalGameNum and not app.room.roomInfo.isShowDismiss then
- -- 打开结算
- local view = PKRoomCountAllView:new(data.response);
- view:setAnchorPoint(cc.p(0.5, 0.5));
- local visibleSize = getWinSize()
- view:setPosition(cc.p(visibleSize.width/2,visibleSize.height/2))
- self:addChild(view);
-
- self.RoomCountAllViewUI = view;
- view:setVisible(false);
- else
- -- 打开结算
- local view = PKRoomCountAllView:new(data.response);
- view:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(view)
- stopBGMusic()
- self:showGameOverAward()
- end
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runGameDaJuResponse)")
- self:addCallBack(runGameDaJuResponse);
- end
-
- function PKRoomView:onUserReadyResponse()
- self.PlayerView:setPlayerVisible(false)
- for k,v in pairs(app.room.roomInfo.memberList) do
- local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
- self.PlayerView:setPlayerReadyState(nSeatShowId,(v.nPlayerFlag == PKDef.USER_STATE.READY))
- self.PlayerView:updatePlayerInfo(nSeatShowId)
- end
-
- local nUserId = app.room:getMyRecordUserId()
-
- local memberInfo = app.room.roomInfo.memberList[nUserId]
-
- self:setBtnSitDownVisible(memberInfo.nPlayerFlag == PKDef.USER_STATE.SIT_DOWN)
-
- if app.room.roomInfo.nGameStartCount > 0 then
- self.toolView.ui.Items.Button_Leave:setEnabled(false)
- end
-
- if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= app.user.loginInfo.uid then
- self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
- else
- self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
- end
-
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- if app.room.roomInfo.nGameStartCount <= 0 then
- self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
- else
- self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
- end
- end
-
- -- 显示是否可以解散
- self.toolView:checkCanDismiss()
- end
-
-
- function PKRoomView:onDismissResponse(event)
- if not event or not event.response then
- return
- end
- print("onDismissResponse() response = ", event.response)
-
- local response = event.response
-
- --当前时间
- app.room.roomInfo.nDismissStateTime = response.timeLeft
- --总的时间
- app.room.roomInfo.nDismissToTalTime = response.timeLeft --服务器没发解散总时间来。那么就和一开始收到的解散剩余时间一致
- --显示解散(此标志会影响闹钟时间会冻住)
- app.room.roomInfo.nShowDismiss = true
-
- if response.operateType == 1 then
- if response.memberList ~= nil then
- for k,v in pairs(response.memberList) do
- if v.dismissState == 1 then
- local view = require("luaScript.Views.Room.RoomDismissView"):new(v.nUserId,app.room.roomInfo.memberList,response.timeLeft)
- view:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(view);
- return
- end
- end
- else
- local view = require("luaScript.Views.Room.RoomDismissView"):new(response.nUserId,app.room.roomInfo.memberList,response.timeLeft)
- view:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(view);
- end
- else
- local memberStatus={}
- if response.memberList ~= nil then
- for k,v in pairs(response.memberList) do
- table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
- end
- else
- table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
- end
- app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus});
- end
- end
-
- --更新庄家
- function PKRoomView:updateBanker()
- --只显示当前的庄家座位号
- if app.room.roomInfo.nBankerUserId then
- local viewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerUserId)
- if self.PlayerView:setPlayerBankerVisible(viewId,true) then
-
- else
- showTooltip("庄家椅子号"..tostring(viewId).."不匹配")
- end
- end
- end
-
- --显示房主
- function PKRoomView:showOwner()
- --只显示当前的庄家座位号
- local nBankerSeatId = app.room.roomInfo.nRoomOwnedUid
- local viewId = app.room:getViewIdByUserId(nBankerSeatId)
- self.PlayerView:setPlayerOwnerVisible(viewId,true)
- end
-
- function PKRoomView:onOtherDroppedResponse(data)
- if not data.response.nUserId then
- return
- end
- local nUserId = data.response.nUserId
- local nDroppedStatus = data.response.nDroppedStatus
- local memberInfo = app.room.roomInfo.memberList[nUserId]
- if memberInfo then
- memberInfo.nOnlineStatus = nDroppedStatus == 1 and 0 or 1
- end
- local viewId = app.room:getViewIdByUserId(nUserId)
- --[[app.room.offLineUid[tonumber(nUserId)] = (nDroppedStatus == 1)
- if nDroppedStatus == 0 then--如果上线了 离线时间置0
- app.room.offLineTime[tonumber(nUserId)] = 0
- self.PlayerView:reSetClockTime(viewId)
- end--]]
- self.PlayerView:setPlayerOffLine(memberInfo.nOnlineStatus == 1,viewId)
- end
-
- function PKRoomView:goToHall()
- gotoMainView()
- end
-
- function PKRoomView:onUserExitResponseRoom(data)
- local function runUserExitResponseRoom(onEnd)
- log("2000000000-PKRoomView - runUserExitResponseRoom()" )
- local response = data.response
-
- --房间号
- local roomid = app.room.roomInfo.nShowTableId
-
- -- 0: 不退出, 1: 退出
- if response.logoutFlag == 1 then
- self:goToHall()
- end
- --app.room:dispatchEvent({name = "onUserExitResponseHall"});
- logE("88888-onUserExitResponseRoom onEnd")
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runUserExitResponseRoom)" )
- self:addCallBack(runUserExitResponseRoom);
- end
-
- function PKRoomView:initGpsComponent()
-
- local versionCode = getAppVersionCode()
- versionCode = tonumber(versionCode) or 0
-
- logD("RoomView:initGpsComponent() versionCode = ", versionCode)
-
- if isReviewVersion() then
- self.toolView.ui.Items.Button_dingwei:setVisible(false)
- return
- end
-
- -- 创建 gps 组件
- --self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponent"):new(self.ui.Items.Button_GPS)
-
- local function exitRoomCallback()
- local isGameStart = app.room.roomInfo.nGameStartCount > 0
- if isGameStart then
- app.room:requestDismissRoom(1)
- else
- self.ui:sendMsg(app.room, "callLeaveRequest");
- end
- end
-
- local function dismissCallback()
- app.room:requestDismissRoom(1)
- end
-
- self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(4,self.toolView.ui.Items.Button_dingwei,exitRoomCallback,exitRoomCallback)
- self:addChild(self.gpsComponent)
-
- -- GPS 按钮
- self.toolView.ui.Items.Button_dingwei:registerClick(handler(self, self.showGpsView))
- end
-
- -- 更新所有玩家的信息到GPS组件
- function PKRoomView:updateAllGpsInfo()
- local userInfoList = {}
- log("updateAllGpsInfo memberList:"..table.tostring(app.room.roomInfo.memberList))
- for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do
- local nSeatId = memberInfo.nSeatId
- local userInfo = memberInfo.userInfo
- userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
- end
- if self.gpsComponent then
- self.gpsComponent:updateUserInfos(userInfoList)
- end
- end
-
- -- 显示GPS界面
- function PKRoomView:showGpsView()
- print("RoomView:showGpsView()")
-
- local isGameStart = app.room.roomInfo.nGameStartCount > 0
- if self.gpsComponent then
- self.gpsComponent:showGpsView(isGameStart)
- end
- end
-
- --多维数组转 一维数组
- function PKRoomView:ChangeDataToVector(data)
- local tt = {}
- for i = 1, self.lieShuMax do
- for j = 1, self.hangShuMax do
- if data[i][j] then
- table.insert(tt,data[i][j])
- end
- end
- end
- return tt
- end
-
- function PKRoomView:resetShangJiaData()
- self.shangJiaData = {};
- self.shangJiaData.cardList = {};
- self.shangJiaData.cardType = 0;
- self.shangJiaData.nUserId = 0;
- end
-
- function PKRoomView:setWaitBgVisible(bVisible)
- self.ui.Items.Layout_Wait:setVisible(bVisible)
- end
-
- --显示隐藏托管
- function PKRoomView:showTuoGuan(isShow)
- if isShow then
- if not self.tuoguanView then
- self.tuoguanView = import("pk_base.luaScript.Views.Room.PKRoomTuoGuanView"):new()
- self:addChild(self.tuoguanView)
- end
- else
- if self.tuoguanView and not tolua.isnull(self.tuoguanView) then
- self.tuoguanView:removeFromParent()
- self.tuoguanView = nil
- end
- end
- end
-
- --托管结果协议
- function PKRoomView:onTuoGuanResponse(data)
- local function runTuoGuanResponse(onEnd)
- log("2000000000-PKRoomView - (runTuoGuanResponse)")
- local response = data.response
-
- local entrustType = response.entrustType;--托管状态 1-托管中 0-未托管
- local nUserID = response.nUserId;
- local viewId = app.room:getViewIdByUserId(nUserID)
- local isTuoGuan = entrustType == 1;
- if viewId == self:getMeViewId() then
- if isTuoGuan then
- self:showTuoGuan(true)
- self.isTuoGuan = true
- else
- self:showTuoGuan(false)
- self.isTuoGuan = false
- end
-
- end
- self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
-
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-PKRoomView - addCallBack(runTuoGuanResponse)")
-
- self:addCallBack(runTuoGuanResponse)
- end
- --获取托管状态
- function PKRoomView:getTuoGuanState()
- return self.isTuoGuan or false
- end
-
- ---
- -- 显示抽奖界面
- --
- function PKRoomView:showGameOverAward()
- if not (dd and dd.IGameOverAward) then
- return
- end
- self:runDelay(0.1, function ( )
- -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
- dd.IGameOverAward.showAwardView();
- end)
- end
- return PKRoomView;
|