local RedEnvelopRain_Controller = {} local private = {} local EventSystem = require 'Event/EventSystem' local RedEnvelopeRainStar = DataSheetManager.ConstData:GetDataByID("RedEnvelopeRainStar").DateValue local RedEnvelopeRainEnd = DataSheetManager.ConstData:GetDataByID("RedEnvelopeRainEnd").DateValue local RedEnvelopeRainHerald = DataSheetManager.ConstData:GetDataByID("RedEnvelopeRainHerald").DateValue local RedEnvelopRain_RedPointRemoveTime = "RedEnvelopRain_RedPointRemoveTime" function RedEnvelopRain_Controller.OnStartup() EventSystem.Regist(EventID.New_Day_Refresh, private.CalculateRedPoint) EventSystem.Regist(EventID.UI_OperationActivity_InfoChanged, private.CalculateRedPoint) EventSystem.Regist(EventID.Level_BeginLevel, RedEnvelopRain_Controller.BeginLevel) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.CheckIfFuncUnlock) -- GMS private.ActivityType = MDL.OperationActivity.ActivityType.RedEnvelopeRain end function RedEnvelopRain_Controller.GetCurOpenRedEnvelopRainActivityId() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.RedEnvelopeRain) then local info = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType) if info then for activityId, v in pairs(info) do if CTL.OperationActivity.IsOperationActivityOpen(v) then return activityId end end end end return nil end -- 是否在下降红包雨的时间段内 function RedEnvelopRain_Controller.InRedEnvelopRainTime() local curTimestamp = UTL.Time.GetServerTimestamp() local zeroTimestamp = UTL.Time.GetServerZeroTimestamp() if curTimestamp > zeroTimestamp + RedEnvelopeRainStar and curTimestamp < zeroTimestamp + RedEnvelopeRainEnd then return true else return false end end -- 距离下降红包剩余时间 function RedEnvelopRain_Controller.DistanceRedEnvelopRainStartTime() local curTimestamp = UTL.Time.GetServerTimestamp() local zeroTimestamp = UTL.Time.GetServerZeroTimestamp() if curTimestamp < zeroTimestamp + RedEnvelopeRainStar then return zeroTimestamp + RedEnvelopeRainStar - curTimestamp else return 0 end end function RedEnvelopRain_Controller.ResidueRedEnvelopRainForeshowTime() local curTimestamp = UTL.Time.GetServerTimestamp() local zeroTimestamp = UTL.Time.GetServerZeroTimestamp() if curTimestamp < zeroTimestamp + RedEnvelopeRainHerald then return false, zeroTimestamp + RedEnvelopeRainHerald - curTimestamp -- 还未到预告期 elseif curTimestamp >= zeroTimestamp + RedEnvelopeRainHerald and curTimestamp < zeroTimestamp + RedEnvelopeRainStar then return true, zeroTimestamp + RedEnvelopeRainStar - curTimestamp -- 在预告期内 end return false, 0 end function RedEnvelopRain_Controller.GetAllGoldIndex() local allGoldNum = MDL.RedEnvelopRain.GetAllGoldNum() local shardLen = MDL.RedEnvelopRain.GetShardLen() local isMax, imageIndex = false, 1 for _, v in MDL.OperationActivity.RedEnvelopeRainReward:GetEnumerator() do if shardLen == v.ServerNum then if v.GoldMin == v.GoldMax then if allGoldNum >= v.GoldMin then isMax = true imageIndex = v.ID break end else if allGoldNum >= v.GoldMin and allGoldNum <= v.GoldMax then imageIndex = v.ID break end end end end return isMax, imageIndex end -- 返回对应地区的 充值提示数据 (1RMB/2美分/3日元) function RedEnvelopRain_Controller.GetRechargeData() local curActivityId = RedEnvelopRain_Controller.GetCurOpenRedEnvelopRainActivityId() if GameAppInfo.IsChinesePackage() then return MDL.OperationActivity.RedEnvelopeRainReChargeReward:GetDataByActivityID_ID(curActivityId, 1) elseif GameAppInfo.IsJapanesePackage() then return MDL.OperationActivity.RedEnvelopeRainReChargeReward:GetDataByActivityID_ID(curActivityId, 3) elseif GameAppInfo.IsVietnamPackage() then return MDL.OperationActivity.RedEnvelopeRainReChargeReward:GetDataByActivityID_ID(curActivityId, 4) else return MDL.OperationActivity.RedEnvelopeRainReChargeReward:GetDataByActivityID_ID(curActivityId, 2) end end function RedEnvelopRain_Controller.RemoveRedPoint() PersistentData.PlayerData:Set(RedEnvelopRain_RedPointRemoveTime, UTL.Time.GetServerTimestamp(), true) CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.RedEnvelopeRain) end function RedEnvelopRain_Controller.BeginLevel() -- 取消计时 if private.timerHandle then TimerUtil.Remove(private.timerHandle) private.timerHandle = nil end -- 判读是否开启计时 if LevelManager.IsTown then local redEnvelopeRainShow = CTL.OperationActivity.IsOperationActivityTypeOpen(private.ActivityType) and CTL.OperationActivity.IsOperationActivityTypeUnlock(private.ActivityType) and MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.RedEnvelopeRain) if redEnvelopeRainShow then if RedEnvelopRain_Controller.InRedEnvelopRainTime() then private.timerHandle = TimerUtil.Interval(MDL.RedEnvelopRain.UpdateRedEnvelopeRainRewardReq, 2, 1) -- 多2秒防止客户端服务器时间有差距 else local time = RedEnvelopRain_Controller.DistanceRedEnvelopRainStartTime() if time > 0 then private.timerHandle = TimerUtil.Interval(MDL.RedEnvelopRain.UpdateRedEnvelopeRainRewardReq, time + 2, 1) -- 多2秒防止客户端服务器时间有差距 end end end end end function private.CalculateRedPoint() if not PersistentData.PlayerData then return end local redPointRemoveTime = PersistentData.PlayerData:Get(RedEnvelopRain_RedPointRemoveTime, 0) if redPointRemoveTime < UTL.Time.GetDayStartTimestamp() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.RedEnvelopeRain) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.RedEnvelopeRain) end end function private.CheckIfFuncUnlock(funcId, isUnlock) if funcId == MDL.Unlock.FunctionType.RedEnvelopeRain and not isUnlock then --关闭各种相关界面 if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIRedEnvelopeRainMain) then UIManager.CloseView(Const_UI_Lua.UIEnum.UIRedEnvelopeRainMain) end if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIRedEnvelopeRainReward) then UIManager.CloseView(Const_UI_Lua.UIEnum.UIRedEnvelopeRainReward) end if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIRedEnvelopeRainCountDown) then CTL.HomeMain.ClosePushedView(Const_UI_Lua.UIEnum.UIRedEnvelopeRainCountDown) end if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIRedEnvelopeRainStart) then CTL.HomeMain.ClosePushedView(Const_UI_Lua.UIEnum.UIRedEnvelopeRainStart) end end end return RedEnvelopRain_Controller