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

474 lines
20 KiB
Lua

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 ActivityManage = oo.class(activity)
function ActivityManage:Init()
end
--初始玩家活动显示相关数据
function ActivityManage:LoginChangeData( player , isLogin)
if isLogin == nil then
isLogin = true
end
--如果没有数据 则进行初始化
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
if next(player.gameData.activityManage) == nil and player.gameData.level >= cfgSValue.activityUnlockLvl then
for i = 1 , dataType.ActivityType_EndActivity - 1 , 1 do
player.gameData.activityManage[ i ] = {}
player.gameData.activityManage[ i ].id = 0 --该活动的id 默认为0
player.gameData.activityManage[ i ].redDot1 = false --是否显示红点 新活动使用
player.gameData.activityManage[ i ].redDot2 = false --是否显示红点 活动内有红点使用
end
--新人签到另作处理
if skynet.GetTime() < player.gameData.playerLand.endTime and player.gameData.playerLand.isShow then
player.gameData.activityManage[ dataType.ActivityType_PlayerLand ].id = 3
player.gameData.activityManage[ dataType.ActivityType_PlayerLand ].redDot1 = true
player.gameData.activityManage[ dataType.ActivityType_PlayerLand ].redDot2 = false
end
self:ChangeData( player , isLogin)
self:RedDotManage( player , isLogin )
elseif next(player.gameData.activityManage) ~= nil and player.gameData.level >= cfgSValue.activityUnlockLvl then
--重置红点
skynet.server.msgTips:Reset(player , 78)
skynet.server.msgTips:Reset(player , 80)
for k , v in pairs(player.gameData.activityManage) do
v.redDot2 = false
--红点管理-78
if v.redDot1 and isLogin then
skynet.server.msgTips:AddNoNotice(player , 78)
end
end
self:ChangeData( player , isLogin)
self:RedDotManage( player , isLogin )
end
end
--展示所有开启的活动
function ActivityManage:Show( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivityManageShow", c2sData.data ))
local activityType = c2sData.data.activityType
local data = {}
data.activityInfos = {}
self:ChangeData( player )
self:RedDotManage( player )
local showRedDot2 = false --对应活动中是否还有红点
for k , v in pairs(player.gameData.activityManage) do
if k == activityType and v.redDot1 then
--消除对应红点
v.redDot1 = false
skynet.server.msgTips:Reduce(player , 78)
end
if v.redDot2 then
showRedDot2 = true
end
end
if not showRedDot2 then
skynet.server.msgTips:ReduceAll(player , 80)
end
--返回客户端需要的数据
for k , v in pairs(player.gameData.activityManage) do
if v.id > 0 then
if v.redDot1 or v.redDot2 then
table.insert(data.activityInfos , {id = v.id , redDot = true})
else
table.insert(data.activityInfos , {id = v.id , redDot = false})
end
end
end
--如果类型是通行证 返回对应数据
if dataType.ActivityType_PassCheck == activityType then
data.points = player.gameData.passCheck.score
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityManageShow")
s2cData.data = assert(pb.encode("S2CActivityManageShow", data))
end
--更新活动相关数据
function ActivityManage:ChangeData( player , isLogin )
local havaNewActivity = false --是否有新的活动开启
local haveEndActivity = false --是否有活动结束
local allStartActivity = self:GetAllActivityInfo( player )
local notStartType = {} --记录未开启活动的类型
for k , v in pairs(player.gameData.activityManage) do
if type(k) ~= "number" then
--处理下错误数据 重新加载活动管理数据
player.gameData.activityManage = {}
break
end
end
local oldCount=0
--查询原有活动数量
for _, value in pairs(player.gameData.activityManage) do
if value.id ~= 0 then
oldCount=oldCount+1
end
end
for i = 1,dataType.ActivityType_EndActivity - 1,1 do
table.insert(notStartType , i)
--如果有新的活动类型 同步老玩家数据
if player.gameData.activityManage[ i ] == nil then
player.gameData.activityManage[ i ] = {}
player.gameData.activityManage[ i ].id = 0 --该活动的id 默认为0
player.gameData.activityManage[ i ].redDot1 = false --是否显示红点 新活动使用
player.gameData.activityManage[ i ].redDot2 = false --是否显示红点 活动内有红点使用
end
end
for k , v in pairs(allStartActivity) do
local cfgActivity = skynet.server.gameConfig:GetPlayerCurCfg( player , "Activity" , v.id)
--开启了的活动对应值置为0
notStartType[cfgActivity.activityType] = 0
if player.gameData.activityManage[ cfgActivity.activityType ]~=nil
and player.gameData.activityManage[ cfgActivity.activityType ].id ~= v.id then
--该活动是新开始的 但之前未开启
player.gameData.activityManage[ cfgActivity.activityType ].id = v.id
player.gameData.activityManage[ cfgActivity.activityType ].redDot1 = true
player.gameData.activityManage[ cfgActivity.activityType ].redDot2 = false
havaNewActivity = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 78)
else
skynet.server.msgTips:Add(player , 78)
end
end
end
--处理一下新人签到
if player.gameData.activityManage[ dataType.ActivityType_PlayerLand ].id > 0 then
for k , v in pairs(notStartType) do
--代表新人签到不用显示了
if k == dataType.ActivityType_PlayerLand and v > 0 then
--主动推送当前活动信息
local data = {}
data.activityInfos = skynet.server.activity:GetAllActivityInfo( player )
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_UpdateShowUI" , data )
break
end
end
end
--清除没有开始的活动
for k , v in pairs(notStartType) do
if v > 0 then
player.gameData.activityManage[ v ].id = 0
player.gameData.activityManage[ v ].redDot1 = false
player.gameData.activityManage[ v ].redDot2 = false
end
end
--查询现有有活动数量
local newCount=0
for _, value in pairs(player.gameData.activityManage) do
if value.id ~= 0 then
newCount=newCount+1
end
end
log.debug("原有活动数量:"..oldCount.." 新活动数量:"..newCount)
haveEndActivity=oldCount~=newCount
return havaNewActivity or haveEndActivity
end
--活动管理面板红点系统
function ActivityManage:RedDotManage( player , isLogin )
--如果开启的活动中有对应的红点存在 则修改对应数据
for k , v in pairs(player.gameData.activityManage) do
if k == dataType.ActivityType_FlipCard and v.id > 0 then
--翻翻乐奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 102).count
--翻翻乐红点
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 103).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_Labyrinth and v.id > 0 then
--迷宫奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 76).count
--迷宫指南针红点
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 77).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_PlayerLand and v.id > 0 then
--新人签到红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 40).count
if redDotCount1 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_PassCheck and v.id > 0 then
--通行证奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 24).count
--通行证普通任务红点
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 25).count
--通行证限时任务红点
local redDotCount3 = skynet.server.msgTips:GetOneTips(player , 26).count
if redDotCount1 > 0 or redDotCount2 > 0 or redDotCount3 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_Raffle and v.id > 0 then
--限时卡池奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 68).count
--限时卡池登陆红点
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 69).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_AdvancePack and v.id > 0 then
elseif k == dataType.ActivityType_SignActivity and v.id > 0 then
--签到活动奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 79).count
if redDotCount1 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_Carnival and v.id > 0 then
--嘉年华任务奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 87).count
--嘉年华每日任宝箱红点
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 88).count
-- 嘉年华累计大奖红点
local redDotCount3 = skynet.server.msgTips:GetOneTips(player , 89).count
if redDotCount1 > 0 or redDotCount2 > 0 or redDotCount3 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_LimitedAccum and v.id > 0 then
--限时累充奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 94).count
if redDotCount1 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_DecoWeek and v.id > 0 then
--嘉年华任务奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 96).count
--嘉年华每日任宝箱红点
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 97).count
-- 嘉年华累计大奖红点
local redDotCount3 = skynet.server.msgTips:GetOneTips(player , 98).count
if redDotCount1 > 0 or redDotCount2 > 0 or redDotCount3 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_DreamLife and v.id > 0 then
--若来任务奖励红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 99).count
--若来商店红点
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 100).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_MatchStuff and v.id > 0 then
--好物匹配奖励
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 104).count
--好物匹配奖励
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 105).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_NewPlayerRaffle and v.id > 0 then
--新手限定卡池红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 106).count
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 107).count
local redDotCount3 = skynet.server.msgTips:GetOneTips(player , 108).count
if redDotCount1 > 0 or redDotCount2 > 0 or redDotCount3 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_Puzzle and v.id > 0 then
--拼图活动红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 110).count
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 111).count
local redDotCount3 = skynet.server.msgTips:GetOneTips(player , 112).count
if redDotCount1 > 0 or redDotCount2 > 0 or redDotCount3 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_SeekTreasure and v.id > 0 then
--寻味之旅红点
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 113).count
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 114).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_DailyRiddle and v.id > 0 then
--每日答题
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 119).count
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 120).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
end
elseif k == dataType.ActivityType_ActivityReplicaStore and v.id > 0 then
--复刻商店
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 123).count
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 124).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
elseif k == dataType.ActivityType_BindBox and v.id > 0 then
--盲盒
local redDotCount1 = skynet.server.msgTips:GetOneTips(player , 125).count
local redDotCount2 = skynet.server.msgTips:GetOneTips(player , 126).count
if redDotCount1 > 0 or redDotCount2 > 0 then
if not v.redDot2 then
v.redDot2 = true
if isLogin then
skynet.server.msgTips:AddNoNotice(player , 80)
else
skynet.server.msgTips:Add(player , 80)
end
end
else
v.redDot2 = false
end
end
end
end
skynet.server.activityManage = ActivityManage
return ActivityManage