164 lines
4.2 KiB
Lua
164 lines
4.2 KiB
Lua
------------------------------------------------
|
|
--作者: _SqL_
|
|
--日期: 2019-12-04
|
|
--文件: DailyCheck.lua
|
|
--模块: DailyCheck
|
|
--描述: 福利每日签到
|
|
------------------------------------------------
|
|
|
|
local DailyCheck = {
|
|
-- 今日是否签到
|
|
IsCheck = false,
|
|
-- 累计签到天数
|
|
DayNum = 0,
|
|
-- 今日正常可签哪一天
|
|
CheckInDay = 0,
|
|
-- 补签ID
|
|
MakeUpCfgId = 0,
|
|
-- 签到类型 0:正常签到 1:补签
|
|
CheckType = -1,
|
|
-- 第几轮奖励
|
|
Round = 0,
|
|
-- 正常签到的列表
|
|
CheckList = List:New(),
|
|
-- 补签的列表
|
|
MakeUpList = List:New(),
|
|
-- 已领取的奖励列表
|
|
RewardList = List:New(),
|
|
-- 奖励配置
|
|
RewardCfgList = nil,
|
|
-- 签到配置
|
|
DailyCheckCfgList = List:New(),
|
|
--是否提示
|
|
IsShowTips = true,
|
|
--最大签到天数
|
|
MaxDay = 0,
|
|
}
|
|
|
|
function DailyCheck:Initialize()
|
|
IsShowTips = true;
|
|
self.DailyCheckCfgList:Clear()
|
|
DataConfig.DataSignReward:Foreach(function(k, v)
|
|
self.MaxDay = self.MaxDay < v.Day and v.Day or self.MaxDay;
|
|
self.DailyCheckCfgList:Add(v)
|
|
end)
|
|
table.sort(self.DailyCheckCfgList, function(a, b)
|
|
return a.Day < b.Day
|
|
end)
|
|
return self
|
|
end
|
|
|
|
function DailyCheck:UnInitialize()
|
|
self.Round = 0
|
|
self.CheckList:Clear()
|
|
self.MakeUpList:Clear()
|
|
self.RewardList:Clear()
|
|
self.DailyCheckCfgList:Clear()
|
|
if self.RewardCfgList then
|
|
self.RewardCfgList = nil
|
|
end
|
|
end
|
|
|
|
-- 检测红点显示
|
|
function DailyCheck:CheckShowRedPoint()
|
|
local _showRed = false
|
|
if not self.IsCheck then
|
|
_showRed = true
|
|
else
|
|
_showRed = self:CheckRewardRed()
|
|
end
|
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.WelfareDailyCheck, _showRed)
|
|
end
|
|
|
|
-- 检测是否有奖励可以领取
|
|
function DailyCheck:CheckRewardRed()
|
|
if self.RewardCfgList then
|
|
for i=1, #self.RewardCfgList do
|
|
if self.DayNum >= self.RewardCfgList[i].Day
|
|
and (not self.RewardList:Contains(self.RewardCfgList[i].Id)) then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- 检测是否可以领奖
|
|
function DailyCheck:CheckIsReward(id)
|
|
if self.RewardList:Contains(id) then
|
|
return false
|
|
end
|
|
local _cfg = DataConfig.DataSignRewardCumulative[id]
|
|
if _cfg then
|
|
return _cfg.Day <= self.DayNum
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- 获取当前轮奖励配置
|
|
function DailyCheck:GetCurrRoundRewardCfg()
|
|
local _cfg = List:New()
|
|
DataConfig.DataSignRewardCumulative:Foreach(function(k, v)
|
|
if v.Round == self.Round then
|
|
_cfg:Add(v)
|
|
end
|
|
end)
|
|
table.sort( _cfg, function(a, b)
|
|
return a.Day < b.Day
|
|
end)
|
|
return _cfg
|
|
end
|
|
|
|
-- 请求签到
|
|
function DailyCheck:ReqDayCheckIn(id, checkType)
|
|
local _req = {}
|
|
_req.typ = 1
|
|
_req.cfgID = id
|
|
if checkType == 1 then
|
|
self.MakeUpCfgId = id
|
|
end
|
|
if not checkType then
|
|
_req.typ = 2
|
|
end
|
|
self.CheckType = checkType
|
|
GameCenter.Network.Send("MSG_Welfare.ReqDayCheckIn", _req)
|
|
end
|
|
|
|
-- 每日签到数据
|
|
function DailyCheck:GS2U_ResDayCheckInData(msg)
|
|
self.IsCheck = msg.isCheckIn
|
|
self.DayNum = msg.day
|
|
self.CheckInDay = msg.checkInDay > self.MaxDay and self.MaxDay or msg.checkInDay
|
|
if msg.checkIns then
|
|
self.CheckList = List:New(msg.checkIns)
|
|
else
|
|
self.CheckList = List:New()
|
|
end
|
|
if msg.checkIn2s then
|
|
self.MakeUpList = List:New(msg.checkIn2s)
|
|
else
|
|
self.MakeUpList = List:New()
|
|
end
|
|
if msg.rewardCfgID then
|
|
self.RewardList = List:New(msg.rewardCfgID)
|
|
end
|
|
if self.Round ~= msg.round or (not self.RewardCfgList) then
|
|
self.Round = msg.round
|
|
self.RewardCfgList = self:GetCurrRoundRewardCfg()
|
|
end
|
|
|
|
if self.CheckType == 0 and self.IsCheck then
|
|
Utils.ShowPromptByEnum("WELFARE_SignSuccess")
|
|
self.CheckType = -1
|
|
end
|
|
if self.CheckType == 1 and self.MakeUpList:Contains(self.MakeUpCfgId) then
|
|
Utils.ShowPromptByEnum("RetroactiveSucced")
|
|
self.CheckType = -1
|
|
self.MakeUpCfgId = 0
|
|
end
|
|
self:CheckShowRedPoint()
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_WELFARE_DAILYCHECK_REFRESH)
|
|
end
|
|
|
|
return DailyCheck
|