701 lines
31 KiB
Lua
701 lines
31 KiB
Lua
|
|
local skynet = require "skynet"
|
||
|
|
local oo = require "Class"
|
||
|
|
local pb = require "pb"
|
||
|
|
local log = require "Log"
|
||
|
|
local json =require "json"
|
||
|
|
local errorInfo = require "ErrorInfo"
|
||
|
|
local dataType = require "DataType"
|
||
|
|
local redisKeyUrl = require "RedisKeyUrl"
|
||
|
|
local group = require "Group"
|
||
|
|
local GroupScene = oo.class(group)
|
||
|
|
|
||
|
|
GroupScene.maxLevelLimt = 8
|
||
|
|
GroupScene.moduelArch = {}
|
||
|
|
|
||
|
|
function GroupScene:Init()
|
||
|
|
--读取家园建筑表
|
||
|
|
local cfgAllCommunityArch = skynet.server.gameConfig:GetPlayerAllCfg( nil , "CommunityArch")
|
||
|
|
local isExist = false
|
||
|
|
--初始化地图列表 建筑类型 1-公园 2-集市 3-图书馆 4-甜品店 5-地面 --修改Tag
|
||
|
|
for k, v in pairs( cfgAllCommunityArch ) do
|
||
|
|
if v.optionName ~= nil and v.optionName ~= 0 and v.optionName ~= "" then
|
||
|
|
if next(self.moduelArch) == nil then
|
||
|
|
table.insert(self.moduelArch,{ optionName = v.optionName , type = v.archPlace })
|
||
|
|
else
|
||
|
|
for i, v1 in pairs(self.moduelArch) do
|
||
|
|
if v1.optionName == v.optionName then
|
||
|
|
isExist = true
|
||
|
|
break
|
||
|
|
end
|
||
|
|
end
|
||
|
|
if not isExist then
|
||
|
|
table.insert(self.moduelArch,{ optionName = v.optionName , type = v.archPlace })
|
||
|
|
end
|
||
|
|
isExist = false
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园显示
|
||
|
|
function GroupScene:Show( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGroupSceneShow", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
|
||
|
|
local partnerId = player.gameData.partner.id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( partnerId )
|
||
|
|
local groupId = curDetail.groupId
|
||
|
|
|
||
|
|
if not self:IsVaildParam( "groupId" , groupId ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoGroupMember
|
||
|
|
else
|
||
|
|
data.publicPlot = {}
|
||
|
|
data.privatePlot = {}
|
||
|
|
local curGroup = self:GetGroup( groupId )
|
||
|
|
|
||
|
|
--获取公共地块 (新版本此处需要处理旧版本数据,同步到新版本数据结构) --修改Tag
|
||
|
|
data.publicPlot.communityLevel = curGroup.communityLevel
|
||
|
|
data.publicPlot.archs = {}
|
||
|
|
local redisKey = string.format( redisKeyUrl.GameServerGroupPublicPlot, groupId )
|
||
|
|
local plots = skynet.server.redis:lrange( redisKey , 0 , -1)
|
||
|
|
--log.info("===========家园公共建筑数据库条数===============",#plots)
|
||
|
|
--旧版本数据特殊处理 一个家园仅会执行一次,更新后每个家园第一次有人进入时执行以下逻辑
|
||
|
|
if #plots <=4 then
|
||
|
|
--处理旧版本数据,同时加入新版本数据
|
||
|
|
local cache = {}
|
||
|
|
local btn5 , btn6 , btn7 ,btn8 = false,false,false,false
|
||
|
|
for k1, v1 in ipairs(self.moduelArch) do
|
||
|
|
for k, v in pairs(plots) do
|
||
|
|
local arch = json:decode( v )
|
||
|
|
if v1.optionName == "archBtn_1" then
|
||
|
|
if arch.type == v1.type then
|
||
|
|
cache = { type = arch.type , progress = arch.progress , level = arch.level , styleId = arch.styleId , optionName = "archBtn_1" , isShow = true }
|
||
|
|
if arch.level >= 4 then
|
||
|
|
btn5 = true
|
||
|
|
end
|
||
|
|
break
|
||
|
|
end
|
||
|
|
elseif v1.optionName == "archBtn_2" then
|
||
|
|
if arch.type == v1.type then
|
||
|
|
cache = { type = arch.type , progress = arch.progress , level = arch.level , styleId = arch.styleId , optionName = "archBtn_2" , isShow = true }
|
||
|
|
if arch.level >= 4 then
|
||
|
|
btn6 = true
|
||
|
|
end
|
||
|
|
break
|
||
|
|
end
|
||
|
|
elseif v1.optionName == "archBtn_3" then
|
||
|
|
if arch.type == v1.type then
|
||
|
|
cache = { type = arch.type , progress = arch.progress , level = arch.level , styleId = arch.styleId , optionName = "archBtn_3" , isShow = true }
|
||
|
|
if arch.level >= 4 then
|
||
|
|
btn7 = true
|
||
|
|
end
|
||
|
|
break
|
||
|
|
end
|
||
|
|
elseif v1.optionName == "archBtn_4" then
|
||
|
|
if arch.type == v1.type then
|
||
|
|
cache = { type = arch.type , progress = arch.progress , level = arch.level , styleId = arch.styleId , optionName = "archBtn_4" , isShow = true }
|
||
|
|
if arch.level >= 4 then
|
||
|
|
btn8 = true
|
||
|
|
end
|
||
|
|
break
|
||
|
|
end
|
||
|
|
else
|
||
|
|
if (v1.optionName == "archBtn_5" and btn5) or (v1.optionName == "archBtn_6" and btn6) or (v1.optionName == "archBtn_7" and btn7) or (v1.optionName == "archBtn_8" and btn8) then
|
||
|
|
cache = { type = v1.type , progress = 0 , level = 1 , styleId = 1 , optionName = v1.optionName , isShow = false }
|
||
|
|
else
|
||
|
|
cache = { type = v1.type , progress = 0 , level = 0 , styleId = 0 , optionName = v1.optionName , isShow = false }
|
||
|
|
end
|
||
|
|
break
|
||
|
|
end
|
||
|
|
end
|
||
|
|
if k1 > 4 then
|
||
|
|
skynet.server.redis:rpush( redisKey, json:encode(cache))
|
||
|
|
else
|
||
|
|
skynet.server.redis:lset( redisKey, k1 - 1 , json:encode(cache))
|
||
|
|
end
|
||
|
|
|
||
|
|
end
|
||
|
|
--路面类型单独处理
|
||
|
|
cache = { type = 5 , progress = 0 , level = 0 , styleId = 41 , optionName = "RoadType" , isShow = true }
|
||
|
|
skynet.server.redis:rpush( redisKey , json:encode(cache))
|
||
|
|
plots = skynet.server.redis:lrange( redisKey , 0 , -1)
|
||
|
|
end
|
||
|
|
--log.info("===========家园公共建筑展示===============",json:encode(plots))
|
||
|
|
for k, v in pairs(plots) do
|
||
|
|
local arch = json:decode( v )
|
||
|
|
table.insert( data.publicPlot.archs , arch )
|
||
|
|
end
|
||
|
|
|
||
|
|
--获取私有地块
|
||
|
|
redisKey = string.format( redisKeyUrl.GameServerGroupPrivatePlot, groupId )
|
||
|
|
plots = skynet.server.redis:lrange( redisKey , 0 , -1)
|
||
|
|
for k, v in pairs(plots) do
|
||
|
|
local plot = json:decode( v )
|
||
|
|
local house = {}
|
||
|
|
local archs = {}
|
||
|
|
house,archs = self:GetHouseAndArchs( player , plot.archs )
|
||
|
|
|
||
|
|
if 0 == plot.plotId then
|
||
|
|
--修复因之前超员BUG导致的plotId为0的情况
|
||
|
|
plot.plotId = k
|
||
|
|
skynet.server.redis:lset( redisKey , plot.plotId - 1 , json:encode( plot ))
|
||
|
|
end
|
||
|
|
|
||
|
|
table.insert( data.privatePlot , { plotId = plot.plotId , partnerId = plot.partnerId , house = house , archs = archs } )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
local activityId, startTime, endTime , id = skynet.server.activity:GetActivityInfo( player , dataType.ActivityType_GroupDoubleMaterial )
|
||
|
|
data.activityId = id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( player.gameData.partner.id )
|
||
|
|
data.identity = curDetail.groupIdentityType
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupSceneShow")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGroupSceneShow", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园摆放
|
||
|
|
function GroupScene:Put( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGroupScenePut", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
|
||
|
|
local sceneOp = c2sData.data.sceneOp --操作家园信息
|
||
|
|
if not sceneOp then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
|
|
else
|
||
|
|
data.sceneOp = {}
|
||
|
|
|
||
|
|
--if not self:IsVaildParam( "groupId" , groupId ) then
|
||
|
|
-- s2cData.code = errorInfo.ErrorCode.NoGroupMember
|
||
|
|
--else
|
||
|
|
local curHouse = player.gameData.house[ 11 ]
|
||
|
|
if not player:GetSwitch( dataType.SwitchType_GainGarden ) or not curHouse then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoUnlockGarden
|
||
|
|
else
|
||
|
|
--local plotInfo = skynet.server.redis:lindex( redisKey , plotId - 1 ) --获取家园信息
|
||
|
|
--plotInfo = json:decode(plotInfo)
|
||
|
|
--local allArchs = plotInfo.archs
|
||
|
|
local partnerId = player.gameData.partner.id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( partnerId )
|
||
|
|
local groupId = curDetail.groupId
|
||
|
|
local plotId = tonumber(curDetail.groupPlotId) --地图ID
|
||
|
|
|
||
|
|
local allArchs = curHouse.groupGarden.archs
|
||
|
|
local isSuc = nil
|
||
|
|
for k, v in pairs( sceneOp ) do
|
||
|
|
isSuc = false
|
||
|
|
log.debug(string.format("玩家 %d 家园摆放 操作类型 %d" , player.userId , v.opType))
|
||
|
|
if self.PutType_House == v.opType and self:AddToPlot( player , allArchs , v.arch ) then --新增家具到房间
|
||
|
|
isSuc = true
|
||
|
|
elseif self.PutType_Bag == v.opType and self:RemoveToPlot( player , allArchs , v.arch ) then --从房间中移出家具
|
||
|
|
isSuc = true
|
||
|
|
elseif self.PutType_Move == v.opType and v.lastPos and self:MoveToPlot( player , allArchs , v.arch , v.lastPos ) then --移动家具
|
||
|
|
isSuc = true
|
||
|
|
elseif self.PutType_Operate == v.opType and self:OperatePlot( player , allArchs , v.arch) then --原地操作
|
||
|
|
isSuc = true
|
||
|
|
end
|
||
|
|
if isSuc then
|
||
|
|
table.insert( data.sceneOp , v )
|
||
|
|
else
|
||
|
|
log.debug(string.format("玩家 %d 家园场景 操作失败类型 %d 家具ID %d " , player.userId , v.opType , v.arch.id ))
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
self:SyncGarden( player , groupId , plotId , allArchs )
|
||
|
|
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_107 , groupId , partnerId , plotId , 1 )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupScenePut")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGroupScenePut", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园搬家
|
||
|
|
function GroupScene:Move( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGroupSceneMove", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
|
||
|
|
local partnerId = player.gameData.partner.id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( partnerId )
|
||
|
|
local groupId = curDetail.groupId
|
||
|
|
local redisKey = string.format( redisKeyUrl.GameServerGroupPrivatePlot, groupId )
|
||
|
|
|
||
|
|
local srcPlotId = tonumber(curDetail.groupPlotId) --原地块ID
|
||
|
|
local dstPlotId = c2sData.data.plotId --目标地块ID
|
||
|
|
|
||
|
|
if not self:IsVaildParam( "plotId" , dstPlotId ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
|
|
elseif not self:IsVaildParam( "groupId" , groupId ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoGroupMember
|
||
|
|
else
|
||
|
|
local srcPlotInfo = json:decode(skynet.server.redis:lindex( redisKey , srcPlotId - 1 ))
|
||
|
|
local dstPlotInfo = json:decode(skynet.server.redis:lindex( redisKey , dstPlotId -1 ))
|
||
|
|
|
||
|
|
if "" == srcPlotInfo.partnerId or "" ~= dstPlotInfo.partnerId then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
|
|
else
|
||
|
|
--将玩家的房间数据设置到新的地块上
|
||
|
|
skynet.server.personal:SetDetail( partnerId ,"groupPlotId", dstPlotId )
|
||
|
|
--初始化新土地
|
||
|
|
self:InitScenePlot( player , groupId , dstPlotId , partnerId)
|
||
|
|
--还原旧土地
|
||
|
|
self:ResetScenePlot( groupId , srcPlotId )
|
||
|
|
|
||
|
|
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_106 , groupId , partnerId , srcPlotId , dstPlotId )
|
||
|
|
|
||
|
|
data.srcPrivatePlot = {}
|
||
|
|
data.srcPrivatePlot.plotId = srcPlotId
|
||
|
|
data.srcPrivatePlot.partnerId = ""
|
||
|
|
data.srcPrivatePlot.house = {}
|
||
|
|
data.srcPrivatePlot.archs = {}
|
||
|
|
|
||
|
|
data.dstPrivatePlot = {}
|
||
|
|
data.dstPrivatePlot.plotId = dstPlotId
|
||
|
|
data.dstPrivatePlot.partnerId = partnerId
|
||
|
|
data.dstPrivatePlot.house = {}
|
||
|
|
data.dstPrivatePlot.archs = {}
|
||
|
|
data.dstPrivatePlot.house , data.dstPrivatePlot.archs = self:GetHouseAndArchs( player , srcPlotInfo.archs )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupSceneMove")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGroupSceneMove", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园建设 具体界面展示
|
||
|
|
function GroupScene:ContributeShow( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGroupSceneContributeShow", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
local partnerId = player.gameData.partner.id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( partnerId )
|
||
|
|
local groupId = curDetail.groupId
|
||
|
|
|
||
|
|
if not self:IsVaildParam( "groupId" , groupId ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoGroupMember
|
||
|
|
else
|
||
|
|
skynet.server.groupRank:CheckRankStatus( player , groupId )
|
||
|
|
|
||
|
|
data.publicPlot = {}
|
||
|
|
local curGroup = self:GetGroup( groupId )
|
||
|
|
|
||
|
|
--获取公共地块
|
||
|
|
data.publicPlot.communityLevel = curGroup.communityLevel
|
||
|
|
data.publicPlot.archs = {}
|
||
|
|
local redisKey = string.format( redisKeyUrl.GameServerGroupPublicPlot, groupId )
|
||
|
|
local plots = skynet.server.redis:lrange( redisKey , 0 , -1)
|
||
|
|
for k, v in pairs(plots) do
|
||
|
|
local arch = json:decode( v )
|
||
|
|
table.insert( data.publicPlot.archs , arch )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupSceneContributeShow")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGroupSceneContributeShow", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园建设 贡献
|
||
|
|
function GroupScene:Contribute( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGroupSceneContribute", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
|
||
|
|
local myPartnerId = player.gameData.partner.id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( myPartnerId )
|
||
|
|
local groupId = curDetail.groupId
|
||
|
|
|
||
|
|
local archType = c2sData.data.archType --建筑类型
|
||
|
|
local contributeType = c2sData.data.contributeType --捐赠类型
|
||
|
|
local optionName = c2sData.data.optionName --建筑组别
|
||
|
|
if not self:IsVaildParam( "archType" , archType ) or not self:IsVaildParam( "contributeType" , contributeType ) or not optionName then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
|
|
elseif not self:IsVaildParam( "groupId" , groupId ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoGroupMember
|
||
|
|
else
|
||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
|
|
local counts = cfgSValue.communityMaterialValue --单次捐献的建材数量、建造进度、贡献值收益
|
||
|
|
local goodsId = nil
|
||
|
|
if self.ContributeType_Wood == contributeType then --木材
|
||
|
|
goodsId = 8
|
||
|
|
elseif self.ContributeType_Cement == contributeType then --水泥
|
||
|
|
goodsId = 9
|
||
|
|
elseif self.ContributeType_Rebar == contributeType then --钢筋
|
||
|
|
goodsId = 10
|
||
|
|
end
|
||
|
|
|
||
|
|
--先扣除材料
|
||
|
|
if not skynet.server.bag:RemoveGoods( player , dataType.GoodsType_Prop , goodsId , counts[1] ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughGoods
|
||
|
|
else
|
||
|
|
local isSuc,communityLevel, communityExp ,isUpgrade = false ,0 , 0 ,false --是否升级
|
||
|
|
local curGroup = self:GetGroup( groupId )
|
||
|
|
local redisKey = string.format( redisKeyUrl.GameServerGroupPublicPlot, groupId )
|
||
|
|
local allArchs = skynet.server.redis:lrange( redisKey , 0 , -1)
|
||
|
|
local hasUnlock = false
|
||
|
|
local unlockArchIds = {}
|
||
|
|
for k, v in pairs( allArchs ) do
|
||
|
|
local arch = json:decode( v )
|
||
|
|
if archType == arch.type and optionName == arch.optionName then
|
||
|
|
isSuc,communityLevel , communityExp , isUpgrade , hasUnlock = self:AddContributeValue( player , curGroup , arch , counts , allArchs , redisKey , unlockArchIds )
|
||
|
|
if isSuc then
|
||
|
|
local jsonArch = json:encode( arch )
|
||
|
|
--更新下缓存
|
||
|
|
allArchs[ k ] = jsonArch
|
||
|
|
--成功捐献
|
||
|
|
data.communityLevel = communityLevel
|
||
|
|
data.communityExp = communityExp
|
||
|
|
data.arch = arch
|
||
|
|
data.hasUnlock = hasUnlock
|
||
|
|
data.unlockArchIds = unlockArchIds
|
||
|
|
|
||
|
|
skynet.server.redis:lset( redisKey , k - 1 , jsonArch )
|
||
|
|
skynet.server.levelTask:Modify( player , 66 , 1 )
|
||
|
|
skynet.server.achieveTask:Modify( player , 66 , 1)
|
||
|
|
skynet.server.taskListEvent:Modify( player , 66 , 1)
|
||
|
|
skynet.server.taskListEvent:Modify( player , 32 , 1 )
|
||
|
|
player:AddExpForType( 16 )
|
||
|
|
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_108 , groupId , myPartnerId , goodsId , counts[1] , isUpgrade , communityLevel , communityExp )
|
||
|
|
else
|
||
|
|
--未成功,将材料返还
|
||
|
|
s2cData.code = errorInfo.ErrorCode.AlreadyFinish
|
||
|
|
skynet.server.bag:AddGoods( player , dataType.GoodsType_Prop , goodsId , counts[1] )
|
||
|
|
end
|
||
|
|
break
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
--[[
|
||
|
|
if next(data) == nil then
|
||
|
|
--未成功,将材料返还
|
||
|
|
s2cData.code = errorInfo.ErrorCode.AlreadyFinish
|
||
|
|
skynet.server.bag:AddGoods( player , dataType.GoodsType_Prop , goodsId , counts[1] )
|
||
|
|
end
|
||
|
|
]]
|
||
|
|
|
||
|
|
if isUpgrade then
|
||
|
|
--将家园的升级消息推给家园所有在线玩家
|
||
|
|
local upgradeData = {}
|
||
|
|
upgradeData.communityLevel = communityLevel
|
||
|
|
upgradeData.communityExp = communityExp
|
||
|
|
local redisKey = string.format( redisKeyUrl.GameServerGroupContributionScoreZSet, groupId )
|
||
|
|
local memebers = skynet.server.redis:zrange( redisKey , 0 , -1 )
|
||
|
|
for k, partnerId in pairs( memebers ) do
|
||
|
|
local playerInfo = skynet.server.personal:GetDetail( partnerId )
|
||
|
|
if playerInfo and playerInfo.isOnline and true == playerInfo.isOnline then
|
||
|
|
skynet.server.gameServer:SendMsgToOnlineUser( partnerId , "CMD_S2C_GroupUpgrade" , upgradeData )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupSceneContribute")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGroupSceneContribute", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园场景公共建筑变化风格
|
||
|
|
function GroupScene:ChangeStyle( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGroupSceneChangeStyle", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
|
||
|
|
local myPartnerId = player.gameData.partner.id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( myPartnerId )
|
||
|
|
local groupId = curDetail.groupId
|
||
|
|
|
||
|
|
local archType = c2sData.data.type --建筑类型
|
||
|
|
local archStyleId = c2sData.data.styleId --建筑风格ID
|
||
|
|
local optionName = c2sData.data.optionName --建筑组别
|
||
|
|
if not self:IsVaildParam( "archType" , archType ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
|
|
elseif not self:IsVaildParam( "groupId" , groupId ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoGroupMember
|
||
|
|
elseif not self:IsLeader( myPartnerId ) then --只有园长才能修改风格
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoRight
|
||
|
|
else
|
||
|
|
data.type = archType
|
||
|
|
data.styleId = archStyleId
|
||
|
|
data.optionName = optionName
|
||
|
|
|
||
|
|
local redisKey = string.format( redisKeyUrl.GameServerGroupPublicPlot, groupId )
|
||
|
|
local allArchs = skynet.server.redis:lrange( redisKey , 0 , -1)
|
||
|
|
for k, v in pairs( allArchs ) do
|
||
|
|
local arch = json:decode( v )
|
||
|
|
if archType == arch.type then
|
||
|
|
arch.isShow = false
|
||
|
|
if (optionName == arch.optionName and archStyleId >= 1 and archStyleId <= arch.level) or optionName == "RoadType" then
|
||
|
|
--设置最新的风格ID
|
||
|
|
arch.styleId = archStyleId
|
||
|
|
arch.isShow = true
|
||
|
|
end
|
||
|
|
skynet.server.redis:lset( redisKey , k - 1 , json:encode( arch ))
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupSceneChangeStyle")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGroupSceneChangeStyle", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园私有土地房屋改变
|
||
|
|
function GroupScene:ChangeHouse( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGroupSceneChangeHouse", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
|
||
|
|
local house = c2sData.data.house --建筑类型
|
||
|
|
local curHouse = player.gameData.house[ 11 ]
|
||
|
|
if not house or not self:IsHouseID( player , house.id ) then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
|
|
elseif not player:GetSwitch( dataType.SwitchType_GainGarden ) or not curHouse then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoUnlockGarden
|
||
|
|
else
|
||
|
|
local goodsCount = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Garden , house.id )
|
||
|
|
if 0 == goodsCount then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoExistHouse
|
||
|
|
else
|
||
|
|
data.house = house
|
||
|
|
local allArchs = curHouse.groupGarden.archs
|
||
|
|
local partnerId = player.gameData.partner.id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( partnerId )
|
||
|
|
local groupId = curDetail.groupId
|
||
|
|
local plotId = tonumber(curDetail.groupPlotId) --地图ID
|
||
|
|
|
||
|
|
for k, v in pairs( allArchs ) do
|
||
|
|
if self:IsHouseID( player , v.id ) then
|
||
|
|
allArchs[ k ] =house
|
||
|
|
self:SyncGarden( player , groupId , plotId , allArchs )
|
||
|
|
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_107 , groupId , partnerId , plotId , 2 )
|
||
|
|
break
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupSceneChangeHouse")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGroupSceneChangeHouse", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园庭院展示
|
||
|
|
function GroupScene:GardenShow( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGroupSceneGardenShow", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
|
||
|
|
local partnerId = player.gameData.partner.id
|
||
|
|
local curDetail = skynet.server.personal:GetDetail( partnerId )
|
||
|
|
local groupId = curDetail.groupId
|
||
|
|
local groupPlotId = curDetail.groupPlotId
|
||
|
|
local curHouse = player.gameData.house[ 11 ]
|
||
|
|
|
||
|
|
if not curHouse then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoUnlockGarden
|
||
|
|
else
|
||
|
|
data.privatePlot = {}
|
||
|
|
data.privatePlot.plotId = groupPlotId
|
||
|
|
data.privatePlot.partnerId = partnerId
|
||
|
|
data.privatePlot.house = {}
|
||
|
|
data.privatePlot.archs = {}
|
||
|
|
|
||
|
|
--获取我的地块
|
||
|
|
--local redisKey = string.format( redisKeyUrl.GameServerGroupPrivatePlot, groupId )
|
||
|
|
--local plot = json:decode(skynet.server.redis:lindex( redisKey , groupPlotId - 1 ))
|
||
|
|
data.privatePlot.house , data.privatePlot.archs = self:GetHouseAndArchs( player , curHouse.groupGarden.archs )
|
||
|
|
end
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupSceneGardenShow")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGroupSceneGardenShow", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园增加贡献值
|
||
|
|
function GroupScene:AddContributeValue( player , curGroup , arch , counts , allArchs , redisKey , unlockArchIds )
|
||
|
|
local communityLevel = curGroup.communityLevel --家园等级
|
||
|
|
local communityExp = curGroup.communityExp --家园经验
|
||
|
|
local groupId = curGroup.id
|
||
|
|
local myPartnerId = player.gameData.partner.id
|
||
|
|
local isUpgrade = false --是否升级
|
||
|
|
local hasUnlock = false
|
||
|
|
--counts[2] = 10000 --测试要删除
|
||
|
|
--前置判断 仅判断基础4建筑和路面以外的
|
||
|
|
if arch.optionName ~= "archBtn_1" and arch.optionName ~= "archBtn_2" and arch.optionName ~= "archBtn_3" and arch.optionName ~= "archBtn_4" and arch.optionName ~= "RoadType" then
|
||
|
|
--该建筑前置仍处于未解锁状态
|
||
|
|
if arch.level == 0 then
|
||
|
|
return false , communityLevel , communityExp , isUpgrade , hasUnlock
|
||
|
|
end
|
||
|
|
end
|
||
|
|
--找到家园建筑对应的配置 同时提前将可能会解锁的建筑加入表中方便后续处理
|
||
|
|
local curCfgCommunityArch = nil
|
||
|
|
local nextCfgCommunityArch = nil
|
||
|
|
local mayUnlockArch = {}
|
||
|
|
local cfgAllCommunityArch = skynet.server.gameConfig:GetPlayerAllCfg( player , "CommunityArch")
|
||
|
|
for k, v in pairs( cfgAllCommunityArch ) do
|
||
|
|
if arch.level == v.archLevel and arch.optionName == v.optionName then
|
||
|
|
curCfgCommunityArch = v
|
||
|
|
end
|
||
|
|
if curCfgCommunityArch ~= nil and curCfgCommunityArch.id == v.unlockArch and curCfgCommunityArch.optionName == v.optionName then
|
||
|
|
nextCfgCommunityArch = v
|
||
|
|
end
|
||
|
|
if curCfgCommunityArch ~= nil and curCfgCommunityArch.id == v.unlockArch and curCfgCommunityArch.optionName ~= v.optionName then
|
||
|
|
table.insert(mayUnlockArch,v)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
--已经无后续可用升级
|
||
|
|
if nextCfgCommunityArch == nil then
|
||
|
|
return false , communityLevel , communityExp , isUpgrade , hasUnlock
|
||
|
|
end
|
||
|
|
|
||
|
|
--小于才进行累加建筑进度
|
||
|
|
arch.progress = arch.progress + counts[2]
|
||
|
|
|
||
|
|
if arch.progress >= curCfgCommunityArch.archProgress then
|
||
|
|
--建筑升级
|
||
|
|
arch.progress = arch.progress - curCfgCommunityArch.archProgress
|
||
|
|
arch.level = arch.level + 1
|
||
|
|
arch.styleId = arch.level
|
||
|
|
--升级成功判断有无解锁平行分支的建筑组别
|
||
|
|
if next(mayUnlockArch) ~= nil then
|
||
|
|
for k, v in pairs(mayUnlockArch) do
|
||
|
|
for k1, v1 in pairs( allArchs ) do
|
||
|
|
local cacheArch = json:decode( v1 )
|
||
|
|
if v.optionName == cacheArch.optionName then
|
||
|
|
cacheArch.level = 1
|
||
|
|
cacheArch.styleId = 1
|
||
|
|
hasUnlock = true
|
||
|
|
table.insert(unlockArchIds,v.id)
|
||
|
|
local jsonArch = json:encode( cacheArch )
|
||
|
|
allArchs[ k1 ] = jsonArch
|
||
|
|
skynet.server.redis:lset( redisKey , k1 - 1 , jsonArch )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
communityExp = communityExp + curCfgCommunityArch.archLvlValue
|
||
|
|
if communityLevel > self.maxLevelLimt then
|
||
|
|
communityLevel = self.maxLevelLimt
|
||
|
|
else
|
||
|
|
--找到家园表的当前配置
|
||
|
|
local curCfgCommunity = skynet.server.gameConfig:GetPlayerAllCfg( player , "Community")
|
||
|
|
for k, v in pairs( curCfgCommunity ) do
|
||
|
|
if communityLevel == v.communityLvl then
|
||
|
|
curCfgCommunity = v
|
||
|
|
break
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
if communityExp >= curCfgCommunity.communityLvlValue then
|
||
|
|
--家园升级
|
||
|
|
communityLevel = communityLevel + 1
|
||
|
|
if communityLevel > self.maxLevelLimt then
|
||
|
|
communityLevel = self.maxLevelLimt
|
||
|
|
end
|
||
|
|
communityExp = communityExp - curCfgCommunity.communityLvlValue
|
||
|
|
isUpgrade = true
|
||
|
|
end
|
||
|
|
self:SetGroupInfo( groupId , "communityLevel" , communityLevel , "communityExp" , communityExp )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
local curRankStatus = skynet.server.groupRank:GetRankStatus( player )
|
||
|
|
if self.RankStatus_Acc == curRankStatus then
|
||
|
|
--只有累积状态才统计分数
|
||
|
|
local redisKey = string.format( redisKeyUrl.GameServerGroupContributionScoreZSet, groupId )
|
||
|
|
skynet.server.redis:zincrby( redisKey , counts[3] , myPartnerId )
|
||
|
|
end
|
||
|
|
|
||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_44")
|
||
|
|
player:MoneyChange(dataType.MoneyType_ContributeCoin , counts[3] , eventId )
|
||
|
|
skynet.server.personal:AccDetail( myPartnerId ,"groupContributeScore", counts[3])
|
||
|
|
self:AccGroupInfo( groupId , "contributeScore" , counts[3] )
|
||
|
|
return true , communityLevel , communityExp , isUpgrade , hasUnlock
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园新增到地块
|
||
|
|
function GroupScene:AddToPlot( player , allArchs , arch )
|
||
|
|
local archId = arch.id
|
||
|
|
local count1 = self:GetPropCount( allArchs , archId )
|
||
|
|
local count2 = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Garden , archId )
|
||
|
|
if self:IsHouseID( player , archId ) then
|
||
|
|
return false
|
||
|
|
elseif count1 >= count2 then
|
||
|
|
return false
|
||
|
|
else
|
||
|
|
--拥有商品才能使用
|
||
|
|
table.insert( allArchs , arch)
|
||
|
|
skynet.server.npcTask:Modify( player , 110 , 1 , 0 , archId )
|
||
|
|
skynet.server.taskListEvent:Modify( player , 110 , 1)
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园从地块中移出
|
||
|
|
function GroupScene:RemoveToPlot( player , allArchs , arch )
|
||
|
|
local archId = arch.id
|
||
|
|
local archPos = arch.nowPos
|
||
|
|
|
||
|
|
for k, v in pairs( allArchs ) do
|
||
|
|
if not self:IsHouseID( player , archId ) and archId == v.id and
|
||
|
|
skynet.server.common:Distance( archPos.x , archPos.y , v.nowPos.x , v.nowPos.y) <= 0.1 then
|
||
|
|
table.remove( allArchs , k)
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
end
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
--家园在地块中移动
|
||
|
|
function GroupScene:MoveToPlot( player , allArchs , arch , lastPos )
|
||
|
|
local archId = arch.id
|
||
|
|
local archPos = arch.nowPos
|
||
|
|
|
||
|
|
for k, v in pairs( allArchs ) do
|
||
|
|
local srcPosDistance = skynet.server.common:Distance( lastPos.x , lastPos.y , v.nowPos.x , v.nowPos.y) --原位置距离
|
||
|
|
local dstPosDistance = skynet.server.common:Distance( archPos.x , archPos.y , v.nowPos.x , v.nowPos.y) --目标位置距离
|
||
|
|
if v.id == archId and srcPosDistance <= 0.1 and dstPosDistance >= 0 then
|
||
|
|
v.nowPos = archPos
|
||
|
|
v.rotateType = arch.rotateType
|
||
|
|
v.isPutInFurniture = arch.isPutInFurniture
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
end
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
--原地操作
|
||
|
|
function GroupScene:OperatePlot( player , allArchs , arch )
|
||
|
|
local archId = arch.id
|
||
|
|
local archPos = arch.nowPos
|
||
|
|
|
||
|
|
for k, v in pairs( allArchs ) do
|
||
|
|
local isSamePos = skynet.server.common:Distance( archPos.x , archPos.y , v.nowPos.x , v.nowPos.y ) <= 0.1
|
||
|
|
if isSamePos and v.id == archId then
|
||
|
|
v.nowPos = arch.nowPos
|
||
|
|
v.rotateType = arch.rotateType
|
||
|
|
v.isPutInFurniture = arch.isPutInFurniture
|
||
|
|
v.clickType = arch.clickType
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
end
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
--获取房子和建筑信息
|
||
|
|
function GroupScene:GetHouseAndArchs( player , allArchs )
|
||
|
|
local house = {}
|
||
|
|
local archs = {}
|
||
|
|
|
||
|
|
for k, v in pairs( allArchs ) do
|
||
|
|
if self:IsHouseID( player , v.id ) then
|
||
|
|
house = v
|
||
|
|
else
|
||
|
|
table.insert( archs , v)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
return house , archs
|
||
|
|
end
|
||
|
|
|
||
|
|
--当前道具数量
|
||
|
|
function GroupScene:GetPropCount( allArchs , id )
|
||
|
|
local count = 0
|
||
|
|
for k, v in pairs(allArchs) do
|
||
|
|
if id == v.id then
|
||
|
|
count = count + 1
|
||
|
|
end
|
||
|
|
end
|
||
|
|
return count
|
||
|
|
end
|
||
|
|
|
||
|
|
skynet.server.groupScene = GroupScene
|
||
|
|
return GroupScene
|