2023-07-14 19:35:33 +00:00
|
|
|
XLottoManagerCreator = function()
|
|
|
|
local XLottoGroupEntity = require("XEntity/XLotto/XLottoGroupEntity")
|
2024-09-01 20:49:41 +00:00
|
|
|
---@class XLottoManager
|
2023-07-14 19:35:33 +00:00
|
|
|
local XLottoManager = {}
|
|
|
|
local GET_LOTTO_DATA_INTERVAL = 10
|
|
|
|
local LastGetLottoRewardInfoTimes = 0
|
|
|
|
local LottoGroupDataDic = {}
|
2024-09-01 20:49:41 +00:00
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
local METHOD_NAME = {
|
|
|
|
LottoInfoRequest = "LottoInfoRequest",
|
|
|
|
LottoRequest = "LottoRequest",
|
|
|
|
LottoBuyTicketRequest = "LottoBuyTicketRequest",
|
|
|
|
}
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
local IsInterceptUiObtain = false
|
|
|
|
local CacheReward = nil
|
|
|
|
local RuleTagIndex = 1
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
function XLottoManager.Init()
|
2024-09-01 20:49:41 +00:00
|
|
|
RuleTagIndex = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
--region RuleTagIndex
|
|
|
|
function XLottoManager.SetRuleTagIndex(index)
|
|
|
|
RuleTagIndex = index
|
2023-07-14 19:35:33 +00:00
|
|
|
end
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
function XLottoManager.GetRuleTagIndex()
|
|
|
|
return RuleTagIndex
|
|
|
|
end
|
|
|
|
--endregion
|
|
|
|
|
|
|
|
--region Ui
|
|
|
|
function XLottoManager.OpenLottoUi(groupId, param1)
|
|
|
|
if XFunctionManager.DetectionFunction(XFunctionManager.FunctionName.Lotto) then
|
|
|
|
XLottoManager.GetLottoRewardInfoRequest(function()
|
|
|
|
---@type XLottoGroupEntity
|
|
|
|
local entity = LottoGroupDataDic[groupId]
|
|
|
|
if not entity then
|
|
|
|
XUiManager.TipError(CS.XTextManager.GetText("ActivityBranchNotOpen"))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local UiName = XLottoConfigs.GetLottoOpenUiName(groupId)
|
|
|
|
if not string.IsNilOrEmpty(UiName) then
|
|
|
|
XLuaUiManager.Open(UiName, entity, nil, entity:GetUiBackGround(), param1)
|
|
|
|
else
|
|
|
|
XLuaUiManager.Open("UiLotto", entity, nil, entity:GetUiBackGround(), param1)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.OnActivityEnd()
|
|
|
|
XUiManager.TipText("LottoActivityOver")
|
|
|
|
XLuaUiManager.RunMain()
|
2023-07-14 19:35:33 +00:00
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
--endregion
|
2023-07-14 19:35:33 +00:00
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
--region LocalCacheData
|
|
|
|
local _GetSkipCacheKey = function(lottoGroupId)
|
|
|
|
return string.format("LottoSkipAnim_%s_%s", XPlayer.Id, lottoGroupId)
|
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.GetSkipAnim(lottoGroupId)
|
|
|
|
return XSaveTool.GetData(_GetSkipCacheKey(lottoGroupId))
|
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.SetSkipAnim(lottoGroupId, value)
|
|
|
|
XSaveTool.SaveData(_GetSkipCacheKey(lottoGroupId), value)
|
|
|
|
end
|
|
|
|
|
|
|
|
local _GetFirstCacheKey = function(lottoGroupId)
|
|
|
|
return string.format("LottoFirstAnim_%s_%s", XPlayer.Id, lottoGroupId)
|
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.GetFirstAnim(lottoGroupId)
|
|
|
|
return not XSaveTool.GetData(_GetFirstCacheKey(lottoGroupId))
|
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.SetFirstAnim(lottoGroupId, value)
|
|
|
|
XSaveTool.SaveData(_GetFirstCacheKey(lottoGroupId), value)
|
|
|
|
end
|
|
|
|
--endregion
|
|
|
|
|
|
|
|
function XLottoManager.GetIsInterceptUiObtain()
|
|
|
|
return IsInterceptUiObtain
|
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.CacheWeaponFashionRewards(reward)
|
|
|
|
CacheReward = reward
|
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.GetWeaponFashionCacheReward()
|
|
|
|
return CacheReward
|
|
|
|
end
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
function XLottoManager.GetLottoGroupDataList()
|
|
|
|
local list = {}
|
2024-09-01 20:49:41 +00:00
|
|
|
for _, groupData in pairs(LottoGroupDataDic or {}) do
|
|
|
|
table.insert(list, groupData)
|
2023-07-14 19:35:33 +00:00
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
|
|
|
table.sort(list, function(a, b)
|
2023-07-14 19:35:33 +00:00
|
|
|
return a:GetPriority() < b:GetPriority()
|
|
|
|
end)
|
2024-09-01 20:49:41 +00:00
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
return list
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
function XLottoManager.UpdateLottoGroupData(lottoDrawInfoList)
|
|
|
|
local tmpInfoList = {}
|
|
|
|
LottoGroupDataDic = {}
|
2024-09-01 20:49:41 +00:00
|
|
|
for _, drawInfo in pairs(lottoDrawInfoList or {}) do
|
2023-07-14 19:35:33 +00:00
|
|
|
local drawCfg = XLottoConfigs.GetLottoCfgById(drawInfo.Id)
|
|
|
|
if drawCfg then
|
|
|
|
LottoGroupDataDic[drawCfg.LottoGroupId] = LottoGroupDataDic[drawCfg.LottoGroupId] or XLottoGroupEntity.New(drawCfg.LottoGroupId)
|
|
|
|
tmpInfoList[drawCfg.LottoGroupId] = tmpInfoList[drawCfg.LottoGroupId] or {}
|
2024-09-01 20:49:41 +00:00
|
|
|
table.insert(tmpInfoList[drawCfg.LottoGroupId], drawInfo)
|
2023-07-14 19:35:33 +00:00
|
|
|
end
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
|
|
|
for groupId, infoList in pairs(tmpInfoList or {}) do
|
|
|
|
table.sort(infoList, function(a, b)
|
2023-07-14 19:35:33 +00:00
|
|
|
return a.Priority < b.Priority
|
|
|
|
end)
|
2024-09-01 20:49:41 +00:00
|
|
|
LottoGroupDataDic[groupId]:UpdateData({ DrawInfoList = infoList })
|
2023-07-14 19:35:33 +00:00
|
|
|
end
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
function XLottoManager.UpdateLottoDrawData(lottoDrawId, data)
|
|
|
|
local drawCfg = XLottoConfigs.GetLottoCfgById(lottoDrawId)
|
|
|
|
if drawCfg then
|
|
|
|
local drawData = LottoGroupDataDic[drawCfg.LottoGroupId]:GetDrawData()
|
|
|
|
local rewardList = drawData:GetLottoRewardList()
|
|
|
|
table.insert(rewardList, data.LottoRewardId)
|
|
|
|
local tmpData = {}
|
|
|
|
tmpData.ExtraRewardState = data.ExtraRewardState
|
|
|
|
tmpData.LottoRecords = data.LottoRecords
|
|
|
|
tmpData.LottoRewards = rewardList
|
|
|
|
drawData:UpdateData(tmpData)
|
|
|
|
end
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
function XLottoManager.GetLottoRewardInfoRequest(cb)
|
|
|
|
local now = XTime.GetServerNowTimestamp()
|
|
|
|
if LastGetLottoRewardInfoTimes and now - LastGetLottoRewardInfoTimes <= GET_LOTTO_DATA_INTERVAL then
|
|
|
|
if cb then cb() end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
XNetwork.Call(METHOD_NAME.LottoInfoRequest, {}, function(res)
|
2024-09-01 20:49:41 +00:00
|
|
|
if res.Code ~= XCode.Success then
|
|
|
|
XUiManager.TipCode(res.Code)
|
2023-07-14 19:35:33 +00:00
|
|
|
if cb then cb() end
|
2024-09-01 20:49:41 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
XLottoManager.UpdateLottoGroupData(res.LottoInfos)
|
|
|
|
LastGetLottoRewardInfoTimes = XTime.GetServerNowTimestamp()
|
|
|
|
if cb then cb() end
|
|
|
|
end)
|
2023-07-14 19:35:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.DoLotto(lottoId, cb, errorCb)
|
2024-09-01 20:49:41 +00:00
|
|
|
IsInterceptUiObtain = true
|
2023-07-14 19:35:33 +00:00
|
|
|
XNetwork.Call(METHOD_NAME.LottoRequest, { Id = lottoId }, function(res)
|
2024-09-01 20:49:41 +00:00
|
|
|
IsInterceptUiObtain = false
|
|
|
|
if res.Code ~= XCode.Success then
|
|
|
|
XUiManager.TipCode(res.Code)
|
|
|
|
if errorCb then errorCb() end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
XLottoManager.UpdateLottoDrawData(lottoId, res)
|
|
|
|
if cb then cb(res.RewardList, res.ExtraRewardList) end
|
|
|
|
end)
|
2023-07-14 19:35:33 +00:00
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
function XLottoManager.BuyTicket(lottoId, BuyTicketRuleId, ticketKey, cb)
|
2024-09-01 20:49:41 +00:00
|
|
|
XNetwork.Call(METHOD_NAME.LottoBuyTicketRequest, { LottoId = lottoId, TicketId = BuyTicketRuleId, TicketKey = ticketKey }, function(res)
|
|
|
|
if res.Code ~= XCode.Success then
|
|
|
|
XUiManager.TipCode(res.Code)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local reward = XRewardManager.CreateRewardGoodsByTemplate({ TemplateId = res.ItemId, Count = res.ItemCount })
|
|
|
|
if cb then cb({ reward }) end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function XLottoManager.GetTemplateQuality(templateId)
|
|
|
|
local templateIdData = XGoodsCommonManager.GetGoodsShowParamsByTemplateId(templateId)
|
|
|
|
local Type = XTypeManager.GetTypeById(templateId)
|
|
|
|
local quality
|
|
|
|
if Type == XArrangeConfigs.Types.Wafer then
|
|
|
|
quality = templateIdData.Star
|
|
|
|
elseif Type == XArrangeConfigs.Types.Weapon then
|
|
|
|
quality = templateIdData.Star
|
|
|
|
elseif Type == XArrangeConfigs.Types.Character then
|
|
|
|
quality = XCharacterConfigs.GetCharMinQuality(templateId)
|
|
|
|
else
|
|
|
|
quality = XTypeManager.GetQualityById(templateId)
|
|
|
|
end
|
|
|
|
return quality
|
2023-07-14 19:35:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
XLottoManager.Init()
|
|
|
|
return XLottoManager
|
2024-09-01 20:49:41 +00:00
|
|
|
end
|