HomeServer/Server/AllServer/GameServer/Group/GroupManage.lua
2024-11-20 15:41:37 +08:00

1244 lines
57 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 GroupManage = oo.class(group)
GroupManage.ShowType_JoinList = 1 --加入列表
GroupManage.ShowType_GroupInfo = 2 --家园信息
GroupManage.JoinType_Freedom = 1 --自由加入
GroupManage.JoinType_Audit = 2 --审批加入
GroupManage.QueryType_Recommond = 1 --家园推荐
GroupManage.QueryType_ID = 2 --家园ID查询
GroupManage.QueryType_NickName = 3 --家园昵称查询
GroupManage.ShowGroupMaxCount = 6 --显示家园最大数量
GroupManage.MaxGetGroupCount = 100 --最大获取在线家园数量
GroupManage.RefreshGroupInterval = 3600 --刷新群信息间隔时间
--[[
{"group",
{
{"isAdd", false , "是否加入家园" } ,
{"data", {} , "消息提示数据" } ,
{"reward", {} , "红点奖励" } ,
} ,
"消息提示" } ,
]]
--[[
GroupManage
家园ID 家园名称、家园宣言、家园徽章、加入家园方式(自由加入和审批加入)、加入等级限制
]]
function GroupManage:Init()
skynet.server.timer:Add( dataType.Timer_SyncGroupList , self.RefreshGroupInterval , self["SyncGroupList"] , self )
end
--同步群数据
function GroupManage:SyncGroupList()
local redisKey = redisKeyUrl.GameServerGroupAllZSet
local queryData = skynet.server.redis:zrevrange( redisKey , 0, self.MaxGetGroupCount -1 )
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( nil , "SValue")
local outOfTime = ( cfgSValue.friendChatSave ) * 3600 --好友聊天内容有效期
local curTime = skynet.GetTime()
self.onlineGroupList = {}
--根据找到的数据获取详情
for k, v in pairs( queryData ) do
local curInfo = self:GetGroup( v )
if curInfo and curInfo.memberCount < cfgSValue.communityNum then
table.insert( self.onlineGroupList , curInfo)
end
--需要清理聊天记录
if curInfo and curInfo.cleanChatMsgTime and curTime >= curInfo.cleanChatMsgTime then
local groupId = curInfo.id
local msgKey = string.format( redisKeyUrl.GameServerGroupMsgRecordZSet , groupId )
local msgList = skynet.server.redis:zrange( msgKey , 0 , -1 ) --将聊天记录全部取出
local tmpMsg = nil
local startPos,endPos = 0,0 --过期消息的开始位置和结束位置
for k, v in pairs( msgList ) do
tmpMsg = json:decode( v )
if curTime >= tonumber(tmpMsg.updateTime) + outOfTime then
if 0 == startPos then
--记录开始和结束位置
startPos = tmpMsg.msgId
endPos = tmpMsg.msgId
elseif 0 ~= startPos then
--记录结束位置
endPos = tmpMsg.msgId
end
end
end
if 0 ~= startPos then
--删除所有过期数据
skynet.server.redis:zremrangebyscore( msgKey , startPos , endPos)
self:SetGroupInfo( groupId , "cleanChatMsgTime" , curTime + outOfTime )
end
end
end
end
--家园显示
function GroupManage:Show( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupShow", c2sData.data ))
local data = {}
local myPartnerId = player.gameData.partner.id
local curDetail = skynet.server.personal:GetDetail( myPartnerId )
local myGroupId = curDetail.groupId
if not self:IsVaildParam( "groupId" , myGroupId ) then
s2cData.code = errorInfo.ErrorCode.NoGroupMember
else
data.groupInfo = self:GetGroupAllInfo( player )
--发放别人赠送的材料
local needGoods = json:decode(curDetail.groupNeedGoods or "{}")
for k, v in pairs( needGoods ) do
skynet.server.bag:AddGoods( player , v.goodsType , v.goodsId , v.goodsCount )
player.gameData.group.helpCount = player.gameData.group.helpCount + 1
end
local needCount = #needGoods
if needCount >= 1 then
--互助次数统计到整个家园上面
local redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , myGroupId )
skynet.server.redis:hincrby( redisKey , "helpCount" , needCount )
skynet.server.personal:SetDetail( myPartnerId ,"groupNeedGoods", "{}" )
end
--修改群的最新活跃时间
local redisKey = redisKeyUrl.GameServerGroupAllZSet
skynet.server.redis:zadd( redisKey , skynet.GetTime() , myGroupId )
--检查福利是否能获得
self:CheckContributeReward( player , myGroupId )
skynet.server.levelTask:Modify( player , 89 , 1 )
skynet.server.taskListEvent:Modify( player , 89 , 1 )
skynet.server.msgTips:ReduceAll(player , 65 )
end
data.groupInfo.member.birthdayDate=player.gameData.personal.birthday.birthdayDate
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupShow")
s2cData.data = assert(pb.encode("S2CGroupShow", data))
end
--家园创建
function GroupManage:Create( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupCreate", c2sData.data ))
local data = {}
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local nexJoinTime = cfgSValue.communityReEnterTime * 3600 --下一次加入时间
local curPartner = player.gameData.partner
local curDetail = skynet.server.personal:GetDetail( curPartner.id )
local groupId = curDetail.groupId
local name = c2sData.data.name
local declaration = c2sData.data.declaration
local badgeId = c2sData.data.badgeId
local joinType = c2sData.data.joinType
local minJoinLevel = c2sData.data.minJoinLevel
local myLevel = player.gameData.level
if not self:IsVaildParam( "groupName" , name ) or not self:IsVaildParam( "declaration" , declaration ) or not self:IsVaildParam( "badgeId" , badgeId )
or not self:IsVaildParam( "joinType" , joinType ) or not self:IsVaildParam( "minJoinLevel" , minJoinLevel ) then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif skynet.server.common:IsMaskWords( name ) then
s2cData.code = errorInfo.ErrorCode.ExistMaskWords
elseif skynet.server.common:IsMaskWords( declaration ) then
s2cData.code = errorInfo.ErrorCode.ExistMaskWords
elseif not player:GetSwitch( dataType.SwitchType_GainGarden ) then
s2cData.code = errorInfo.ErrorCode.NoUnlockGarden
elseif "" ~= groupId then
s2cData.code = errorInfo.ErrorCode.AlreadyExistGroup
elseif myLevel < cfgSValue.communityUnlockLvl then
s2cData.code = errorInfo.ErrorCode.LevelLimit
elseif skynet.GetTime() < tonumber(curDetail.groupExitTime) + nexJoinTime then
--退出时间冻结期,无法加入
local hour = math.ceil(((tonumber(curDetail.groupExitTime) + nexJoinTime) - skynet.GetTime()) / 3600)
s2cData.code = errorInfo.ErrorCode.ExistGroupFreezeTime
s2cData.desc = string.format(errorInfo.ErrorMsg[ s2cData.code ] , hour )
else
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_43")
if not player:MoneyChange( dataType.MoneyType_Coin , -cfgSValue.communityCreate , eventId ) then
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
else
local myPartnerId = player.gameData.partner.id
local whileCount = 0
--开始创建家园
while true do
whileCount = whileCount + 1
if whileCount >= 100 then
s2cData.code = errorInfo.ErrorCode.OPFailed
break
end
local groupId = skynet.server.common:RandIDNoIAndL( 10 ) --生成10位随机ID
local redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , groupId )
if not skynet.server.redis:exists( redisKey ) then
--计算排行榜状态和时间
local rankStatus , nexRankStatusTime = self:CalcRankStatusAndTime()
local nextRewardTime = self:CalcContributeRewardTime()
--扣除金币
skynet.server.redis:hmset( redisKey , --初始化家园信息
"id" , groupId ,
"name" , name , --家园名称
"declaration" , declaration , --家园宣言
"badgeId" , badgeId , --徽章ID
"joinType" , joinType , --加入类型
"minJoinLevel" , minJoinLevel, --最小加入等级
"memberCount", 0, --成员数量
"leader" , myPartnerId , --园长
"viceLeader1" , "" , --副园长1
"viceLeader2" , "", --副园长2
"communityLevel",1 , --社区等级
"communityExp",0 , --社区经验
"contributeScore",0, --所有人的贡献分数
"contributeReward",0, --福利奖励
"nextContributeRewardTime", nextRewardTime , --下一次福利时间
"rankStatus", rankStatus , --排行榜状态
"nexRankStatusTime", nexRankStatusTime , --排行榜下一个状态时间
"createTime", skynet.GetTime() , --创建时间
"cleanChatMsgTime", skynet.GetTime() --清理聊天消息的时间
)
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_100 , groupId , myPartnerId , name , declaration , badgeId , joinType , minJoinLevel )
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_109 , groupId , myPartnerId , rankStatus , nexRankStatusTime )
--添加到家园集合
local redisKey = redisKeyUrl.GameServerGroupAllZSet
skynet.server.redis:zadd( redisKey , skynet.GetTime() , groupId )
redisKey = string.format( redisKeyUrl.GameServerGroupPublicPlot, groupId )
local arch = { }
--读取家园建筑表
local cfgAllCommunityArch = skynet.server.gameConfig:GetPlayerAllCfg( player , "CommunityArch")
local cacheArch = {}
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(cacheArch) == nil then
table.insert(cacheArch,{ optionName = v.optionName , type = v.archPlace })
else
for i, v1 in pairs(cacheArch) do
if v1.optionName == v.optionName then
isExist = true
break
end
end
if not isExist then
table.insert(cacheArch,{ optionName = v.optionName , type = v.archPlace })
end
isExist = false
end
end
end
for k, v in ipairs(cacheArch) do
if k <= 4 then
arch = { type = v.type , progress = 0 , level = 1 , styleId = 1 , optionName = v.optionName , isShow = true }
else
arch = { type = v.type , progress = 0 , level = 0 , styleId = 0 , optionName = v.optionName , isShow = false }
end
skynet.server.redis:rpush( redisKey , json:encode(arch))
end
--路面类型单独处理
arch = { type = 5 , progress = 0 , level = 0 , styleId = 41 , optionName = "RoadType" , isShow = true }
skynet.server.redis:rpush( redisKey , json:encode(arch))
--初始化地图列表 建筑类型 1-公园 2-集市 3-图书馆 4-甜品店
--local arch1 = { type = 1 , progress = 0 , level = 1 , styleId = 1 }
--local arch2 = { type = 2 , progress = 0 , level = 1 , styleId = 1 }
--local arch3 = { type = 3 , progress = 0 , level = 1 , styleId = 1 }
--local arch4 = { type = 4 , progress = 0 , level = 1 , styleId = 1 }
--
--skynet.server.redis:rpush( redisKey , json:encode(arch1) , json:encode(arch2), json:encode(arch3), json:encode(arch4))
redisKey = string.format( redisKeyUrl.GameServerGroupPrivatePlot, groupId )
local plotInfos = {}
for i = 1, self.MaxMapCount, 1 do
plotInfos[ i ] = json:encode({ plotId = i , partnerId = "" , archs = {}})
end
skynet.server.redis:rpush( redisKey , plotInfos[ 1 ] , plotInfos[ 2 ] , plotInfos[ 3 ] , plotInfos[ 4 ] , plotInfos[ 5 ] , plotInfos[ 6 ] ,
plotInfos[ 7 ] , plotInfos[ 8 ] , plotInfos[ 9 ] , plotInfos[ 10 ] , plotInfos[ 11 ] , plotInfos[ 12 ])
--添加成员
self:AddMember( player , groupId , myPartnerId , self.IdentityType_Leader )
--同步群信息
self:SyncOnlineGroupInfo( groupId , self.GroupOpType_Create , true )
data.groupInfo = self:GetGroupAllInfo( player )
log.debug(string.format("玩家 %d 家园 成功创建 家园ID %s 伙伴ID %s ", player.userId , groupId , myPartnerId))
break
end
end
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupCreate")
s2cData.data = assert(pb.encode("S2CGroupCreate", data))
end
--家园加入
function GroupManage:Join( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupJoin", c2sData.data ))
local data = {}
local curPartner = player.gameData.partner
local myPartnerId = curPartner.id
local curDetail = skynet.server.personal:GetDetail( myPartnerId )
local myGroupId = curDetail.groupId
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local nexJoinTime = cfgSValue.communityReEnterTime * 3600 --下一次加入时间
local communityNum = cfgSValue.communityNum --最大加入人数
local groupId = c2sData.data.groupId
local curGroup = self:GetGroup( groupId )
local myLevel = player.gameData.level
if "" ~= myGroupId then
s2cData.code = errorInfo.ErrorCode.AlreadyExistGroup
elseif not player:GetSwitch( dataType.SwitchType_GainGarden ) then
s2cData.code = errorInfo.ErrorCode.NoUnlockGarden
elseif not self:IsExistGroup( groupId ) then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif curGroup.memberCount >= communityNum then
s2cData.code = errorInfo.ErrorCode.MaxLimit
elseif skynet.GetTime() < tonumber(curDetail.groupExitTime) + nexJoinTime then
local hour = math.ceil(((tonumber(curDetail.groupExitTime) + nexJoinTime) - skynet.GetTime()) / 3600)
s2cData.code = errorInfo.ErrorCode.ExistGroupFreezeTime
s2cData.desc = string.format(errorInfo.ErrorMsg[ s2cData.code ] , hour )
elseif myLevel < cfgSValue.communityUnlockLvl or myLevel < curGroup.minJoinLevel then
s2cData.code = errorInfo.ErrorCode.LevelLimit
else
local redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , groupId )
if not curGroup then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
data.joinType = curGroup.joinType
if self.JoinType_Freedom == curGroup.joinType then
self:AddMember( player , groupId , myPartnerId , self.IdentityType_Member )
data.groupInfo = self:GetGroupAllInfo( player )
skynet.server.levelTask:Modify( player , 89 , 1 )
skynet.server.taskListEvent:Modify( player , 89 , 1 )
self:ResetAllMsgTips( myPartnerId )
log.debug(string.format("玩家 %d 家园 直接加入 家园ID %s 伙伴ID %s ", player.userId , groupId , curPartner.id))
elseif self.JoinType_Audit == curGroup.joinType then
--skynet.server.redis:multi()
--玩家申请加入
local redisKey = string.format( redisKeyUrl.GameServerGroupUserApplyJoinZSet , groupId )
if nil ~= skynet.server.redis:zrank( redisKey , curPartner.id ) then
s2cData.code = errorInfo.ErrorCode.AlreadyApply
else
--未申请的才能申请
skynet.server.redis:zadd( redisKey , skynet.GetTime() , curPartner.id )
redisKey = string.format( redisKeyUrl.GameServerGroupMyApplyJoinZSet , curPartner.id )
skynet.server.redis:zadd( redisKey , skynet.GetTime() , groupId )
--给3位领导发红点信息
if "" ~= curGroup.leader then
skynet.server.partner:SendMsgTips( curGroup.leader , 60 , true )
end
if "" ~= curGroup.viceLeader1 then
skynet.server.partner:SendMsgTips( curGroup.viceLeader1 , 60 , true )
end
if "" ~= curGroup.viceLeader2 then
skynet.server.partner:SendMsgTips( curGroup.viceLeader2 , 60 , true )
end
data.groupInfo = {}
log.debug(string.format("玩家 %d 家园 申请加入 家园ID %s 伙伴ID %s ", player.userId , groupId , curPartner.id))
end
end
self:SyncOnlineGroupInfo( groupId , self.GroupOpType_Update , true )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupJoin")
s2cData.data = assert(pb.encode("S2CGroupJoin", data))
end
--家园退出
function GroupManage:Quit( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupQuit", c2sData.data ))
local data = {}
local curPartner = player.gameData.partner
local myPartnerId = curPartner.id
local curDetail = skynet.server.personal:GetDetail( myPartnerId )
local groupId = curDetail.groupId
local groupPlotId = curDetail.groupPlotId
local cmd = c2sData.cmd
if not self:IsVaildParam( "groupId" , groupId ) then
s2cData.code = errorInfo.ErrorCode.NoGroupMember
elseif player:IsMsgTooFast( cmd ) then
s2cData.code = errorInfo.ErrorCode.RequestMsgTooFast
else
local redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , groupId )
if not skynet.server.redis:exists( redisKey) then
s2cData.code = errorInfo.ErrorCode.NoExistGroup
else
skynet.server.personal:SetDetail( myPartnerId , "groupExitTime" , skynet.GetTime())
if errorInfo.Suc == s2cData.code then
--副园长和成员继续走退出流程
self:DeleteMember( player.userId , groupId , myPartnerId , groupPlotId )
log.debug(string.format("玩家 %d 家园 申请退出 家园ID %s 伙伴ID %s 身份类型 %d", player.userId , groupId , curPartner.id , curDetail.groupIdentityType))
end
self:SyncOnlineGroupInfo( groupId , self.GroupOpType_Update , true )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupQuit")
s2cData.data = assert(pb.encode("S2CGroupQuit", data))
end
--家园查询
function GroupManage:Query( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupQuery", c2sData.data ))
local data = {}
data.groupInfo = {}
local queryType = c2sData.data.queryType
local queryValue = c2sData.data.queryValue
local curPartner = player.gameData.partner
local curDetail = skynet.server.personal:GetDetail( curPartner.id )
local groupId = queryValue
if not queryType or queryType < self.QueryType_Recommond or queryType > self.QueryType_ID then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif self.QueryType_ID == queryType and not self:IsVaildParam( "groupId" , groupId ) then
s2cData.code = errorInfo.ErrorCode.NoExistGroup
else
local redisKey = nil
local myPlayerId = player.gameData.partner.id
local groupList = {}
if self.QueryType_Recommond == queryType then
data.groupInfo = self:Recommond( player )
elseif self.QueryType_ID == queryType and queryValue then
table.insert( groupList , queryValue )
elseif self.QueryType_NickName == queryType and queryValue then
--[[
redisKey = redisKeyUrl.GameServerGroupNickNameZSet
local tmpQueryData = skynet.server.redis:zscan( redisKey ,0,"match" , string.format("*%s*",queyValue)) --根据关键字模糊查询相关昵称
for k, v in pairs( tmpQueryData[2] ) do
if 2 == k and myPlayerId ~= v then
table.insert( groupList , v )
end
end
]]
else
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
end
if self.QueryType_ID == queryType or self.QueryType_NickName == queryType then
data.groupInfo = self:GroupJoinInfo( curPartner.id , groupList)
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupQuery")
s2cData.data = assert(pb.encode("S2CGroupQuery", data))
end
--家园更新信息(园长/副园长)
function GroupManage:UpdateInfo( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupUpdateInfo", c2sData.data ))
local data = {}
local curGroup = player.gameData.group
local declaration = c2sData.data.declaration
local badgeId = c2sData.data.badgeId
local joinType = c2sData.data.joinType
local minJoinLevel = c2sData.data.minJoinLevel
local partnerId = player.gameData.partner.id
local curDetail = skynet.server.personal:GetDetail( partnerId )
local groupId = curDetail.groupId
if not self:IsVaildParam( "declaration" , declaration ) or not self:IsVaildParam( "badgeId" , badgeId ) or
not self:IsVaildParam( "joinType" , joinType ) or not self:IsVaildParam( "minJoinLevel" , minJoinLevel )then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif not self:IsVaildParam( "groupId" , groupId ) then
s2cData.code = errorInfo.ErrorCode.NoGroupMember
elseif skynet.server.common:IsMaskWords( declaration ) then
s2cData.code = errorInfo.ErrorCode.ExistMaskWords
elseif not self:IsManage( partnerId ) then
s2cData.code = errorInfo.ErrorCode.NoRight
else
local redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , groupId )
skynet.server.redis:hmset( redisKey ,"declaration" , declaration , "badgeId" , badgeId ,"joinType" , joinType ,"minJoinLevel" , minJoinLevel)
self:SyncOnlineGroupInfo( groupId , self.GroupOpType_Update , true )
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_102 , groupId , partnerId , declaration , badgeId , joinType , minJoinLevel )
data.groupInfo = self:GetGroupAllInfo( player )
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupUpdateInfo")
s2cData.data = assert(pb.encode("S2CGroupUpdateInfo", data))
end
--家园家园改变身份(园长/副园长)
function GroupManage:ChangeIdentity( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupChangeIdentity", c2sData.data ))
local data = {}
local myPartnerId = player.gameData.partner.id
local myDetail = skynet.server.personal:GetDetail( myPartnerId )
local myGroupId = myDetail.groupId
local toPartnerId = c2sData.data.partnerId
local toIdentityType = c2sData.data.identityType
local toDetail = skynet.server.personal:GetDetail( toPartnerId )
local toGroupId = toDetail.groupId
if not toDetail or not self:IsVaildParam( "partnerId" , toPartnerId ) or not self:IsVaildParam( "identityType" , toIdentityType ) or myPartnerId == toPartnerId then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif not self:IsLeader( myPartnerId ) then --只有园长才能把园长身份转给别人
s2cData.code = errorInfo.ErrorCode.NoRight
elseif myGroupId ~= toGroupId then
s2cData.code = errorInfo.ErrorCode.NoGroupMember
else
local redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , myGroupId )
local viceIdentityInfo = skynet.server.redis:hmget( redisKey , "viceLeader1" , "viceLeader2")
local viceCount = 0
for k, v in pairs( viceIdentityInfo ) do
if "" ~= v then
viceCount = viceCount + 1
end
end
if self.IdentityType_ViceLeader == toIdentityType and viceCount >= 2 then
--设置副管理员数量大于2就不能再设了
s2cData.code = errorInfo.ErrorCode.MaxLimit
else
if self.IdentityType_ViceLeader == toDetail.groupIdentityType then --被转让的人如果是副园长,就清理标记
for k, v in pairs( viceIdentityInfo ) do
if 1 == k and toPartnerId == v then
skynet.server.redis:hset( redisKey , "viceLeader1" , "" )
break
elseif 2 == k and toPartnerId == v then
skynet.server.redis:hset( redisKey , "viceLeader2" , "" )
break
end
end
end
if self.IdentityType_Leader == toIdentityType then --园长交换
skynet.server.redis:hset( redisKey , "leader" , toPartnerId ) --将玩家设为园长
skynet.server.personal:SetDetail( myPartnerId , "groupIdentityType" , self.IdentityType_Member ) --将自己身份改为成员
skynet.server.personal:SetDetail( toPartnerId , "groupIdentityType" , self.IdentityType_Leader ) --将玩家身份改为园长
elseif self.IdentityType_ViceLeader == toIdentityType then --园长指定副园长
for k, v in pairs( viceIdentityInfo ) do
--找个指定的空位安置副园长
if 1 == k and "" == v then
skynet.server.redis:hset( redisKey , "viceLeader1" , toPartnerId )
break
elseif 2 == k and "" == v then
skynet.server.redis:hset( redisKey , "viceLeader2" , toPartnerId )
break
end
end
skynet.server.personal:SetDetail( toPartnerId , "groupIdentityType" , self.IdentityType_ViceLeader) --将玩家身份改为副园长
elseif self.IdentityType_Member == toIdentityType then
skynet.server.personal:SetDetail( toPartnerId , "groupIdentityType" , self.IdentityType_Member ) --将玩家身份改为园长
end
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_103 , myGroupId , myPartnerId , toPartnerId , toIdentityType )
self:SyncOnlineGroupInfo( myGroupId , self.GroupOpType_Update , true )
data.member = self:GetMember( myGroupId , myPartnerId )
log.debug(string.format("玩家 %d 家园 成员 %s 指定成员类型 %d", player.userId , toPartnerId , toIdentityType ))
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupChangeIdentity")
s2cData.data = assert(pb.encode("S2CGroupChangeIdentity", data))
end
--家园请求加入的玩家列表(园长/副园长)
function GroupManage:ApplyList( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupApplyList", c2sData.data ))
local data = {}
local myPartnerId = player.gameData.partner.id
local curDetail = skynet.server.personal:GetDetail( myPartnerId )
local groupId = curDetail.groupId
if not self:IsVaildParam( "groupId" , groupId ) then
s2cData.code = errorInfo.ErrorCode.NoGroupMember
elseif not self:IsManage( myPartnerId ) then
s2cData.code = errorInfo.ErrorCode.NoRight
else
data.partnerInfos = {}
local groupId = self:GetGroupID( player )
local redisKey = string.format( redisKeyUrl.GameServerGroupUserApplyJoinZSet , groupId )
local partnerIds = skynet.server.redis:zrange( redisKey , 0 , -1 )
for k , partnerId in pairs( partnerIds ) do
local curDetail = skynet.server.personal:GetDetail( partnerId )
if curDetail then
table.insert( data.partnerInfos , curDetail )
end
end
--[[
skynet.server.msgTips:Reduce(player , 60 )
if #data.partnerInfos > 0 then
skynet.server.msgTips:Add(player , 60 )
end]]
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupApplyList")
s2cData.data = assert(pb.encode("S2CGroupApplyList", data))
end
--家园审核(园长/副园长)
function GroupManage:Audit( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupAudit", c2sData.data ))
local data = {}
local myPartnerId = player.gameData.partner.id
local joinPartnerId = c2sData.data.partnerId
local isAgree = c2sData.data.isAgree
local myDetail = skynet.server.personal:GetDetail( myPartnerId )
local myGroupId = myDetail.groupId
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local nexJoinTime = cfgSValue.communityReEnterTime * 3600 --下一次加入时间
local communityNum = cfgSValue.communityNum --最大加入人数
local curGroup = self:GetGroup( myGroupId )
local joinDetail = skynet.server.personal:GetDetail( joinPartnerId )
if not self:IsVaildParam( "partnerId" , joinPartnerId ) then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif not self:IsManage( myPartnerId ) then
s2cData.code = errorInfo.ErrorCode.NoRight
elseif true == isAgree and curGroup.memberCount >= communityNum then
s2cData.code = errorInfo.ErrorCode.MaxLimit
elseif true == isAgree and skynet.GetTime() < tonumber(joinDetail.groupExitTime) + nexJoinTime then
s2cData.code = errorInfo.ErrorCode.ExitGroupOver24Hour
else
--从申请的列表中删除该玩家
local redisKey = string.format( redisKeyUrl.GameServerGroupMyApplyJoinZSet , joinPartnerId )
skynet.server.redis:zrem( redisKey , myGroupId )
redisKey = string.format( redisKeyUrl.GameServerGroupUserApplyJoinZSet , myGroupId )
skynet.server.redis:zrem( redisKey , joinPartnerId )
local joinGroupId = joinDetail.groupId
if not joinDetail then
s2cData.code = errorInfo.ErrorCode.NoExistUser
elseif isAgree and "" ~= joinGroupId then
s2cData.code = errorInfo.ErrorCode.AlreadyExistGroup
else
local myPartnerId = player.gameData.partner.id
if isAgree then
self:ResetAllMsgTips( joinPartnerId )
--加入到家园
self:AddMember( player , myGroupId , joinPartnerId , self.IdentityType_Member )
skynet.server.partner:SendMsgTips( joinPartnerId , 65 , true )
end
local isHaveJoin = false --是否还有加入的玩家
data.partnerInfos = {}
local partnerIds = skynet.server.redis:zrange( redisKey , 0 , -1 )
for k , partnerId in pairs( partnerIds ) do
local curDetail = skynet.server.personal:GetDetail( partnerId )
if curDetail then
table.insert( data.partnerInfos , curDetail )
isHaveJoin = true
end
end
if not isHaveJoin then
--没有加入的了就清空红点
if "" ~= curGroup.leader then
skynet.server.partner:ReduceAllMsgTips( curGroup.leader , 60)
end
if "" ~= curGroup.viceLeader1 then
skynet.server.partner:ReduceAllMsgTips( curGroup.viceLeader1 , 60)
end
if "" ~= curGroup.viceLeader2 then
skynet.server.partner:ReduceAllMsgTips( curGroup.viceLeader2 , 60)
end
end
self:SyncOnlineGroupInfo( myGroupId , self.GroupOpType_Update , true )
data.member = self:GetMember( myGroupId , myPartnerId )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupAudit")
s2cData.data = assert(pb.encode("S2CGroupAudit", data))
end
--家园踢出成员
function GroupManage:Kick( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupKick", c2sData.data ))
local data = {}
local myPartnerId = player.gameData.partner.id
local kickPartnerId = c2sData.data.partnerId
local cmd = c2sData.cmd
if not self:IsVaildParam( "partnerId" , kickPartnerId ) or myPartnerId == kickPartnerId then --不能踢自己
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif not self:IsManage( myPartnerId ) then
s2cData.code = errorInfo.ErrorCode.NoRight
elseif player:IsMsgTooFast( cmd ) then
s2cData.code = errorInfo.ErrorCode.RequestMsgTooFast
else
local myDetail = skynet.server.personal:GetDetail( myPartnerId )
local kickDetail = skynet.server.personal:GetDetail( kickPartnerId )
local isRight = false
if self.IdentityType_Leader == myDetail.groupIdentityType then --园长可以踢一切人
isRight = true
elseif self.IdentityType_ViceLeader == myDetail.groupIdentityType and self.IdentityType_Member == kickDetail.groupIdentityType then --副园长可以踢成员
isRight = true
end
if not isRight then
--非成员不允许踢出
s2cData.code = errorInfo.ErrorCode.NoRight
else
local groupId = myDetail.groupId
local kickGroupPlotId = kickDetail.groupPlotId
self:DeleteMember( tonumber( kickDetail.userId ) , groupId , kickPartnerId , kickGroupPlotId)
self:SyncOnlineGroupInfo( groupId , self.GroupOpType_Update , true )
--发送邮件
local content = string.format("您已被移出 %s 家园请24小时后再加入新的家园吧" , groupId )
skynet.server.mail:SendAsyncMailForPartnerId( kickPartnerId , skynet.server.mail.MailType_Msg , "退出家园" , content , {})
data.partnerId = kickPartnerId
data.member = self:GetMember( groupId , myPartnerId )
--被踢后,如果玩家在线也需要通知,并关闭所有红点
skynet.server.gameServer:SendMsgToOnlineUser( kickPartnerId , "CMD_S2C_GroupKickByLeader" , {} )
self:ResetAllMsgTips( kickPartnerId )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupKick")
s2cData.data = assert(pb.encode("S2CGroupKick", data))
end
--家园解散(园长)
function GroupManage:Dissolve( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupDissolve", c2sData.data ))
local data = {}
local myPartnerId = player.gameData.partner.id
local groupId = self:GetGroupID( player )
if not self:IsVaildParam( "groupId" , groupId ) then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif not self:IsLeader( myPartnerId ) then
s2cData.code = errorInfo.ErrorCode.NoRight
else
--同步群信息
self:SyncOnlineGroupInfo( groupId , self.GroupOpType_Dissolve , true )
local redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , groupId )
skynet.server.redis:del( redisKey )
redisKey = redisKeyUrl.GameServerGroupAllZSet
skynet.server.redis:zrem( redisKey , groupId )
redisKey = string.format( redisKeyUrl.GameServerGroupPublicPlot , groupId )
skynet.server.redis:del( redisKey )
redisKey = string.format( redisKeyUrl.GameServerGroupPrivatePlot , groupId )
skynet.server.redis:del( redisKey )
redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , groupId )
skynet.server.redis:del( redisKey )
redisKey = string.format( redisKeyUrl.GameServerGroupDreamLifeTaskList , groupId )
skynet.server.redis:del( redisKey )
redisKey = string.format( redisKeyUrl.GameServerGroupContributionScoreZSet, groupId )
--将所有玩家的群ID置空
local allPartnerId = skynet.server.redis:zrange( redisKey , 0 , -1 )
for k, v in pairs( allPartnerId ) do
skynet.server.personal:SetDetail( v , "groupId", "" , "groupExitTime" , skynet.GetTime())
end
skynet.server.redis:del( redisKey )
skynet.server.gameRecord:Add( player.userId , dataType.GameRecordType_101 , groupId , myPartnerId )
log.debug(string.format("玩家 %d 家园 解散 家园ID %s 操作人ID %s ", player.userId , groupId , player.gameData.partner.id ))
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupDissolve")
s2cData.data = assert(pb.encode("S2CGroupDissolve", data))
end
--家园签到
function GroupManage:Signin( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupSignin", c2sData.data ))
local data = {}
local signInType = c2sData.data.signInType
if signInType < 1 or signInType > 3 then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
local myPartnerId = player.gameData.partner.id
local curDetail = skynet.server.personal:GetDetail( myPartnerId )
if 0 ~= curDetail.groupSignInType then
s2cData.code = errorInfo.ErrorCode.AlreadyGet
else
local groupId = self:GetGroupID( player )
local groupInfo = self:GetGroup( groupId )
local communityLevel = groupInfo.communityLevel
--根据家园等级获取打卡奖励
local signReward = nil
local signMaterialReward = nil
local cfgAllCommunity = skynet.server.gameConfig:GetPlayerAllCfg( player , "Community")
for k, v in pairs( cfgAllCommunity ) do
if communityLevel == v.communityLvl then
signReward = v.signReward
signMaterialReward = v.signMaterialReward
break
end
end
skynet.server.levelTask:Modify( player , 90 , 1 )
skynet.server.taskListEvent:Modify( player , 90 , 1 )
--随机发放奖励
local randIndex = math.random( 1 , #signReward )
local curRewardId = signReward[ randIndex ]
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_72")
player:GiveReward( curRewardId , eventId)
--打卡建材奖励
local curMaterialReward = signMaterialReward[ signInType ]
local rewardInfo = skynet.server.common:Split( curMaterialReward ,"_" )
rewardInfo[1],rewardInfo[2] = tonumber(rewardInfo[1]),tonumber(rewardInfo[2])
skynet.server.bag:AddGoods( player , dataType.GoodsType_Prop, rewardInfo[1] , rewardInfo[2] )
skynet.server.personal:SetDetail( myPartnerId , "groupSignInType" , signInType )
data.signInType = signInType
data.rewardId = curRewardId
data.rewardGoods = { goodsType = dataType.GoodsType_Prop , goodsId = rewardInfo[1] , goodsCount = rewardInfo[2] }
skynet.server.msgTips:ReduceAll(player , 38)
log.debug(string.format("玩家 %d 家园 签到 家园ID %s 伙伴ID %s 获取奖励 %d", player.userId , groupId , myPartnerId , curRewardId))
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupSignin")
s2cData.data = assert(pb.encode("S2CGroupSignin", data))
end
--家园福利展示
function GroupManage:WelfareShow( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupWelfareShow", c2sData.data ))
local data = {}
local curGroup = player.gameData.group
local myPartnerId = player.gameData.partner.id
local myDetail = skynet.server.personal:GetDetail( myPartnerId )
local signInType = myDetail.groupSignInType
local myGroupId = myDetail.groupId
local curGroupInfo = self:GetGroupInfo( myGroupId , "contributeScore" , "contributeReward" , "helpCount" )
local contributeScore = tonumber(curGroupInfo[1] or 0)
local contributeReward = tonumber(curGroupInfo[2] or 0)
local helpCount = tonumber(curGroupInfo[3] or 0)
local redisKey = string.format( redisKeyUrl.GameServerGroupContributeRewardRecordSet, myGroupId )
local isGainWelfare = true
if contributeReward > 0 and skynet.server.redis:sismember( redisKey , myPartnerId ) then
--有福利并且没领取,就可以领
isGainWelfare = false
end
data.signInType = signInType;
data.contributeScore = contributeScore;
data.isGainWelfare = isGainWelfare
data.helpCount = helpCount
data.gainHelpCounts = {}
for k, v in pairs( curGroup.helpGainReward ) do
table.insert( data.gainHelpCounts , v )
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupWelfareShow")
s2cData.data = assert(pb.encode("S2CGroupWelfareShow", data))
end
--获取家园福利
function GroupManage:ContributeRewardGain( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupContributeRewardGain", c2sData.data ))
local data = {}
local myPartnerId = player.gameData.partner.id
local myDetail = skynet.server.personal:GetDetail( myPartnerId )
local myGroupId = myDetail.groupId
--检查福利是否能获得
self:CheckContributeReward( player , myGroupId )
local groupData = self:GetGroupInfo( myGroupId , "contributeReward")
local rewardId = tonumber(groupData[1])
if 0 == rewardId then
s2cData.code = errorInfo.ErrorCode.NowNoWelfare
else
local redisKey = string.format( redisKeyUrl.GameServerGroupContributeRewardRecordSet, myGroupId )
if skynet.server.redis:sismember( redisKey , myPartnerId ) then
--发放贡献奖励
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_95")
player:GiveReward( rewardId , eventId)
--删除奖励记录
skynet.server.redis:srem( redisKey , myPartnerId )
data.rewardId = rewardId
else
s2cData.code = errorInfo.ErrorCode.AlreadyGet
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupContributeRewardGain")
s2cData.data = assert(pb.encode("S2CGroupContributeRewardGain", data))
end
--家园帮助奖励领取
function GroupManage:HelpRewardGain( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupHelpRewardGain", c2sData.data ))
local data = {}
local curGroup = player.gameData.group
local helpCount,rewardId = self:CheckHelpReward( player )
if 0 ~= helpCount then
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_96")
player:GiveReward( rewardId , eventId)
table.insert( curGroup.helpGainReward , helpCount )
data.rewardId = rewardId
data.gainHelpCounts = {}
for k, v in pairs( curGroup.helpGainReward ) do
table.insert( data.gainHelpCounts , v )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupHelpRewardGain")
s2cData.data = assert(pb.encode("S2CGroupHelpRewardGain", data))
end
--检查是不是有帮助奖励
function GroupManage:CheckHelpReward( player )
local curGroup = player.gameData.group
local myPartnerId = player.gameData.partner.id
local myDetail = skynet.server.personal:GetDetail( myPartnerId )
local myGroupId = myDetail.groupId
local curGroupInfo = self:GetGroupInfo( myGroupId , "helpCount" )
local groupHelpCount = tonumber(curGroupInfo[1] or 0)
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
for k1, v1 in pairs( cfgSValue.communityHelpExtraReward ) do
local parseData = skynet.server.common:Split( v1 ,"_" )
local helpCount = tonumber(parseData[1])
local rewardId = tonumber(parseData[2])
--检查下是否领取奖励
local isGain =false
for k2, v2 in pairs( curGroup.helpGainReward ) do
if helpCount == v2 then
isGain = true
break
end
end
--如果未获得,并且数量大于了就可以领取
if not isGain and groupHelpCount >= helpCount then
return helpCount,rewardId
end
end
return 0,0
end
--家园添加成员
function GroupManage:AddMember( player , groupId , partnerId , identityType )
local userId = player.userId
local redisKey = string.format( redisKeyUrl.GameServerGroupContributionScoreZSet, groupId )
skynet.server.redis:zadd( redisKey , 0 , partnerId )
local redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , groupId )
skynet.server.redis:hincrby( redisKey , "memberCount" , 1 )
--找出地图中一个空地
local redisKey = string.format( redisKeyUrl.GameServerGroupPrivatePlot, groupId )
local mapList = skynet.server.redis:lrange( redisKey , 0 , -1 )
local plotId = 0
for k, v in pairs(mapList) do
local info = json:decode(v)
if "" == info.partnerId then
plotId = info.plotId
break
end
end
--初始化地块
self:InitScenePlot( player , groupId , plotId , partnerId )
--将加入的家园ID设置到个人信息中
skynet.server.personal:SetDetail( partnerId ,
"groupId", groupId ,
"groupIdentityType" , identityType ,
"groupJoinTime" , skynet.GetTime() ,
"groupSignInType" ,0 , --是否签到
"groupContributeScore" , 0 , --贡献分
"groupPlotId", plotId,
"groupExitTime" , 0 ,
"groupRandId" , 0 , --排行榜ID
"groupNeedGoods","{}"
)
skynet.server.gameRecord:Add( userId , dataType.GameRecordType_104 , groupId , partnerId , identityType , plotId )
end
--家园删除成员
function GroupManage:DeleteMember( userId , groupId , partnerId , plotId )
local redisKey = string.format( redisKeyUrl.GameServerGroupContributionScoreZSet, groupId )
skynet.server.redis:zrem( redisKey , partnerId )
redisKey = string.format( redisKeyUrl.GameServerGroupInfoHash , groupId )
skynet.server.redis:hincrby( redisKey , "memberCount" , -1 )
self:ResetScenePlot( groupId , plotId )
--先检查下玩家的身份信息
local IdentityInfo = skynet.server.redis:hmget( redisKey ,"viceLeader1" , "viceLeader2")
for k, v in pairs( IdentityInfo ) do
if 1 == k and partnerId == v then
skynet.server.redis:hset( redisKey , "viceLeader1" , "")
elseif 2 == k and partnerId == v then
skynet.server.redis:hset( redisKey , "viceLeader2" , "")
end
end
--删除个人详情中的群信息
skynet.server.personal:SetDetail( partnerId , "groupId", "" , "groupRandId" , 0 , "groupExitTime" , skynet.GetTime())
skynet.server.gameRecord:Add( userId , dataType.GameRecordType_105 , groupId , partnerId , plotId )
end
--获取家园加入信息
function GroupManage:GroupJoinInfo( partnerId , groupList )
local redisKey = string.format( redisKeyUrl.GameServerGroupMyApplyJoinZSet , partnerId )
local groupInfo = {}
local myApplyJoin = skynet.server.redis:zrange( redisKey , 0 , -1)
for k1, v1 in pairs( groupList ) do
local curInfo = self:GetGroup( v1 )
if curInfo then
--检查玩家是否申请该家园
local isApply = false
for k2, v2 in pairs( myApplyJoin ) do
if v1 == v2 then
isApply = true
break
end
end
--获取会长的昵称
local leaderPartnerId = curInfo.leader
local leaderNickName = ""
local leaderHeadId = 0
local leaderHeadFrameId = 0
local curDetail = skynet.server.personal:GetDetail( leaderPartnerId )
if curDetail then
leaderNickName = curDetail.nickName or ""
leaderHeadId = curDetail.headId
leaderHeadFrameId = curDetail.headFrameId
end
--组织返回数据
--自定义头像
if leaderHeadId == 0 and curDetail.DIYHeadInfo ~= nil then
table.insert( groupInfo , {
id = curInfo.id ,
name = curInfo.name ,
level = curInfo.communityLevel ,
badgeId = curInfo.badgeId,
isApply = isApply,
curMemberCount = curInfo.memberCount,
leaderHeadId = leaderHeadId,
leaderHeadFrameId = leaderHeadFrameId,
leaderNickName = leaderNickName,
declaration = curInfo.declaration,
joinType = curInfo.joinType,
leaderDIYHeadInfo = curDetail.DIYHeadInfo
})
else
table.insert( groupInfo , {
id = curInfo.id ,
name = curInfo.name ,
level = curInfo.communityLevel ,
badgeId = curInfo.badgeId,
isApply = isApply,
curMemberCount = curInfo.memberCount,
leaderHeadId = leaderHeadId,
leaderHeadFrameId = leaderHeadFrameId,
leaderNickName = leaderNickName,
declaration = curInfo.declaration,
joinType = curInfo.joinType
})
end
end
end
return groupInfo
end
--家园推荐
function GroupManage:Recommond( player )
local myPartnerId = player.gameData.partner.id
local tmpGroup = player.tmpData.group
local groupInfo = {}
local firstQuery = true
--是否存在好友
local function IsExistGroup( groupId )
for k, v in pairs( tmpGroup.alreadyQueryList ) do
if groupId == v then
return true
end
end
return false
end
--查询家园
local function QueryGroup()
local count = 0
local isEnough = false
--我申请的加入列表
local redisKey = string.format( redisKeyUrl.GameServerGroupMyApplyJoinZSet , myPartnerId )
local myApplyJoin = skynet.server.redis:zrange( redisKey , 0 , -1)
for k, v in pairs( self.onlineGroupList ) do
if not IsExistGroup( v.id ) then
table.insert( tmpGroup.alreadyQueryList , v.id )
--检查玩家是否申请该家园
local isApply = false
for k2, v2 in pairs( myApplyJoin ) do
if v.id == v2 then
isApply = true
break
end
end
--获取会长的昵称
local leaderPartnerId = v.leader
local leaderNickName = ""
local leaderHeadId = 0
local leaderHeadFrameId = 0
local curDetail = skynet.server.personal:GetDetail( leaderPartnerId )
if curDetail then
leaderNickName = curDetail.nickName or ""
leaderHeadId = curDetail.headId
leaderHeadFrameId = curDetail.headFrameId
end
--自定义头像
if leaderHeadId == 0 and curDetail.DIYHeadInfo ~= nil then
table.insert( groupInfo , {
id = v.id ,
name = v.name ,
level = v.communityLevel ,
badgeId = v.badgeId,
isApply = isApply,
curMemberCount = v.memberCount,
leaderHeadId = leaderHeadId,
leaderNickName = leaderNickName,
declaration = v.declaration,
joinType = v.joinType,
leaderHeadFrameId = leaderHeadFrameId,
leaderDIYHeadInfo = curDetail.DIYHeadInfo
})
else
table.insert( groupInfo , {
id = v.id ,
name = v.name ,
level = v.communityLevel ,
badgeId = v.badgeId,
isApply = isApply,
curMemberCount = v.memberCount,
leaderHeadId = leaderHeadId,
leaderNickName = leaderNickName,
declaration = v.declaration,
joinType = v.joinType,
leaderHeadFrameId = leaderHeadFrameId
})
end
count = count + 1
end
if count >= self.MaxQueryCount then
isEnough = true
break
end
end
if 0 == #groupInfo and firstQuery then
firstQuery = false
tmpGroup.alreadyQueryList = {}
QueryGroup()
end
end
QueryGroup()
return groupInfo
end
--检查福利
function GroupManage:CheckContributeReward( player , myGroupId )
--检测一下,是否更新家园福利奖励
local curGroupInfo = self:GetGroupInfo( myGroupId , "nextContributeRewardTime", "contributeScore" )
local nextContributeRewardTime = tonumber(curGroupInfo[1])
local contributeScore = tonumber(curGroupInfo[2])
if skynet.GetTime() >= nextContributeRewardTime then
-- 设置下一次福利时间
self:SetGroupInfo( myGroupId , "nextContributeRewardTime" , self:CalcContributeRewardTime())
--计算福利
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local communityContribute = cfgSValue.communityContribute --所有贡献范围
local communityContributeReward = cfgSValue.communityContributeReward
for k, v in pairs( communityContribute) do
local range = skynet.server.common:Split( v ,"_" )
if contributeScore >= tonumber(range[1]) and contributeScore <= tonumber(range[2]) then
--设置发放福利
self:SetGroupInfo( myGroupId , "contributeReward" , communityContributeReward[ k ] )
--存在领取记录就删除
local redisContributeRewardKey = string.format( redisKeyUrl.GameServerGroupContributeRewardRecordSet, myGroupId )
if skynet.server.redis:exists( redisContributeRewardKey ) then
skynet.server.redis:del( redisContributeRewardKey )
end
--遍历当前该家园的所有好友ID , 将能领取奖励的ID全部写入进云
local redisContributionScoreKey = string.format( redisKeyUrl.GameServerGroupContributionScoreZSet, myGroupId )
local rankList = skynet.server.redis:zrange( redisContributionScoreKey , 0 , -1 )
local partnerIdList = {}
for k, partnerId in pairs(rankList) do
table.insert( partnerIdList, partnerId )
end
skynet.server.redis:sadd( redisContributeRewardKey , table.unpack( partnerIdList ))
break
end
end
end
end
skynet.server.groupManage = GroupManage
return GroupManage