local CycleRecharge_Model = {} local EventSystem = require('Event/EventSystem') local activity_cycle_recharge_opt_pb = require('Proto.activity_cycle_recharge_opt_pb') local private = {} local Week_Recharge_ActivityID = 30 local Month_Recharge_ActivityID = 31 function CycleRecharge_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageCycleRechargeReward, nil) NetManager.RegisterMsgCB(MessageEnums.MessageContinuousCycleRechargeReward, nil) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushContinuousCycleRechargeChange, private.OnCycleRechargeChange) private.point = 0 private.received = {} EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.RefreshRedPoint) end function CycleRecharge_Model.OnShutdown() private.point = 0 private.received = {} end function CycleRecharge_Model.GetRechargePoint() return private.point end function CycleRecharge_Model.GetReceivedRecharge() return private.received end function CycleRecharge_Model.IsRewardReceive(id) for _, v in ipairs(private.received) do if id == v then return true end end end function CycleRecharge_Model.SyncRechargeInfo(info) private.point = info.point--当期充值积分 private.received = info.received--已领取的奖励id列表 EventSystem.Dispatch(EventID.UI_CycleRecharge_RefreshInfo) EventSystem.Dispatch(EventID.UI_CycleRecharge_UpdateRedPoint) end function CycleRecharge_Model.ClaimRechargeRewardReq(activityId, gear) local msg = activity_cycle_recharge_opt_pb.CycleRechargeRewardReq() msg.activityId = activityId msg.gear = gear NetManager.SendMessage(MessageEnums.MessageCycleRechargeReward, msg) end --周期累充 function CycleRecharge_Model.GetWeekActivityID() return private.weekInfo and private.weekInfo.activityId end function CycleRecharge_Model.GetWeekActivityInfo() return private.weekInfo end function CycleRecharge_Model.IsOpenWeekActivity() local serverTime = UTL.Time.GetServerTimestamp() return private.weekInfo and private.weekInfo.activityId > 0 and private.weekInfo.startTime < serverTime and private.weekInfo.endTime > serverTime and MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.WeekTotalCharge) end function CycleRecharge_Model.IsGetWeekReward(id) return private.weekInfo and table.containValue(private.weekInfo.received, id) end function CycleRecharge_Model.GetMonthActivityID() return private.monthInfo and private.monthInfo.activityId end function CycleRecharge_Model.GetMonthActivityInfo() return private.monthInfo end function CycleRecharge_Model.IsOpenMonthActivity() local serverTime = UTL.Time.GetServerTimestamp() return private.monthInfo and private.monthInfo.activityId > 0 and private.monthInfo.startTime < serverTime and private.monthInfo.endTime > serverTime and MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.MonthTotalCharge) end function CycleRecharge_Model.IsGetMonthReward(id) return private.monthInfo and table.containValue(private.monthInfo.received, id) end function CycleRecharge_Model.SyncWeekInfos(rechargeInfoList) for i, v in ipairs(rechargeInfoList) do if v.activityType == Week_Recharge_ActivityID then private.weekInfo = v elseif v.activityType == Month_Recharge_ActivityID then private.monthInfo = v end end end function CycleRecharge_Model.ContinuousCycleRechargeRewardReq(activityId, gear) local msg = activity_cycle_recharge_opt_pb.ContinuousCycleRechargeRewardReq() msg.activityId = activityId msg.gear = gear NetManager.SendMessage(MessageEnums.MessageContinuousCycleRechargeReward, msg) end function private.RefreshWeekRedPoint() if CycleRecharge_Model.IsOpenWeekActivity() then local curScore = private.weekInfo.point for index, v in MDL.OperationActivity.WeekCycleRecharge:GetEnumeratorByActivityID(private.weekInfo.activityId) do if v.GroupID == private.weekInfo.RewardGroupId and curScore >= v.RechargeNum and not CycleRecharge_Model.IsGetWeekReward(v.StageID) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.WeekTotalCharge_Week) return end end end CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.WeekTotalCharge_Week) end function private.RefreshMonthRedPoint() if CycleRecharge_Model.IsOpenMonthActivity() then local curScore = private.monthInfo.point for index, v in MDL.OperationActivity.MonthCycleRecharge:GetEnumeratorByActivityID(private.monthInfo.activityId) do if curScore >= v.RechargeNum and not CycleRecharge_Model.IsGetMonthReward(v.StageID) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.WeekTotalCharge_Month) return end end end CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.WeekTotalCharge_Month) end function private.RefreshRedPoint() private.RefreshWeekRedPoint() private.RefreshMonthRedPoint() end function private.OnCycleRechargeChange(msg) local isOpen = MDL.CycleRecharge.IsOpenWeekTotalCharge() for i, v in ipairs(msg.changeInfo) do if v.activityType == Week_Recharge_ActivityID then private.weekInfo = v private.RefreshWeekRedPoint() elseif v.activityType == Month_Recharge_ActivityID then private.monthInfo = v private.RefreshMonthRedPoint() end end EventSystem.Dispatch(EventID.UI_WeekCharge_RefreshCharge) if isOpen ~= MDL.CycleRecharge.IsOpenWeekTotalCharge() then EventSystem.Dispatch(EventID.FunctionUnlockUpdate, MDL.Unlock.FunctionType.WeekAndMonthTotalCharge, MDL.CycleRecharge.IsOpenWeekTotalCharge()) end end function CycleRecharge_Model.IsAnyUnlock() return MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.WeekTotalCharge) or MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.MonthTotalCharge) end function CycleRecharge_Model.GetFunctionID() return MDL.Unlock.FunctionType.WeekAndMonthTotalCharge end function CycleRecharge_Model.IsOpenWeekTotalCharge() return CycleRecharge_Model.IsAnyUnlock() and (MDL.CycleRecharge.IsOpenWeekActivity() or MDL.CycleRecharge.IsOpenMonthActivity()) end return CycleRecharge_Model