HomeServer/Server/AllServer/GameServer/Activity/ActivityDecoWeek.lua

1307 lines
61 KiB
Lua
Raw Normal View History

2024-11-20 15:41:09 +08:00
local skynet = require "skynet"
local oo = require "Class"
local log = require "Log"
local pb = require "pb"
local dataType = require "DataType"
local errorInfo = require "ErrorInfo"
local activity = require "Activity"
local sqlUrl = require "SqlUrl"
local db = require "DB"
local json =require "json"
local redisKeyUrl = require "RedisKeyUrl"
local serverId = tonumber(skynet.getenv "serverId")
local ActivityDecoWeek = oo.class()
ActivityDecoWeek.ActivityType = dataType.ActivityType_DecoWeek
ActivityDecoWeek.ActivityStatus_No = 0 --无状态
ActivityDecoWeek.ActivityStatus_Join = 1 --参赛阶段
ActivityDecoWeek.ActivityStatus_Vote = 2 --评选阶段
ActivityDecoWeek.ActivityStatus_Balance = 3 --结算阶段
ActivityDecoWeek.DesignType_Human = 1 --设计类型人类
ActivityDecoWeek.DesignType_AI = 2 --设计类型AI
ActivityDecoWeek.ActivityMaxDesignCount = 5 --每期最多设计5次
ActivityDecoWeek.StartCoinId = 20 --星芒币ID
ActivityDecoWeek.HotDesignMaxCount = 50
ActivityDecoWeek.RefreshDecoWeekDesignInterval = 600 --刷新装修周设计间隔时间 300
ActivityDecoWeek.RefreshDesignMaxCount = 100 --刷新设计最大数量
--[[
18:00:00 23:59:59
0:00:00 15:59:59
16:00:00 17:59:59
稿
NPC作品刷新次数不计入
-
]]
function ActivityDecoWeek:Init()
self.highScoreDesigns = {} --当前服高分设计
skynet.server.timer:Add( dataType.Timer_SyncActivityDecoWeekDesignList , self.RefreshDecoWeekDesignInterval , self["SyncHotDesignList"] , self )
end
--同步热门设计数据
function ActivityDecoWeek:SyncHotDesignList()
local activityThemeId,activityStatus = self:GetCurActivityInfo()
local redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekHumanVoteScoreZSet , activityThemeId )
local designCount = skynet.server.redis:zcard( redisKey ) --获取设计数量
if 0 == designCount then
--如果没有设计信息就用NPC数据
redisKey = redisKeyUrl.GameServerActivityDecoWeekNpcVoteScoreZSet
designCount = skynet.server.redis:zcard( redisKey )
end
--获取设计详情
local function GetDesignDetail( queryData )
local listDesigns = {}
queryData = redisKeyUrl:CovertTable(queryData)
for partnerId , score in pairs( queryData ) do
table.insert( listDesigns , { partnerId = partnerId , score = score })
end
return listDesigns
end
local cfgSValue = skynet.server.gameConfig:GetAllCfg( "SValue" )
local hotRange = math.ceil(cfgSValue.heatWeeklyContestWork * designCount)
if hotRange > 500 then
--超过500只给500
hotRange = 500
end
local queryData = skynet.server.redis:zrevrange( redisKey , 0 , hotRange , "withscores" ) --每次获取50个高分数据
self.highScoreDesigns = GetDesignDetail( queryData )
end
--检查是否有新数据
function ActivityDecoWeek:LoginInitData( player )
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivityDecoWeek ) then
return
end
if not player.gameData.activity[ self.ActivityType ] then
player.gameData.activity[ self.ActivityType ] = {}
end
local activityThemeId,activityStatus,stageStartTime = self:GetCurActivityInfo()
local activity = player.gameData.activity[ self.ActivityType ]
--投票券清空逻辑(活动id对不上时、周赛阶段不为投票阶段时)
if activity.themeId ~= nil then
if activity.themeId ~= activityThemeId or ( activity.themeId == activityThemeId and activityStatus ~= self.ActivityStatus_Vote ) then
--当前周赛id和玩家数据周赛id不一致时 清空投票券
if skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30) > 0 then
skynet.server.bag:RemoveGoods(player, dataType.GoodsType_Prop, 30, skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30))
--防止周一零点周赛服时间延迟导致的清空周一免费投票券
if skynet.server.common:GetDayInWeek() == 1 and player.gameData.todayGain.weeklyDesignFreeVote then
skynet.server.bag:AddGoods(player, dataType.GoodsType_Prop, 30, 5)
end
end
end
end
--新解锁功能没有主题ID 或者 当前活动ID不一致才初始化数据
if not activity.themeId or activity.themeId ~= activityThemeId then
local isLastThemeId = activity.themeId or 0 --上一期参加过的主题ID
local isLastSubmitDesign = activity.isSubmitDesign or false --上一期是否已经提交过设计
activity.themeId = activityThemeId --当前活动的ID
activity.isSubmitDesign = false --是否提交过方案
activity.weekVoteCount = 0 --本周投票数量
activity.joinThemes = {} --参加过的主题
activity.designFileName = "" --设计的文件名
activity.rewardIds = {} --已经领取的奖励ID
activity.nowShowVoteInfos = {} --当前正在显示的投票信息
activity.historyShowHotDesigns = {} --历史显示的投票信息
activity.historyShowVotes = {} --已经显示投票的玩家
activity.historyVotes = {} --已经投票的玩家
activity.designCount = 0 --主题装修周设计数量
activity.openShowCount = 0 --打开界面次数
activity.getAllWeekReward = false --本周已经获取全部投票累计度奖励
activity.totalReward = {}
activity.tierReward = {}
local myParentId = player.gameData.partner.id
skynet.server.personal:SetDetail( myParentId ,
"decoWeekOpenShowCount" , 0 , --打开界面次数
"decoWeekDesignTime" , 0 ,
"decoWeekDesignUrl" , "" ,
"decoWeekDesignOssUrl" , "" ,
"decoWeekLastThemeId" , isLastThemeId , --上一期参加过的主题ID
"decoWeekIsLastSubmitDesign" , isLastSubmitDesign , --上一期是否已经提交过设计
"decoWeekRankRange" , 0 , --排行榜范围
"decoWeekRewardId" , 0 , --奖励ID
"decoWeekRewardStatus" , dataType.DecoWeekRewardStatus_No ) --奖励状态
--player:InitTestAccount( false )
end
self:CheckMsgTips( player , activityThemeId , activityStatus)
end
--主题装修周显示
function ActivityDecoWeek:Show( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekShow", c2sData.data ))
local data = {}
--更新活动主题ID 和 活动状态
local activityThemeId,activityStatus,stageStartTime,stageEndTime = self:GetCurActivityInfo()
if self.ActivityStatus_No == activityStatus then
s2cData.code = errorInfo.ErrorCode.InvaildOpForCurActivityStatus
else
--检查是否有新数据
self:LoginInitData( player )
local myParentId = player.gameData.partner.id
local todayGain = player.gameData.todayGain
local activity = player.gameData.activity[ self.ActivityType ]
--增加周赛交互次数
skynet.server.personal:AccDetail( myParentId ,"decoWeekOpenShowCount", 1 )
data.themeId = activityThemeId
data.activityStatus = activityStatus
data.stageStartTime = stageStartTime
data.stageEndTime = stageEndTime
data.isSubmitDesign = activity.isSubmitDesign
data.todayVoteCount = todayGain.weekDesignVoteCount
data.weekVoteCount = activity.weekVoteCount
data.todayBuyVoteCount = todayGain.weeklyDesignBuyVoteCount
if activity.isSubmitDesign then
data.myDesignInfo = self:GetDesignInfo( myParentId , activityThemeId , activityStatus , stageStartTime , stageEndTime ) --我提交过设计,就发送下我的投票信息
else
data.myDesignInfo = {}
end
data.hotDesignInfo = self:GetHotVoteInfo( activityThemeId , activityStatus , stageStartTime , stageEndTime , activity.historyShowHotDesigns ) or {}
data.rewardIds = activity.rewardIds
data.surplusDesignCount = self.ActivityMaxDesignCount - activity.designCount
--检查是否有未领取的上期结算奖励
local mulDetail = skynet.server.personal:GetMulDetail( myParentId , "decoWeekLastRankRange" ,"decoWeekLastRewardId","decoWeekLastRewardCanGet")
local rankRange = mulDetail[1] or 0
local rewardId = mulDetail[2] or 0
local rewardCanGet = mulDetail[3] or false
if rewardCanGet then
data.haveWeekReward = true
data.rankRange = rankRange * 100
data.rewardId = rewardId
local lastFinalReward = player:RewardShow( rewardId )
activity.lastFinalReward = {}
activity.lastFinalReward = lastFinalReward
data.lastTierRewardsInfo = activity.lastFinalReward
else
data.haveWeekReward = false
data.rankRange = rankRange * 100
data.rewardId = rewardId
data.lastTierRewardsInfo = activity.lastFinalReward
end
--投票累计奖励展示
data.rewardsInfo = {}
if activity.totalReward == nil or next(activity.totalReward) == nil then
local cfgOneWeekly = skynet.server.gameConfig:GetCurCfg( "WeeklyContest" , activityThemeId )
local voteReward = cfgOneWeekly.voteReward
for k, v in pairs( voteReward ) do
local rewardInfo = skynet.server.common:Split( v ,"_" )
rewardInfo[1] = tonumber(rewardInfo[1])
rewardInfo[2] = tonumber(rewardInfo[2])
local rewardResult = {}
rewardResult.rewardId = rewardInfo[1]
rewardResult.rewardsInfo = {}
local finalReward = player:RewardShow( rewardInfo[2] )
if finalReward ~= nil or next(finalReward) ~= nil then
rewardResult.rewardsInfo = finalReward
end
table.insert(data.rewardsInfo,rewardResult)
end
activity.totalReward = {}
activity.totalReward = data.rewardsInfo
else
data.rewardsInfo = activity.totalReward
end
--排名奖励展示
data.tierRewardsInfo = {}
if activity.tierReward == nil or next(activity.tierReward) == nil then
local cfgOneWeekly = skynet.server.gameConfig:GetCurCfg( "WeeklyContest" , activityThemeId )
local rankReward = cfgOneWeekly.rankReward
for k, v in pairs( rankReward ) do
local rewardId = tonumber(v)
local rewardResult = {}
rewardResult.rewardId = tonumber(cfgOneWeekly.rankRange[k]) * 100
rewardResult.rewardsInfo = {}
local finalReward = player:RewardShow( rewardId )
if finalReward ~= nil or next(finalReward) ~= nil then
rewardResult.rewardsInfo = finalReward
end
table.insert(data.tierRewardsInfo,rewardResult)
end
activity.tierReward = {}
activity.tierReward = data.tierRewardsInfo
else
data.tierRewardsInfo = activity.tierReward
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekShow")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekShow", data))
end
--主动领取结算奖励
function ActivityDecoWeek:GetWeekReward( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekGetWeekReward", c2sData.data ))
local data = {}
data.finalRewardInfo = {}
--获取玩家当前待领取的奖励id
local myParentId = player.gameData.partner.id
local detail = skynet.server.personal:GetMulDetail( myParentId , "decoWeekLastRewardId" ,"decoWeekLastRewardCanGet")
local rewardId = detail[1] or 0
local rewardCanGet = detail[2] or false
--如果未领取状态则发对应奖励,并更新状态
if rewardId ~= 0 and rewardCanGet then
--发奖逻辑
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_143")
local _,finalReward = player:GiveReward( rewardId , eventId )
if finalReward ~= nil and next(finalReward) ~= nil then
data.finalRewardInfo = finalReward
end
--发完奖励更新奖励领取状态
skynet.server.personal:SetDetail( myParentId , "decoWeekLastRewardCanGet" , false )
--处理离线消息
local redisKey = string.format( redisKeyUrl.GameServerPersonalOfflineMsgList , myParentId )
local allOfflineMsg = skynet.server.redis:lrange( redisKey , 0 , -1)
local curThemeId,activityStatus = self:GetCurActivityInfo()
for k, jsonData in pairs( allOfflineMsg ) do
local msgData = json:decode( jsonData )
local data = msgData.data
if dataType.OfflineMsgType_ActivityDecoRankId == msgData.type then
local activityThemeId = data.activityThemeId or 0
if activityThemeId ~= nil and activityThemeId ~= 0 and activityThemeId ~= "" and self.ActivityStatus_Balance ~= activityStatus and activityThemeId == curThemeId - 1 then
skynet.server.redis:lrem(redisKey,1,jsonData)
break
elseif activityThemeId ~= nil and activityThemeId ~= 0 and activityThemeId ~= "" and self.ActivityStatus_Balance == activityStatus and activityThemeId == curThemeId then
skynet.server.redis:lrem(redisKey,1,jsonData)
break
end
end
end
data.isSuc = true
data.rewardId = rewardId
else
data.isSuc = false
data.rewardId = 0
end
--清除红点
skynet.server.msgTips:ReduceAll( player , 122 )
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekGetWeekReward")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekGetWeekReward", data))
end
--主题装修周设计投稿
function ActivityDecoWeek:DesignSubmit( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekDesignSubmit", c2sData.data ))
local data = {}
local extensionName = c2sData.data.extensionName
local binaryData = c2sData.data.binaryData
local todayGain = player.gameData.todayGain
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local activity = player.gameData.activity[ self.ActivityType ]
local activityThemeId , activityStatus, stageStartTime , stageEndTime = self:GetCurActivityInfo()
if activity.designCount >= self.ActivityMaxDesignCount then --每期最多上传5次
s2cData.code = errorInfo.ErrorCode.MaxLimit
elseif "jpg" ~= string.lower(extensionName) then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif self.ActivityStatus_Join ~= activityStatus then
s2cData.code = errorInfo.ErrorCode.InvaildOpForCurActivityStatus
elseif skynet.server.bag:GetGoodsStat( player , dataType.GoodsType_Furniture ) < cfgSValue.weeklyContestCondition then
s2cData.code = errorInfo.ErrorCode.FurnitureNotEnoughNoDesign
else
local myPartnerId = player.gameData.partner.id
if not activity.isSubmitDesign then
--本期第一次提交设计
activity.isSubmitDesign = true
table.insert( activity.joinThemes , activity.themeId )
else
--删除原来的设计图片
self:RemoveDesignFile( activityThemeId ,activity.designFileName)
skynet.server.msgTips:ReduceAll(player , 96)
end
--默认增加10曝光次数
local redisKey = redisKeyUrl.GameServerActivityDecoWeekNeedExpouseCountZSet
skynet.server.redis:zadd( redisKey , 10 , myPartnerId )
--平均曝光次数为0
redisKey = redisKeyUrl.GameServerActivityDecoWeekAveExpouseCountZSet
skynet.server.redis:zadd( redisKey , 0 , myPartnerId )
--生成32位随机ID 自己的PartnerID(12位) + 20位随机码
activity.designFileName = string.format("%s_%d" , myPartnerId , activityThemeId )--myPartnerId..skynet.server.common:RandID(20)
--保存图片
local saveUrl,designOssUrl = self:SaveDesignFile( activityThemeId , activity.designFileName , binaryData )
--设置相关信息
activity.designCount = activity.designCount + 1
redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekHumanVoteScoreZSet , activityThemeId )
skynet.server.redis:zadd( redisKey , 0 , myPartnerId )
skynet.server.personal:SetDetail( myPartnerId , "decoWeekDesignTime" , skynet.GetTime() , "decoWeekDesignUrl" , saveUrl , "decoWeekDesignOssUrl" , designOssUrl )
skynet.server.redisCache:UpdatePersonalDetail( myPartnerId )
data.myDesignInfo = self:GetDesignInfo( myPartnerId , activityThemeId , activityStatus , stageStartTime , stageEndTime)
data.surplusDesignCount = self.ActivityMaxDesignCount - activity.designCount
log.debug(string.format("玩家 %d 装修周赛 提交设计 文件名 %s Url %s", player.userId , activity.designFileName , saveUrl))
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekDesignSubmit")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekDesignSubmit", data))
end
--主题装修周星芒商城显示
function ActivityDecoWeek:StoreShow( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekStoreShow", c2sData.data ))
local data = {}
data.shopInfos = {}
local activityThemeId,activityStatus = self:GetCurActivityInfo()
if self.ActivityStatus_No == activityStatus then
s2cData.code = errorInfo.ErrorCode.InvaildOpForCurActivityStatus
else
--获取当期星芒商城
local cfgOneWeekly = skynet.server.gameConfig:GetCurCfg( "WeeklyContest" , activityThemeId )
local contestShopContent = cfgOneWeekly.contestShopContent
for k1, v1 in pairs( contestShopContent ) do
--获取商城里的售卖信息
local cfgOneContestShop = skynet.server.gameConfig:GetCurCfg( "WeeklyContestShop" , v1 )
local furnitureStuff = cfgOneContestShop.furnitureStuff
local decorationStuff = cfgOneContestShop.decorationStuff
local sellGoods = {}
for k2, v2 in pairs( furnitureStuff ) do
--遍历该套装下的所有家具
local buyCount = 0
if player:IsBuyGoods( dataType.GoodsType_Furniture , v2 ) then
buyCount = 1
end
table.insert( sellGoods , { id = v2 , buyCount = buyCount , type = dataType.GoodsType_Furniture })
end
for k2, v2 in pairs( decorationStuff ) do
--遍历该套装下的所有装修
local buyCount = 0
if player:IsBuyGoods( dataType.GoodsType_Decorate , v2 ) then
buyCount = 1
end
table.insert( sellGoods , { id = v2 , buyCount = buyCount , type = dataType.GoodsType_Decorate })
end
table.insert( data.shopInfos , { suitId = v1 , sellGoods = sellGoods })
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekStoreShow")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekStoreShow", data))
end
--主题装修周星芒商城购买
function ActivityDecoWeek:StoreBuy( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekStoreBuy", c2sData.data ))
local data = {}
data.buyGoods = {}
local activityThemeId,activityStatus = self:GetCurActivityInfo()
local buySuitId = c2sData.data.buySuitId
local buyGoods = c2sData.data.buyGoods
local goodsId = buyGoods.id
local goodsCount = buyGoods.buyCount
local goodsType = buyGoods.type
if buySuitId <= 0 or goodsId <= 0 and goodsCount <= 0 and goodsType <= 0 then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif self.ActivityStatus_No == activityStatus then
s2cData.code = errorInfo.ErrorCode.InvaildOpForCurActivityStatus
else
local cfgOneWeekly = skynet.server.gameConfig:GetCurCfg( "WeeklyContestShop" , buySuitId )
if not cfgOneWeekly then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
local stuff = {}
local startCoin = 0
if dataType.GoodsType_Furniture == goodsType then
stuff = cfgOneWeekly.furnitureStuff
startCoin = cfgOneWeekly.furnitureStarCoin
elseif dataType.GoodsType_Decorate == goodsType then
stuff = cfgOneWeekly.decorationStuff
startCoin = cfgOneWeekly.decorationStarCoin
end
--根据配置获取当前期售卖的东西
for k, v in pairs( stuff ) do
if goodsId == v then
if not skynet.server.bag:RemoveGoods( player , dataType.GoodsType_Prop , self.StartCoinId , startCoin[ k ] * goodsCount ) then
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
else
--正常发货
skynet.server.bag:AddGoods(player, goodsType , goodsId, goodsCount )
data.buySuitId = buySuitId
data.buyGoods = { id = goodsId , buyCount = goodsCount , type = goodsType }
end
break
end
end
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekStoreBuy")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekStoreBuy", data))
end
--主题装修周往期热门设计展示
function ActivityDecoWeek:HotDesignShow( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekHotDesignShow", c2sData.data ))
local data = {}
data.designInfos = {}
local activityThemeId,activityStatus = self:GetCurActivityInfo()
if self.ActivityStatus_No == activityStatus then
s2cData.code = errorInfo.ErrorCode.InvaildOpForCurActivityStatus
else
local redisKey = redisKeyUrl.GameServerActivityDecoWeekTopDesignList
local queryData = skynet.server.redis:lrange( redisKey , 0 , -1 )
for k, v in pairs( queryData ) do
table.insert( data.designInfos , json:decode( v ) )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekHotDesignShow")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekHotDesignShow", data))
end
--主题装修周投票展示
function ActivityDecoWeek:VoteShow( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekVoteShow", c2sData.data ))
local data = {}
data.voteInfos = {}
local activityThemeId,activityStatus,stageStartTime,stageEndTime = self:GetCurActivityInfo()
if self.ActivityStatus_Vote ~= activityStatus then
s2cData.code = errorInfo.ErrorCode.InvaildOpForCurActivityStatus
else
activity.nowShowVoteInfos = {}
local randLowIndex = math.random( 1 , 2 ) --随机索引12为高价值
local voteInfo = nil
for i = 1, 2, 1 do
if randLowIndex == i then
voteInfo = self:GetNextVoteInfo( player , activityThemeId , activityStatus , stageStartTime , stageEndTime , true )
else
voteInfo = self:GetNextVoteInfo( player , activityThemeId , activityStatus , stageStartTime , stageEndTime , false )
end
if voteInfo then
table.insert( data.voteInfos , voteInfo )
end
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekVoteShow")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekVoteShow", data))
end
--主题装修周购买投票券
function ActivityDecoWeek:BuyVote( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekBuyVote", c2sData.data ))
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local todayGain = player.gameData.todayGain
local data = {}
--获取当前背包中投票券数量如果已经达到储存上限则不可继续购买
local voteCount = skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30);
if voteCount >= cfgSValue.weeklyContestVoteMax then
s2cData.code = errorInfo.ErrorCode.MaxLimit
else
local buyCount = todayGain.weeklyDesignBuyVoteCount
local curDiscount = 1
local weeklyContestVoteBuyDiscount = cfgSValue.weeklyContestVoteBuyDiscount
--计算当前折扣
for k , v in pairs(weeklyContestVoteBuyDiscount) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if buyCount < arr[1] then
curDiscount = arr[2]
break
end
end
local price = cfgSValue.weeklyContestVoteCost * curDiscount
-- 消耗玩家蜗壳币
local eventId = pb.enum("EnumMoneyChangeEventID", "EventID_131")
local isSuc = player:MoneyChange(pb.enum("EnumGoodsType", "VoluteCoin"), -price, eventId)
--成功购买
if isSuc then
todayGain.weeklyDesignBuyVoteCount = todayGain.weeklyDesignBuyVoteCount + 1
buyCount = todayGain.weeklyDesignBuyVoteCount
skynet.server.bag:AddGoods(player, dataType.GoodsType_Prop, 30, 1)
local weeklyContestBuyVoteReward = cfgSValue.weeklyContestBuyVoteReward
--判断是否需要发放购买的额外奖励
for k , v in pairs(weeklyContestBuyVoteReward) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if buyCount <= arr[1] then
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_132")
player:GiveReward(arr[2] , eventId , 1)
data.rewardId = arr[2]
break
end
end
else
s2cData.code = errorInfo.ErrorCode.VoluteNotEnough
end
data.isSuc = isSuc
data.todayBuyVoteCount = buyCount
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekBuyVote")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekBuyVote", data))
end
--主题装修周投票
function ActivityDecoWeek:Vote( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekVote", c2sData.data ))
local data = {}
local myParentId = player.gameData.partner.id
local byPartnerId = c2sData.data.partnerId --被投票者
local todayGain = player.gameData.todayGain
local activity = player.gameData.activity[ self.ActivityType ]
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local activityThemeId,activityStatus,stageStartTime,stageEndTime = self:GetCurActivityInfo()
if "" == byPartnerId or #byPartnerId > 12 or byPartnerId == myParentId then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30) <= 0 then --检查投票券数量
s2cData.code = errorInfo.ErrorCode.NoEnoughProp
elseif self.ActivityStatus_Vote ~= activityStatus then
s2cData.code = errorInfo.ErrorCode.InvaildOpForCurActivityStatus
elseif not self:IsExistSignPlayer( activityThemeId , byPartnerId , activity.nowShowVoteInfos ) then --检查玩家是否本期设计过
s2cData.code = errorInfo.ErrorCode.NoExistUser
else
local addScore = 1 --需要增加分数
local redisKey = ""
if self:IsNpc( byPartnerId) then
redisKey = redisKeyUrl.GameServerActivityDecoWeekNpcVoteScoreZSet
else
redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekHumanVoteScoreZSet , activityThemeId )
--投票介入
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local tmpRedisKey = redisKeyUrl.GameServerActivityDecoWeekHumanVoteAdjustScoreZSet
skynet.server.redis:zincrby( tmpRedisKey , 1 , byPartnerId )
local adjustScore = tonumber(skynet.server.redis:zscore( tmpRedisKey , byPartnerId )) or 0 --获取被投票者的最新调整分数
if adjustScore >= cfgSValue.weeklyContestVoteReward[1] then
--调整分数满足,就多给玩家一些投票数量
addScore =addScore + cfgSValue.weeklyContestVoteReward[2]
skynet.server.redis:zrem( tmpRedisKey , byPartnerId )
end
end
--成功投票加1分
todayGain.weekDesignVoteCount = todayGain.weekDesignVoteCount + 1
activity.weekVoteCount = activity.weekVoteCount + 1
--如果进入调节阶段则不统计投票
if not self:IsVoteAdjust(activityStatus,stageEndTime) then
skynet.server.redis:zincrby( redisKey , addScore , byPartnerId )
end
skynet.server.taskListEvent:Modify( player , 116 , 1)
--统计所有投票分数不包括NPC
if not self:IsNpc( byPartnerId) then
redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekInfoHash )
skynet.server.redis:hincrby( redisKey , "allVoteScore" , addScore )
end
table.insert( activity.historyVotes , byPartnerId )
data.todayVoteCount = todayGain.weekDesignVoteCount
data.weekVoteCount = activity.weekVoteCount
activity.nowShowVoteInfos = {}
data.voteInfos = {}
local randLowIndex = math.random( 1 , 2 ) --随机索引1和2为高价值
local voteInfo = nil
for i = 1, 2, 1 do
if randLowIndex == i then
voteInfo = self:GetNextVoteInfo( player , activityThemeId , activityStatus , stageStartTime , stageEndTime , true )
else
voteInfo = self:GetNextVoteInfo( player , activityThemeId , activityStatus , stageStartTime , stageEndTime , false )
end
if voteInfo then
table.insert( data.voteInfos , voteInfo )
end
end
--测试用,记得注释掉
--skynet.server.bag:RemoveGoods(player, dataType.GoodsType_Prop, 30, 7)
--消耗一张投票券
skynet.server.bag:RemoveGoods(player, dataType.GoodsType_Prop, 30, 1)
if skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30) == 0 or activity.getAllWeekReward then
skynet.server.msgTips:ReduceAll(player , 98)
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekVote")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekVote", data))
end
--主题装修周往期热门设计展示
function ActivityDecoWeek:VoteRewardGet( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekVoteRewardGet", c2sData.data ))
local data = {}
local rewardId = c2sData.data.rewardId
local activityThemeId,activityStatus = self:GetCurActivityInfo()
if self.ActivityStatus_No == activityStatus then
s2cData.code = errorInfo.ErrorCode.InvaildOpForCurActivityStatus
else
local isGain = false
local activity = player.gameData.activity[ self.ActivityType ]
for k, v in pairs( activity.rewardIds ) do
if rewardId == v then
--已经领取过该奖励
isGain = true
break
end
end
if isGain then
s2cData.code = errorInfo.ErrorCode.AlreadyGet
else
--未领取过该奖励
local activityThemeId,activityStatus = self:GetCurActivityInfo()
local cfgOneWeekly = skynet.server.gameConfig:GetCurCfg( "WeeklyContest" , activityThemeId )
local voteReward = cfgOneWeekly.voteReward
for k, v in pairs( voteReward ) do
local rewardInfo = skynet.server.common:Split( v ,"_" )
rewardInfo[1] = tonumber(rewardInfo[1])
rewardInfo[2] = tonumber(rewardInfo[2])
if rewardId == rewardInfo[1] and rewardId <= activity.weekVoteCount then
data.finalRewardInfo = {}
data.gainRewardId = rewardInfo[2]
isGain = true
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_103")
local _,finalReward = player:GiveReward( rewardInfo[2] , eventId )
if finalReward ~= nil and next(finalReward) ~= nil then
data.finalRewardInfo = finalReward
end
table.insert( activity.rewardIds ,rewardInfo[1] )
skynet.server.msgTips:ReduceAll(player , 97)
log.debug(string.format("玩家 %d 装修周赛 奖励ID %d 福利ID %d", player.userId , rewardInfo[1] , rewardInfo[2]))
break
end
end
if not isGain then
--未找到该奖励的ID
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
end
end
data.rewardIds = activity.rewardIds
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekVoteRewardGet")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekVoteRewardGet", data))
end
--主题装修周个人投稿展示
function ActivityDecoWeek:MyDesignShow( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityDecoWeekMyDesignShow", c2sData.data ))
local myParentId = player.gameData.partner.id
local data = {}
data.myDesignInfo = {}
local cfgSValue = skynet.server.gameConfig:GetAllCfg( "SValue" )
local activityThemeId,activityStatus = self:GetCurActivityInfo()
for i = 1, 100, 1 do
local info = {}
local redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekHumanVoteScoreZSet , i )
if skynet.server.redis:exists( redisKey) then
info.score = skynet.server.redis:zscore( redisKey , myParentId ) or 0
info.score = info.score * cfgSValue.weeklyContestHeatValue
info.themeId = i
table.insert( data.myDesignInfo , info)
end
if i >= activityThemeId then
break
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityDecoWeekMyDesignShow")
s2cData.data = assert(pb.encode("S2CActivityDecoWeekMyDesignShow", data))
end
--获取当前活动信息
function ActivityDecoWeek:GetCurActivityInfo()
local redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekInfoHash )
local activityInfo = skynet.server.redis:hmget( redisKey , "activityThemeId" , "activityStatus", "stageStartTime" , "stageEndTime" )
activityInfo = redisKeyUrl:CovertValue(activityInfo)
local activityThemeId = activityInfo[1] or 0
local activityStatus = activityInfo[2] or 0
local stageStartTime = activityInfo[3] or 0
local stageEndTime = activityInfo[4] or 0
return tonumber(activityThemeId) , tonumber(activityStatus) , tonumber(stageStartTime) , tonumber(stageEndTime)
end
--获取主题装修周设计信息
function ActivityDecoWeek:GetDesignInfo( myParentId , activityThemeId , activityStatus , stageStartTime , stageEndTime)
local data = {}
local redisKey = nil
if self:IsNpc( myParentId) then
redisKey = redisKeyUrl.GameServerActivityDecoWeekNpcVoteScoreZSet
local designTime = skynet.server.personal:GetCurDetail( myParentId , "decoWeekDesignTime")
if 0 == designTime then
--NPC没有设计时间
if self.ActivityStatus_Join == activityStatus then
--在设计阶段被人刷出来了就给NPC随机个时间范围从阶段开始到目前
local diffTime = skynet.GetTime() - stageStartTime
if diffTime <= 0 then
diffTime = math.random(1 , 36000)
end
skynet.server.personal:SetDetail( myParentId ,"decoWeekDesignTime", stageStartTime + math.random(1 , diffTime))
end
end
else
redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekHumanVoteScoreZSet , activityThemeId )
end
local curDetail = skynet.server.redisCache:GetPersonalDetail( myParentId ) --获取个人详细信息
if curDetail then
local cfgSValue = skynet.server.gameConfig:GetAllCfg( "SValue")
local myScore = tonumber(skynet.server.redis:zscore( redisKey , myParentId ) or 0 ) * cfgSValue.weeklyContestHeatValue
data.themeId = activityThemeId
data.partnerId = myParentId
data.nickName = curDetail.nickName
data.score = myScore
if skynet.server.gameConfig:IsOnline() then
data.designUrl = curDetail.decoWeekDesignOssUrl
else
data.designUrl = curDetail.decoWeekDesignUrl
end
data.designTime = curDetail.decoWeekDesignTime
end
return data
end
--移除设计文件
function ActivityDecoWeek:RemoveDesignFile( activityThemeId , fileName )
local gameName = skynet.server.gameConfig.GameName
if skynet.server.gameConfig:IsTest() then
gameName = gameName.."_Test"
end
local filePath = string.format("../upload/%s/Images/ActivityDecoWeek/%d" , gameName , activityThemeId )
filePath = string.format("%s/%s.%s" , filePath , fileName , "jpg" )
os.execute("rm -rf ".. filePath)
end
--保存设计文件
function ActivityDecoWeek:SaveDesignFile( activityThemeId , fileName , binaryData )
local gameName = skynet.server.gameConfig.GameName
if skynet.server.gameConfig:IsTest() then
gameName = gameName.."_Test"
end
local filePath = string.format("../upload/%s/Images/ActivityDecoWeek/%d" , gameName , activityThemeId )
if not skynet.server.common:IsExistFolder( filePath ) then
--不存在文件夹就创建文件夹
os.execute("mkdir -p ".. filePath)
end
--写入二进制文件
filePath = string.format("%s/%s.%s" , filePath , fileName , "jpg" )
skynet.server.common:WriteBinaryFileData( filePath , binaryData )
--组装URL
local designUrl = ""
local designOssUrl = ""
local newDesignUrl = string.format("%s/Images/ActivityDecoWeek/%d" , gameName , activityThemeId )
if skynet.server.gameConfig:IsOnline() then
local cfgBasicConfig = skynet.server.gameConfig:GetAllCfg( "BasicConfig" )
designUrl = string.format("https://%s/%s/%s.jpg" , cfgBasicConfig.domain , newDesignUrl , fileName )
designOssUrl = string.format("https://%s/%s/%s.jpg" , cfgBasicConfig.ossUrl , newDesignUrl , fileName )
else
designUrl = string.format("http://%s/%s/%s.jpg" , skynet.externalIp , newDesignUrl , fileName)
end
return designUrl , designOssUrl
end
--是否存在设计玩家
function ActivityDecoWeek:IsExistSignPlayer( activityThemeId , partnerId , nowShowVoteInfos )
local isExistVote = skynet.server.common:IsExist( partnerId , nowShowVoteInfos )
if not isExistVote then
return false
end
local redisKey = ""
if self:IsNpc( partnerId) then
redisKey = redisKeyUrl.GameServerActivityDecoWeekNpcVoteScoreZSet
else
redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekHumanVoteScoreZSet , activityThemeId )
end
local isDesign = skynet.server.redis:zrank( redisKey , partnerId )
if isDesign then
return true
end
return false
end
--获取下一个投票信息
function ActivityDecoWeek:GetNextVoteInfo( player , activityThemeId , activityStatus , stageStartTime , stageEndTime , isHighValue )
local canVotePartnerIds = {}
local myPartnerId = player.gameData.partner.id
local activity = player.gameData.activity[ self.ActivityType ]
local historyShowVotes = activity.historyShowVotes --历史显示的投票信息
local nowShowVoteInfos = activity.nowShowVoteInfos --当前自己展示的投票信息
local isAveMode = false
--将自己的好友ID传进到历史投票里自己不能给自己投
if not skynet.server.common:IsExist( myPartnerId , historyShowVotes ) then
table.insert( historyShowVotes , myPartnerId)
end
--遍历所有热门信息
local function QueryCanVote()
local redisKey = redisKeyUrl.GameServerActivityDecoWeekNeedExpouseCountZSet
if skynet.server.gameConfig:IsTest() then
local testData = skynet.server.redis:zrevrange( redisKey , 0 , -1 , "withscores" )
log.info("周赛 获取需要曝光数据" , skynet.server.common:TableToString(testData))
log.info("周赛 获取自己历史的数据" , skynet.server.common:TableToString(historyShowVotes))
log.info("周赛 是否高价值" , isHighValue)
log.info("周赛 自己的ID" , myPartnerId)
end
local redisData = {}
if isHighValue then
--如果是高价值先找出10分以上的5个玩家按降序来排
redisData = skynet.server.redis:zrevrangebyscore( redisKey , "+inf" , 11 , "limit" , 0 , 5 )
else
--如果是低价值就找出10分以下并且1分以上的5个玩家按降序来排
redisData = skynet.server.redis:zrevrangebyscore( redisKey , 10 , 1 , "limit" , 0 , 5 )
end
if skynet.server.gameConfig:IsTest() then
log.info("周赛 第一次获取5个玩家数据 " , skynet.server.common:TableToString(redisData))
end
if 0 == #redisData then
if isHighValue then
--如果高价值玩家没有就找5个从高到低的玩家
redisData = skynet.server.redis:zrevrangebyscore( redisKey , "+inf" , 1 , "limit" , 0 , 5 )
else
--如果低价值玩家没有就找5个从低到高的玩家
redisData = skynet.server.redis:zrangebyscore( redisKey , 1 , "+inf" , "limit" , 0 , 5 )
end
end
if skynet.server.gameConfig:IsTest() then
log.info("周赛 第二次获取5个玩家数据 " , skynet.server.common:TableToString(redisData))
end
if 0 == #redisData then
--所有玩家都没有展示次数了,就采用平均曝光模式
redisKey = redisKeyUrl.GameServerActivityDecoWeekAveExpouseCountZSet
redisData = skynet.server.redis:zrange( redisKey , 0 , 4 ) --先找出5个平均曝光次数最少的玩家
isAveMode = true
if skynet.server.gameConfig:IsTest() then
local testData = skynet.server.redis:zrevrange( redisKey , 0 , -1 , "withscores" )
log.info("周赛 获取所有平均曝光数据" , skynet.server.common:TableToString(testData))
end
end
--对找到的玩家,只要不是自己,不是历史出现过,不是当前正在显示的,就加进来
for k, v in pairs( redisData ) do
if v ~= myPartnerId and not skynet.server.common:IsExist( v , historyShowVotes ) and not skynet.server.common:IsExist( v , nowShowVoteInfos ) then
table.insert( canVotePartnerIds , v)
end
end
if skynet.server.gameConfig:IsTest() then
log.info("周赛 最后获得的数据" , skynet.server.common:TableToString(canVotePartnerIds))
end
end
QueryCanVote()
local count = #canVotePartnerIds
if 0 == count then
--清除下历史投票,再来找。
historyShowVotes = {}
QueryCanVote()
end
count = #canVotePartnerIds
if 0 == count then
--没有一个玩家那就获取NPC的数据
local redisKey = redisKeyUrl.GameServerActivityDecoWeekNpcVoteScoreZSet
local queryData = skynet.server.redis:zrange( redisKey , 0 , -1 , "withscores" )
queryData = redisKeyUrl:CovertTable(queryData)
for partnerId , score in pairs( queryData ) do
if not skynet.server.common:IsExist( partnerId , nowShowVoteInfos ) then
table.insert( canVotePartnerIds , partnerId )
end
end
count = #canVotePartnerIds
if count > 0 then
--如果有NPC数据就随机选一个
local randIndex = math.random( 1 , count )
local npcPartnerId = canVotePartnerIds[ randIndex ]
canVotePartnerIds = {}
table.insert( canVotePartnerIds , npcPartnerId )
log.debug("周赛 最后获得NPC的数据" , npcPartnerId)
end
end
count = #canVotePartnerIds
if 0 == count then
return nil
else
--local noVotePartnerId = canVotePartnerIds[ 1 ]
local randIndex = math.random( 1 , count ) --之前是取的第一个投票玩家,现在改成随机一个投票的玩家
local noVotePartnerId = canVotePartnerIds[ randIndex ]
local noVoteInfo = self:GetDesignInfo( noVotePartnerId , activityThemeId , activityStatus , stageStartTime , stageEndTime )
if noVoteInfo then
table.insert( historyShowVotes , noVotePartnerId)
table.insert( nowShowVoteInfos , noVotePartnerId )
if not self:IsNpc( noVotePartnerId ) then
--增加所有曝光次数
local redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekInfoHash )
skynet.server.redis:hincrby( redisKey , "allExposureCount" , 1 )
if not isAveMode then
--还有剩余曝光次数就减少1次
redisKey = redisKeyUrl.GameServerActivityDecoWeekNeedExpouseCountZSet
skynet.server.redis:zincrby( redisKey , -1 , noVotePartnerId )
else
--开始平均曝光增加1次
redisKey = redisKeyUrl.GameServerActivityDecoWeekAveExpouseCountZSet
skynet.server.redis:zincrby( redisKey , 1 , noVotePartnerId )
end
end
end
return noVoteInfo
end
end
--获取热门的投票信息
function ActivityDecoWeek:GetHotVoteInfo( activityThemeId , activityStatus , stageStartTime , stageEndTime , historyShowHotDesigns )
local canShowPartnerIds = {}
local function QueryHotDesign()
--遍历所有热门信息,过滤掉我已经投票的玩家
for k, v in pairs( self.highScoreDesigns ) do
if not skynet.server.common:IsExist( v.partnerId , historyShowHotDesigns ) then
table.insert( canShowPartnerIds , v.partnerId )
end
end
end
QueryHotDesign()
local count = #canShowPartnerIds
if 0 == count then
historyShowHotDesigns = {} --清空历史显示再查询
QueryHotDesign()
end
count = #canShowPartnerIds
if 0 == count then
--没有一个玩家那就获取NPC的数据
local redisKey = redisKeyUrl.GameServerActivityDecoWeekNpcVoteScoreZSet
local queryData = skynet.server.redis:zrevrange( redisKey , 0 , self.HotDesignMaxCount , "withscores" )
queryData = redisKeyUrl:CovertTable(queryData)
for partnerId , score in pairs( queryData ) do
if not skynet.server.common:IsExist( partnerId , historyShowHotDesigns ) then
table.insert( canShowPartnerIds , partnerId )
table.insert( historyShowHotDesigns , partnerId)
break
end
end
end
local showVoteInfos = {}
local randList = skynet.server.common:RandNoRepeatItem( 1 , canShowPartnerIds )
for k, partnerId in pairs( randList ) do
table.insert( historyShowHotDesigns , partnerId)
showVoteInfos = self:GetDesignInfo( partnerId , activityThemeId , activityStatus , stageStartTime , stageEndTime )
break
end
return showVoteInfos
end
--检查有不有消息提示
function ActivityDecoWeek:CheckMsgTips( player , activityThemeId , activityStatus )
if 0 == activityThemeId or 0 == activityStatus then
return
end
skynet.server.msgTips:Reset(player , 96)
skynet.server.msgTips:Reset(player , 97)
skynet.server.msgTips:Reset(player , 98)
skynet.server.msgTips:Reset(player , 122)
--周赛投稿已开启红点
local activity = player.gameData.activity[ self.ActivityType ]
if self.ActivityStatus_Join == activityStatus and not activity.isSubmitDesign then
skynet.server.msgTips:Add( player , 96 )
end
--周赛奖励可领取时
local cfgOneWeekly = skynet.server.gameConfig:GetCurCfg( "WeeklyContest" , activityThemeId )
local voteReward = cfgOneWeekly.voteReward
for k, v in pairs( voteReward ) do
local rewardInfo = skynet.server.common:Split( v ,"_" )
rewardInfo[1] = tonumber(rewardInfo[1])
--如果满足奖励并且没有领取就发红点
local isExistReward = skynet.server.common:IsExist( rewardInfo[1] , activity.rewardIds )
if not isExistReward and activity.weekVoteCount >= rewardInfo[1] then
skynet.server.msgTips:Add( player , 97 )
break
elseif isExistReward and k == #voteReward then
activity.getAllWeekReward = true
end
end
--周赛有剩余投票次数可使用且周投票进度未满
if self.ActivityStatus_Vote == activityStatus and not activity.getAllWeekReward and skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30)>0 then
skynet.server.msgTips:Add( player , 98 )
end
--有未领取的结算奖励添加红点
local myParentId = player.gameData.partner.id
local detail = skynet.server.personal:GetDetail( myParentId , "decoWeekLastRewardId")
local rewardId = detail or 0
if rewardId ~= 0 then
skynet.server.msgTips:Add( player , 122 )
end
end
--是否投票调节阶段(投票阶段结束前30分钟停止投票计分)
function ActivityDecoWeek:IsVoteAdjust( activityStatus , stageEndTime )
if self.ActivityStatus_Vote == activityStatus and stageEndTime - skynet.GetTime() <= 1800 then
--如果投票阶段还剩半小时小时就进入调节状态
return true
end
return false
end
--是否为NPC
function ActivityDecoWeek:IsNpc( partnerId )
if string.find( partnerId , "Npc_") then
return true
end
return false
end
--解锁系统后立刻执行的逻辑
function ActivityDecoWeek:UnlockSystemFunc(player)
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivityDecoWeek ) then
return
end
local activityThemeId,activityStatus = self:GetCurActivityInfo()
local activity = player.gameData.activity[ self.ActivityType ]
if activityStatus == self.ActivityStatus_Vote and not activity and not player.gameData.todayGain.weeklyDesignFreeVote then
self:LoginInitData(player)
skynet.server.bag:AddGoods(player, dataType.GoodsType_Prop, 30, 5)
skynet.server.msgTips:Add( player , 98 )
player.gameData.todayGain.weeklyDesignFreeVote = true
end
end
--免费投票券发放逻辑
function ActivityDecoWeek:GetFreeVote( player )
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivityDecoWeek ) then
return
end
if player.gameData.todayGain.weeklyDesignFreeVote then
return
end
local activity = player.gameData.activity[ self.ActivityType ]
local activityThemeId,activityStatus,stageStartTime = self:GetCurActivityInfo()
if activityStatus == self.ActivityStatus_Vote then
--防止跳时间登陆数据有误
if activity.themeId ~= activityThemeId then
self:LoginInitData( player )
end
--要补发投票阶段开始后玩家漏掉登陆的天数对应的投票券 加一秒处理0点会计算出0的情况
local lastDay = math.ceil(( player.basicInfo.lastLoginTime - stageStartTime + 1 ) /3600/24 )
local toDay = math.ceil(( skynet.GetTime() - stageStartTime + 1 ) /3600/24 )
if lastDay < 0 then
lastDay = 0
elseif lastDay == 0 then
lastDay = 1
end
local count = (toDay - lastDay) * 5
if count <= 0 then
count = 5
end
if skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30) < 0 then
skynet.server.bag:AddGoods(player, dataType.GoodsType_Prop, 30, -skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30))
end
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
if count + skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30) > cfgSValue.weeklyContestVoteMax then
count = cfgSValue.weeklyContestVoteMax - skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30)
end
skynet.server.bag:AddGoods(player, dataType.GoodsType_Prop, 30, count)
skynet.server.msgTips:Add( player , 98 )
player.gameData.todayGain.weeklyDesignFreeVote = true
local data = {}
data.voteNum = count
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_ActivityDecoWeekFreeVote" , data )
elseif activityStatus ~= self.ActivityStatus_Vote and skynet.server.common:GetDayInWeek() == 1 then --周一零点可能出现周赛服和游戏服时间不同步的问题这里做单独处理
--防止跳时间登陆数据有误
if activity.themeId ~= activityThemeId then
self:LoginInitData( player )
end
if skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30) < 0 then
skynet.server.bag:AddGoods(player, dataType.GoodsType_Prop, 30, -skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 30))
end
skynet.server.bag:AddGoods(player, dataType.GoodsType_Prop, 30, 5)
skynet.server.msgTips:Add( player , 98 )
player.gameData.todayGain.weeklyDesignFreeVote = true
local data = {}
data.voteNum = 5
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_ActivityDecoWeekFreeVote" , data )
end
end
--[[
--同步设计数据(废弃)
function ActivityDecoWeek:SyncHotDesignListOld()
local activityThemeId,activityStatus = self:GetCurActivityInfo()
--获取设计详情
local function GetDesignDetail( queryData )
local listDesigns = {}
queryData = redisKeyUrl:CovertTable(queryData)
for partnerId , score in pairs( queryData ) do
table.insert( listDesigns , { partnerId = partnerId , score = score })
end
return listDesigns
end
--获取设计数据
local function GetDesignData( isHighScoreDesign )
local redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekInfoHash )
local allVoteScore = skynet.server.redis:hget( redisKey , "allVoteScore" ) or 0 --所有投票分数
redisKey = string.format( redisKeyUrl.GameServerActivityDecoWeekHumanVoteScoreZSet , activityThemeId )
local designCount = skynet.server.redis:zcard( redisKey ) --获取设计数量
if 0 == designCount then
--如果没有设计信息就用NPC数据
redisKey = redisKeyUrl.GameServerActivityDecoWeekNpcVoteScoreZSet
designCount = skynet.server.redis:zcard( redisKey )
end
local queryData = nil
if isHighScoreDesign then
--热门数据
local cfgSValue = skynet.server.gameConfig:GetAllCfg( "SValue" )
local hotRange = math.ceil(cfgSValue.heatWeeklyContestWork * designCount)
queryData = skynet.server.redis:zrevrange( redisKey , 0 , hotRange , "withscores" ) --每次获取50个高分数据
self.highScoreDesigns = GetDesignDetail( queryData )
else
local allAveVoteScore = 0
if designCount > 0 then
allAveVoteScore = math.floor( allVoteScore / designCount ) --所有平均投票分数
end
if 0 == allAveVoteScore then
--由于没有平均分就获取50个最低分的数据
self.lowScoreArea = {}
self.highScoreArea = {}
queryData = skynet.server.redis:zrange( redisKey , 0 , self.RefreshDesignMaxCount , "withscores" )
queryData = redisKeyUrl:CovertTable(queryData)
local isSingleNum = true --是否单数
for partnerId, score in pairs( queryData ) do
if isSingleNum then
isSingleNum = false
table.insert( self.lowScoreArea , { partnerId = partnerId , score = score })
else
isSingleNum = true
table.insert( self.highScoreArea , { partnerId = partnerId , score = score })
end
end
else
--根据平均投票分数划分低分区和高分区
queryData = skynet.server.redis:zrangebyscore( redisKey , 0 , allAveVoteScore , "withscores", "limit" , self.lowScoreOffset , self.RefreshDesignMaxCount )
if #queryData > 0 then
--成功获取数据,就增加偏移量
self.lowScoreOffset = self.lowScoreOffset + self.RefreshDesignMaxCount
else
--未获取数据就偏移量归0并重新获取
self.lowScoreOffset = 0
queryData = skynet.server.redis:zrangebyscore( redisKey , 0 , allAveVoteScore , "withscores", "limit" , self.lowScoreOffset , self.RefreshDesignMaxCount )
end
self.lowScoreArea = GetDesignDetail( queryData )
queryData = skynet.server.redis:zrangebyscore( redisKey , allAveVoteScore + 1 , 99999999 , "withscores", "limit" , self.highScoreOffset , self.RefreshDesignMaxCount )
if #queryData > 0 then
--成功获取数据,就增加偏移量
self.highScoreOffset = self.highScoreOffset + self.RefreshDesignMaxCount
else
--未获取数据就偏移量归0并重新获取
self.highScoreOffset = 0
queryData = skynet.server.redis:zrangebyscore( redisKey , allAveVoteScore + 1 , 99999999 , "withscores", "limit" , self.highScoreOffset , self.RefreshDesignMaxCount )
end
self.highScoreArea = GetDesignDetail( queryData )
end
--如果玩家设计数量小于10加入NPC的设计进来,方便测试时,玩家设计的数量比较少的情况
--[[
if designCount <= 10 then
queryData = skynet.server.redis:zrange( redisKeyUrl.GameServerActivityDecoWeekNpcVoteScoreZSet , 0 , self.RefreshDesignMaxCount , "withscores" )
queryData = redisKeyUrl:CovertTable(queryData)
local isSingleNum = true --是否单数
for partnerId, score in pairs( queryData ) do
if isSingleNum then
isSingleNum = false
table.insert( self.lowScoreArea , { partnerId = partnerId , score = score })
else
isSingleNum = true
table.insert( self.highScoreArea , { partnerId = partnerId , score = score })
end
end
end
end
end
if self.ActivityStatus_No == activityStatus then
return
elseif self.ActivityStatus_Vote == activityStatus then
GetDesignData( false )
end
--获取热门数据
GetDesignData( true )
end
]]
skynet.server.activityDecoWeek = ActivityDecoWeek
return ActivityDecoWeek