328 lines
9.7 KiB
Lua
328 lines
9.7 KiB
Lua
|
|
|||
|
------------------------------------------------
|
|||
|
--作者: 王圣
|
|||
|
--日期: 2019-07-11
|
|||
|
--文件: ServeCrazyData.lua
|
|||
|
--模块: ServeCrazyData
|
|||
|
--描述: 开服狂欢数据
|
|||
|
------------------------------------------------
|
|||
|
--引用
|
|||
|
local TimeUtils = CS.Thousandto.Core.Base.TimeUtils;
|
|||
|
local ItemData = require "Logic.ServeCrazy.ServeCrazyItemData"
|
|||
|
local ServeCrazyData = {
|
|||
|
--Type对应相应功能type
|
|||
|
Type = 0,
|
|||
|
--打开排行榜的类型
|
|||
|
RankType = 0,
|
|||
|
--当前功能是否开放
|
|||
|
IsOpen = false,
|
|||
|
--当前功能是否结束
|
|||
|
IsEnd = false,
|
|||
|
--我的排名
|
|||
|
MyRank = 0,
|
|||
|
--我的等级
|
|||
|
Mylevel = 0,
|
|||
|
--结算时间
|
|||
|
LeftTime = 0,
|
|||
|
SyncTime = 0,
|
|||
|
--结算天数 开服第几天结算
|
|||
|
EndDay = 0,
|
|||
|
--持续时间
|
|||
|
HoldTime = 1,
|
|||
|
--菜单按钮名字
|
|||
|
MenuName = nil,
|
|||
|
--简单描述
|
|||
|
UIDes = nil,
|
|||
|
--texture名字
|
|||
|
TextureName = nil,
|
|||
|
TexTetureName = nil,
|
|||
|
--领取描述
|
|||
|
DicRewardDes = Dictionary:New(),
|
|||
|
--需要客户端处理的奖励配置表Id
|
|||
|
CfgId = 0,
|
|||
|
--CfgId对应的奖励领取状态0: 未达成 1:可以领取 2:已领取
|
|||
|
RewardState = 0,
|
|||
|
--
|
|||
|
ValueName = nil,
|
|||
|
--奖励道具 key:奖励序列
|
|||
|
DicItem = Dictionary:New(),
|
|||
|
--对配置表Id进行排序
|
|||
|
ListCfgId = List:New(),
|
|||
|
|
|||
|
--快捷提升相关
|
|||
|
ListFuncId = List:New(),
|
|||
|
ListFuncName = List:New(),
|
|||
|
ListFuncIcon = List:New(),
|
|||
|
|
|||
|
--实时领取奖励状态字典 key : cfgId value: state
|
|||
|
DicRunTimeReward = Dictionary:New(),
|
|||
|
--子类型字典
|
|||
|
DicSubType = Dictionary:New(),
|
|||
|
|
|||
|
LimitShopId = 0,
|
|||
|
LimitShopCondition = nil,
|
|||
|
LimitShopId2 = 0,
|
|||
|
LimitShopCondition2 = nil,
|
|||
|
}
|
|||
|
function ServeCrazyData:New()
|
|||
|
local _m = Utils.DeepCopy(self)
|
|||
|
return _m
|
|||
|
end
|
|||
|
|
|||
|
--解析数据
|
|||
|
function ServeCrazyData:ParseCfg(cfg)
|
|||
|
if cfg == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
self.Type = cfg.Type
|
|||
|
self.SubType = cfg.SubType
|
|||
|
self.RankType = cfg.RankType
|
|||
|
self.ValueName = cfg.ShowName
|
|||
|
self.IsOpen = false
|
|||
|
self.ListCfgId:Add(cfg.Id)
|
|||
|
self.DicRewardDes:Add(cfg.Id,cfg.Showstring)
|
|||
|
--self.DicRunTimeReward:Add(cfg.Id,0)
|
|||
|
self.DicSubType:Add(cfg.Id,cfg.SubType)
|
|||
|
local list = Utils.SplitStr(cfg.Rew,';')
|
|||
|
for i = 1,#list do
|
|||
|
local item = ItemData:New()
|
|||
|
item:Parase(list[i])
|
|||
|
local listItem = nil
|
|||
|
if self.DicItem:ContainsKey(cfg.Id) then
|
|||
|
listItem = self.DicItem[cfg.Id]
|
|||
|
listItem:Add(item)
|
|||
|
else
|
|||
|
listItem = List:New()
|
|||
|
listItem:Add(item)
|
|||
|
self.DicItem:Add(cfg.Id,listItem)
|
|||
|
end
|
|||
|
end
|
|||
|
self:ParseRankCfg()
|
|||
|
end
|
|||
|
|
|||
|
function ServeCrazyData:AddData(cfg)
|
|||
|
if cfg == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
self.SubType = cfg.SubType
|
|||
|
self.ListCfgId:Add(cfg.Id)
|
|||
|
self.DicRewardDes:Add(cfg.Id,cfg.Showstring)
|
|||
|
--self.DicRunTimeReward:Add(cfg.Id,0)
|
|||
|
self.DicSubType:Add(cfg.Id,cfg.SubType)
|
|||
|
local list = Utils.SplitStr(cfg.Rew,';')
|
|||
|
for i = 1,#list do
|
|||
|
local item = ItemData:New()
|
|||
|
item:Parase(list[i])
|
|||
|
local listItem = nil
|
|||
|
if self.DicItem:ContainsKey(cfg.Id) then
|
|||
|
listItem = self.DicItem[cfg.Id]
|
|||
|
listItem:Add(item)
|
|||
|
else
|
|||
|
listItem = List:New()
|
|||
|
listItem:Add(item)
|
|||
|
self.DicItem:Add(cfg.Id,listItem)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function ServeCrazyData:ParseRankCfg()
|
|||
|
local cfg = DataConfig.DataNewSeverRank[self.Type]
|
|||
|
if cfg == nil then
|
|||
|
return nil
|
|||
|
end
|
|||
|
self.MenuName = cfg.Showname
|
|||
|
self.UIDes = cfg.Des
|
|||
|
self.EndDay = cfg.ServerEndTime
|
|||
|
self.HoldTime = cfg.Time
|
|||
|
self.TexTetureName = cfg.DesTexture
|
|||
|
self.TextureName = cfg.ShowTexture
|
|||
|
self.LimitShopId = cfg.OpenLimitShop
|
|||
|
self.LimitShopCondition = cfg.LimitShopCondition
|
|||
|
self.LimitShopId2 = cfg.OpenLimitShop2
|
|||
|
self.LimitShopCondition2 = cfg.LimitShopCondition2
|
|||
|
self.ListFuncIcon:Clear()
|
|||
|
self.ListFuncName:Clear()
|
|||
|
self.ListFuncId:Clear()
|
|||
|
self.ListFuncName:Add(cfg.Iconname1)
|
|||
|
self.ListFuncName:Add(cfg.Iconname2)
|
|||
|
self.ListFuncName:Add(cfg.Iconname3)
|
|||
|
self.ListFuncIcon:Add(cfg.Icon1)
|
|||
|
self.ListFuncIcon:Add(cfg.Icon2)
|
|||
|
self.ListFuncIcon:Add(cfg.Icon3)
|
|||
|
self.ListFuncId:Add(cfg.Path1)
|
|||
|
self.ListFuncId:Add(cfg.Path2)
|
|||
|
self.ListFuncId:Add(cfg.Path3)
|
|||
|
end
|
|||
|
|
|||
|
--解析消息数据
|
|||
|
function ServeCrazyData:ParaseMsg(msg)
|
|||
|
self.MyRank = msg.rank
|
|||
|
self.Mylevel = msg.curValue
|
|||
|
self.CfgId = 0--msg.level
|
|||
|
self.RewardState = 0--msg.state
|
|||
|
if msg.pList ~= nil then
|
|||
|
for i = 1,#msg.pList do
|
|||
|
if self.DicRunTimeReward:ContainsKey(msg.pList[i].id) then
|
|||
|
self.DicRunTimeReward[msg.pList[i].id] = msg.pList[i].state
|
|||
|
else
|
|||
|
self.DicRunTimeReward:Add(msg.pList[i].id,msg.pList[i].state)
|
|||
|
end
|
|||
|
if msg.pList[i].state == 1 then
|
|||
|
--显示主界面Icon上的红点
|
|||
|
--GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.ServeCrazy,true)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--设置功能开启状态
|
|||
|
function ServeCrazyData:SetFunctionState()
|
|||
|
--当前开服第几天
|
|||
|
local curOpenTime = Time.GetOpenSeverDay()--GameCenter.ServeCrazySystem:GetCurOpenTime()
|
|||
|
local hour = TimeUtils.GetStampTimeHHNotZone(math.floor( GameCenter.HeartSystem.ServerZoneTime ))
|
|||
|
if curOpenTime<0 then
|
|||
|
return
|
|||
|
end
|
|||
|
if self.Type ==1 then
|
|||
|
if curOpenTime <=self.EndDay then
|
|||
|
self.IsOpen = true
|
|||
|
--判断功能是否结束
|
|||
|
if curOpenTime == self.EndDay then
|
|||
|
if hour >= GameCenter.ServeCrazySystem.ReFreshTime then
|
|||
|
--判断是否大于刷新时间 活动结束
|
|||
|
self.IsEnd = true
|
|||
|
else
|
|||
|
self.IsEnd = false
|
|||
|
end
|
|||
|
end
|
|||
|
else
|
|||
|
--当前活动已经结束
|
|||
|
self.IsOpen = true
|
|||
|
self.IsEnd = true
|
|||
|
end
|
|||
|
else
|
|||
|
if curOpenTime <= self.EndDay then
|
|||
|
if curOpenTime == self.EndDay then
|
|||
|
--活动已经到了结束当前 判断是否超过刷新时间
|
|||
|
self.IsOpen = true
|
|||
|
if hour >= GameCenter.ServeCrazySystem.ReFreshTime then
|
|||
|
--超过刷新时间
|
|||
|
self.IsEnd = true
|
|||
|
else
|
|||
|
self.IsEnd = false
|
|||
|
end
|
|||
|
elseif self.EndDay - curOpenTime == self.HoldTime then
|
|||
|
--现在时间在活动结束头一天 判断是否到了该活动的刷新时间
|
|||
|
self.IsEnd = false
|
|||
|
--策划说的加一个小时
|
|||
|
if hour>= GameCenter.ServeCrazySystem.ReFreshTime + 1 then
|
|||
|
--已经到了刷新时间活动开启
|
|||
|
self.IsOpen = true
|
|||
|
else
|
|||
|
--该活动还没有开启
|
|||
|
self.IsOpen = false
|
|||
|
end
|
|||
|
elseif self.EndDay - curOpenTime>1 then
|
|||
|
self.IsOpen = false
|
|||
|
end
|
|||
|
else
|
|||
|
self.IsOpen = true
|
|||
|
self.IsEnd = true
|
|||
|
end
|
|||
|
end
|
|||
|
if self.IsOpen and not self.IsEnd then
|
|||
|
--计算结束倒计时
|
|||
|
local seconds = 23 * 3600
|
|||
|
local min = TimeUtils.GetStampTimeMMNotZone(math.ceil( GameCenter.HeartSystem.ServerZoneTime ))
|
|||
|
local sec = TimeUtils.GetStampTimeSSNotZone(math.ceil( GameCenter.HeartSystem.ServerZoneTime ))
|
|||
|
local curSeconds = hour * 3600 + min * 60 + sec
|
|||
|
local allSeconds = 24 * 3600
|
|||
|
self.LeftTime = (allSeconds- curSeconds) + seconds + (self.EndDay - curOpenTime - 1)*allSeconds
|
|||
|
self.SyncTime = Time.GetRealtimeSinceStartup()
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--根据id获取奖励描述
|
|||
|
function ServeCrazyData:GetRewardDesById(id)
|
|||
|
if self.DicRewardDes:ContainsKey(id) then
|
|||
|
return self.DicRewardDes[id]
|
|||
|
end
|
|||
|
return nil
|
|||
|
end
|
|||
|
|
|||
|
--根据id获取实时领取奖励的状态
|
|||
|
function ServeCrazyData:GetRunTimeRewardState(id)
|
|||
|
if self.DicRunTimeReward:ContainsKey(id) then
|
|||
|
return self.DicRunTimeReward[id]
|
|||
|
end
|
|||
|
return 0
|
|||
|
end
|
|||
|
|
|||
|
function ServeCrazyData:SetRunTimeRewardState(id, state)
|
|||
|
if self.DicRunTimeReward:ContainsKey(id) then
|
|||
|
self.DicRunTimeReward[id] = state
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function ServeCrazyData:HaveReward()
|
|||
|
local isHave = false
|
|||
|
self.DicRunTimeReward:Foreach(function(k, v)
|
|||
|
if v == 1 then
|
|||
|
isHave = true
|
|||
|
end
|
|||
|
end)
|
|||
|
return isHave
|
|||
|
end
|
|||
|
|
|||
|
--根据id获取subType类型
|
|||
|
function ServeCrazyData:GetSubType(id)
|
|||
|
if self.DicSubType:ContainsKey(id) then
|
|||
|
return self.DicSubType[id]
|
|||
|
end
|
|||
|
--默认是1
|
|||
|
return 1
|
|||
|
end
|
|||
|
|
|||
|
function ServeCrazyData:GetSortCfgIdList()
|
|||
|
local dicSort = Dictionary:New()
|
|||
|
for i = 1,#self.ListCfgId do
|
|||
|
if self.DicRunTimeReward:ContainsKey(self.ListCfgId[i]) then
|
|||
|
local sort = 0
|
|||
|
local state = self.DicRunTimeReward[self.ListCfgId[i]]
|
|||
|
if state == 0 then
|
|||
|
sort = 1000
|
|||
|
elseif state == 1 then
|
|||
|
sort = 0
|
|||
|
elseif state == 2 then
|
|||
|
sort = 2000
|
|||
|
end
|
|||
|
dicSort:Add(self.ListCfgId[i],sort)
|
|||
|
else
|
|||
|
dicSort:Add(self.ListCfgId[i],1000)
|
|||
|
end
|
|||
|
end
|
|||
|
self.ListCfgId:Sort(function(a,b)
|
|||
|
local sort1 = dicSort[a]
|
|||
|
local sort2 = dicSort[b]
|
|||
|
return sort1 + a <sort2 + b
|
|||
|
end )
|
|||
|
return self.ListCfgId
|
|||
|
end
|
|||
|
|
|||
|
--获取剩余时间
|
|||
|
function ServeCrazyData:GetLeftTime()
|
|||
|
if self.LeftTime == 0 then
|
|||
|
return -1
|
|||
|
end
|
|||
|
return self.LeftTime - (Time.GetRealtimeSinceStartup()- self.SyncTime)
|
|||
|
end
|
|||
|
|
|||
|
--通过配置表id获取奖励道具list
|
|||
|
function ServeCrazyData:GetRewardItems(cfgId)
|
|||
|
if self.DicItem:ContainsKey(cfgId) then
|
|||
|
return self.DicItem[cfgId]
|
|||
|
end
|
|||
|
return nil
|
|||
|
end
|
|||
|
|
|||
|
return ServeCrazyData
|