136 lines
3.9 KiB
Lua
136 lines
3.9 KiB
Lua
------------------------------------------------
|
|
--作者: _SqL_
|
|
--日期: 2019-12-05
|
|
--文件: DailyGift.lua
|
|
--模块: DailyGift
|
|
--描述: 福利每日礼包
|
|
------------------------------------------------
|
|
|
|
local DailyGift = {
|
|
-- 本次购买的礼包id
|
|
CurrBuyGiftId = nil,
|
|
-- 免费礼包
|
|
FreeGifts = List:New(),
|
|
-- 已购买列表
|
|
ReceiveList = List:New(),
|
|
-- 每日礼包列表
|
|
DailyGiftList = List:New(),
|
|
--是否购买完毕
|
|
IsAllBuy = false,
|
|
--是否第一次进游戏需要显示红点
|
|
IsFirstShow = true,
|
|
}
|
|
|
|
function DailyGift:Initialize()
|
|
self.IsFirstShow = true
|
|
self.DailyGiftList:Clear()
|
|
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.WelfareDailyGift, false)
|
|
GameCenter.RegFixEventHandle(LogicLuaEventDefine.EID_EVENT_REFESH_PAY_DATA, self.OnPayDataRefresh, self)
|
|
return self
|
|
end
|
|
|
|
function DailyGift:UnInitialize()
|
|
self.ReceiveList:Clear()
|
|
self.DailyGiftList:Clear()
|
|
GameCenter.UnRegFixEventHandle(LogicLuaEventDefine.EID_EVENT_REFESH_PAY_DATA, self.OnPayDataRefresh, self)
|
|
end
|
|
|
|
function DailyGift:OnPayDataRefresh(obj, sender)
|
|
self.DailyGiftList:Clear()
|
|
self.FreeGifts:Clear()
|
|
GameCenter.PaySystem.PayDataIdDict:Foreach(
|
|
function(k, v)
|
|
--2是礼包类型的数据
|
|
if v.ServerCfgData.RechargeType == 2 then
|
|
self.DailyGiftList:Add(k)
|
|
if v.ServerCfgData.Money == 0 then
|
|
self.FreeGifts:Add(k)
|
|
end
|
|
end
|
|
end
|
|
)
|
|
table.sort(self.DailyGiftList, function(a, b)
|
|
return a < b
|
|
end)
|
|
self:CheckIsAllBuy()
|
|
self:CheckDailyGiftRed()
|
|
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.WelfareDailyGift, #self.DailyGiftList > 0)
|
|
end
|
|
|
|
function DailyGift:CheckDailyGiftRed()
|
|
local _red = false
|
|
if self.IsFirstShow then
|
|
_red = true
|
|
else
|
|
for i = 1, #self.FreeGifts do
|
|
if not self.ReceiveList:Contains(self.FreeGifts[i]) then
|
|
_red = true
|
|
break
|
|
end
|
|
end
|
|
end
|
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.WelfareDailyGift, _red)
|
|
end
|
|
|
|
function DailyGift:CheckIsAllBuy()
|
|
self.IsAllBuy = true
|
|
for i = 1, #self.DailyGiftList do
|
|
local _isReceive = self.ReceiveList:Contains(self.DailyGiftList[i])
|
|
if not _isReceive then
|
|
self.IsAllBuy = false
|
|
break
|
|
end
|
|
end
|
|
end
|
|
|
|
function DailyGift:CheckIsBuySomeone()
|
|
local IsHaveBuy = false
|
|
for i = 1, #self.DailyGiftList do
|
|
local _isReceive = self.ReceiveList:Contains(self.DailyGiftList[i]) and self.DailyGiftList[i] ~= self.FreeGifts[1]
|
|
if _isReceive then
|
|
IsHaveBuy = true
|
|
return IsHaveBuy
|
|
end
|
|
end
|
|
return IsHaveBuy
|
|
end
|
|
|
|
function DailyGift:GetOnekeyBuyID()
|
|
for key, value in pairs(GameCenter.PaySystem.PayDataIdDict) do
|
|
if value.ServerCfgData.RechargeType == 14 then
|
|
return value.Id
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
--请求充值购买每日礼包
|
|
function DailyGift:ReqBuyDailyGift(id)
|
|
self.CurrBuyGiftId = id
|
|
--1. 如果是0元购直接发请求购买
|
|
if self.FreeGifts:Contains(self.CurrBuyGiftId) then
|
|
local _reqBuyMsg = ReqMsg.MSG_Recharge.ReqRecharge:New()
|
|
_reqBuyMsg.id = self.CurrBuyGiftId
|
|
_reqBuyMsg:Send()
|
|
--2. 走真实的充值流程
|
|
else
|
|
GameCenter.PaySystem:PayByCfgId(self.CurrBuyGiftId)
|
|
end
|
|
end
|
|
|
|
--返回每日礼包数据
|
|
function DailyGift:GS2U_ResDailyGiftData(msg)
|
|
if msg.buyIDs then
|
|
self.ReceiveList = List:New(msg.buyIDs)
|
|
else
|
|
self.ReceiveList = List:New()
|
|
end
|
|
self:CheckIsAllBuy()
|
|
self:CheckDailyGiftRed()
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_WELFARE_DAILYGIFT_REFRESH, self.CurrBuyGiftId)
|
|
if self.CurrBuyGiftId then
|
|
self.CurrBuyGiftId = nil
|
|
end
|
|
end
|
|
|
|
return DailyGift |