100 lines
3.1 KiB
Lua
100 lines
3.1 KiB
Lua
local BountyManager = class("BountyManager", BaseModule)
|
|
|
|
function BountyManager:showBountyMainUI()
|
|
UIManager:showUI("app/ui/bounty/bounty_main_ui")
|
|
end
|
|
|
|
function BountyManager:showBountyBuyUI()
|
|
DataManager.BountyData:markPopBought()
|
|
UIManager:showUI("app/ui/bounty/bounty_buy_ui")
|
|
end
|
|
|
|
function BountyManager:claimReward(index, isPro)
|
|
local args = {
|
|
level = index,
|
|
is_pro = isPro,
|
|
}
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.BountyRewardReq, args, {}, self.onClaimReward, BIReport.ITEM_GET_TYPE.BOUNTY_REWARD)
|
|
end
|
|
|
|
function BountyManager:onClaimReward(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
if result.rewards then
|
|
-- 读表获取该层奖励 如果是箱子走单独奖励展示接口
|
|
local isSpecialBox = false
|
|
local index = result.reqData.level
|
|
local isPro = result.reqData.is_pro
|
|
local info = DataManager.BountyData:getSeasonInfoByLevel(index)
|
|
local rewardType
|
|
local rewardId
|
|
if info then
|
|
local reward = isPro and info.reward_pro or info.reward
|
|
rewardType = reward and reward.type
|
|
rewardId = reward and reward.id
|
|
if rewardType == GConst.REWARD_TYPE.ITEM then
|
|
local itemCfgInfo = ConfigManager:getConfig("item")[rewardId]
|
|
if itemCfgInfo and itemCfgInfo.type == GConst.ItemConst.ITEM_TYPE.BOX then
|
|
isSpecialBox = true
|
|
end
|
|
end
|
|
end
|
|
if isSpecialBox then
|
|
ModuleManager.ShopManager:showBoxOpenUI({type = GConst.ShopConst.BOX_REWARD_TYPE.BOUNTY, params = rewardId, rewards = result.rewards})
|
|
else
|
|
GFunc.showRewardBox(result.rewards)
|
|
end
|
|
end
|
|
if result.reqData.is_pro ~= nil then
|
|
if result.reqData.is_pro then
|
|
DataManager.BountyData:onClaimProReward(result.reqData.level)
|
|
else
|
|
DataManager.BountyData:onClaimReward(result.reqData.level)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function BountyManager:buyBountyLevel()
|
|
if not DataManager.BountyData:getIfCanBuyLevel() then
|
|
return
|
|
end
|
|
local cost = DataManager.BountyData:getBuyBountyLevelCost()
|
|
local costId = GFunc.getRewardId(cost)
|
|
local costNum = GFunc.getRewardNum(cost)
|
|
if not GFunc.checkCost(costId, costNum, true) then
|
|
return
|
|
end
|
|
local params ={
|
|
titleTx = I18N:getGlobalText(I18N.GlobalConst.BOUNTY_BUY_LEVEL_TITLE),
|
|
content = I18N:getGlobalText(I18N.GlobalConst.BOUNTY_BUY_LEVEL_COUNTENT),
|
|
boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL,
|
|
showToday = GConst.MESSAGE_BOX_SHOW_TODAY.BOUNTY_BUY_LEVEL,
|
|
costId = costId,
|
|
costNum = costNum,
|
|
okFunc = function()
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.BountyLevelUnlockReq, {}, {}, self.onBoughtBountyLevel, BIReport.ITEM_GET_TYPE.BOUNTY_UNLOCK_LEVEL)
|
|
end,
|
|
}
|
|
GFunc.showMessageBox(params)
|
|
end
|
|
|
|
function BountyManager:onBoughtBountyLevel(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
DataManager.BountyData:onBoughtLevel()
|
|
end
|
|
end
|
|
|
|
function BountyManager:buyBounty(advanced)
|
|
if not DataManager.BountyData:getIsOpen() then
|
|
return
|
|
end
|
|
PayManager:purchasePackage(DataManager.BountyData:getGiftId(advanced), PayManager.PURCHARSE_TYPE.ACT_GIFT)
|
|
end
|
|
|
|
function BountyManager:onBoughtBountyFinish(result)
|
|
if result.status == 0 then
|
|
DataManager.BountyData:setBought(result.season, result.level)
|
|
end
|
|
end
|
|
|
|
return BountyManager |