Files
Main/Assets/GameAssets/Resources/Lua/Logic/FristCharge/FristChargeSystem.lua
2025-01-25 04:38:09 +08:00

311 lines
10 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

------------------------------------------------
-- 作者: xsp
-- 日期: 2019-07-31
-- 文件: FristChargeSystem.lua
-- 模块: FristChargeSystem
-- 描述: 首充系统
------------------------------------------------
local FristChargeSystem = {
-- 开启续充需要充值的元宝数量
NeedGoldCount = 0,
-- 续充起始配置id
ReChargeStartID = 0,
-- 续充结束配置id
ReChargeEndID = 0,
-- 续充数据
ReChargeData = nil,
-- 等级 弹出首充引导
Levels = Dictionary:New(),
-- 任务 弹出首充引导
Tasks = Dictionary:New(),
-- 首充消息
MsgFristData = nil,
-- 百元首充消息
MsgHundredData = nil,
-- 配置Id对应的天数
DayDic = {},
-- 百元首充领取最大天数
MaxDayByHundred = 0,
-- 首充最大天数
MaxDayByFirst = 0,
-- 首充和百元首充的状态k:配置id, v:FirstChargeState
StateDic = {},
-- 首充id列表
FirstIds = nil,
-- 百元首充id列表
HundredIds = nil,
StartShowTime = 5 * 60,
NoticesParams = nil,
StartTime = 0,
NeedShowFirstPayForm = false,
IsShowFirstPayForm = false,
}
-- 续充数据
local L_ChargeData = {
-- 配置ID
CfgID = 0,
-- 黄金数量
GoldCount = 0,
-- 当前配置是否已领奖
IsReward = false,
-- 功能是否开启
IsOpen = false
}
local L_Time = {}
function FristChargeSystem:Initialize()
-- 首充
local _ids1 = {}
-- 续充
local _ids2 = {}
-- 百元首充
local _ids3 = {}
-- 遍历配置表
DataConfig.DataRechargeAward:Foreach(function(k, v)
if v.AwardType == 0 then
table.insert(_ids1, k)
elseif v.AwardType == 1 then
table.insert(_ids2, k)
elseif v.AwardType == 2 then
table.insert(_ids3, k)
end
end)
-- 排序 id小的陪前面
table.sort(_ids1, function(a, b)
return a < b
end)
table.sort(_ids2, function(a, b)
return a < b
end)
table.sort(_ids3, function(a, b)
return a < b
end)
self.FirstIds = _ids1;
self.HundredIds = _ids3;
-- 获取续充第一天ID
self.ReChargeStartID = _ids2[1]
-- 获取续充最后一天ID
self.ReChargeEndID = _ids2[#_ids2]
-- 设置ID和天数的对应关系
for i = 1, #_ids1 do
self.DayDic[_ids1[i]] = i;
self.StateDic[_ids1[i]] = FirstChargeState.NoMoney;
end
for i = 1, #_ids2 do
self.DayDic[_ids2[i]] = i;
end
for i = 1, #_ids3 do
self.DayDic[_ids3[i]] = i;
self.StateDic[_ids1[i]] = FirstChargeState.NoMoney;
end
-- 首充最大天数
self.MaxDayByFirst = #_ids1;
-- 百元首充领取最大天数
self.MaxDayByHundred = #_ids3;
-- 获取触发打开界面的任务ID
local _taskCfg = DataConfig.DataGlobal[GlobalName.RechargeAwardTaskid]
if _taskCfg then
local _strs = Utils.SplitStr(_taskCfg.Params, ";")
for i = 1, #_strs do
local _arr = Utils.SplitNumber(_strs[i], "_")
self.Tasks:Add(_arr[1], _arr[2])
end
end
-- 获取触发打开界面的等级
local _levelCfg = DataConfig.DataGlobal[GlobalName.RechargeAwardLevel]
if _levelCfg then
local _strs = Utils.SplitStr(_levelCfg.Params, ";")
for i = 1, #_strs do
local _arr = Utils.SplitNumber(_strs[i], "_")
self.Levels:Add(_arr[1], _arr[2])
end
end
-- 开启续充需要充值的元宝数量
local _firstCfg = DataConfig.DataRechargeAward[1]
if _firstCfg then
self.NeedGoldCount = tonumber(_firstCfg.NeedRecharge)
end
--配置开服天数范围内每天首次累计在线时间到达5分钟弹出首充小提示框
self.NoticesParams = nil
local _noticeParams = DataConfig.DataGlobal[1957].Params
if _noticeParams ~= nil then
self.NoticesParams = Utils.SplitNumber(_noticeParams, "_")
end
-- 任务触发
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_TASKFINISH, self.CheckTaskOpenTipsForm, self)
end
-- 充值改变
-- MSG_Vip.ResVipRechageMoney
function FristChargeSystem:UnInitialize()
self.Tasks:Clear()
self.Levels:Clear()
self.DayDic = {}
self.StartTime = 0
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_TASKFINISH, self.CheckTaskOpenTipsForm, self)
end
-- 判断是否完成任务打开引导界面
function FristChargeSystem:CheckTaskOpenTipsForm(taskId, sender)
local _isRecharge = GameCenter.VipSystem.CurRecharge <= 0;
if _isRecharge and self.Tasks:ContainsKey(taskId) then
if self.Tasks[taskId] == 1 then
-- 功能已开启
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_FIRST_RECHAGE_TIPS)
elseif self.Tasks[taskId] == 2 then
AudioPlayer.PlayUI("snd_ui_shouchongb");
GameCenter.PushFixEvent(UIEventDefine.UIFristChargeForm_Open, true)
end
end
end
function FristChargeSystem:SetState(ids, MsgData)
if not MsgData then
return;
end
local _curDay = self.DayDic[MsgData.cfgID] or 0;
local _isOpen = _curDay > 1 or _curDay == 1 and MsgData.goldCount >= DataConfig.DataRechargeAward[ids[1]].NeedRecharge;
for i = 1, #ids do
local _id = ids[i];
local _day = self.DayDic[_id];
local _cfg = DataConfig.DataRechargeAward[_id]
if _isOpen then
local _count = _curDay - _day;
if _count > 0 then
self.StateDic[_id] = FirstChargeState.Geted;
elseif _count == 0 then
self.StateDic[_id] = MsgData.isReward and FirstChargeState.Geted or FirstChargeState.CanGet;
elseif _count == -1 then
self.StateDic[_id] = FirstChargeState.NextCanGet;
elseif _count == -2 then
self.StateDic[_id] = FirstChargeState.NextNextCanGet;
end
else
self.StateDic[_id] = FirstChargeState.NoMoney;
end
end
end
-- 首充信息返回
function FristChargeSystem:ResFCChargeData(msg)
local _rechargeOpen = false
-- 首充
self.MsgFristData = msg.firstData;
if msg.firstData then
-- 首充第一天奖励领取完毕 开启续充功能
local _curDay = self.DayDic[msg.firstData.cfgID] or 0;
if _curDay > self.MaxDayByFirst or (msg.firstData.goldCount >= self.NeedGoldCount) then
_rechargeOpen = true
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.ReCharge, _rechargeOpen)
end
self:SetState(self.FirstIds, self.MsgFristData)
end
-- 续充
if msg.nextData then
if not self.ReChargeData then
self.ReChargeData = Utils.DeepCopy(L_ChargeData)
self.ReChargeData.IsOpen = true
end
self.ReChargeData.CfgID = msg.nextData.cfgID
self.ReChargeData.GoldCount = msg.nextData.goldCount
self.ReChargeData.IsReward = msg.nextData.isReward
if msg.nextData.cfgID == self.ReChargeEndID and msg.nextData.isReward then
_rechargeOpen = false
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.ReCharge, _rechargeOpen)
end
local _cfg = DataConfig.DataRechargeAward[msg.nextData.cfgID]
if _cfg then
local _redPoint = (not msg.nextData.isReward) and (msg.nextData.goldCount >= _cfg.NeedRecharge)
if _cfg.AwardType == 1 then
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.ReCharge, _redPoint)
end
end
end
if _rechargeOpen and (not self.ReChargeData) then
self.ReChargeData = Utils.DeepCopy(L_ChargeData)
self.ReChargeData.IsOpen = true
end
-- 百元首充
self.MsgHundredData = msg.hundredData;
self:SetState(self.HundredIds, self.MsgHundredData)
self:RefreshState();
self.StartTime = Time.GetRealtimeSinceStartup()
local _openDay = Time.GetOpenSeverDay()
self.NeedShowFirstPayForm = self.NoticesParams[1] <= _openDay and _openDay <= self.NoticesParams[2]
self.StartShowTime = self.NoticesParams[3] * 60
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_FIRST_CHARGE_REFRESH)
end
-- 刷新状态
function FristChargeSystem:RefreshState()
local _firstComplete = self.MsgFristData and (self.DayDic[self.MsgFristData.cfgID] == self.MaxDayByFirst and self.MsgFristData.isReward) or false;
local _hundredComplete = self.MsgHundredData and (self.DayDic[self.MsgHundredData.cfgID] == self.MaxDayByHundred and self.MsgHundredData.isReward) or false;
-- 首充奖励领取完成 关闭首充功能
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.FirstCharge, not (_firstComplete and _hundredComplete))
if not (_firstComplete and _hundredComplete) then
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.FirstCharge, self:IsRedpoint())
end
end
-- 首充和百元首充是否有小红点
function FristChargeSystem:IsRedpoint()
return self:IsRedpointByFirst() or self:IsRedpointByHundred()
end
-- 首充是否有小红点
function FristChargeSystem:IsRedpointByFirst()
local _cfg = DataConfig.DataRechargeAward[self.MsgFristData.cfgID]
if _cfg then
return (not self.MsgFristData.isReward) and (self.MsgFristData.goldCount >= _cfg.NeedRecharge)
end
return false
end
-- 百元首充是否有小红点
function FristChargeSystem:IsRedpointByHundred()
local _cfg = DataConfig.DataRechargeAward[self.MsgHundredData.cfgID]
if _cfg then
return (not self.MsgHundredData.isReward) and (self.MsgHundredData.goldCount >= _cfg.NeedRecharge)
end
return false
end
-- 请求首充续充数据
function FristChargeSystem:ReqFCChargeData()
local _req = {}
_req.typ = 2
GameCenter.Network.Send("MSG_Commercialize.ReqCommercialize", _req)
end
-- 请求领取奖励
function FristChargeSystem:ReqFCChargeReward(id)
if Utils.IsLockTime(self, self.ReqFCChargeReward) then
return;
end
local _msg = {}
_msg.cfgID = id
GameCenter.Network.Send("MSG_Commercialize.ReqFCChargeReward", _msg)
end
--更新
function FristChargeSystem:Update(deltaTime)
if (self.NeedShowFirstPayForm and not self.IsShowFirstPayForm and GameCenter.VipSystem.CurRecharge <= 0) then
if self.StartTime > 0 and Time.GetRealtimeSinceStartup() - self.StartTime >= self.StartShowTime then
--弹出首充Tips界面
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_FIRST_RECHAGE_TIPS)
self.IsShowFirstPayForm = true
end
end
end
return FristChargeSystem