202 lines
6.9 KiB
Lua
202 lines
6.9 KiB
Lua
------------------------------------------------
|
|
--作者: dhq
|
|
--日期: 2021-06-30
|
|
--文件: PrefectRomanceSystem.lua
|
|
--模块: PrefectRomanceSystem
|
|
--描述: 完美情缘系统
|
|
------------------------------------------------
|
|
local L_TimeUtils = CS.Thousandto.Core.Base.TimeUtils;
|
|
|
|
--//模块定义
|
|
local PrefectRomanceSystem =
|
|
{
|
|
TaskDict = nil,
|
|
RankFuncList = nil,
|
|
--排行的数据
|
|
RankData = {},
|
|
--商城的数据[id,count]
|
|
ShopDict = nil,
|
|
--活动剩余时间
|
|
LeftTime = nil,
|
|
}
|
|
|
|
--//成员函数定义
|
|
--初始化
|
|
function PrefectRomanceSystem:Initialize()
|
|
self.TaskDict = Dictionary:New()
|
|
self.ShopDict = Dictionary:New()
|
|
|
|
--解析排行配置的功能跳转按钮信息
|
|
local _params = DataConfig.DataGlobal[1961].Params
|
|
self.RankFuncList = List:New()
|
|
local _ps = Utils.SplitStr(_params, ';')
|
|
for i = 2, _ps[1] + 1 do
|
|
local _s = Utils.SplitStr(_ps[i], '_')
|
|
local _icon = _ps[_ps[1] + i]
|
|
local _data = {}
|
|
_data.FunId = _s[1]
|
|
_data.Name = _s[2]
|
|
_data.Icon = _icon
|
|
self.RankFuncList:Add(_data)
|
|
end
|
|
|
|
if self.TimerID ~= nil then
|
|
GameCenter.TimerEventSystem:RemoveTimerEvent(self.TimerID)
|
|
end
|
|
--添加计时器 每天凌晨1秒执行
|
|
self.TimerID = GameCenter.TimerEventSystem:AddTimeStampDayEvent(1, 86400,
|
|
true, nil, function(id, remainTime, param)
|
|
self:GetLeftTime()
|
|
end)
|
|
|
|
DataConfig.DataMarryActivityTask:ForeachCanBreak(
|
|
function(_id, _cfg)
|
|
self.TaskDict[_id] = {
|
|
Cfg = _cfg,
|
|
taskID = _id,
|
|
progress = 0,
|
|
state = false
|
|
}
|
|
end
|
|
)
|
|
end
|
|
|
|
--反初始化
|
|
function PrefectRomanceSystem:UnInitialize()
|
|
self.TaskDict:Clear()
|
|
self.RankFuncList:Clear()
|
|
self.ShopDict:Clear()
|
|
--删除计时器
|
|
GameCenter.TimerEventSystem:RemoveTimerEvent(self.TimerID)
|
|
end
|
|
|
|
function PrefectRomanceSystem:SetOpenServerTime(time)
|
|
self.ServerOpenTime = math.floor(time / 1000) + GameCenter.HeartSystem.ServerZoneOffset
|
|
self:GetLeftTime()
|
|
end
|
|
|
|
-- 获取活动剩余时间
|
|
function PrefectRomanceSystem:GetLeftTime()
|
|
if self.ServerOpenTime == nil then
|
|
return 0
|
|
end
|
|
if self.EndTime == nil then
|
|
local _day = tonumber(DataConfig.DataGlobal[1960].Params)
|
|
-- 获取开服当天是几点
|
|
local _hour, _min, _sec = L_TimeUtils.GetStampTimeHHMMSSNotZone(math.floor(self.ServerOpenTime))
|
|
local _curSeconds = _hour * 3600 + _min * 60 + _sec
|
|
-- 计算结束时间
|
|
self.EndTime = self.ServerOpenTime - _curSeconds + _day * 86400
|
|
end
|
|
self.LeftTime = self.EndTime - GameCenter.HeartSystem.ServerZoneTime
|
|
local _funcIsVisible = true
|
|
if self.LeftTime <= 0 then
|
|
_funcIsVisible = false
|
|
end
|
|
if self.FuncIsVisible ~= _funcIsVisible then
|
|
self.FuncIsVisible = _funcIsVisible
|
|
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.PrefectRomance, _funcIsVisible)
|
|
end
|
|
return self.LeftTime
|
|
end
|
|
|
|
--情缘商店购买响应
|
|
function PrefectRomanceSystem:ResMarryActivityShopBuy(msg)
|
|
if msg ~= nil then
|
|
local _list = msg.shopInfoList
|
|
if _list ~= nil then
|
|
for i = 1, #_list do
|
|
local _data = _list[i]
|
|
if _data.shopId ~= nil and _data.buyCount ~= nil then
|
|
if self.ShopDict:ContainsKey(_data.shopId) then
|
|
self.ShopDict[_data.shopId] = _data.buyCount
|
|
else
|
|
self.ShopDict:Add(_data.shopId, _data.buyCount)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_PREFECT_GIFT_REFESH, msg)
|
|
end
|
|
|
|
--完美情缘获取 亲密度返回
|
|
function PrefectRomanceSystem:ResMarryActivityIntimacy(msg)
|
|
self.RankData = {}
|
|
self.RankData.Rank = msg.rank
|
|
self.RankData.Intimacy = msg.intimacy
|
|
self.RankData.ReceivedList = List:New()
|
|
--已领奖励ID
|
|
local _hasReceivedDict = Dictionary:New()
|
|
if msg.rankRewardEd ~= nil then
|
|
self.RankData.ReceivedList:AddRange(msg.rankRewardEd)
|
|
for i = 1, #msg.rankRewardEd do
|
|
local _id = msg.rankRewardEd[i]
|
|
_hasReceivedDict[_id] = _id
|
|
end
|
|
end
|
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.PrefectSpouse, false);
|
|
DataConfig.DataMarryActivityRank:ForeachCanBreak(
|
|
function(_id, _cfg)
|
|
--还没领取奖励的
|
|
if not _hasReceivedDict:ContainsKey(_id) then
|
|
if msg.rank ~= nil then
|
|
--只用管0[个人]的
|
|
if _cfg.RewardType == 0 then
|
|
--达标的
|
|
if msg.intimacy >= _cfg.Limit then
|
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.PrefectSpouse, true);
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
)
|
|
--刷新排行数据
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_PREFECT_RANK_REFESH, msg)
|
|
end
|
|
|
|
--情缘任务进度刷新
|
|
function PrefectRomanceSystem:ResRefreshMarryActivityTask(msg)
|
|
if msg.taskData ~= nil then
|
|
local _taskDatas = msg.taskData
|
|
for i = 1, #_taskDatas do
|
|
--ID
|
|
local _id = _taskDatas[i].taskID
|
|
self.TaskDict[_id].taskID = _taskDatas[i].taskID
|
|
self.TaskDict[_id].progress = _taskDatas[i].progress
|
|
self.TaskDict[_id].state = _taskDatas[i].state
|
|
end
|
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.PrefectTask, false);
|
|
DataConfig.DataMarryActivityTask:ForeachCanBreak(
|
|
function(_id, _cfg)
|
|
if self.TaskDict:ContainsKey(_id) then
|
|
local _data = self.TaskDict[_id]
|
|
if _cfg.Type == 1 then
|
|
local _cond = Utils.SplitStr(_cfg.Condition, '_')
|
|
local _count = #_cond
|
|
--没有领奖并且达成条件了就设置红点
|
|
if not _data.state and _data.progress >= tonumber(_cond[_count]) then
|
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.PrefectTask, true);
|
|
return true
|
|
end
|
|
else
|
|
if not _data.state and _data.progress >= tonumber(_cfg.Rate) then
|
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.PrefectTask, true);
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
)
|
|
end
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_PREFECT_TASK_REFESH)
|
|
end
|
|
|
|
--更新心跳
|
|
function PrefectRomanceSystem:Update(dt)
|
|
end
|
|
|
|
return PrefectRomanceSystem
|