c1_lua/lua/app/module/shop/shop_manager.lua
2023-05-29 17:15:54 +08:00

212 lines
7.4 KiB
Lua

local ShopManager = class("ShopManager", BaseModule)
function ShopManager:showBoxHeroUI(type)
UIManager:showUI("app/ui/shop/box_hero_ui", {type = type})
end
function ShopManager:showBoxLevelUI()
UIManager:showUI("app/ui/shop/box_level_ui")
end
function ShopManager:showBoxOpenUI(params)
UIManager:showUI("app/ui/shop/box_open_ui", params)
end
-- 商店宝箱奖励展示界面
function ShopManager:showBoxRewardUI(params)
UIManager:showUI("app/ui/shop/box_reward_ui", params)
end
function ShopManager:showBoxLevelUpUI(params)
UIManager:showUI("app/ui/shop/box_level_up_ui", params)
end
-- 触发弹窗礼包
function ShopManager:triggerGiftPopUI(actType, actId)
if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.ACT_GIFT_SHOW_OPEN, true) then
self:showGiftPopUI(actType, actId, false)
DataManager.ShopData:removePopUpGift(actType, actId)
end
end
function ShopManager:showGiftPopUI(actType, actId, onlySelf)
if actType == PayManager.PURCHARSE_TYPE.ACT_GIFT and actId == GConst.ShopConst.FIRST_RECHARGE_ID then
UIManager:showUI("app/ui/shop/first_recharge_pop_ui")
else
UIManager:showUI("app/ui/shop/gift_pop_ui", {type = actType, id = actId, onlySelf = onlySelf})
end
end
-- 触发金币弹窗礼包
function ShopManager:triggerCoinGiftPopUI(actId)
self:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.ACT_GIFT, actId)
end
-- 触发成长礼包
function ShopManager:triggerGrowUpGiftPopUI(actId)
self:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.GROW_UP_GIFT, actId)
end
-- 购买每日特惠商品
function ShopManager:buyMallDailyGift(id, isAd)
if not DataManager.ShopData:getMallDailyIsOpen() then
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_DESC))
return
end
local params = {id = id}
local rewards, costs = DataManager.ShopData:getMallDailyRewardAndCost(id)
if costs then
if not GFunc.checkCost(costs.id, costs.num, true) then
-- 尝试触发金币礼包
if costs.id == GConst.ItemConst.ITEM_ID_GOLD then
self:tryTriggerCoinGift()
end
return
end
end
-- 二次弹窗确认
if costs then
local isCoin = costs.id == GConst.ItemConst.ITEM_ID_GOLD
local params ={
titleTx = I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_31),
content = isCoin and I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_32) or I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_33),
boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL,
showToday = GConst.MESSAGE_BOX_SHOW_TODAY.HOT_SELL_BUY,
costId = costs.id,
costNum = costs.num,
okFunc = function()
local responseData = {
rewards = rewards,
costs = costs
}
self:sendMessage(ProtoMsgType.FromMsgEnum.BuyMallDailyReq, params, responseData, self.buyMallDailyGiftFinish, BIReport.ITEM_GET_TYPE.MALL_DAILY)
end,
}
GFunc.showMessageBox(params)
else
local responseData = {
rewards = rewards,
costs = costs
}
self:sendMessage(ProtoMsgType.FromMsgEnum.BuyMallDailyReq, params, responseData, self.buyMallDailyGiftFinish, BIReport.ITEM_GET_TYPE.MALL_DAILY)
end
end
function ShopManager:buyMallDailyGiftFinish(result)
if result.err_code == GConst.ERROR_STR.SUCCESS then
GFunc.showRewardBox(result.rewards)
DataManager.ShopData:updateMallDailyGoods(result.good_info)
end
end
-- 重置每日特惠商品(type 1广告 2钻石)
function ShopManager:resetMallDailyGift(type)
if not DataManager.ShopData:getMallDailyIsOpen() then
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_DESC))
return
end
if type == 2 then -- 钻石刷新
if not GFunc.checkCost(GConst.ItemConst.ITEM_ID_GEM, DataManager.ShopData:getMallDailyDiamondResetCost(), true) then
return
end
end
local params = {reset_type = type}
local responseData = {}
if type == 2 then
local costs = {type = GConst.REWARD_TYPE.ITEM, id = GConst.ITEM_ID_GEM, num = DataManager.ShopData:getMallDailyDiamondResetCost()}
responseData.costs = costs
end
self:sendMessage(ProtoMsgType.FromMsgEnum.MallDailyResetReq, params, responseData, self.resetMallDailyGiftFinish, BIReport.ITEM_GET_TYPE.MALL_DAILY_RESET)
end
function ShopManager:resetMallDailyGiftFinish(result)
if result.err_code == GConst.ERROR_STR.SUCCESS then
local resetType = result.reqData and result.reqData.reset_type
if resetType == 1 then -- 免费的
DataManager.ShopData:addMallDailyAdResetCount()
else
DataManager.ShopData:addMallDailyDiamondResetCount()
end
DataManager.ShopData:initMallDaily(result.mall_daily_info)
end
end
-- 跨天刷新每日商店数据
function ShopManager:mallDailyGiftOverDay()
local params = {}
local responseData = {}
self:sendMessage(ProtoMsgType.FromMsgEnum.MallDailyOverDayReq, params, responseData, self.mallDailyGiftOverDayFinish)
end
function ShopManager:mallDailyGiftOverDayFinish(result)
-- 消息无用 仅为了触发推送
end
function ShopManager:onMallDailyReset(result)
if result.status == 0 then
DataManager.ShopData:initMallDaily(result.mall_daily_info)
end
end
-- 常规金币
function ShopManager:buyMallIdleCoin(id, isAd)
local params = {id = id, ad = isAd}
local rewardNum, costs = DataManager.ShopData:getCommonDailyCoinDataById(id)
local responseData = {
rewards = {type = GConst.REWARD_TYPE.ITEM, id = GConst.ITEM_ID_GOLD, num = rewardNum},
costs = costs
}
self:sendMessage(ProtoMsgType.FromMsgEnum.BuyMallIdleReq, params, responseData, self.buyMallIdleCoinFinish, BIReport.ITEM_GET_TYPE.MALL_IDLE)
end
function ShopManager:buyMallIdleCoinFinish(result)
if result.err_code == GConst.ERROR_STR.SUCCESS then
GFunc.showRewardBox(result.rewards)
DataManager.ShopData:initCommonDailyGoldGift(result.ad_count)
end
end
-- 推送助力礼包
function ShopManager:onTriggerLevelUpGift(result)
DataManager.ShopData:onTriggerLevelUpGift(result.current_level_up_gift)
end
-- 尝试触发金币礼包
function ShopManager:tryTriggerCoinGift()
local triggerId = DataManager.ShopData:checkAndGetCoinGiftTriggerId()
if triggerId then
local params = {gold_gift_id = triggerId}
local responseData = {}
self:sendMessage(ProtoMsgType.FromMsgEnum.TriggerGoldGiftReq, params, responseData, self.tryTriggerCoinGiftFinish)
else
-- 不满足触发条件
if EDITOR_MODE then
Logger.log("不满足金币礼包触发条件")
end
end
end
function ShopManager:tryTriggerCoinGiftFinish(result)
if result.status == 0 then
DataManager.ShopData:onTriggerCoinGift(result.reqData.gold_gift_id)
-- 立即触发金币弹窗
self:triggerCoinGiftPopUI(result.reqData.gold_gift_id)
end
end
-- 推送成长礼包
function ShopManager:onTriggerGrowUpGift(result)
DataManager.ShopData:onTriggerGrowUpGift(result.add_grow_up_gift)
-- 有2种情况 1.处于英雄升级/解锁界面 立即触发弹窗 2.购买了成长礼包,此时仅标记,在奖励弹窗结束后再弹
if UIManager:getTopUIObj() == UIManager.UI_PATH.HERO_DETAIL_UI then
self:triggerGrowUpGiftPopUI(result.add_grow_up_gift.current_grow_up_id)
end
end
return ShopManager