章节礼包与新手礼包

This commit is contained in:
CloudJ 2023-05-24 16:00:43 +08:00
parent 9ac84611b4
commit eb531423dd
13 changed files with 314 additions and 31 deletions

View File

@ -75,6 +75,8 @@ BIReport.ITEM_GET_TYPE = {
MALL_TREASURE = "MallTreasure", -- 常驻钻石礼包
MALL_DAILY = "MallDaily", -- 每日特惠
MALL_DAILY_RESET = "MallDailyReset",
FIRST_RECHARGE = "FirstRecharge",
BEGINNER_GIFT = "BeginnerGift",
ACT_CHAPTER_STORE = "ActChapterStore", -- 章节礼包
SUMMON = "Summon",
PLAYER_LV_UP = "PlayerLvUp",
@ -121,6 +123,8 @@ BIReport.BATTLE_TYPE = {
}
BIReport.GIFT_TYPE = {
FIRST_RECHARGE = "FirstRecharge",
BEGINNER_GIFT = "BeginnerGift",
BOUNTY = "Bounty",
GOLD_PIG = "GoldPig",
MALL_TREASURE = "MallTreasure",

View File

@ -126,7 +126,7 @@ function DataManager:initWithServerData(data)
self.DailyTaskData:init(data.task_daily)
self.IdleData:init(data.idle)
-- self.SevenDayData:init(data.SevenDayData)
self.ShopData:initCrossDay()
self.ShopData:initBase()
self.ShopData:initActGift(data.act) -- 礼包购买信息
self.ShopData:initMallDaily(data.mall_daily) -- 每日特惠
self.ShopData:initCommonDailyGoldGift(data.mall_idle and data.mall_idle.ad_count) -- 常驻金币礼包

View File

@ -11,6 +11,8 @@ PayManager.PURCHARSE_TYPE = {
}
PayManager.PURCHARSE_ACT_TYPE = {
FIRST_RECHARGE = 1,
BEGINNER_GIFT = 4,
BOUNTY = 7,
}
@ -23,6 +25,8 @@ PayManager.PURCHARSE_TYPE_CONFIG = {
PayManager.BI_ITEM_GET_TYPE = {
[PayManager.PURCHARSE_TYPE.ACT_GIFT] = {
[PayManager.PURCHARSE_ACT_TYPE.FIRST_RECHARGE] = BIReport.ITEM_GET_TYPE.FIRST_RECHARGE,
[PayManager.PURCHARSE_ACT_TYPE.BEGINNER_GIFT] = BIReport.ITEM_GET_TYPE.BEGINNER_GIFT,
[PayManager.PURCHARSE_ACT_TYPE.BOUNTY] = BIReport.ITEM_GET_TYPE.BOUNTY,
},
[PayManager.PURCHARSE_TYPE.ACT_GOLD_PIG] = BIReport.ITEM_GET_TYPE.GOLD_PIG,
@ -32,6 +36,8 @@ PayManager.BI_ITEM_GET_TYPE = {
PayManager.BI_GIFT_TYPE = {
[PayManager.PURCHARSE_TYPE.ACT_GIFT] = {
[PayManager.PURCHARSE_ACT_TYPE.FIRST_RECHARGE] = BIReport.GIFT_TYPE.FIRST_RECHARGE,
[PayManager.PURCHARSE_ACT_TYPE.BEGINNER_GIFT] = BIReport.GIFT_TYPE.BEGINNER_GIFT,
[PayManager.PURCHARSE_ACT_TYPE.BOUNTY] = BIReport.GIFT_TYPE.BOUNTY,
},
[PayManager.PURCHARSE_TYPE.ACT_GOLD_PIG] = BIReport.GIFT_TYPE.GOLD_PIG,
@ -79,6 +85,19 @@ function PayManager:getGiftType(purchaseType, id)
end
end
function PayManager:getGiftConfigInfo(purchaseType, id)
local cfgName = PayManager.PURCHARSE_TYPE_CONFIG[purchaseType]
if not cfgName then
return
end
local cfg = ConfigManager:getConfig(cfgName)
local cfg = ConfigManager:getConfig(cfgName)
if not cfg or not cfg[id] then
return
end
return cfg[id]
end
function PayManager:purchasePackage(id, purchaseType)
local cfgName = PayManager.PURCHARSE_TYPE_CONFIG[purchaseType]
if not cfgName then

View File

@ -399,6 +399,15 @@ if NOT_PUBLISH then
Logger.printTable(map)
end
end
if Input.GetKeyDown(KeyCode.Q) then
-- 标记可弹出新手礼包
DataManager.ShopData:markPopUpGiftForBeginnerGift()
end
if Input.GetKeyDown(KeyCode.W) then
-- 章节通关 标记可弹出章节礼包
DataManager.ShopData:markPopUpGiftForActChapterStore(4)
end
end
Game._releaseOnApplicationFocus = Game.onApplicationFocus

View File

@ -98,6 +98,13 @@ function ChapterManager:endFightFinish(result)
local data = {}
data.max_chapter = newMaxChapter
CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
-- 标记可弹出新手礼包
if newMaxChapter == 1 then
DataManager.ShopData:markPopUpGiftForBeginnerGift()
end
-- 章节通关 标记可弹出章节礼包
DataManager.ShopData:markPopUpGiftForActChapterStore(newMaxChapter)
end
ModuleManager.TaskManager:addFightTaskProgress(reqData)

View File

@ -1,16 +1,5 @@
local ShopConst = class("ShopConst", BaseModule)
-- 服务器pb对应的类型
ShopConst.GIFT_TYPE = {
ACT_GIFT = 1,
GOLD_PIG = 2,
CHAPTER_GIFT = 3,
GROW_UP_GIFT = 4,
MALL_TREASURE = 5,
}
ShopConst.ACT_GIFT_ID = {
BEGINNER_GIFT = 40102 -- 新手礼包ID
}
ShopConst.BEGINNER_GIFT_ID = 40102 -- 新手礼包ID
return ShopConst

View File

@ -21,6 +21,12 @@ function ShopManager:showBoxLevelUpUI(params)
UIManager:showUI("app/ui/shop/box_level_up_ui", params)
end
-- 弹窗礼包
function ShopManager:showGiftPopUI(params)
UIManager:showUI("app/ui/shop/gift_pop_ui", params)
end
-- 购买每日特惠商品
function ShopManager:buyMallDailyGift(id, isAd)
if not DataManager.ShopData:getMallDailyIsOpen() then

View File

@ -774,7 +774,14 @@ end
-- 检查礼包
function MainCityUI:checkGift()
-- TODOJ
local actType, actId = DataManager.ShopData:getNextPopGiftData()
if actType and actId then
-- 触发弹窗
ModuleManager.ShopManager:showGiftPopUI({type = actType, id = actId})
-- 移除
DataManager.ShopData:removePopUpGift(actType, actId)
return true
end
end
return MainCityUI

View File

@ -39,7 +39,7 @@ function BeginnerSellCell:init()
end
function BeginnerSellCell:refresh()
local actGiftId = GConst.ShopConst.ACT_GIFT_ID.BEGINNER_GIFT
local actGiftId = GConst.ShopConst.BEGINNER_GIFT_ID
local cfgInfo = ConfigManager:getConfig("act_gift")[actGiftId]
-- 超值
if cfgInfo.value then
@ -87,7 +87,7 @@ function BeginnerSellCell:getCellHeight()
end
function BeginnerSellCell:getIsOpen()
return true -- TOODJ
return not DataManager.ShopData:getBeginnerGiftHasBuy()
end
function BeginnerSellCell:setVisible(visible)
@ -95,7 +95,7 @@ function BeginnerSellCell:setVisible(visible)
end
function BeginnerSellCell:onClickGift(id)
Logger.logHighlight("Click id:%s", id) -- TODOJ
PayManager:purchasePackage(id, PayManager.PURCHARSE_TYPE.ACT_GIFT)
end
return BeginnerSellCell

View File

@ -25,7 +25,7 @@ function GemCell:refresh(id, cfgInfo)
local reward = cfgInfo.reward[1]
local limit = cfgInfo.limit or 0
local adMaxTimes = cfgInfo.daily or 0
local bought = DataManager.ShopData:getGiftBoughtNum(GConst.ShopConst.GIFT_TYPE.MALL_TREASURE, id)
local bought = DataManager.ShopData:getGiftBoughtNum(PayManager.PURCHARSE_TYPE.MALL_TREASURE, id)
local isFree = rechargeId == nil
local hasDoubleTimes = bought < limit
@ -79,7 +79,7 @@ function GemCell:onClickGift(id, isAd)
if isAd then
local cfgInfo = DataManager.ShopData:getMallTreasureConfig()[id]
local adMaxTimes = cfgInfo.daily or 0
local bought = DataManager.ShopData:getGiftBoughtNum(GConst.ShopConst.GIFT_TYPE.MALL_TREASURE, id)
local bought = DataManager.ShopData:getGiftBoughtNum(PayManager.PURCHARSE_TYPE.MALL_TREASURE, id)
local adLeftCount = adMaxTimes - bought
if adLeftCount > 0 then
SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.MALL_TREASURE, function ()

View File

@ -0,0 +1,166 @@
local GiftPopUI = class("GiftPopUI", BaseUI)
local GIFT_BG_NAME = {
[PayManager.PURCHARSE_TYPE.ACT_GIFT] = {
[PayManager.PURCHARSE_ACT_TYPE.BEGINNER_GIFT] = "assets/arts/textures/background/shop/shop_gift_banner_2_1.png", -- TODOJ
},
[PayManager.PURCHARSE_TYPE.CHAPTER_GIFT] = "assets/arts/textures/background/shop/shop_gift_banner_1_1.png", -- TODOJ
}
local GIFT_TITLE_TEXT = {
[PayManager.PURCHARSE_TYPE.ACT_GIFT] = {
[PayManager.PURCHARSE_ACT_TYPE.BEGINNER_GIFT] = "新手礼包TD", -- TODOJ
},
[PayManager.PURCHARSE_TYPE.CHAPTER_GIFT] = "章节礼包TD", -- TODOJ
}
local MAX_ITEM_NUM = 4
function GiftPopUI:ctor(params)
params = params or {}
self.actType = params.type
self.actId = params.id
end
function GiftPopUI:isFullScreen()
return false
end
function GiftPopUI:getPrefabPath()
return "assets/prefabs/ui/shop/gift_pop_ui.prefab"
end
function GiftPopUI:onLoadRootComplete()
if not self.actType or not self.actId then
self:closeUI()
end
self.uiMap = self.root:genAllChildren()
self.uiMap["gift_pop_ui.close_btn"]:addClickListener(function()
self:checkNextPopGiftOrClose()
end)
self.titleTx = self.uiMap["gift_pop_ui.bg.title"]
self.banner = self.uiMap["gift_pop_ui.bg.banner"]
self.offNode = self.uiMap["gift_pop_ui.bg.off_img"]
self.offText = self.uiMap["gift_pop_ui.bg.off_img.text"]
self.itemNodeLayout = self.uiMap["gift_pop_ui.bg.item_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT)
self.itemNodeList = {}
self.itemCellList = {}
self.itemTextList = {}
self.itemHelpList = {}
for i = 1, MAX_ITEM_NUM do
table.insert(self.itemNodeList, self.uiMap["gift_pop_ui.bg.item_" .. i])
table.insert(self.itemCellList, CellManager:addCellComp(self.uiMap["gift_pop_ui.bg.item_".. i .. ".item_cell"], GConst.TYPEOF_LUA_CLASS.ITEM_CELL))
table.insert(self.itemTextList, self.uiMap["gift_pop_ui.bg.item_".. i .. ".num"])
table.insert(self.itemHelpList, self.uiMap["gift_pop_ui.bg.item_" .. i .. ".help"])
end
self.timeNode = self.uiMap["gift_pop_ui.bg.time_node"]
self.timeText = self.uiMap["gift_pop_ui.bg.time_node.text"]
self.buyBtn = self.uiMap["gift_pop_ui.bg.buy_btn"]
self.buyBtnTx = self.uiMap["gift_pop_ui.bg.buy_btn.text"]
self.buyBtnIcon = self.uiMap["gift_pop_ui.bg.buy_btn.icon"]
self.buyBtn:addClickListener(function()
self:onClickGift()
end)
self:_bind()
self:scheduleGlobal(function()
self:updateTime()
end, 1)
self:refresh()
end
function GiftPopUI:_bind()
self:bind(DataManager.ShopData, "isDirty", function()
self:refresh(true)
end)
end
function GiftPopUI:refresh(needCheck)
if needCheck then
-- 如果已经购买过了 则切为下一个或关闭UI 目前都是唯一礼包
local bought = DataManager.ShopData:getGiftBoughtNum(self.actType, self.actId)
if bought > 0 then
self:checkNextPopGiftOrClose()
return
end
end
if self.actType == PayManager.PURCHARSE_TYPE.ACT_GIFT then
local type = PayManager:getGiftConfigInfo(self.actType, self.actId).type
self.titleTx:setText(GIFT_TITLE_TEXT[self.actType][type])
self.banner:setTexture(GIFT_BG_NAME[self.actType][type])
else
self.titleTx:setText(GIFT_TITLE_TEXT[self.actType])
self.banner:setTexture(GIFT_BG_NAME[self.actType])
end
local cfgInfo = PayManager:getGiftConfigInfo(self.actType, self.actId)
if cfgInfo then
local off = cfgInfo.value or 0
if off < 10 then -- 统一为百分比格式
off = off * 100
end
if off > 0 then
self.offNode:setVisible(true)
self.offText:setText(tostring(off) .. "%")
else
self.offNode:setVisible(false)
end
end
local rewards = cfgInfo.reward or {}
for i = 1, MAX_ITEM_NUM do
if i <= #rewards then
self.itemNodeList[i]:setVisible(true)
self.itemCellList[i]:refreshByCfg(rewards[i].id, 0)
self.itemCellList[i]:setNum("")
self.itemTextList[i]:setText(rewards[i].num)
self.itemCellList[i]:addClickListener(function()
ModuleManager.TipsManager:showItemTips(rewards[i].id, self.itemCellList[i]:getBaseObject())
end)
self.itemHelpList[i]:setVisible(false)
else
self.itemNodeList[i]:setVisible(false)
end
end
self.itemNodeLayout:RefreshLayout()
local rechargeId = cfgInfo.recharge_id
if rechargeId then
self.buyBtnTx:setText(GFunc.getFormatPrice(rechargeId))
end
self:updateTime()
end
function GiftPopUI:updateTime()
-- TODOJ
end
function GiftPopUI:onClickGift()
PayManager:purchasePackage(self.actId, self.actType)
end
function GiftPopUI:checkNextPopGiftOrClose()
local actType, actId = DataManager.ShopData:getNextPopGiftData()
if actType and actId then
-- 更新数据
self.actType = actType
self.actId = actId
self:refresh()
-- 移除弹窗列表
DataManager.ShopData:removePopUpGift(actType, actId)
else
self:closeUI()
end
end
return GiftPopUI

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 61eca75f20973c44cb9ede981da0583b
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}

View File

@ -4,8 +4,12 @@ function ShopData:ctor()
self.data.isDirty = false
end
function ShopData:clear()
function ShopData:initBase()
self:initActChapterStoreData()
self:initCrossDay()
end
function ShopData:clear()
DataManager:unregisterCrossDayFunc("ShopData")
end
@ -24,12 +28,10 @@ end
-- 初始化购买的礼包
function ShopData:initActGift(act)
if EDITOR_MODE then
Logger.logHighlight("初始化 initActGift")
Logger.printTable(act)
end
act = act or {}
local gifts = act.gifts or {}
-- 转为map结构
@ -93,6 +95,35 @@ function ShopData:updateGiftInfo(gift)
self:setDirty()
end
-- 标记一个礼包需要弹出 在条件允许时会弹出
function ShopData:markPopUpGift(actType, actId)
if not self.needPopUpGift then
self.needPopUpGift = {}
end
if not self.needPopUpGift[actType] then
self.needPopUpGift[actType] = {}
end
table.insert(self.needPopUpGift[actType], actId)
end
function ShopData:removePopUpGift(actType, actId)
if self.needPopUpGift then
if self.needPopUpGift[actType] then
for index, id in ipairs(self.needPopUpGift[actType]) do
if id == actId then
table.remove(self.needPopUpGift[actType], index)
break
end
end
end
end
end
-- 获取待处理弹出礼包结构 {type:[id1,id2,...]}
function ShopData:getPopUpGift()
return self.needPopUpGift
end
-- 通用礼包结束 ----------------------------------------------------------------------------------------------
-- 每日特惠部分 **********************************************************************************************
@ -255,13 +286,7 @@ end
-- 常驻钻石礼包结束 ----------------------------------------------------------------------------------------------
-- 章节礼包 act_chapter_store **********************************************************************************************
function ShopData:getActChapterStoreConfig()
return ConfigManager:getConfig("act_chapter_store")
end
-- 特定章节礼包是否已购买
function ShopData:getActChapterStoreHasBuy(chapterId)
-- 章节礼包的id-chapterId相互对应map
function ShopData:initActChapterStoreData()
if not self.actChapterStoreMap then
self.actChapterStoreId2ChapterIdMap = {}
self.actChapterStoreChapterId2IdMap = {}
@ -271,9 +296,17 @@ function ShopData:getActChapterStoreHasBuy(chapterId)
self.actChapterStoreChapterId2IdMap[cfgInfo.chapter] = id
end
end
end
function ShopData:getActChapterStoreConfig()
return ConfigManager:getConfig("act_chapter_store")
end
-- 特定章节礼包是否已购买
function ShopData:getActChapterStoreHasBuy(chapterId)
-- 章节礼包的id-chapterId相互对应map
local actId = self.actChapterStoreChapterId2IdMap[chapterId]
if self:getGiftBoughtNum(GConst.ShopConst.GIFT_TYPE.CHAPTER_GIFT, actId) == 0 then
if self:getGiftBoughtNum(PayManager.PURCHARSE_TYPE.CHAPTER_GIFT, actId) == 0 then
return false
else
return true
@ -283,7 +316,7 @@ end
-- 根据当前章节,获取可购买的id数组
function ShopData:getActChapterStoreCanBuyActIds()
local list = {}
local curChapterId = DataManager.ChapterData:getChapterId()
local curChapterId = DataManager.ChapterData:getMaxChapterId()
for id = curChapterId, 1, -1 do
if not self:getActChapterStoreHasBuy(id) then
table.insert(list, self.actChapterStoreChapterId2IdMap[id])
@ -292,8 +325,41 @@ function ShopData:getActChapterStoreCanBuyActIds()
return list
end
function ShopData:markPopUpGiftForActChapterStore(chapterId)
local actId = self.actChapterStoreChapterId2IdMap[chapterId]
self:markPopUpGift(PayManager.PURCHARSE_TYPE.CHAPTER_GIFT, actId)
end
-- 获取下一个需要弹出的礼包数据
function ShopData:getNextPopGiftData()
local popUpGift = self:getPopUpGift()
if popUpGift then
for actType, actIdList in pairs(popUpGift) do
-- 弹窗顺序待处理 TODOJ
for _, actId in ipairs(actIdList) do
return actType, actId
end
end
end
end
-- 章节礼包结束 ----------------------------------------------------------------------------------------------
-- 新手礼包 **********************************************************************************************
function ShopData:markPopUpGiftForBeginnerGift()
self:markPopUpGift(PayManager.PURCHARSE_TYPE.ACT_GIFT, GConst.ShopConst.BEGINNER_GIFT_ID)
end
function ShopData:getBeginnerGiftHasBuy()
if self:getGiftBoughtNum(PayManager.PURCHARSE_TYPE.ACT_GIFT, GConst.ShopConst.BEGINNER_GIFT_ID) == 0 then
return false
else
return true
end
end
-- 新手礼包结束 ----------------------------------------------------------------------------------------------
-- 初始化成长礼包
function ShopData:initGrowUpGift(growUpGift)
end