296 lines
9.2 KiB
Lua
296 lines
9.2 KiB
Lua
|
|
|||
|
------------------------------------------------
|
|||
|
--作者: 王圣
|
|||
|
--日期: 2019-07-19
|
|||
|
--文件: ServerActiveSystem.lua
|
|||
|
--模块: ServerActiveSystem
|
|||
|
--描述: 开服活动系统
|
|||
|
------------------------------------------------
|
|||
|
--引用
|
|||
|
local ActiveComData = require "Logic.ServerActive.ServerActiveComData"
|
|||
|
local RedPacketData = require "Logic.ServerActive.ServeRedPacketData"
|
|||
|
local ExChangeData = require "Logic.ServerActive.ServeExChangeData"
|
|||
|
local TimeUtils = CS.Thousandto.Core.Base.TimeUtils
|
|||
|
local ServerActiveSystem = {
|
|||
|
--[红包模块数据]------------
|
|||
|
--可领取红包总额
|
|||
|
RpGoldNum = 0,
|
|||
|
--红包总个数据
|
|||
|
RedPacketNum = 7,
|
|||
|
--红包领取状态 0 : 未达到领取条件 1:可以领取 2:已领取
|
|||
|
RpRewardState = 0,
|
|||
|
--七日红包剩余时间
|
|||
|
RpLeftTime = 0,
|
|||
|
RpSyncTime = 0,
|
|||
|
--元宝Icon
|
|||
|
RpGoldIcon = 0,
|
|||
|
--红包数据List
|
|||
|
ListRedPacketData = List:New(),
|
|||
|
--[红包模块数据]------------
|
|||
|
|
|||
|
--[集字兑换数据]------------
|
|||
|
--说明
|
|||
|
ExChangeExplain = nil,
|
|||
|
ExChangeTitlePicName = nil,
|
|||
|
ListExChangeData = List:New(),
|
|||
|
--[集字兑换数据]------------
|
|||
|
|
|||
|
--通用模型数据类型字典 包含几个相同标签页数据
|
|||
|
DicActiveComData = Dictionary:New(),
|
|||
|
--红点字典
|
|||
|
DicRedPoint = Dictionary:New(),
|
|||
|
}
|
|||
|
|
|||
|
function ServerActiveSystem:Initialize()
|
|||
|
self.DicActiveComData:Clear()
|
|||
|
self.DicRedPoint:Clear()
|
|||
|
DataConfig.DataNewSeverActive:Foreach(function(k, v)
|
|||
|
local comData = nil
|
|||
|
local key = v.Type
|
|||
|
if self.DicActiveComData:ContainsKey(key) then
|
|||
|
comData = self.DicActiveComData[key]
|
|||
|
comData:AddData(v)
|
|||
|
else
|
|||
|
comData = ActiveComData:New()
|
|||
|
comData:ParaseCfg(v)
|
|||
|
self.DicActiveComData[key] = comData
|
|||
|
end
|
|||
|
end)
|
|||
|
|
|||
|
--初始化红包List
|
|||
|
local globCfg = DataConfig.DataGlobal[1573]
|
|||
|
if globCfg ~= nil then
|
|||
|
local list = Utils.SplitStr(globCfg.Params,';')
|
|||
|
if list ~= nil then
|
|||
|
for i = 1,#list do
|
|||
|
local rpData = RedPacketData:New()
|
|||
|
rpData:Parase(list[i],i)
|
|||
|
self.ListRedPacketData:Add(rpData)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--初始化集字兑换数据
|
|||
|
DataConfig.DataNewSeverExchange:Foreach(function(k, v)
|
|||
|
local exChangeData = ExChangeData:New()
|
|||
|
exChangeData:ParaseCfg(v)
|
|||
|
self.ListExChangeData:Add(exChangeData)
|
|||
|
end)
|
|||
|
|
|||
|
--红点
|
|||
|
for i = 1,ServerActiveEnum.Count -1 do
|
|||
|
self.DicRedPoint:Add(i,false)
|
|||
|
end
|
|||
|
--注册道具改变消息
|
|||
|
--GameCenter.RegFixEventHandle(LogicEventDefine.EVENT_ITEM_CHANGE_UPDATE, self.OnItemChanged,self)
|
|||
|
end
|
|||
|
|
|||
|
function ServerActiveSystem:UnInitialize()
|
|||
|
--GameCenter.UnRegFixEventHandle(LogicEventDefine.EVENT_ITEM_CHANGE_UPDATE, self.OnItemChanged,self)
|
|||
|
end
|
|||
|
|
|||
|
--道具改变
|
|||
|
function ServerActiveSystem:OnItemChanged(obj, sender)
|
|||
|
if self.ListExChangeData~= nil then
|
|||
|
local itemID = obj
|
|||
|
local isEnable = true
|
|||
|
for i = 1,#self.ListExChangeData do
|
|||
|
local data = self.ListExChangeData[i]
|
|||
|
for m = 1,#data.ListCostItem do
|
|||
|
local ItemData = data.ListCostItem[m]
|
|||
|
local num = GameCenter.ItemContianerSystem:GetItemCountFromCfgId(ItemData.Id)
|
|||
|
if num < ItemData.Num then
|
|||
|
isEnable = false
|
|||
|
break
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
if isEnable then
|
|||
|
--显示主功能红点
|
|||
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.ServerActive,true)
|
|||
|
self.DicRedPoint[ServerActiveEnum.Collect] = true
|
|||
|
else
|
|||
|
self.DicRedPoint[ServerActiveEnum.Collect] = false
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--根据id值获取对应的ComData数据
|
|||
|
function ServerActiveSystem:GetComActiveDataById(id)
|
|||
|
if self.DicActiveComData:ContainsKey(id) then
|
|||
|
return self.DicActiveComData[id]
|
|||
|
end
|
|||
|
return nil
|
|||
|
end
|
|||
|
|
|||
|
--根据cfgId 获取对应ComData数据
|
|||
|
function ServerActiveSystem:GetComActiveDataByCfgId(cfgId)
|
|||
|
local cfg = DataConfig.DataNewSeverActive[cfgId]
|
|||
|
if cfg ~= nil then
|
|||
|
local key = cfg.Type
|
|||
|
if self.DicActiveComData:ContainsKey(key) then
|
|||
|
return self.DicActiveComData[key]
|
|||
|
end
|
|||
|
end
|
|||
|
return nil
|
|||
|
end
|
|||
|
|
|||
|
--根据cfgId 获取comdata中的taskdata
|
|||
|
function ServerActiveSystem:GetTaskDataByCfgId(cfgId)
|
|||
|
local data = nil
|
|||
|
local cfg = DataConfig.DataNewSeverActive[cfgId]
|
|||
|
if cfg ~= nil then
|
|||
|
local key = cfg.Type
|
|||
|
if self.DicActiveComData:ContainsKey(key) then
|
|||
|
data = self.DicActiveComData[key]
|
|||
|
end
|
|||
|
end
|
|||
|
if data ~= nil then
|
|||
|
for i = 1,#data.ListTask do
|
|||
|
if data.ListTask[i].CfgId == cfgId then
|
|||
|
return data.ListTask[i]
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
return nil
|
|||
|
end
|
|||
|
|
|||
|
--更新红点数据
|
|||
|
function ServerActiveSystem:UpdateRedPoint()
|
|||
|
self.DicActiveComData:Foreach(function(k, v)
|
|||
|
local haveRedPoint = false
|
|||
|
for i = 1, #v.ListTask do
|
|||
|
if v.ListTask[i].RewardState == 1 then
|
|||
|
haveRedPoint = true
|
|||
|
break
|
|||
|
end
|
|||
|
end
|
|||
|
if self.DicRedPoint:ContainsKey(k) then
|
|||
|
self.DicRedPoint[k] = haveRedPoint
|
|||
|
end
|
|||
|
end)
|
|||
|
end
|
|||
|
|
|||
|
--获取七日红包活动剩余时间
|
|||
|
--获取剩余时间
|
|||
|
function ServerActiveSystem:GetLeftTime()
|
|||
|
return self.RpLeftTime - (Time.GetRealtimeSinceStartup()- self.RpSyncTime)
|
|||
|
end
|
|||
|
|
|||
|
-------------------req消息(Msg)相关------------------
|
|||
|
--请求活动列表
|
|||
|
function ServerActiveSystem:ReqOpenServerSpecAc()
|
|||
|
GameCenter.Network.Send("MSG_OpenServerAc.ReqOpenServerSpecAc")
|
|||
|
end
|
|||
|
|
|||
|
--请求领奖
|
|||
|
function ServerActiveSystem:ReqOpenServerSpecReward(cfgId)
|
|||
|
GameCenter.Network.Send("MSG_OpenServerAc.ReqOpenServerSpecReward", {id = cfgId})
|
|||
|
end
|
|||
|
|
|||
|
--请求领取红包
|
|||
|
function ServerActiveSystem:ReqOpenServerSpecRed()
|
|||
|
GameCenter.Network.Send("MSG_OpenServerAc.ReqOpenServerSpecRed")
|
|||
|
end
|
|||
|
|
|||
|
--请求兑换
|
|||
|
function ServerActiveSystem:ReqOpenServerSpecExchange(id)
|
|||
|
GameCenter.Network.Send("MSG_OpenServerAc.ReqOpenServerSpecReward", {type = id})
|
|||
|
end
|
|||
|
|
|||
|
-------------------res消息(Msg)相关------------------
|
|||
|
--上线推送红点
|
|||
|
function ServerActiveSystem:ResOpenServerSpecRedDot(result)
|
|||
|
if result == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
--控制主界面是否显示红点
|
|||
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.ServerActive,result.state)
|
|||
|
--设置剩余兑换次数
|
|||
|
if result.exchangeList ~= nil then
|
|||
|
for i = 1,#self.ListExChangeData do
|
|||
|
self.ListExChangeData[i]:ParaseMsg(result.exchangeList[i])
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--请求活动列表返回
|
|||
|
function ServerActiveSystem:ResOpenServerSpecAc(result)
|
|||
|
if result == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
if result.specList ~= nil then
|
|||
|
for i = 1,#result.specList do
|
|||
|
--获取分页类型
|
|||
|
local data = self:GetComActiveDataByCfgId(result.specList[i].id)
|
|||
|
if data~= nil then
|
|||
|
data:ParaseMsg(result.specList[i])
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
--设置红包可领总额
|
|||
|
self.RpGoldNum = 0
|
|||
|
if result.redList ~= nil then
|
|||
|
for i = 1,#result.redList do
|
|||
|
self.RpGoldNum = self.RpGoldNum + result.redList[i]
|
|||
|
self.ListRedPacketData[i]:ParaseMsg(result.redList[i])
|
|||
|
end
|
|||
|
else
|
|||
|
end
|
|||
|
self.RpRewardState = result.redState
|
|||
|
--设置兑换数据
|
|||
|
if result.exchangeList ~= nil then
|
|||
|
for i = 1,#self.ListExChangeData do
|
|||
|
self.ListExChangeData[i]:ParaseMsg(result.exchangeList[i])
|
|||
|
end
|
|||
|
end
|
|||
|
self:UpdateRedPoint()
|
|||
|
--获取当前开服时间
|
|||
|
local time = math.floor( GameCenter.HeartSystem.ServerTime - result.openTime )
|
|||
|
self.CurDay = math.floor( time/(24*3600) ) + 1
|
|||
|
local totalDay = tonumber(DataConfig.DataGlobal[1572].Params)
|
|||
|
local liveSeconds = totalDay * (24 * 60 *60)
|
|||
|
|
|||
|
local seconds = 24 * 3600
|
|||
|
local hour, min, sec = TimeUtils.GetStampTimeHHMMSS(math.floor(GameCenter.HeartSystem.ServerTime))
|
|||
|
local curSeconds = hour * 3600 + min * 60 + sec
|
|||
|
self.RpLeftTime = liveSeconds - ((self.CurDay - 1) * (24 * 60 *60) + curSeconds )
|
|||
|
self.RpSyncTime = Time.GetRealtimeSinceStartup()
|
|||
|
--发送更新UI消息
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SERVERACTIVEFORM_UPDATE)
|
|||
|
end
|
|||
|
|
|||
|
--前面四个活动领奖返回
|
|||
|
function ServerActiveSystem:ResOpenServerSpecReward(result)
|
|||
|
if result == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
local taskData = self:GetTaskDataByCfgId(result.id)
|
|||
|
if taskData ~= nil then
|
|||
|
taskData.RewardState = 2
|
|||
|
taskData.LeftNum = result.remain
|
|||
|
end
|
|||
|
--发送更新UI消息
|
|||
|
self:UpdateRedPoint()
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SERVERACTIVEFORM_UPDATE)
|
|||
|
end
|
|||
|
|
|||
|
--领取红包返回
|
|||
|
function ServerActiveSystem:ResOpenServerSpecRed(result)
|
|||
|
if result == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
--发送更新UI消息
|
|||
|
self.IsRewardRedPacket = true
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SERVERACTIVEFORM_UPDATE)
|
|||
|
end
|
|||
|
|
|||
|
--兑换返回
|
|||
|
function ServerActiveSystem:ResOpenServerSpecExchange(result)
|
|||
|
if result == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
--发送更新UI消息
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SERVERACTIVEFORM_UPDATE)
|
|||
|
end
|
|||
|
return ServerActiveSystem
|