miduo_client/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitManager.lua

314 lines
11 KiB
Lua

RecruitManager = {}
local this = RecruitManager
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
local lotteryRewardConfig = ConfigManager.GetConfig(ConfigName.LotteryRewardConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local dailyRewardConfig = ConfigManager.GetConfig(ConfigName.DialRewardConfig)
--活动抽卡类型(动态的数据)
local drawtType={
FindFairySingle=0,
FindFairyTen=0
}
this.freeUseTimeList={} --免费抽卡容器
function this.Initialize()
this.randCount = 0 --英雄抽卡已招募次数
this.isCanOpenBox = false
this.boxReward = {}
this.recruitFreeUseTime = 0 --现在只剩下秘盒招募在用了
this.isTenRecruit = 0 --首次十连
this.isFirstEnterElementScroll=true
this.isFirstEnterHeroScroll=true
this.InitPreData()
end
--请求抽卡 1抽卡类型 2回调 3特权id
function this.RecruitRequest(recruitType, func, privilegeId)
local data=this.GetExpendData(recruitType)
local itemId,itemNum=data[1],data[2] --默认
--Log("BagManager.GetItemCountById(itemId) ".. BagManager.GetItemCountById(itemId).." itemNum "..itemNum)
--Log(tostring(this.freeUseTimeList[privilegeId]))
if BagManager.GetItemCountById(itemId) >= itemNum or (this.freeUseTimeList[privilegeId] and this.freeUseTimeList[privilegeId] >= 1) or isFindFairyFree then
NetManager.RecruitRequest(recruitType, function(msg)
local lotteryType=ConfigManager.GetConfigData(ConfigName.LotterySetting,recruitType).LotteryType --若是活动招募,目前活动招募是东海寻仙,分多期
if (RecruitType.Single == recruitType or RecruitType.NormalSingle==recruitType or RecruitType.TimeLimitSingle==recruitType or RecruitType.QianKunBoxSingle==recruitType) then --若某抽卡类型有免费次数
if this.freeUseTimeList[privilegeId] and this.freeUseTimeList[privilegeId] >= 1 then
PrivilegeManager.RefreshPrivilegeUsedTimes(privilegeId, 1)
this.freeUseTimeList[privilegeId] = PrivilegeManager.GetPrivilegeRemainValue(privilegeId)
CheckRedPointStatus(RedPointType.Recruit_Red)
CheckRedPointStatus(RedPointType.Recruit_Normal)
CheckRedPointStatus(RedPointType.TimeLimited)
CheckRedPointStatus(RedPointType.QianKunBox)
end
end
if func then
func(msg)
end
end)
end
end
--5点刷新数据
function this.RefreshFreeTime()
this.freeUseTimeList[38] = PrivilegeManager.GetPrivilegeRemainValue(38)
this.freeUseTimeList[14] = PrivilegeManager.GetPrivilegeRemainValue(14)
this.freeUseTimeList[32] = PrivilegeManager.GetPrivilegeRemainValue(32)
if (ActTimeCtrlManager.SingleFuncState(1)) then
CheckRedPointStatus(RedPointType.Recruit_Red)
CheckRedPointStatus(RedPointType.Recruit_Normal)
CheckRedPointStatus(RedPointType.TimeLimited)
CheckRedPointStatus(RedPointType.QianKunBox)
end
Game.GlobalEvent:DispatchEvent(GameEvent.Recruit.OnRecruitRefreshData)
end
--刷新招募红点
function this.CheckRecuritRedPoint()
if (this.freeUseTimeList[14] >= 1) then
return true
else
return false
end
end
--刷新普通招募红点
function this.CheckRecuritNormalPoint()
if (this.freeUseTimeList[38] >= 1) then
return true
else
return false
end
end
--刷新限时招募红点
-- function this.CheckRecuritNormalPoint()
-- if (this.freeUseTimeList[32] >= 1) then
-- return true
-- else
-- return false
-- end
-- end
function this.InitPreData()
this.previewHeroData = {}
this.previewFriendData={}
this.previewNormalData={}
this.previewElementData={}
this.previewLuckData = {} --- 幸运探宝
this.previewGhostFindData = {}
this.previewTimeLimitedData = {}--限时招募
this.previewTimeLimitedUPData={}
this.previewLotterySoulData = {}--乾坤宝囊其他奖励
this.previewLotterySoulUPData={}--乾坤宝囊魂印up保底
if(#this.previewHeroData>=1) then
return
end
-- 根据当前期获取卡池信息
local curActivityId=ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FindFairy)
local data=nil
if curActivityId~=nil then --活动招募
data= ConfigManager.GetConfigDataByDoubleKey(ConfigName.LotterySetting,"ActivityId",curActivityId,"LotteryType",3)
end
for i, v in ConfigPairs(lotteryRewardConfig) do
if(v.Pool==1) then--钻石招募
table.insert(this.previewHeroData, v)
end
if v.Pool==2 then--友情
table.insert(this.previewFriendData,v)
end
if v.Pool==3 then --普抽
table.insert(this.previewNormalData,v)
end
if(v.Pool==11 or v.Pool==12 or v.Pool==13 or v.Pool==14) then-- or v.Pool==15 光暗被移除
table.insert(this.previewElementData, v)
end
if(v.Pool==101) then--限时招募
table.insert(this.previewTimeLimitedData, v)
end
if(v.Pool==1011) then--限时招募up英雄
table.insert(this.previewTimeLimitedUPData, v)
end
if(v.Pool==4401) then--乾坤宝囊其他奖励
table.insert(this.previewLotterySoulData, v)
end
if(v.Pool==1021) then--乾坤宝囊魂印up保底
table.insert(this.previewLotterySoulUPData, v)
end
if data~=nil then
if(v.Pool == data.DiamondBoxContain[1][1]) then
table.insert(this.previewGhostFindData, v)
end
end
end
for key, value in ConfigPairs(dailyRewardConfig) do
table.insert( this.previewLuckData, value)
end
if #this.previewLuckData > 1 then
table.sort(this.previewLuckData, function(a, b)
if itemConfig[a.Reward[1]].Quantity == itemConfig[b.Reward[1]].Quantity then
return a.Reward[1] > b.Reward[1]
else
return itemConfig[a.Reward[1]].Quantity > itemConfig[b.Reward[1]].Quantity
end
end)
end
table.sort(this.previewHeroData, function(a, b)
if itemConfig[a.Reward[1]].HeroStar[2] == itemConfig[b.Reward[1]].HeroStar[2] then
if a.Quality == b.Quality then
return a.Id < b.Id
else
return a.Quality > b.Quality
end
else
return itemConfig[a.Reward[1]].HeroStar[2]>itemConfig[b.Reward[1]].HeroStar[2]
end
end)
--友情
table.sort(this.previewFriendData, function(a, b)
if itemConfig[a.Reward[1]].HeroStar[2] == itemConfig[b.Reward[1]].HeroStar[2] then
if a.Quality == b.Quality then
return a.Id < b.Id
else
return a.Quality > b.Quality
end
else
return itemConfig[a.Reward[1]].HeroStar[2]>itemConfig[b.Reward[1]].HeroStar[2]
end
end)
--普抽
table.sort(this.previewNormalData, function(a, b)
if itemConfig[a.Reward[1]].HeroStar[2] == itemConfig[b.Reward[1]].HeroStar[2] then
if a.Quality == b.Quality then
return a.Id < b.Id
else
return a.Quality > b.Quality
end
else
return itemConfig[a.Reward[1]].HeroStar[2]>itemConfig[b.Reward[1]].HeroStar[2]
end
end)
--元素
table.sort(this.previewElementData, function(a, b)
if (itemConfig[a.Reward[1]].Quantity == itemConfig[b.Reward[1]].Quantity) then
if (a.Quality == b.Quality) then
return a.Id > b.Id
else
return a.Quality > b.Quality
end
else
return itemConfig[a.Reward[1]].Quantity > itemConfig[b.Reward[1]].Quantity
end
end)
-- 东海找鬼
table.sort(this.previewGhostFindData, function(a, b)
if itemConfig[a.Reward[1]].Quantity == itemConfig[b.Reward[1]].Quantity then
return a.Weight > b.Weight
else
return itemConfig[a.Reward[1]].Quantity > itemConfig[b.Reward[1]].Quantity
end
end)
-- 限时招募
table.sort(this.previewTimeLimitedData, function(a, b)
if itemConfig[a.Reward[1]].Quantity == itemConfig[b.Reward[1]].Quantity then
return a.Weight > b.Weight
else
return itemConfig[a.Reward[1]].Quantity > itemConfig[b.Reward[1]].Quantity
end
end)
--乾坤宝囊其他奖励
table.sort(this.previewLotterySoulData, function(a, b)
if itemConfig[a.Reward[1]].Quantity == itemConfig[b.Reward[1]].Quantity then
return a.Weight > b.Weight
else
return itemConfig[a.Reward[1]].Quantity > itemConfig[b.Reward[1]].Quantity
end
end)
--乾坤宝囊魂印Up保底
table.sort(this.previewLotterySoulUPData, function(a, b)
if itemConfig[a.Reward[1]].Quantity == itemConfig[b.Reward[1]].Quantity then
return a.Weight > b.Weight
else
return itemConfig[a.Reward[1]].Quantity > itemConfig[b.Reward[1]].Quantity
end
end)
end
--获取抽卡奖励预览数据
function this.GetRewardPreviewData(type)
if type == PRE_REWARD_POOL_TYPE.RECRUIT then
return this.previewHeroData
elseif type == PRE_REWARD_POOL_TYPE.ELEMENT_RECRUIT then
return this.previewElementData
elseif type == PRE_REWARD_POOL_TYPE.LUCK_FIND then
return this.previewLuckData
elseif type == PRE_REWARD_POOL_TYPE.GHOST_FIND then
return this.previewGhostFindData
elseif type ==PRE_REWARD_POOL_TYPE.FRIEND then
return this.previewFriendData
elseif type==PRE_REWARD_POOL_TYPE.NORMAL then
return this.previewNormalData
elseif type==PRE_REWARD_POOL_TYPE.TIME_LIMITED then
return this.previewTimeLimitedData
elseif type==PRE_REWARD_POOL_TYPE.TIME_LIMITED_UP then
return this.previewTimeLimitedUPData
elseif type==PRE_REWARD_POOL_TYPE.LOTTERY_SOUL then--乾坤宝囊其他奖励
return this.previewLotterySoulData
elseif type==PRE_REWARD_POOL_TYPE.LOTTERY_SOUL_UP then--乾坤宝囊魂印Up保底
return this.previewLotterySoulUPData
end
end
--获取英雄星级数据的最大长度(动态) type 数据类型 star 星级
function this.GetHeroMaxLengthByStar_Dynamic(type,star)
local d={}
for i, v in ipairs(this.GetRewardPreviewData(type)) do
if itemConfig[v.Reward[1]].HeroStar[2]==star then
table.insert(d,v)
end
end
return #d
end
--获取抽卡消耗数据
--根据数据长度遍历;若前者不足 返回后者数据;若都不足 返回最后那组数据;若前者足 显示前者
function this.GetExpendData(type)
local d
local k=0
for i, v in ipairs(lotterySetting[type].CostItem) do
if BagManager.GetItemCountById(v[1])>=v[2] then
d=v
break
else
k=k+1
end
end
local l=#lotterySetting[type].CostItem
if k==l then
return lotterySetting[type].CostItem[l]
end
return d
end
return this