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

141 lines
4.9 KiB
Lua

------------------------------------------------
-- 作者: yangqf
-- 日期: 2021-08-31
-- 文件: ZeroBuySystem.lua
-- 模块: ZeroBuySystem
-- 描述: 零元购系统
------------------------------------------------
local RedPointCustomCondition = CS.Thousandto.Code.Logic.RedPointCustomCondition
local TimeUtils = CS.Thousandto.Core.Base.TimeUtils
local ZeroBuySystem = {
BuyState = nil,
OpenState = nil,
CfgList = nil,
--服务器开服时间
ServerOpenTime = nil,
--当前开服天数
CurOpenServerDay = 0,
}
function ZeroBuySystem:Initialize()
self.CfgList = List:New()
DataConfig.DataFreeNewshop:Foreach(function(k, cfg)
self.CfgList:Add(cfg)
end)
self.BuyState = nil
self.ServerOpenTime = nil
--每天凌晨10秒执行
self.TimerID = GameCenter.TimerEventSystem:AddTimeStampDayEvent(10, 86400,
true, nil, function(id, remainTime, param)
self:CheckOpenState(true)
end)
end
function ZeroBuySystem:UnInitialize()
end
--检测开启状态
function ZeroBuySystem:CheckOpenState(addBuyRP)
if self.ServerOpenTime == nil then
return
end
if self.BuyState == nil then
self.BuyState = {}
end
GameCenter.RedPointSystem:CleraFuncCondition(FunctionStartIdCode.FreeShop2)
GameCenter.RedPointSystem:CleraFuncCondition(FunctionStartIdCode.FreeShopVIP)
self.OpenState = {}
self.CurOpenServerDay = TimeUtils.GetDayOffsetNotZone(self.ServerOpenTime, math.floor(GameCenter.HeartSystem.ServerZoneTime)) + 1
local _funcIsOpen = false
local _vipIsOpen = false
local _haveNotBuy = false
local _vipNotBuy = false
for i = 1, #self.CfgList do
local _cfg = self.CfgList[i]
local _isOpen = false
if self.CurOpenServerDay >= _cfg.OpenTime then
_isOpen = true
end
local _isClose = true
local _buyData = self.BuyState[_cfg.Id]
if _buyData == nil or not _buyData.IsGet then
_isClose = false
end
if _isOpen and not _isClose then
if _cfg.Id == 1 then
_vipIsOpen = true
end
_funcIsOpen = true
--开启状态
self.OpenState[_cfg.Id] = true
if _buyData == nil or _buyData.BuyTime <= 0 then
_haveNotBuy = true
if _cfg.Id == 1 then
_vipNotBuy = true
end
if addBuyRP then
if _cfg.Id == 1 then
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.FreeShopVIP, _cfg.Id * 10000, RedPointCustomCondition(true))
end
--还未购买,增加购买红点
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.FreeShop2, _cfg.Id * 10000, RedPointCustomCondition(true))
end
else
--已经购买,判断是否已经到达天数
if self.CurOpenServerDay >= _cfg.Time then
if _cfg.Id == 1 then
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.FreeShopVIP, _cfg.Id * 10000 + 1, RedPointCustomCondition(true))
end
--增加领取红点
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.FreeShop2, _cfg.Id * 10000 + 1, RedPointCustomCondition(true))
end
end
end
end
if addBuyRP and _haveNotBuy then
if _vipNotBuy then
GameCenter.MainFunctionSystem:SetFunctionEffect(FunctionStartIdCode.FreeShopVIP, true)
end
GameCenter.MainFunctionSystem:SetFunctionEffect(FunctionStartIdCode.FreeShop2, true)
end
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.FreeShop2, _funcIsOpen)
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.FreeShopVIP, _vipIsOpen)
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_REFRESH_ZEROBUY_FORM)
end
--设置开服时间
function ZeroBuySystem:SetOpenServerTime(time)
--检查开启情况
self.ServerOpenTime = math.floor(time / 1000) + GameCenter.HeartSystem.ServerZoneOffset
self:CheckOpenState(true)
end
--上线初始化
function ZeroBuySystem:SyncOnlineInitNewFreeShop(msg)
self.BuyState = {}
if msg.zeroBuyList ~= nil then
for i = 1, #msg.zeroBuyList do
local _msgData = msg.zeroBuyList[i]
self.BuyState[_msgData.id] = {IsGet = _msgData.isGet, BuyTime = _msgData.buyTime}
end
end
self:CheckOpenState(true)
end
--购买或领取返回
function ZeroBuySystem:SyncBuyNewFreeShopResult(msg)
if self.BuyState == nil then
self.BuyState = {}
end
self.BuyState[msg.buyData.id] = {IsGet = msg.buyData.isGet, BuyTime = msg.buyData.buyTime}
if msg.type == 1 then
--1代表购买
elseif msg.type == 2 then
--2代表领奖
end
self:CheckOpenState(false)
end
return ZeroBuySystem