140 lines
4.9 KiB
Lua
140 lines
4.9 KiB
Lua
RecruitTreasureManager = {}
|
|
local this = RecruitTreasureManager
|
|
local summonTreasure = ConfigManager.GetConfig(ConfigName.SummonTreasure)
|
|
local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityGroups,"PageType",ActivityTypeDef.RecruitTreasure)
|
|
local UniversalWelfareConfig=ConfigManager.GetConfig(ConfigName.UniversalWelfareConfig)
|
|
function this.Initialize()
|
|
this.treasureData = {}
|
|
end
|
|
|
|
function this.GetRecruitTreasureData(actId,goodsId)
|
|
if not this.treasureData[actId] then
|
|
this.treasureData[actId] = {}
|
|
this.treasureData[actId] = this.GetConfigDataByActId(actId)
|
|
end
|
|
local actData = ActivityGiftManager.GetActivityInfoByType(actId)
|
|
if actData then
|
|
for i = 1,#actData.mission do
|
|
local index = this.GetMissionIndex(this.treasureData[actId],actData.mission[i].missionId)
|
|
if index > 0 then
|
|
this.treasureData[actId][index].state = actData.mission[i].state -- -1 完美领取 1 已领取
|
|
else
|
|
LogError(string.format("招募秘宝%s中有一个不存在的missionId%s",actId,actData.mission[i].missionId))
|
|
end
|
|
end
|
|
for k,v in ipairs(this.treasureData[actId]) do
|
|
if v.state == 0 then
|
|
if actData.value >= v.cout then
|
|
v.state = 2
|
|
end
|
|
elseif v.state == 1 then
|
|
if this.CheckIsBuyTreasureByGoodsId(goodsId) then
|
|
v.state = 3
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return this.treasureData[actId]
|
|
end
|
|
|
|
function this.CheckIsBuyTreasureByGoodsId(goodsId)
|
|
local goodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.RecruiteTreasure,goodsId)
|
|
return goodsInfo and goodsInfo.isBought > 0
|
|
end
|
|
|
|
function this.GetConfigDataByActId(actId)
|
|
local data = {}
|
|
LogError("actid==="..actId)
|
|
local configs = ConfigManager.TryGetAllConfigsDataByKey(ConfigName.SummonTreasure,"Grade",actId)
|
|
for i = 1,#configs do
|
|
if not data[i] then
|
|
data[i] = {}
|
|
end
|
|
data[i].missionId = configs[i].Id
|
|
data[i].cout = configs[i].Count
|
|
data[i].reward = {}
|
|
if configs[i].Reward then
|
|
for j = 1,#configs[i].Reward do
|
|
table.insert(data[i].reward,{id = configs[i].Reward[j][1],num = configs[i].Reward[j][2],type = 1})
|
|
end
|
|
end
|
|
if configs[i].TreasureReward then
|
|
for j = 1,#configs[i].TreasureReward do
|
|
table.insert(data[i].reward,{id = configs[i].TreasureReward[j][1],num = configs[i].TreasureReward[j][2],type = 2})
|
|
end
|
|
end
|
|
data[i].state = 0 -- -1 完美领取 1 已领取 2 未领取过可领取 3 领取过可完美领取 0 未达成
|
|
end
|
|
return data
|
|
end
|
|
|
|
function this.GetMissionIndex(configs,id)
|
|
for i = 1,#configs do
|
|
if configs[i].missionId == id then
|
|
return i
|
|
end
|
|
end
|
|
return -1
|
|
end
|
|
|
|
function this.GetAllRewardData(actId,goodsId)
|
|
local rewardData = {}
|
|
local rewardData1 = {}
|
|
local actData = ActivityGiftManager.GetActivityInfoByType(actId)
|
|
local data = this.GetRecruitTreasureData(actId,goodsId)
|
|
for k,v in ipairs(data) do
|
|
--0 未达成 3 可再次领取 2 可领取 1 已领取 -1 完美领取(充钱领取过的)
|
|
if v.reward then
|
|
for n,m in ipairs(v.reward) do
|
|
if m.type == 2 then
|
|
table.insert(rewardData1,m)
|
|
if actData.value >= v.cout then
|
|
table.insert(rewardData,m)
|
|
end
|
|
else
|
|
if (v.state == 0 or v.state == 2) and actData.value >= v.cout then
|
|
table.insert(rewardData,m)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return rewardData,rewardData1
|
|
end
|
|
|
|
function this.GetRedPointStatus(red)
|
|
local actId,goodId = 0
|
|
for i = 1,#configs do
|
|
if configs[i].RpType == red then
|
|
actId = configs[i].ActId
|
|
goodId = configs[i].ShopData[1][1]
|
|
break
|
|
end
|
|
end
|
|
local data = this.GetRecruitTreasureData(actId,goodId)
|
|
for i = 1,#data do
|
|
if data[i].state == 2 or data[i].state == 3 then
|
|
return true
|
|
end
|
|
end
|
|
local isShow=this.GetQuanMinRed(actId)
|
|
return isShow
|
|
end
|
|
function this.GetQuanMinRed(actId)
|
|
local activityData=ActivityGiftManager.GetActivityInfoByType(10502)
|
|
if activityData and activityData.mission then
|
|
for i = 1, #activityData.mission do
|
|
local mission=activityData.mission[i]
|
|
if UniversalWelfareConfig[mission.missionId] and UniversalWelfareConfig[mission.missionId].GlobalActivity==actId then
|
|
if activityData.mission[i].state==1 then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
|
|
|
|
return this |