local skynet = require "skynet" local oo = require "Class" local pb = require "pb" local log = require "Log" local errorInfo = require "ErrorInfo" local dataType = require "DataType" local redisKeyUrl = require "RedisKeyUrl" local sqlUrl = require "SqlUrl" local json = require "json" local serverId = tonumber(skynet.getenv "serverId") local shop = require "Shop" local DoubleSpace = oo.class(shop) DoubleSpace.houseId = 6 --双人空间的房子 DoubleSpace.ShopTypeNo = 12 --友爱商店在配置中的商店ID DoubleSpace.MaxNickNameLen = 21 --最大昵称长度 --初始装修方案列表 DoubleSpace.initDeco = {} --双人空间已经购买的房间id列表rediskey DoubleSpace.doubleSpaceBuyHouseKey = "doubleSpaceBuyHouse" --双人空间已购买的装修方案列表rediskey[% 房间id] DoubleSpace.doubleSpaceBuyDecoKey = "doubleSpaceBuyDecoList_%s" function DoubleSpace:Init() --默认方案 local decorate = {} table.insert( decorate , { facilityType = dataType.DecorateType_Floor , facilityId = 1 , decoId = 25 }) table.insert( decorate , { facilityType = dataType.DecorateType_Floor , facilityId = 2 , decoId = 24 }) table.insert( decorate , { facilityType = dataType.DecorateType_Floor , facilityId = 3 , decoId = 24 }) table.insert( decorate , { facilityType = dataType.DecorateType_WallPaper , facilityId = 1 , decoId = 23 }) table.insert( decorate , { facilityType = dataType.DecorateType_WallPaper , facilityId = 2 , decoId = 23 }) table.insert( decorate , { facilityType = dataType.DecorateType_WallPaper , facilityId = 3 , decoId = 23 }) table.insert( decorate , { facilityType = dataType.DecorateType_Door , facilityId = 1 , decoId = 26 }) table.insert( decorate , { facilityType = dataType.DecorateType_Door , facilityId = 2 , decoId = 26 }) table.insert( decorate , { facilityType = dataType.DecorateType_Bar , facilityId = 1 , decoId = 27 }) table.insert( decorate , { facilityType = dataType.DecorateType_Eave , facilityId = 0 , decoId = 210 }) table.insert( decorate , { facilityType = dataType.DecorateType_OutDeco , facilityId = 0 , decoId = 211 }) --table.insert( decorate , { facilityType = dataType.DecorateType_OutDoorDeco , facilityId = 0 , decoId = 0 }) table.insert( decorate , { facilityType = dataType.DecorateType_OutDoorFloor , facilityId = 0 , decoId = 262 }) DoubleSpace.initDeco[DoubleSpace.houseId]=decorate --阳光友居 local decorate2 = {} table.insert( decorate2 , { facilityType = dataType.DecorateType_WallPaper , facilityId = 1 , decoId = 23 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_WallPaper , facilityId = 2 , decoId = 23 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_WallPaper , facilityId = 3 , decoId = 23 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_WallPaper , facilityId = 4 , decoId = 23 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_WallPaper , facilityId = 5 , decoId = 23 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_WallPaper , facilityId = 6 , decoId = 23 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_Floor , facilityId = 1 , decoId = 24 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_Floor , facilityId = 2 , decoId = 24 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_Floor , facilityId = 3 , decoId = 24 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_Floor , facilityId = 4 , decoId = 24 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_Stair , facilityId = 1 , decoId = 163 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_HandRail , facilityId = 1 , decoId = 164 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_Door , facilityId = 1 , decoId = 26 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_Bar , facilityId = 1 , decoId = 27 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_Eave , facilityId = 0 , decoId = 210 }) table.insert( decorate2 , { facilityType = dataType.DecorateType_OutDeco , facilityId = 0 , decoId = 211 }) DoubleSpace.initDeco[14]=decorate2 end --初始化玩家数据 function DoubleSpace:InitData( player ) local myPlayerId = player.gameData.partner.id skynet.server.personal:SetDetail( myPlayerId ,"doubleSpaceCount", 0 ) end --初始装修 function DoubleSpace:InitDeco(houseId) return self.initDeco[houseId] end --创建双人空间 function DoubleSpace:Cretate( player , otherPartnerId ) local addHouseIdList = {} local myPartnerId = player.gameData.partner.id --添加默认房间 self:AddHouseInfo(player, otherPartnerId , self.houseId,true ) table.insert(addHouseIdList,self.houseId) --检查已购买的房间 local myBuyHouseList = self:GetBuyHouseIdList(myPartnerId) --获取好友购买房间信息 local otherBuyHouseList = self:GetBuyHouseIdList(otherPartnerId) if next(myBuyHouseList) and next(otherBuyHouseList) then for _, myHouseId in ipairs(myBuyHouseList) do for _, otherHouseId in ipairs(otherBuyHouseList) do --共同都有这个房屋 if myHouseId == otherHouseId then --添加房间 self:AddHouseInfo(player, otherPartnerId , myHouseId ) table.insert(addHouseIdList, otherHouseId) --添加装修方案 local myBuyHouseDecList=self:GetBuyHouseDecorateList(myPartnerId, myHouseId) local otherBuyHouseDecList=self:GetBuyHouseDecorateList(otherPartnerId, otherHouseId) if next(myBuyHouseDecList) and next(otherBuyHouseDecList) then for _, myBuyHouseDec in ipairs(myBuyHouseDecList) do for _, otherBuyHouseDec in ipairs(otherBuyHouseDecList) do --共同都有这个装修方案 if myBuyHouseDec == otherBuyHouseDec then --添加装方案 self:AddHouseDeco( player, otherPartnerId , myHouseId ,myBuyHouseDec ) end end end end end end end end skynet.server.personal:SetDetail( myPartnerId ,"isExistDoubleSpace", true) --是否存在双人空间 skynet.server.personal:SetDetail( otherPartnerId ,"isExistDoubleSpace", true) --是否存在双人空间 skynet.server.personal:AccDetail( myPartnerId ,"doubleSpaceCount", 1) --增加双人空间数量 skynet.server.personal:AccDetail( otherPartnerId ,"doubleSpaceCount", 1) --增加双人空间数量 --我同意创建双人间,我增加双人空间户型,解锁该房间主要是在商店里刷出门和护栏 local s2cData ={} for _, tempHouseId in ipairs(addHouseIdList) do skynet.server.house:Add( player , tempHouseId , s2cData , false) end skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_200 , myPartnerId , otherPartnerId ) end --更新双人空间数据到redis,isdwell是否居住 function DoubleSpace:AddHouseInfo(player, otherPartnerId , houseId,isDwell ) isDwell = isDwell or false local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local createTime=skynet.GetTime() local createTimeRedis = skynet.server.redis:hget( myInfoKey , "createTime" ) if type(createTimeRedis) == "number" then createTime=createTimeRedis end local allHouseId=json:encode({ houseId }) local allHouseIdRedisJson = skynet.server.redis:hget( myInfoKey , "allHouseId" ) if allHouseIdRedisJson ~= nil then local allHouseIdRedis=json:decode(allHouseIdRedisJson) --是否存在 local isExist=false --判断是否存在 for _, value in ipairs(allHouseIdRedis) do if value == houseId then isExist = true break end end if not isExist then table.insert(allHouseIdRedis, houseId) end allHouseId=json:encode(allHouseIdRedis) end if isDwell then skynet.server.redis:hmset( myInfoKey , "spaceName", "温馨小家" , --空间名称 "allHouseId" , allHouseId , --所有房间ID "createTime", createTime , --创建时间 self:GetMyKey("curHouseId" , myPartnerId ) , houseId , --我当前房间ID self:GetMyKey("curHouseId" , otherPartnerId ) , houseId , --好友当前房间ID self:GetMyKey("decorates" , houseId ) , json:encode(self:InitDeco(houseId))--, --室内装修 )--self:GetMyKey("furnitures" , houseId ) , json:encode({}) --装修家具信息 --创建的时候才加家具 if houseId ==self.houseId then skynet.server.redis:hmset( myInfoKey , self:GetMyKey("furnitures" , houseId ) , json:encode({}), self:GetMyKey("decoPartnerId" , houseId ) , "" , --当前房间装修玩家) self:GetMyKey("decoStartTime" , houseId ) , 0 ) --当前房间开始装修时间 end else skynet.server.redis:hmset( myInfoKey , "spaceName", "温馨小家" , --空间名称 "allHouseId" , allHouseId , --所有房间ID "createTime", createTime --创建时间 --self:GetMyKey("decorates" , houseId ) , json:encode(self:InitDeco(houseId)) --室内装修 )--self:GetMyKey("furnitures" , houseId ) , json:encode({}) end --添加房屋 self:AddBuyHouseId(player, myPartnerId , houseId ) self:AddBuyHouseId(player, otherPartnerId , houseId ) end --获取双人空间当前房间已有的房间列表 function DoubleSpace:GetDoubleSpaceHouseIdList( player, otherPartnerId ) --房屋 local houseIdList = {} local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local houseIdRedisListJson = skynet.server.redis:hget( myInfoKey ,"allHouseId") --已有的房间 if houseIdRedisListJson== nil then return houseIdList end local houseIdRedisList=json:decode(houseIdRedisListJson) for _, value in pairs(houseIdRedisList) do table.insert( houseIdList , value ) end return houseIdList end --启动房间 function DoubleSpace:StartHouse( player, otherPartnerId ,houseId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --是否启用当前装修方案 skynet.server.redis:hset( myInfoKey ,self:GetMyKey("curHouseId" , myPartnerId ) , houseId ) --已有的装修方案 end --获取当前房间ID function DoubleSpace:GetCurHouseId( myPartnerId , otherPartnerId ) local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local curHouseId = skynet.server.redis:hget( redisKey , self:GetMyKey("curHouseId" , myPartnerId )) return tonumber( curHouseId ) end --更新双人空间装修方案 function DoubleSpace:AddHouseDeco( player, otherPartnerId , houseId ,schemeId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --装修方案 local allSchemeId=json:encode({ schemeId }) local allSchemeIdListJson = skynet.server.redis:hget( myInfoKey ,self:GetMyKey("allHouseSchemeId" , houseId) ) if allSchemeIdListJson ~= nil then local allSchemeIdList=json:decode(allSchemeIdListJson) --判断是否存在 for _, value in ipairs(allSchemeIdList) do if value == schemeId then return end end table.insert(allSchemeIdList, schemeId) --allSchemeIdList 去重复 allSchemeIdList=RemoveRepeat(allSchemeIdList) allSchemeId=json:encode(allSchemeIdList) end --防止覆盖更新这里一一判断 if not skynet.server.redis:hget(myInfoKey, self:GetMyKey2("decorates" , houseId,schemeId )) then skynet.server.redis:hset( myInfoKey ,self:GetMyKey2("decorates" , houseId,schemeId ) , json:encode(self:InitDeco(houseId))) --室内装修 end if not skynet.server.redis:hget(myInfoKey, self:GetMyKey2("furnitures" , houseId,schemeId )) then skynet.server.redis:hset( myInfoKey ,self:GetMyKey2("furnitures" , houseId,schemeId ) , json:encode({})) --装修家具信息 end skynet.server.redis:hmset( myInfoKey , -- self:GetMyKey2("decorates" , houseId,schemeId ) , json:encode(self:InitDeco(houseId)), --室内装修 -- self:GetMyKey2("furnitures" , houseId,schemeId ) , json:encode({}), --装修家具信息 self:GetMyKey2("decoPartnerId" , houseId,schemeId ) , "" , --当前房间装修玩家 self:GetMyKey2("decoStartTime" , houseId,schemeId ) , 0 , --当前房间开始装修时间 self:GetMyKey("allHouseSchemeId" , houseId),allSchemeId) --已有的装修方案 --添加装修方案 self:AddBuyHouseDecorate( myPartnerId , houseId , schemeId ) self:AddBuyHouseDecorate( otherPartnerId , houseId , schemeId ) end --获取双人空间当前房间已有的装修方案 function DoubleSpace:GetDoubleSpaceDecorateScheme( player, otherPartnerId , houseId ) --装修方案,默认是0 免费 local schemeIdList = {} local cfgSchemeAll =skynet.server.gameConfig:GetPlayerAllCfg(player, "Scheme" ) for k , v in pairs(cfgSchemeAll) do if v.value == houseId and v.currencyBuy == 0 then table.insert( schemeIdList , v.id ) break end end local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local schemeIdRedisListJson = skynet.server.redis:hget( myInfoKey ,self:GetMyKey("allHouseSchemeId" , houseId)) --已有的装修方案 if schemeIdRedisListJson ==nil then return schemeIdList end local schemeIdRedisList = json:decode(schemeIdRedisListJson) for key, value in pairs(schemeIdRedisList) do table.insert( schemeIdList , value ) end return schemeIdList end --启动装修方案 function DoubleSpace:StartDecorate( player, otherPartnerId ,schemeId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --是否启用当前装修方案 skynet.server.redis:hset( myInfoKey ,self:GetMyKey("curHouseSchemeId" , myPartnerId ),schemeId ) --已有的装修方案 end --获取当前装修方案 function DoubleSpace:GetCurScheme( player, otherPartnerId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --是否启用当前装修方案 local schemeId = skynet.server.redis:hget( myInfoKey ,self:GetMyKey("curHouseSchemeId" , myPartnerId ) ) --已有的装修方案 if schemeId == nil or (type(schemeId) ~="number" and schemeId =="") then return 37 end return tonumber(schemeId) end --双人空间展示 function DoubleSpace:Show( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceShow", c2sData.data )) s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceShow") local data = {} local otherPartnerId = c2sData.data.partnerId if not otherPartnerId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam return end self:CheckExistHouse( player ) local myPartnerId = player.gameData.partner.id local curHouseId = self:GetCurHouseId( myPartnerId , otherPartnerId ) if curHouseId == nil then s2cData.code = errorInfo.ErrorCode.NoExistDoubleSpace return end --获取正在开启的装修方案 local curDecorateId=self:GetCurScheme(player,otherPartnerId) local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local spaceInfo = skynet.server.redis:hmget( redisKey , "spaceName" , self:GetMyKey("curHouseId" , myPartnerId ), self:GetMyKey2("decoPartnerId" , curHouseId, curDecorateId) , self:GetMyKey2("decoStartTime" , curHouseId,curDecorateId ) , self:GetMyKey2("decorates" , curHouseId ,curDecorateId) , self:GetMyKey2("furnitures" , curHouseId,curDecorateId ), "allHouseId") spaceInfo = redisKeyUrl:CovertValue(spaceInfo) data.spaceName = spaceInfo[1] data.curHouseId = spaceInfo[2] --看看另一个玩家是不是还在装修,如果超过10分钟就取消他的资格。 self:CheckStopDeco(myPartnerId , otherPartnerId , curHouseId , curDecorateId , spaceInfo[4] ) data.isCanDeco = self:IsCanDeco(myPartnerId , otherPartnerId , curHouseId,curDecorateId ) data.decorates = json:decode(spaceInfo[5]) data.furnitures = json:decode(spaceInfo[6]) --当前开启的房间和装修 data.curHouseId = curHouseId data.curDecorateId=curDecorateId --房屋显示信息 --获取房屋配置 local houseConfig = skynet.server.gameConfig:GetPlayerAllCfg(player,"House") local doubleSpaceHouse={} for _,v in ipairs(houseConfig) do --双人空间 if v.shopType == 3 then table.insert(doubleSpaceHouse,v) end end data.houseSchemeItemList={} for _, cfgHouse in ipairs(doubleSpaceHouse) do local temHouse=self:BuildBuyHouseInfo(player,otherPartnerId,myPartnerId,cfgHouse.id ) table.insert(data.houseSchemeItemList,temHouse) end --获取对方的个人数据 data.personalInfo = {} local otherDetail = skynet.server.personal:GetDetail( otherPartnerId ) --衣服数据 local clothesData = {} table.insert( clothesData , otherDetail.clothesData1 or 2 ) table.insert( clothesData , otherDetail.clothesData2 or 3 ) table.insert( clothesData , otherDetail.clothesData3 or 10 ) table.insert( clothesData , otherDetail.clothesData4 or 14 ) table.insert( clothesData , otherDetail.clothesData5 or 17 ) table.insert( clothesData , otherDetail.clothesData6 or 16 ) table.insert( clothesData , otherDetail.clothesData7 or 0 ) table.insert( clothesData , otherDetail.clothesData8 or 0 ) table.insert( clothesData , otherDetail.clothesData9 or 0 ) table.insert( clothesData , otherDetail.clothesData10 or 0 ) --肤色 local colorData = {} table.insert( colorData , otherDetail.colorData1 or 1 ) table.insert( colorData , otherDetail.colorData2 or 6 ) table.insert( colorData , otherDetail.colorData3 or 26 ) data.personalInfo.nickName = otherDetail.nickName data.personalInfo.clothesData = clothesData data.personalInfo.colorData = colorData --检查否可以用在当前双人空间 self:CheckDoubleSpaceInSpace( player,otherPartnerId ) s2cData.data = assert(pb.encode("S2CDoubleSpaceShow", data)) end --双人空间设置状态 function DoubleSpace:SetStatus( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceSetStatus", c2sData.data )) local data = {} local otherPartnerId = c2sData.data.partnerId local isStartDeco = c2sData.data.isStartDeco if not otherPartnerId or nil == isStartDeco then s2cData.code = errorInfo.ErrorCode.ErrRequestParam else data.isCanDeco = false local myPartnerId = player.gameData.partner.id local curHouseId = self:GetCurHouseId( myPartnerId , otherPartnerId ) if curHouseId == nil then s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceSetStatus") s2cData.code = errorInfo.ErrorCode.NoExistDoubleSpace return end local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local curDecorateId=self:GetCurScheme(player,otherPartnerId) if self:IsCanDeco(myPartnerId , otherPartnerId , curHouseId , curDecorateId) then --记录下装修的人和装修的时间 if isStartDeco then skynet.server.redis:hmset( myInfoKey , self:GetMyKey2("decoPartnerId" , curHouseId,curDecorateId ) , myPartnerId , self:GetMyKey2("decoStartTime" , curHouseId ,curDecorateId) , skynet.GetTime()) else skynet.server.redis:hmset( myInfoKey , self:GetMyKey2("decoPartnerId" , curHouseId ,curDecorateId) , "" , self:GetMyKey2("decoStartTime" , curHouseId ,curDecorateId) , 0) end data.isCanDeco = true end local spaceInfo = skynet.server.redis:hmget( myInfoKey , self:GetMyKey2("decorates" , curHouseId ,curDecorateId) , self:GetMyKey2("furnitures" , curHouseId ,curDecorateId)) spaceInfo = redisKeyUrl:CovertValue(spaceInfo) data.decorates = json:decode(spaceInfo[1]) data.furnitures = json:decode(spaceInfo[2]) --推送房间装修状态 local playerDetail = skynet.server.personal:GetDetail( otherPartnerId ) --获取个人详情 local isPlaying =skynet.server.playerCenter:IsPlaying(playerDetail.userId) --推送装修状态给好友 local returnValue = skynet.server.playerCenter:IsSameServer( otherPartnerId ) local postData ={} postData.houseId=curHouseId postData.decorateId=curDecorateId postData.isCanDeco = self:IsCanDeco( otherPartnerId ,myPartnerId , curHouseId,curDecorateId ) if true ==returnValue then if playerDetail and isPlaying then skynet.server.gameServer:SendMsgToUser( playerDetail.userId , "CMD_S2C_DoubleSpaceStatus" , postData ) end elseif false ==returnValue then local sendData = {} sendData.userId = playerDetail.userId sendData.cmd = "CMD_S2C_DoubleSpaceStatus" sendData.data = postData local serverCmd = skynet.server.gameServer.GameToGame_NetMsg skynet.server.gameServer:SendMsgToServer( playerDetail.gameServerId , serverCmd, sendData ) end end s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceSetStatus") s2cData.data = assert(pb.encode("S2CDoubleSpaceSetStatus", data)) end --双人空间装修 function DoubleSpace:Decorate( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceDecorate", c2sData.data )) local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID local decorates = c2sData.data.decorates --装修信息 if "" == otherPartnerId or 0 == #decorates then s2cData.code = errorInfo.ErrorCode.ErrRequestParam else --从redis中获取装修信息 local myPartnerId = player.gameData.partner.id local curHouseId = self:GetCurHouseId( myPartnerId , otherPartnerId ) local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local curSchemeId=self:GetCurScheme(player,otherPartnerId) local jsonDecorates = skynet.server.redis:hget( redisKey , self:GetMyKey2("decorates" , curHouseId ,curSchemeId) ) local allDecorates = json:decode( jsonDecorates ) --替换玩家的最新装修信息,然后同步到redis上去 for k1, v1 in pairs( decorates ) do local isExist = false for k2, v2 in pairs( allDecorates ) do local cfgGoods = skynet.server.gameConfig:GetPlayerCurCfg( player , "Decoration" , v1.decoId ) if v2.facilityType == cfgGoods.type and v1.facilityId == v2.facilityId then v2.decoId = v1.decoId isExist = true break end end if not isExist then local cfgGoods = skynet.server.gameConfig:GetPlayerCurCfg( player , "Decoration" , v1.decoId ) if cfgGoods.type == dataType.DecorateType_OutDoorDeco then table.insert( allDecorates , { facilityType = dataType.DecorateType_OutDoorDeco , facilityId = 0 , decoId = v1.decoId }) elseif cfgGoods.type == dataType.DecorateType_OutDoorFloor then --兼容老数据,如果玩家的好友空间没有初始化地板,就给他初始化一个并带上装修ID table.insert( allDecorates , { facilityType = dataType.DecorateType_OutDoorFloor , facilityId = 0 , decoId = v1.decoId }) end end end skynet.server.redis:hset( redisKey , self:GetMyKey2("decorates" , curHouseId ,curSchemeId) , json:encode( allDecorates )) data.partnerId = otherPartnerId data.decorates = allDecorates skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_202 , myPartnerId , otherPartnerId ) end s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceDecorate") s2cData.data = assert(pb.encode("S2CDoubleSpaceDecorate", data)) end --双人空间放置家具 function DoubleSpace:Put( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpacePut", c2sData.data )) local data = {} local myPartnerId = player.gameData.partner.id local otherPartnerId = c2sData.data.partnerId --好友的ID local spaceOp = c2sData.data.spaceOp --操作家园信息 local curHouseId = self:GetCurHouseId( myPartnerId , otherPartnerId ) --获取当前装修方案 local curSchemeId=self:GetCurScheme(player,otherPartnerId) if "" == otherPartnerId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam elseif not self:IsCanDeco(myPartnerId , otherPartnerId , curHouseId , curSchemeId) then s2cData.code = errorInfo.ErrorCode.PartnerDecorating else data.spaceOp = {} --从redis中获取家具信息 local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local jsonFurnitures = skynet.server.redis:hget( redisKey , self:GetMyKey2("furnitures" , curHouseId ,curSchemeId) ) local allFurnitures = json:decode( jsonFurnitures ) local isSuc = nil for k, v in pairs( spaceOp ) do isSuc = false log.debug(string.format("玩家 %d 双人空间摆放 操作类型 %d" , player.userId , v.opType)) if skynet.server.group.PutType_House == v.opType and self:AddToSpace( player , allFurnitures , v.furniture ) then --新增家具到房间 isSuc = true elseif skynet.server.group.PutType_Bag == v.opType and self:RemoveToSpace( player , allFurnitures , v.furniture ) then --从房间中移出家具 isSuc = true elseif skynet.server.group.PutType_Move == v.opType and v.lastPos and self:MoveToSpace( player , allFurnitures , v.furniture , v.lastPos ) then --移动家具 isSuc = true elseif skynet.server.group.PutType_Operate == v.opType and self:OperateSpace( player , allFurnitures , v.furniture) then --原地操作 isSuc = true end if isSuc then --更新装修的信息到redis中去 local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) skynet.server.redis:hset( myInfoKey , self:GetMyKey2("furnitures" , curHouseId ,curSchemeId) , json:encode(allFurnitures)) skynet.server.npcTask:Modify( player , 111 , 1 ) skynet.server.taskListEvent:Modify( player , 111 , 1 ) table.insert( data.spaceOp , v ) player:ResetAllUnUsedGoods() else log.debug(string.format("玩家 %d 双人空间场景 操作失败类型 %d 家具ID %d " , player.userId , v.opType , v.furniture.goodsId )) end end skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_202 , myPartnerId , otherPartnerId ) end s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpacePut") s2cData.data = assert(pb.encode("S2CDoubleSpacePut", data)) end --删除装修 function DoubleSpace:RemoveDecorate( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceRemoveDecorate", c2sData.data )) local otherPartnerId = c2sData.data.partnerId --好友的ID local facilityType = c2sData.data.facilityType local data = {} data.partnerId = otherPartnerId if not otherPartnerId or "" == otherPartnerId or not facilityType or facilityType ~= dataType.DecorateType_OutDoorDeco then s2cData.code = errorInfo.ErrorCode.ErrRequestParam else --从redis中获取装修信息 local myPartnerId = player.gameData.partner.id local curHouseId = self:GetCurHouseId( myPartnerId , otherPartnerId ) local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local curSchemeId=self:GetCurScheme(player,otherPartnerId) local jsonDecorates = skynet.server.redis:hget( redisKey , self:GetMyKey2("decorates" , curHouseId ,curSchemeId) ) local allDecorates = json:decode( jsonDecorates ) for k, v in pairs( allDecorates ) do if facilityType == v.facilityType then table.remove( allDecorates , k ) break end end skynet.server.redis:hset( redisKey , self:GetMyKey2("decorates" , curHouseId ,curSchemeId) , json:encode( allDecorates )) end s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceRemoveDecorate") s2cData.data = assert(pb.encode("S2CDoubleSpaceRemoveDecorate", data)) end --双人空间重命名 function DoubleSpace:Rename( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceRename", c2sData.data )) local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID local spaceName = c2sData.data.spaceName --新的双人空间名 if "" == otherPartnerId or "" == spaceName or #spaceName > self.MaxNickNameLen then s2cData.code = errorInfo.ErrorCode.ErrRequestParam elseif skynet.server.common:IsMaskWords( spaceName ) then s2cData.code = errorInfo.ErrorCode.ExistMaskWords else local myPartnerId = player.gameData.partner.id self:SetInfo( myPartnerId , otherPartnerId , "spaceName" , spaceName ) data.partnerId = otherPartnerId data.spaceName = spaceName end s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceRename") s2cData.data = assert(pb.encode("S2CDoubleSpaceRename", data)) end --双人空间刷新商店 function DoubleSpace:RefreshShop( player ) local doubleSpace = player.gameData.doubleSpace local level = player.gameData.level if not skynet.server.common:IsSameDay( skynet.GetTime() , doubleSpace.shopRefreshTime ) then --随机6件家具 local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture") local cfgShopFurniture = {} --找到指定商店的家具 for k, v in pairs( cfgAllFurniture ) do if self.ShopTypeNo == v.shopType then table.insert( cfgShopFurniture , v ) end end doubleSpace.shopFurniture = {} local curFurniture = skynet.server.common:DeepCopy( doubleSpace.shopFurniture ) --当前展示的商品就不刷出来 local randGoodsList = self:GetAllRandFurniture( player , curFurniture , level , 6 , self.ShopTypeNo ) self:SetShopData( player , dataType.GoodsType_Furniture , randGoodsList ) --随机3件装修 local cfgAllDecoration = skynet.server.gameConfig:GetPlayerAllCfg( player , "Decoration") local cfgShopDecoration = {} --找到指定商店的家具 for k, v in pairs( cfgAllDecoration ) do if self.ShopTypeNo == v.shopType then table.insert( cfgShopDecoration , v ) end end doubleSpace.shopDecorate = {} local curDecorate = skynet.server.common:DeepCopy( doubleSpace.shopDecorate ) --当前展示的商品就不刷出来 randGoodsList = self:GetRandDecoration( player , curDecorate , level , 3 , self.ShopTypeNo ) self:SetShopData( player , dataType.GoodsType_Decorate , randGoodsList ) doubleSpace.shopRefreshTime = skynet.GetTime() end end --双人空间设置商店数据 function DoubleSpace:SetShopData( player , goodsType , randGoodsList ) local doubleSpace = player.gameData.doubleSpace --是否购买 for k, v in pairs( randGoodsList ) do local buyCount = 0 if player:IsBuyGoods( goodsType , v ) then buyCount = 1 end if dataType.GoodsType_Furniture == goodsType then table.insert( doubleSpace.shopFurniture , { id = v , buyCount =buyCount } ) elseif dataType.GoodsType_Decorate == goodsType then table.insert( doubleSpace.shopDecorate , { id = v , buyCount =buyCount } ) end log.debug(string.format("玩家 %d 双人空间 设置商店数据 商品类型 %d 商品ID %d 是否购买 %d" , player.basicInfo.userID , goodsType , v , buyCount )) end end --双人空间商店展示 function DoubleSpace:ShopShow( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceShopShow", c2sData.data )) local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID if "" == otherPartnerId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam else self:RefreshShop( player ) --刷新友爱商店 local doubleSpace = player.gameData.doubleSpace data.partnerId = otherPartnerId data.furnitures = {} data.decorates = {} for k, v in pairs( doubleSpace.shopFurniture ) do local goodsCount = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , v.id ) table.insert( data.furnitures , { id = v.id , buyCount = goodsCount } ) end for k, v in pairs( doubleSpace.shopDecorate ) do local goodsCount = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Decorate , v.id ) table.insert( data.decorates , { id = v.id , buyCount = goodsCount } ) end end s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceShopShow") s2cData.data = assert(pb.encode("S2CDoubleSpaceShopShow", data)) end --双人空间商店购买 function DoubleSpace:ShopBuy( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceShopBuy", c2sData.data )) local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID local buyGoods = c2sData.data.buyGoods --购买商品信息 if "" == otherPartnerId or not self:IsVaildGoodsInfo( buyGoods ) then s2cData.code = errorInfo.ErrorCode.ErrRequestParam else buyGoods.goodsCount = math.abs( buyGoods.goodsCount ) --客户端可能传负数过来,需要绝对值一下 local doubleSpace = player.gameData.doubleSpace local isSucBuy = false if dataType.GoodsType_Furniture == buyGoods.goodsType then for k, v in pairs( doubleSpace.shopFurniture ) do if buyGoods.goodsId == v.id then local moneyType , moneyCount = skynet.server.gameConfig:GetBuyMoney( player , "Furniture" , v.id ) local costCoin = moneyCount * buyGoods.goodsCount local eventId = pb.enum("EnumMoneyChangeEventID","EventID_87" ) if not player:MoneyChange( moneyType , -costCoin , eventId ) then s2cData.code = errorInfo.ErrorCode.NoEnoughMoney else data.partnerId = otherPartnerId data.buyGoods = buyGoods isSucBuy = true end break end end elseif dataType.GoodsType_Decorate == buyGoods.goodsType then local goodsCount = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Decorate , buyGoods.goodsId ) if goodsCount <=0 then for k, v in pairs( doubleSpace.shopDecorate ) do if buyGoods.goodsId == v.id then local moneyType , moneyCount = skynet.server.gameConfig:GetBuyMoney( player , "Decoration" , v.id ) local costCoin = moneyCount * buyGoods.goodsCount local eventId = pb.enum("EnumMoneyChangeEventID","EventID_87" ) if not player:MoneyChange( moneyType , -costCoin , eventId ) then s2cData.code = errorInfo.ErrorCode.NoEnoughMoney else data.partnerId = otherPartnerId data.buyGoods = buyGoods isSucBuy = true end break end end end end if not isSucBuy then s2cData.code = errorInfo.ErrorCode.NoGoodsID else skynet.server.bag:AddGoods( player , buyGoods.goodsType , buyGoods.goodsId , buyGoods.goodsCount ) --成功扣钱发货 skynet.server.levelTask:Modify( player , 83 , 1 ) skynet.server.taskListEvent:Modify( player ,83, 1) log.debug(string.format("玩家 %d 双人空间 商店购买商品 商品类型 %d 商品ID %d 商品数量 %d" , player.userId , buyGoods.goodsType , buyGoods.goodsId , buyGoods.goodsCount )) end end s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceShopBuy") s2cData.data = assert(pb.encode("S2CDoubleSpaceShopBuy", data)) end --双人空间解散 function DoubleSpace:Dissolve( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceDissolve", c2sData.data )) local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID if not otherPartnerId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam else local myPartnerId = player.gameData.partner.id self:RemovePutFurniture(player, myPartnerId, otherPartnerId) local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) skynet.server.redis:del( redisKey ) skynet.server.personal:AccDetail( myPartnerId ,"doubleSpaceCount", -1) --减少双人空间数量 skynet.server.personal:AccDetail( otherPartnerId ,"doubleSpaceCount", -1) --减少双人空间数量 --如果好友在线就将消息转发给他 local msgData,lastMsgId = skynet.server.partner:InitMsg( myPartnerId , otherPartnerId , skynet.server.partner.MsgType_Text ) msgData.msgText = "我已解除双人空间" redisKey = skynet.server.partner:GetMsgKey( myPartnerId , otherPartnerId ) skynet.server.redis:zadd( redisKey , lastMsgId , json:encode(msgData) ) skynet.server.partner:SendMsgToFriend( myPartnerId , otherPartnerId , msgData ) skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_201 , myPartnerId , otherPartnerId ) end s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceDissolve") s2cData.data = assert(pb.encode("S2CDoubleSpaceDissolve", data)) end --获取自己和朋友的双人空间的Key function DoubleSpace:GetMyInfoKey( myPartnerId , otherPlayerId ) local key = "" --谁的ID大就谁在前面 if myPartnerId > otherPlayerId then key = string.format("%s-%s" , myPartnerId , otherPlayerId ) else key = string.format("%s-%s" , otherPlayerId , myPartnerId ) end local redisKey = string.format( redisKeyUrl.GameServerDoubleSpaceInfoHash , key ) return redisKey end --是否能装修 function DoubleSpace:IsCanDeco(myPartnerId , otherPartnerId , curHouseId ,schemeId ) local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) local decoPartnerId = skynet.server.redis:hget( myInfoKey , self:GetMyKey2("decoPartnerId" , curHouseId,schemeId )) if "" == decoPartnerId or myPartnerId == decoPartnerId then return true end return false end --检查是否停止装修 function DoubleSpace:CheckStopDeco(myPartnerId , otherPartnerId , curHouseId , decoPartnerId , decoStartTime ) --如果30分钟还未完成装修,就必须取消他的装修资格,对于客户端有可能不会发送结束装修的消息,所以服务器必须考虑超时自动取消装修状态。 local isUpdate = false local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) if 0 ~= decoStartTime and skynet.GetTime() >= decoStartTime + 1800 then skynet.server.redis:hmset( myInfoKey , self:GetMyKey2("decoPartnerId" , curHouseId ,decoPartnerId) , "" , self:GetMyKey2("decoStartTime" , curHouseId,decoPartnerId ) , 0) end end --设置双人空间信息 function DoubleSpace:SetInfo( myPartnerId , otherPartnerId , ... ) local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) skynet.server.redis:hmset( redisKey , ... ) end --获取我的Key信息 function DoubleSpace:GetMyKey( keyName , value ) return keyName .. "_".. value end --获取我的Key信息-这个函数只能用于装修方案和家具摆件 function DoubleSpace:GetMyKey2(keyName , value1 , value2 ) if value1 == nil then log.info("GetMyKey2 value1 is nil",keyName) end keyName = keyName .. "_"..value1 --获取当前房间方案id,由于有历史数据,这里如果房间是6并且装修方案是免费或者0,这返回原来历史数据的key if value1 == self.houseId and (value2 == 37 or value2 =="") then return keyName end keyName = keyName .. "_"..value2 return keyName end --获取我放置商品数量 function DoubleSpace:GetPutGoodsCount( partnerId , allGoods , id ) --找出我所有的家具 local count = 0 for k, v in pairs( allGoods ) do if partnerId == v.partnerId and id == v.id then count = count + 1 end end return count end --双人空间新增家具到房间 function DoubleSpace:AddToSpace( player , allFurnitures , furniture ) local myPartnerId = player.gameData.partner.id --家具是谁放上去的。 local goodsId = furniture.goodsId local count1 = self:GetPutGoodsCount( myPartnerId , allFurnitures , goodsId ) --当前摆放的数量 local count2 = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , goodsId ) --我背包里的数量 if count1 >= count2 then --摆放的数量已经大于等于背包数量 return false else furniture.partnerId = myPartnerId table.insert( allFurnitures , furniture) count1 = count1 + 1 --成功放置,最大数量+1 skynet.server.bag:AddPutGoodsMaxCount( player , dataType.GoodsType_Furniture , goodsId , count1 ) return true end return false end --双人空间从地块中移出 function DoubleSpace:RemoveToSpace( player , allFurnitures , furniture ) local goodsId = furniture.goodsId local furniturePos = furniture.nowPos for k, v in pairs( allFurnitures ) do if goodsId == v.goodsId and skynet.server.common:Distance( furniturePos.x , furniturePos.y , v.nowPos.x , v.nowPos.y) <= 0.1 then table.remove( allFurnitures , k ) skynet.server.bag:RemovePutGoodsMaxCount( player , dataType.GoodsType_Furniture , goodsId , 1 ) return true end end return false end --双人空间在地块中移动 function DoubleSpace:MoveToSpace( player , allFurnitures , furniture , lastPos ) local goodsId = furniture.goodsId local targetPos = furniture.nowPos for k, v in pairs( allFurnitures ) do local srcPosDistance = skynet.server.common:Distance( lastPos.x , lastPos.y , v.nowPos.x , v.nowPos.y) --原位置距离 local dstPosDistance = skynet.server.common:Distance( targetPos.x , targetPos.y , lastPos.x , lastPos.y) --目标位置距离 if v.goodsId == goodsId and srcPosDistance <= 0.1 and dstPosDistance >= 0 then v.nowPos = targetPos v.rotateType = furniture.rotateType v.isPutInFurniture = furniture.isPutInFurniture v.clickType = furniture.clickType return true end end return false end --双人空间原地操作 function DoubleSpace:OperateSpace( player , allFurnitures , furniture ) local goodsId = furniture.goodsId local furniturePos = furniture.nowPos for k, v in pairs( allFurnitures ) do local isSamePos = skynet.server.common:Distance( furniturePos.x , furniturePos.y , v.nowPos.x , v.nowPos.y ) <= 0.1 if v.goodsId == goodsId and isSamePos then v.nowPos = furniture.nowPos v.rotateType = furniture.rotateType v.isPutInFurniture = furniture.isPutInFurniture v.clickType = furniture.clickType return true end end return false end --是否与好友存在双人空间 function DoubleSpace:IsExist( myPartnerId , otherPartnerId ) local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) if not skynet.server.redis:exists( redisKey ) then return false end return true end --检查有不有双人空间房子 function DoubleSpace:CheckExistHouse( player ) if not skynet.server.house:IsBuyHouse( player , self.houseId ) then local myPartnerId = player.gameData.partner.id local isExist = skynet.server.personal:GetCurDetail( myPartnerId , "isExistDoubleSpace") if true == isExist then local s2cData ={} skynet.server.house:Add( player , self.houseId , s2cData , false) end end end --移除玩家身上放置的家具 function DoubleSpace:RemovePutFurniture(player, myPartnerId , otherPartnerId) local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --获取全部装修配置 local cfgSchemeAll=skynet.server.gameConfig:GetPlayerAllCfg(player,"Scheme") --该房间下的装修 local cfgSchemeList={} for _, value in ipairs(cfgSchemeAll) do for houseId, _ in pairs(self.initDeco) do if value.value==houseId then table.insert(cfgSchemeList,value) break end end end local myRemoveFurnitures = {} local otherRemoveFurnitures = {} for _, cfgScheme in ipairs(cfgSchemeList) do local jsonFurnitures = skynet.server.redis:hget( redisKey , self:GetMyKey2("furnitures" , cfgScheme.value ,cfgScheme.id) ) --不存在家具 if jsonFurnitures == nil or jsonFurnitures == "" then --log.info("双人空间解散 回收家具 失败",json:encode(cfgScheme)) goto continue end local allFurnitures = json:decode( jsonFurnitures ) --log.info("双人空间解散 回收家具",json:encode(cfgScheme),jsonFurnitures) for k, v in pairs( allFurnitures ) do local removeGoodsId = v.goodsId if myPartnerId == v.partnerId then table.insert( myRemoveFurnitures, removeGoodsId ) elseif otherPartnerId == v.partnerId then table.insert( otherRemoveFurnitures, removeGoodsId ) end end ::continue:: end local msgData = {} msgData.removeFurnitures = myRemoveFurnitures skynet.server.personal:AddOfflineMsg( myPartnerId , dataType.OfflineMsgType_DoubleSpaceDissolve , msgData , 45 , 0 ) msgData.removeFurnitures = otherRemoveFurnitures skynet.server.personal:AddOfflineMsg( otherPartnerId , dataType.OfflineMsgType_DoubleSpaceDissolve , msgData , 45 , 0) end --以下是新函数 --添加已购买的双人空间房间id function DoubleSpace:AddBuyHouseId(player,partnerId , houseId ) local isOk=false local houseList =self:GetBuyHouseIdList( partnerId ) --判断是否存在 for _, tempHouseId in ipairs(houseList) do if tempHouseId == houseId then return isOk end end table.insert( houseList , houseId ) isOk=true --保存到rendis local result= skynet.server.personal:SetDetail(partnerId,self.doubleSpaceBuyHouseKey , json:encode( houseList ) ) --local result= skynet.server.redis:hset( redisKey , self.doubleSpaceBuyHouseKey , json:encode( houseList ) ) --[[ if result == nil then log.error("添加已购买的双人空间房间id失败") end ]] --默认购买免费装修方案 local cfgSchemeAll =skynet.server.gameConfig:GetPlayerAllCfg(player, "Scheme" ) for k , v in pairs(cfgSchemeAll) do --添加免费的装修费方案 if v.value == houseId and v.currencyBuy == 0 then self:AddBuyHouseDecorate(partnerId,houseId,v.id) end end return isOk end --获取已购买的双人空间房间id列表 function DoubleSpace:GetBuyHouseIdList( partnerId ) local houseList={} local houseListJson = skynet.server.personal:GetCurDetail(partnerId,self.doubleSpaceBuyHouseKey) --local houseListJson = skynet.server.redis:hget( redisKey , self.doubleSpaceBuyHouseKey ) if houseListJson ~= nil and #houseListJson > 0 then houseList=json:decode( houseListJson ) end --没有6房间 需要把6房间的id加进去 local isSixRoom = false for _, value in ipairs(houseList) do if value == self.houseId then isSixRoom=true break end end if not isSixRoom then table.insert(houseList, self.houseId) end return houseList end --添加已购买的双人空间房间的装修方案 function DoubleSpace:AddBuyHouseDecorate( partnerId , houseId , decorateId ) local isOk =false local redisbuyDecoKey = string.format(self.doubleSpaceBuyDecoKey,houseId) local houseDecorateList =self:GetBuyHouseDecorateList( partnerId , houseId ) for _, tempdecorateId in ipairs(houseDecorateList) do if tempdecorateId == decorateId then return isOk end end table.insert( houseDecorateList , decorateId ) isOk = true --保存到rendis skynet.server.personal:SetDetail(partnerId, redisbuyDecoKey , json:encode( houseDecorateList ) ) return isOk end --获取已购买的双人空间房间的装修方案列表 function DoubleSpace:GetBuyHouseDecorateList( partnerId , houseId ) local houseDecorateList={} local redisbuyDecoKey = string.format(self.doubleSpaceBuyDecoKey,houseId) local houseDecorateListJson = skynet.server.personal:GetCurDetail(partnerId,redisbuyDecoKey) if houseDecorateListJson ~= nil and #houseDecorateListJson >0 then houseDecorateList=json:decode(houseDecorateListJson) else houseDecorateList={} end --如果是6 没有37 则添加37 if houseId == self.houseId then local isSixRoom = false for _, value in ipairs(houseDecorateList) do if value == 37 then isSixRoom=true break end end if not isSixRoom then table.insert(houseDecorateList, 37) end end return houseDecorateList end --购买房产 function DoubleSpace:HouseRentBuy( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceHouseRentBuy", c2sData.data )) s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceHouseRentBuy") local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID local houseId = c2sData.data.houseId --购买房产id local buyType = c2sData.data.buyType --购买类型 1-自己购买 2-邀请好友购买 3-代替好友购买 data.partnerId=otherPartnerId data.houseId=houseId data.buyType=buyType if not otherPartnerId or (buyType ~=1 and buyType ~= 2 and buyType ~= 3) then s2cData.code = errorInfo.ErrorCode.ErrRequestParam return end local myPartnerId = player.gameData.partner.id local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --判断双人空间是否存在 if not self:IsExist(myPartnerId,otherPartnerId) then s2cData.code = errorInfo.ErrorCode.NoExistDoubleSpace return end local partnerId = player.gameData.partner.id if buyType ~=1 then partnerId = otherPartnerId end --判断玩家是否存在该房间 local houseIdList = self:GetBuyHouseIdList(partnerId) for _, tempHouseId in ipairs(houseIdList) do if tempHouseId ==houseId then--房间是否购买 s2cData.code = errorInfo.ErrorCode.ErrRequestParam return end end --获取房间购买信息 local houseInfo = skynet.server.gameConfig:GetPlayerCurCfg( player , "House" , houseId ) if not houseInfo then s2cData.code=errorInfo.ErrorCode.ErrRequestParam return end --自己的等级判断 if buyType ==1 and player.gameData.level < houseInfo.level then s2cData.code=errorInfo.ErrorCode.ErrRequestParam return end --判断玩家等级,好友 local friendLevel = skynet.server.personal:GetCurDetail( otherPartnerId , "level" ) if buyType ~= 1 and friendLevel < houseInfo.level then s2cData.code=errorInfo.ErrorCode.ErrRequestParam return end local eventId = pb.enum("EnumMoneyChangeEventID", "EventID_148") local coin = 0 local coinType = 0 --消耗资源 if houseInfo.currencyBuy ==1 then--金币 coinType=pb.enum("EnumGoodsType", "Coin") coin = houseInfo.coin elseif houseInfo.currencyBuy == 2 then--三叶草 coinType=pb.enum("EnumGoodsType", "Clovers") coin = houseInfo.mapCoin elseif houseInfo.currencyBuy == 3 then--蜗壳币 coinType=pb.enum("EnumGoodsType", "VoluteCoin") coin = houseInfo.voluteCoin end --验证资源 if buyType ~= 2 then --购买 --消耗金币 if not player:MoneyChange(coinType, -(coin/2), eventId) then s2cData.code=errorInfo.ErrorCode.ErrRequestParam log.error("获取房间购买信息失败 GetDoubleSpaceInfo:MoneyChange is false",houseId,houseInfo.coin/2) return end end if buyType == 1 then --添加房屋 self:AddBuyHouseId(player, myPartnerId , houseId ) --自己购买 标记邀请消息为已同意 skynet.server.partner:DoubleSpaceBuyInviteRespond( player , otherPartnerId,skynet.server.partner.MsgType_InviteDoubleSpaceBuyHouse,houseId,0 ) elseif buyType == 3 then --添加房屋 local isOk= self:AddBuyHouseId(player, otherPartnerId , houseId ) if isOk then skynet.server.partner:DoubleSpaceBuyInvite( player , otherPartnerId,skynet.server.partner.MsgType_InviteDoubleSpaceBuyHouseNotice,houseId,0 ) end end --添加房屋 local addHouseIdList ={} --好友邀请,如果好友为购买的房屋, 需要通知好友 if buyType == 2 then local otherBuyHouseIdList = self:GetBuyHouseIdList(otherPartnerId) if next(otherBuyHouseIdList) == nil then skynet.server.partner:DoubleSpaceBuyInvite( player , otherPartnerId,skynet.server.partner.MsgType_InviteDoubleSpaceBuyHouse,houseId,0 ) else local isExist =false for _, value in ipairs(otherBuyHouseIdList) do if value == houseId then isExist = true break end end --不存在房间才会邀请 if not isExist then skynet.server.partner:DoubleSpaceBuyInvite( player , otherPartnerId,skynet.server.partner.MsgType_InviteDoubleSpaceBuyHouse,houseId,0 ) end end else --检查已购买的房间 local myBuyHouseList = self:GetBuyHouseIdList(myPartnerId) --获取好友购买房间信息 local otherBuyHouseList = self:GetBuyHouseIdList(otherPartnerId) if next(myBuyHouseList) and next(otherBuyHouseList) then for _, myHouseId in ipairs(myBuyHouseList) do if myHouseId ~= houseId then goto continue end for _, otherHouseId in ipairs(otherBuyHouseList) do --共同都有这个房屋 if myHouseId == otherHouseId then --添加房间 self:AddHouseInfo(player, otherPartnerId , myHouseId ) table.insert(addHouseIdList, otherHouseId) --检查是否添加默认装修 local myBuyHouseDecList=self:GetBuyHouseDecorateList(myPartnerId, myHouseId) local otherBuyHouseDecList=self:GetBuyHouseDecorateList(otherPartnerId, otherHouseId) if next(myBuyHouseDecList) and next(otherBuyHouseDecList) then for _, myBuyHouseDec in ipairs(myBuyHouseDecList) do for _, otherBuyHouseDec in ipairs(otherBuyHouseDecList) do --共同都有这个装修方案 if myBuyHouseDec == otherBuyHouseDec then --添加装方案 self:AddHouseDeco( player, otherPartnerId , myHouseId ,myBuyHouseDec ) end end end end end end ::continue:: end end end --我同意创建双人间,我增加双人空间户型,解锁该房间主要是在商店里刷出门和护栏 for _, tempHouseId in ipairs(addHouseIdList) do skynet.server.house:Add( player , tempHouseId , s2cData , true) end self:CheckBuyHouseInSpace( player,otherPartnerId, houseId ) --房间有改变通知玩家 if buyType ~= 2 then local playerDetail = skynet.server.personal:GetDetail( otherPartnerId ) --获取个人详情 local isPlaying =skynet.server.playerCenter:IsPlaying(playerDetail.userId) --推送房产信息给好友 local returnValue = skynet.server.playerCenter:IsSameServer( otherPartnerId ) --推送数据 local postData ={} postData.doubleSpaceHouseSchemeItem=self:BuildBuyHouseInfo(player,myPartnerId,otherPartnerId,houseId ) if true ==returnValue then if playerDetail and isPlaying then skynet.server.gameServer:SendMsgToUser( playerDetail.userId , "CMD_S2C_DoubleSpaceHouseBuyInfo" , postData ) end elseif false ==returnValue then --不在同一服务器 local playerDetail = skynet.server.personal:GetDetail( otherPartnerId ) --获取个人详情 local sendData = {} sendData.userId = playerDetail.userId sendData.cmd = "CMD_S2C_DoubleSpaceHouseBuyInfo" sendData.data = postData local serverCmd = skynet.server.gameServer.GameToGame_NetMsg skynet.server.gameServer:SendMsgToServer( playerDetail.gameServerId , serverCmd, sendData ) end --推送自己的房间信息 local pushData ={} pushData.doubleSpaceHouseSchemeItem=self:BuildBuyHouseInfo(player,otherPartnerId,myPartnerId,houseId ) skynet.server.gameServer:SendMsgToUser( player.userId, "CMD_S2C_DoubleSpaceHouseBuyInfo" , pushData ) end s2cData.data = assert(pb.encode("S2CDoubleSpaceHouseRentBuy", data)) end --购买装修方案 function DoubleSpace:HouseRentSchemeBuy( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceHouseRentSchemeBuy", c2sData.data )) s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceHouseRentSchemeBuy") local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID local houseId = c2sData.data.houseId --购买房产id local schemeId = c2sData.data.schemeId --购买装修方案id local buyType = c2sData.data.buyType --购买类型 1-自己购买 2-邀请好友购买 3-自己购买 data.houseId = houseId data.schemeId = schemeId data.buyType = buyType if not otherPartnerId or (buyType ~=1 and buyType ~= 2 and buyType ~= 3) then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("购买装修方案 参数错误",otherPartnerId,buyType,houseId,schemeId) return end local myPartnerId = player.gameData.partner.id local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --判断双人空间是否存在 if not self:IsExist(myPartnerId,otherPartnerId) then s2cData.code = errorInfo.ErrorCode.NoExistDoubleSpace log.info("双人空间未开通 GetDoubleSpaceInfo:redisKey is not exist",redisKey) return end --判断参数是否异常 local cfgScheme=skynet.server.gameConfig:GetPlayerCurCfg( player , "Scheme" , schemeId ) if cfgScheme.value ~= houseId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("参数异常 GetDoubleSpaceInfo:cfgScheme.value ~= houseId",cfgScheme.value,houseId) return end --当前购买者 local partnerId = player.gameData.partner.id if buyType ~=1 then partnerId = otherPartnerId end --判断房屋是否购买 local isBuyHouse =false local houseIdList = self:GetBuyHouseIdList(partnerId) for _, tempHouseId in ipairs(houseIdList) do if tempHouseId ==houseId then isBuyHouse =true break end end if not isBuyHouse then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家没有购买此房屋 GetDoubleSpaceInfo:houseId",houseId) return end --判断玩家是否存在该房间 local schemeList = self:GetBuyHouseDecorateList(partnerId,houseId) for _, tempscheme in ipairs(schemeList) do if tempscheme ==schemeId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未成功购买该装修方案 该方案已购买 GetDoubleSpaceInfo:schemeId is exist",schemeId) return end end local eventId = pb.enum("EnumMoneyChangeEventID", "EventID_148") local coin = 0 local coinType = 0 --免费 if cfgScheme.currencyBuy==0 then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 房间免费 ",schemeId) return elseif cfgScheme.currencyBuy ==1 then--金币 coinType=pb.enum("EnumGoodsType", "Coin") coin = cfgScheme.coin elseif cfgScheme.currencyBuy == 2 then--三叶草 coinType=pb.enum("EnumGoodsType", "Clovers") coin = cfgScheme.mapCoin elseif cfgScheme.currencyBuy == 3 then--蜗壳币 coinType=pb.enum("EnumGoodsType", "VoluteCoin") coin = cfgScheme.voluteCoin end --验证资源 if buyType ~= 2 then --消耗金币 if not player:MoneyChange(coinType, -(coin/2), eventId) then s2cData.code=errorInfo.ErrorCode.ErrRequestParam log.info("购买装修方案失败,资源不足 GetDoubleSpaceInfo:MoneyChange is false",houseId,coin/2,coinType) return end end --自己购买 if buyType == 1 then --添加装修 self:AddBuyHouseDecorate( myPartnerId, houseId ,schemeId) --自己购买 标记邀请消息为已同意 skynet.server.partner:DoubleSpaceBuyInviteRespond( player , otherPartnerId,skynet.server.partner.MsgType_InviteDoubleSpaceBuyHouseScheme,houseId,schemeId ) elseif buyType == 3 then--代购 local isOk= self:AddBuyHouseDecorate( otherPartnerId, houseId ,schemeId) if isOk then skynet.server.partner:DoubleSpaceBuyInvite( player , otherPartnerId,skynet.server.partner.MsgType_InviteDoubleSpaceBuyHouseSchemeNotice,houseId,schemeId ) end end --添加装修方案 local myBuyHouseDecList=self:GetBuyHouseDecorateList(myPartnerId, houseId) local otherBuyHouseDecList=self:GetBuyHouseDecorateList(otherPartnerId, houseId) if next(myBuyHouseDecList) and next(otherBuyHouseDecList) then for _, myBuyHouseDec in ipairs(myBuyHouseDecList) do if myBuyHouseDec ~= schemeId then goto continue end for _, otherBuyHouseDec in ipairs(otherBuyHouseDecList) do --共同都有这个装修方案 if myBuyHouseDec == otherBuyHouseDec then --添加装方案 self:AddHouseDeco( player, otherPartnerId , houseId ,myBuyHouseDec ) end end ::continue:: end end --好友邀请 需要通知好友 if buyType == 2 then local otherBuyHouseschmemIdList = self:GetBuyHouseDecorateList(otherPartnerId,houseId) if next(otherBuyHouseschmemIdList) == nil then skynet.server.partner:DoubleSpaceBuyInvite( player , otherPartnerId,skynet.server.partner.MsgType_InviteDoubleSpaceBuyHouseScheme,houseId,schemeId ) else local isExist =false for _, value in ipairs(otherBuyHouseschmemIdList) do if value == schemeId then isExist = true break end end --不存在房间才会邀请 if not isExist then skynet.server.partner:DoubleSpaceBuyInvite( player , otherPartnerId,skynet.server.partner.MsgType_InviteDoubleSpaceBuyHouseScheme,houseId,schemeId ) end end else--房间有改变通知玩家 local playerDetail = skynet.server.personal:GetDetail( otherPartnerId ) --获取个人详情 local isPlaying =skynet.server.playerCenter:IsPlaying(playerDetail.userId) --推送房产信息给好友 local returnValue = skynet.server.playerCenter:IsSameServer( otherPartnerId ) local postData ={} postData.doubleSpaceHouseSchemeItem=self:BuildBuyHouseInfo(player,myPartnerId,otherPartnerId,houseId ) if true ==returnValue then if playerDetail and isPlaying then skynet.server.gameServer:SendMsgToUser( playerDetail.userId , "CMD_S2C_DoubleSpaceHouseBuyInfo" , postData ) end elseif false ==returnValue then --不在同一服务器 local playerDetail = skynet.server.personal:GetDetail( otherPartnerId ) --获取个人详情 local sendData = {} sendData.userId = playerDetail.userId sendData.cmd = "CMD_S2C_DoubleSpaceHouseBuyInfo" sendData.data = postData local serverCmd = skynet.server.gameServer.GameToGame_NetMsg skynet.server.gameServer:SendMsgToServer( playerDetail.gameServerId , serverCmd, sendData ) end --推送自己的房间信息 local pushData ={} pushData.doubleSpaceHouseSchemeItem=self:BuildBuyHouseInfo(player,otherPartnerId,myPartnerId,houseId ) skynet.server.gameServer:SendMsgToUser( player.userId, "CMD_S2C_DoubleSpaceHouseBuyInfo" , pushData ) end s2cData.data = assert(pb.encode("S2CDoubleSpaceHouseRentSchemeBuy", data)) end --切换房间 function DoubleSpace:ChangeHouse( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceChangeHouse", c2sData.data )) s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceChangeHouse") local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID local houseId = c2sData.data.houseId --购买房产id data.partnerId = otherPartnerId data.houseId = houseId if not otherPartnerId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam return end local myPartnerId = player.gameData.partner.id local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --判断双人空间是否存在 if not self:IsExist(myPartnerId,otherPartnerId) then s2cData.code = errorInfo.ErrorCode.NoExistDoubleSpace log.info("双人空间未开通 GetDoubleSpaceInfo:redisKey is not exist",redisKey) return end --判断玩家是否存在该房间 local isBuyHouse=false local houseIdList = self:GetBuyHouseIdList(myPartnerId) for _, tempHouseId in ipairs(houseIdList) do if tempHouseId ==houseId then isBuyHouse = true break end end if not isBuyHouse then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 房间未购买 GetDoubleSpaceInfo:houseId is exist",houseId) return end --判断房间是否可以切换 local changeHouseIdList = self:GetDoubleSpaceHouseIdList(player,otherPartnerId) if not next(changeHouseIdList ) then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 房间未全部购买 GetDoubleSpaceInfo:houseId is not exist",houseId) return end --是否存在 local isExist = false for _, temHouseId in ipairs(changeHouseIdList) do if temHouseId == houseId then isExist = true break end end if not isExist then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 房间未全部购买 GetDoubleSpaceInfo:houseId is not exist",houseId) return end local curHouseId = self:GetCurHouseId( myPartnerId , otherPartnerId ) --获取正在开启的装修方案 local curDecorateId=self:GetCurScheme(player,otherPartnerId) --取消之前的装修方案 skynet.server.redis:hmset( redisKey , self:GetMyKey2("decoPartnerId" , curHouseId ,curDecorateId) , "" , self:GetMyKey2("decoStartTime" , curHouseId ,curDecorateId) , 0) --设置房间未当前选中房间 self:StartHouse(player,otherPartnerId,houseId) --获取上一个设置的装修方案 local previousSchemeId = self:GetPlayerHouseDecorate(player,otherPartnerId,houseId) --设置房间装修方案 self:StartDecorate(player,otherPartnerId,previousSchemeId) --设置装修方案是默认状态 self:SetPlayerHouseDecorate(player,otherPartnerId,houseId,previousSchemeId) local spaceInfo = skynet.server.redis:hmget( redisKey , self:GetMyKey2("decorates" , houseId ,previousSchemeId) , self:GetMyKey2("furnitures" , houseId,previousSchemeId )) local curHouseId = self:GetCurHouseId( myPartnerId , otherPartnerId ) --获取正在开启的装修方案 local curDecorateId=self:GetCurScheme(player,otherPartnerId) -- --设置当前装修方案 -- skynet.server.redis:hmset( redisKey , -- self:GetMyKey2("decoPartnerId" , curHouseId,curDecorateId ) , myPartnerId , -- self:GetMyKey2("decoStartTime" , curHouseId ,curDecorateId) , skynet.GetTime()) data.decorates = json:decode(spaceInfo[1]) data.furnitures = json:decode(spaceInfo[2]) s2cData.data = assert(pb.encode("S2CDoubleSpaceChangeHouse", data)) end --修改装修方案名称 function DoubleSpace:ChangeDecorateSchemeName(player,c2sData,s2cData) c2sData.data = assert(pb.decode("C2SDoubleSpaceChangeDecorateSchemeName", c2sData.data )) s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceChangeDecorateSchemeName") local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID local houseId = c2sData.data.houseId --购买房产id local schemeId = c2sData.data.houseSchemeId local schemeName = c2sData.data.schemeName data.partnerId = otherPartnerId data.houseId = houseId data.houseSchemeId = schemeId data.schemeName = schemeName if not otherPartnerId or schemeName == "" then s2cData.code = errorInfo.ErrorCode.ErrRequestParam return end local myPartnerId = player.gameData.partner.id local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --判断双人空间是否存在 if not self:IsExist(myPartnerId,otherPartnerId) then s2cData.code = errorInfo.ErrorCode.NoExistDoubleSpace log.info("双人空间未开通 GetDoubleSpaceInfo:redisKey is not exist",redisKey) return end --判断玩家是否存在该房间 local isBuyHouse=false local houseIdList = self:GetBuyHouseIdList(myPartnerId) for _, tempHouseId in ipairs(houseIdList) do if tempHouseId ==houseId then isBuyHouse = true break end end if not isBuyHouse then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 房间未购买 GetDoubleSpaceInfo:houseId is exist",houseId) return end --判断房间是否可以切换 local changeHouseIdList = self:GetDoubleSpaceHouseIdList(player,otherPartnerId) if not next(changeHouseIdList ) then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 房间未全部购买 GetDoubleSpaceInfo:houseId is not exist",houseId,changeHouseIdList) return end --是否存在 local isExist = false for _, temHouseId in ipairs(changeHouseIdList) do if temHouseId == houseId then isExist = true break end end if not isExist then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 房间未购买 GetDoubleSpaceInfo:houseId is not exist",houseId) return end --设置房间装修方案名称 self:SetPlayerHouseDecorateName(player,otherPartnerId,houseId,schemeId,schemeName) s2cData.data = assert(pb.encode("S2CDoubleSpaceChangeDecorateSchemeName", data)) end --切换房间装修方案 function DoubleSpace:ChangeDecorateScheme( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SDoubleSpaceChangeDecorateScheme", c2sData.data )) s2cData.cmd = pb.enum("MsgType","CMD_S2C_DoubleSpaceChangeDecorateScheme") local data = {} local otherPartnerId = c2sData.data.partnerId --好友的ID local houseSchemeId = c2sData.data.houseSchemeId --购买房产装修方案 data.partnerId = otherPartnerId data.houseSchemeId = houseSchemeId if not otherPartnerId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam return end local myPartnerId = player.gameData.partner.id local redisKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --判断双人空间是否存在 if not self:IsExist(myPartnerId,otherPartnerId) then s2cData.code = errorInfo.ErrorCode.NoExistDoubleSpace log.info("双人空间未开通 GetDoubleSpaceInfo:redisKey is not exist",redisKey) return end --获取当前房间id local curHouseId = self:GetCurHouseId( myPartnerId ,otherPartnerId) --判断玩家是否存在该房间 local isBuyHouse = false local houseIdList = self:GetBuyHouseIdList(myPartnerId) for _, tempHouseId in ipairs(houseIdList) do if tempHouseId ==curHouseId then isBuyHouse = true break end end if not isBuyHouse then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 房间已购买 GetBuyHouseIdList:houseId is exist",curHouseId) return end --判断房间是否可以切换 local houseSchemeList = self:GetDoubleSpaceDecorateScheme(player,otherPartnerId,curHouseId) if not next(houseSchemeList ) then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 装修方案未购买 GetDoubleSpaceDecorateScheme:curHouseId is not exist",curHouseId) return end --是否存在 local isExist = false for _, houseScheme in ipairs(houseSchemeList) do if houseScheme == houseSchemeId then isExist = true break end end if not isExist then s2cData.code = errorInfo.ErrorCode.ErrRequestParam log.info("玩家未购买该房间 装修方案未购买 GetDoubleSpaceDecorateScheme:houseSchemeId is not exist",houseSchemeId) return end --获取正在开启的装修方案 local curDecorateId=self:GetCurScheme(player,otherPartnerId) --取消之前的装修方案 skynet.server.redis:hmset( redisKey , self:GetMyKey2("decoPartnerId" , curHouseId ,curDecorateId) , "" , self:GetMyKey2("decoStartTime" , curHouseId ,curDecorateId) , 0) --设置房间装修方案 self:StartDecorate(player,otherPartnerId,houseSchemeId) local curDecorateId=self:GetCurScheme(player,otherPartnerId) -- --设置当前装修方案 -- skynet.server.redis:hmset( redisKey , self:GetMyKey2("decoPartnerId" , curHouseId,curDecorateId ) , myPartnerId , -- self:GetMyKey2("decoStartTime" , curHouseId ,curDecorateId) , skynet.GetTime()) local spaceInfo = skynet.server.redis:hmget( redisKey , self:GetMyKey2("decorates" , curHouseId ,houseSchemeId) , self:GetMyKey2("furnitures" , curHouseId,houseSchemeId )) data.decorates = json:decode(spaceInfo[1]) data.furnitures = json:decode(spaceInfo[2]) --设置装修方案 self:SetPlayerHouseDecorate(player,otherPartnerId,curHouseId,houseSchemeId) s2cData.data = assert(pb.encode("S2CDoubleSpaceChangeDecorateScheme", data)) end --检查购买房产设置成双人空间可以设置 function DoubleSpace:CheckBuyHouseInSpace( player,otherPartnerId, houseId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --判断该房间是否存在 local houseIdListJson= skynet.server.redis:hget( myInfoKey , "allHouseId") --存在数据 if houseIdListJson ~= nil then local houseIdList=json:decode(houseIdListJson) for _, value in ipairs(houseIdList) do --已经存在直接返回 if value == houseId then return end end end --检查已购买的房间 local myBuyHouseList = self:GetBuyHouseIdList(myPartnerId) --获取好友购买房间信息 local otherBuyHouseList = self:GetBuyHouseIdList(otherPartnerId) if next(myBuyHouseList) and next(otherBuyHouseList) then for _, myHouseId in ipairs(myBuyHouseList) do --只检查当前房间 if myHouseId ~= houseId then goto continue end for _, otherHouseId in ipairs(otherBuyHouseList) do --共同都有这个房屋 if myHouseId == otherHouseId then --添加房间 self:AddHouseInfo(player, otherPartnerId , myHouseId ) --添加装修方案 local myBuyHouseDecList=self:GetBuyHouseDecorateList(myPartnerId, myHouseId) local otherBuyHouseDecList=self:GetBuyHouseDecorateList(otherPartnerId, otherHouseId) if next(myBuyHouseDecList) and next(otherBuyHouseDecList) then for _, myBuyHouseDec in ipairs(myBuyHouseDecList) do for _, otherBuyHouseDec in ipairs(otherBuyHouseDecList) do --共同都有这个装修方案 if myBuyHouseDec == otherBuyHouseDec then --添加装方案 self:AddHouseDeco( player, otherPartnerId , myHouseId ,myBuyHouseDec ) end end end end end end ::continue:: end end end --构建房间/装修购买信息 function DoubleSpace:BuildBuyHouseInfo(player,friendPartherId,myPartnerId,houseId ) local spaceDecorateSchemeHouseItem={} spaceDecorateSchemeHouseItem.SpaceDecorateSchemeItemList={} --购买房屋情况 local myBuyHouseList=self:GetBuyHouseIdList(myPartnerId) local otherBuyHouseList=self:GetBuyHouseIdList(friendPartherId) spaceDecorateSchemeHouseItem.buyHouseId=houseId spaceDecorateSchemeHouseItem.myIsBuy=false spaceDecorateSchemeHouseItem.friendIsBuy=false --是否购买 for _, value in ipairs(myBuyHouseList) do if value == spaceDecorateSchemeHouseItem.buyHouseId then spaceDecorateSchemeHouseItem.myIsBuy=true break end end --是否购买 for _, value in ipairs(otherBuyHouseList) do if value == spaceDecorateSchemeHouseItem.buyHouseId then spaceDecorateSchemeHouseItem.friendIsBuy=true break end end --获取全部装修配置 local cfgSchemeAll=skynet.server.gameConfig:GetPlayerAllCfg(player,"Scheme") --该房间下的装修 local cfgSchemeList={} for _, value in ipairs(cfgSchemeAll) do if value.value==houseId then table.insert(cfgSchemeList,value) end end --获取已购买的装修 local mySchemeIdList=self:GetBuyHouseDecorateList(myPartnerId,houseId) local otherSchemeIdList=self:GetBuyHouseDecorateList(friendPartherId,houseId) for _, scheme in ipairs(cfgSchemeList) do local temScheme={} temScheme.decorateId=scheme.id temScheme.decorateName=scheme.defaultName --是否修改过名称 local decorateName=self:GetPlayerHouseDecorateName(player,friendPartherId,houseId,scheme.id ) if decorateName ~= "" then temScheme.decorateName=decorateName end temScheme.myIsBuy=false temScheme.friendIsBuy=false if scheme.currencyBuy == 0 then if spaceDecorateSchemeHouseItem.myIsBuy then temScheme.myIsBuy=true end if spaceDecorateSchemeHouseItem.friendIsBuy then temScheme.friendIsBuy=true end else for _, value in ipairs(mySchemeIdList) do if value == temScheme.decorateId then temScheme.myIsBuy=true break end end for _, value in ipairs(otherSchemeIdList) do if value == temScheme.decorateId then temScheme.friendIsBuy=true break end end end table.insert(spaceDecorateSchemeHouseItem.SpaceDecorateSchemeItemList,temScheme) end return spaceDecorateSchemeHouseItem end --设置玩家房间的装修方案 function DoubleSpace:SetPlayerHouseDecorate(player,friendPartherId,houseId,schemeId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , friendPartherId ) local houseToSchemeList={} --获取该房间的装修方案 local houseIdListJson= skynet.server.redis:hget( myInfoKey ,self:GetMyKey("houseToSchemeIdList",myPartnerId)) if houseIdListJson ~= nil and houseIdListJson ~= "" then houseToSchemeList=json:decode(houseIdListJson) end local isExist=false --是否存在 for _, houseToScheme in ipairs(houseToSchemeList) do if houseToScheme.houseId == houseId then isExist=true houseToScheme.schemeId=schemeId end end if not isExist then table.insert( houseToSchemeList,{houseId=houseId,schemeId=schemeId}) end --判断该房间是否存在 skynet.server.redis:hset( myInfoKey ,self:GetMyKey("houseToSchemeIdList",myPartnerId),json:encode(houseToSchemeList)) end --获取玩家房间的装修方案 function DoubleSpace:GetPlayerHouseDecorate(player,friendPartherId,houseId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , friendPartherId ) local houseToSchemeList={} --获取该房间的装修方案 local houseIdListJson= skynet.server.redis:hget( myInfoKey ,self:GetMyKey("houseToSchemeIdList",myPartnerId)) if houseIdListJson ~= nil and houseIdListJson ~= "" then houseToSchemeList=json:decode(houseIdListJson) end --是否存在 for _, houseToScheme in ipairs(houseToSchemeList) do if houseToScheme.houseId == houseId then return houseToScheme.schemeId end end --返回免费的方案 local cfgSchemeAll =skynet.server.gameConfig:GetPlayerAllCfg(player, "Scheme" ) for k , v in pairs(cfgSchemeAll) do if v.value == houseId and v.currencyBuy == 0 then return v.id end end return 0 end --设置玩家房间的装修方案名称 function DoubleSpace:SetPlayerHouseDecorateName(player,friendPartherId,houseId,schemeId,schemeName ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , friendPartherId ) local houseToSchemeList={} --获取该房间的装修方案 local houseIdListJson= skynet.server.redis:hget( myInfoKey ,self:GetMyKey("houseToSchemeIdList",myPartnerId)) if houseIdListJson ~= nil and houseIdListJson ~= "" then houseToSchemeList=json:decode(houseIdListJson) end local isExist=false --是否存在 for _, houseToScheme in ipairs(houseToSchemeList) do if houseToScheme.houseId == houseId then isExist=true if houseToScheme.schemeList ==nil then houseToScheme.schemeList={} end --查找是否存在 for _, scheme in ipairs(houseToScheme.schemeList) do if scheme.id == schemeId then scheme.name=schemeName goto continue end end --未查找到 table.insert(houseToScheme.schemeList,{id=schemeId,name=schemeName}) --跳出循环(已查找到) ::continue:: break end end if not isExist then table.insert( houseToSchemeList,{houseId=houseId,schemeId=schemeId,schemeList={{id=schemeId,name=schemeName}}}) end --判断该房间是否存在 skynet.server.redis:hset( myInfoKey ,self:GetMyKey("houseToSchemeIdList",myPartnerId),json:encode(houseToSchemeList)) end --获取玩家房间的装修方案名称 function DoubleSpace:GetPlayerHouseDecorateName(player,friendPartherId,houseId,schemeId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , friendPartherId ) local houseToSchemeList={} --获取该房间的装修方案 local houseIdListJson= skynet.server.redis:hget( myInfoKey ,self:GetMyKey("houseToSchemeIdList",myPartnerId)) if houseIdListJson ~= nil and houseIdListJson ~= "" then houseToSchemeList=json:decode(houseIdListJson) end --是否存在 for _, houseToScheme in ipairs(houseToSchemeList) do if houseToScheme.houseId == houseId and houseToScheme.schemeList ~= nil then --查找是否存在 for _, scheme in ipairs(houseToScheme.schemeList) do if scheme.id == schemeId then return scheme.name end end end end return "" end --检查双人空间可以设置 function DoubleSpace:CheckDoubleSpaceInSpace( player,otherPartnerId ) local myPartnerId = player.gameData.partner.id local myInfoKey = self:GetMyInfoKey( myPartnerId , otherPartnerId ) --判断该房间是否存在 local houseIdListJson= skynet.server.redis:hget( myInfoKey , "allHouseId") --检查已购买的房间 local myBuyHouseList = self:GetBuyHouseIdList(myPartnerId) --获取好友购买房间信息 local otherBuyHouseList = self:GetBuyHouseIdList(otherPartnerId) if next(myBuyHouseList) and next(otherBuyHouseList) then for _, myHouseId in ipairs(myBuyHouseList) do for _, otherHouseId in ipairs(otherBuyHouseList) do --共同都有这个房屋 if myHouseId == otherHouseId then --是否存在公共数据 local isExist=true --房间不存在则添加 if houseIdListJson == nil then isExist=false else local houseIdList=json:decode(houseIdListJson) for _, value in ipairs(houseIdList) do --已经存在直接返回 if value == myHouseId then goto continue--直接结束 end end isExist=false ::continue:: end if not isExist then --添加房间 self:AddHouseInfo(player, otherPartnerId , myHouseId ) end --添加装修方案 local myBuyHouseDecList=self:GetBuyHouseDecorateList(myPartnerId, myHouseId) local otherBuyHouseDecList=self:GetBuyHouseDecorateList(otherPartnerId, otherHouseId) if next(myBuyHouseDecList) and next(otherBuyHouseDecList) then for _, myBuyHouseDec in ipairs(myBuyHouseDecList) do for _, otherBuyHouseDec in ipairs(otherBuyHouseDecList) do --共同都有这个装修方案 if myBuyHouseDec == otherBuyHouseDec then --添加装方案 self:AddHouseDeco( player, otherPartnerId , myHouseId ,myBuyHouseDec ) end end end end end end ::continue:: end end end --table去重 function RemoveRepeat(t) local unique={} for _, value in ipairs(t) do unique[value] = true end local newt={} for index,_ in pairs(unique) do table.insert(newt,index) end return newt end skynet.server.doubleSpace = DoubleSpace return DoubleSpace