local RoomCmd=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPCmd") local ZPMessage=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage") local ZPDef=ZPFramework.ZPImport("zp_base.luaScript.ZPDef") local ZPFuc=ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions") local ZPProtocol=ZPFramework.ZPFrameworkClassImprot("zp_base.luaScript.Protocol.ZPProtocol") local Room = class("hejiangRoom" , ZPProtocol) function Room:ctor(net) Room.super.ctor(self , net); end -- 获取房间最大玩家人数 function Room:getMaxPlayerCount() return self.roomInfo.nMaxPlayCount end -- 获取房间人数 function Room:getPlayerCount() local count = 0 for k,v in pairs(self.roomInfo.memberList) do count = count + 1 end return count end -- 重置上局信息 function Room:resetRound() self.roomInfo.quickStartInfo = nil end function Room:resetFastInfo() self.roomInfo.quickStartInfo = nil end function Room:onGameReconnection(status,response) Room.super.onGameReconnection(self,status,response) self:resetRound() local extInfo = json.decode(response.extJson or "") if extInfo and type(extInfo)=='table' and extInfo[tostring(self:getMyUserId())] then local myinfo = extInfo[tostring(self:getMyUserId())] self.roomInfo.hosting = myinfo.hosted or 0--托管状态 self.roomInfo.quickStartInfo = extInfo.faststart--提前开局 else self.roomInfo.hosting = 0 end end --扩展给子类用 function Room:addReconnectionData(response) self.roomInfo.delayPlayer = response.delayPlayer end function Room:isMyself(uid) return uid==self:getMyUserId() end -- 更新玩家的相对椅子号 function Room:updateUserSeateShowId(xiaoSeatId) local myUserId = self:getMyRecordUserId() local mySeatId = self.roomInfo.memberList[myUserId].nSeatId self.roomInfo.nUserId = self:getMyRecordUserId() self.roomInfo.nSeatId = mySeatId --除了自己的第一次seatid辅助 local anotherSeatID = -1 --[视图椅子号] = userID --[座位号] = userID --[userID] = 视图椅子号 self.seatShowList = {} self.userList = {} self.seatList = {} for k,v in pairs(self.roomInfo.memberList) do if v.nUserId and v.nSeatId then local maxNum = 3--ZPFuc.getCreateRoomPlayerNum() local isChange = false if app.room:getActualPlayerNum() >= 3 then maxNum = 4 end local nSeatShowId --= (v.nSeatId - mySeatId + 4) % 4 if mySeatId <= v.nSeatId then nSeatShowId = v.nSeatId - mySeatId elseif mySeatId > v.nSeatId then nSeatShowId = maxNum - mySeatId + v.nSeatId end if app.room:getActualPlayerNum() == 2 then--self.roomInfo.playerNum == 2 then if (v.nSeatId == mySeatId) then nSeatShowId = 4 else nSeatShowId = 1--两人玩时,对家坐哪里 end elseif app.room:getActualPlayerNum() == 3 then if (v.nSeatId == mySeatId) then nSeatShowId = 4 else --local nSeatShowId = (v.nSeatId - mySeatId + 4) % 4 if nSeatShowId == 2 then if mySeatId > v.nSeatId then nSeatShowId = nSeatShowId + 1 isChange = true else isChange = true nSeatShowId = nSeatShowId - 1 end end if nSeatShowId == 0 then if mySeatId > v.nSeatId then nSeatShowId = nSeatShowId + 1 else nSeatShowId = 3 end --[[elseif (nSeatShowId == 1 or nSeatShowId == 3) and anotherSeatID >= 0 then isChange = true--]] end if anotherSeatID < 0 and not isChange then anotherSeatID = v.nSeatId end end elseif app.room:getActualPlayerNum() == 4 then if (v.nSeatId == mySeatId) and (v.nSeatId ~= self.roomInfo.xiaoSeatId) then nSeatShowId = 4 else if xiaoSeatId and xiaoSeatId >=0 and nSeatShowId == 2 then if mySeatId == xiaoSeatId then if math.abs(mySeatId - v.nSeatId) == 2 then nSeatShowId = 4 end elseif mySeatId > v.nSeatId then isChange = true nSeatShowId = nSeatShowId + 1 else isChange = true nSeatShowId = nSeatShowId - 1 end else end if xiaoSeatId and v.nSeatId == self.roomInfo.xiaoSeatId then nSeatShowId = 2 end end --强制转换小家视角与庄家一致 if mySeatId == xiaoSeatId then if nSeatShowId == 1 then nSeatShowId = 3 elseif nSeatShowId == 3 then nSeatShowId = 1 end end end if nSeatShowId == 0 then nSeatShowId = 4 end if v.nUserId == 0 then nSeatShowId = 2 else if self.seatShowList[nSeatShowId] and isChange == true then if nSeatShowId == 1 then nSeatShowId = 3 elseif nSeatShowId == 3 then nSeatShowId = 1 end elseif self.seatShowList[nSeatShowId] and isChange == false then local olduid = self.seatShowList[nSeatShowId] local oldshowid = self.userList[olduid] local newshowid = 0 if nSeatShowId == 1 then newshowid = 3 elseif nSeatShowId == 3 then newshowid = 1 end self.seatShowList[newshowid] = olduid self.userList[olduid] = newshowid end end self.seatShowList[nSeatShowId] = v.nUserId self.seatList[v.nSeatId] = v.nUserId self.userList[v.nUserId] = nSeatShowId end end logD("User:updateUserSeateShowId(), seatShowList", table.tostring(self.seatShowList)) logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList)) logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList)) end return Room;