关卡宝箱

This commit is contained in:
xiekaidong 2023-04-15 14:45:42 +08:00
parent f9541d56d8
commit f74a7f6080
11 changed files with 140 additions and 20 deletions

View File

@ -117,7 +117,8 @@ BIReport.RUNE_OPT_TYPE = {
BIReport.ITEM_GET_TYPE = { BIReport.ITEM_GET_TYPE = {
NEW_PLAYER_INITIAL = "NewPlayerInitial", -- 新玩家创号自带 NEW_PLAYER_INITIAL = "NewPlayerInitial", -- 新玩家创号自带
UPGRADE_HERO = "UpgradeHero", UPGRADE_HERO = "UpgradeHero",
FIGHT_END = "fight_end", FIGHT_END = "FightEnd",
CHAPTER_BOX = "ChapterBox"
} }
BIReport.ADS_CLICK_TYPE = { BIReport.ADS_CLICK_TYPE = {

View File

@ -25,6 +25,8 @@ local LocalizationGlobalConst =
HERO_DESC_5 = "HERO_DESC_5", HERO_DESC_5 = "HERO_DESC_5",
HERO_DESC_6 = "HERO_DESC_6", HERO_DESC_6 = "HERO_DESC_6",
HERO_DESC_7 = "HERO_DESC_7", HERO_DESC_7 = "HERO_DESC_7",
REWARD_PREVIEW_DESC = "REWARD_PREVIEW_DESC",
} }
return LocalizationGlobalConst return LocalizationGlobalConst

View File

@ -11,6 +11,7 @@ local localization_global =
["BTN_TEXT_CANCEL"] = "取消", ["BTN_TEXT_CANCEL"] = "取消",
["BTN_TEXT_OK"] = "确定", ["BTN_TEXT_OK"] = "确定",
["BATTLE_DESC_1"] = "是否退出战斗", ["BATTLE_DESC_1"] = "是否退出战斗",
["ITEM_NOT_ENOUGH"] = "{0}不足", ["ITEM_NOT_ENOUGH"] = "{0}不足",
["START_DESC"] = "开始", ["START_DESC"] = "开始",
["ELEMENT_NAME_1"] = "红色元素", ["ELEMENT_NAME_1"] = "红色元素",
@ -25,6 +26,19 @@ local localization_global =
["HERO_DESC_5"] = "激活", ["HERO_DESC_5"] = "激活",
["HERO_DESC_6"] = "已解锁", ["HERO_DESC_6"] = "已解锁",
["HERO_DESC_7"] = "未解锁", ["HERO_DESC_7"] = "未解锁",
["GET_REWARDS"] = "获得奖励",
["CLICK_CLOSE_DESC"] = "点击关闭",
["REWARD_DESC"] = "奖励",
["CONTINUE_DESC"] = "继续",
["BATTLE_DESC_2"] = "暂停",
["BATTLE_DESC_3"] = "刷新",
["BATTLE_DESC_4"] = "达到",
["BATTLE_DESC_5"] = "胜利",
["BATTLE_DESC_6"] = "失败",
["BATTLE_DESC_7"] = "累计造成总伤害:<color=#89FF76>{0}</color>",
["REWARD_PREVIEW_DESC"] = "奖励预览",
} }
return localization_global return localization_global

View File

@ -1,5 +1,24 @@
local ChapterManager = class("ChapterManager", BaseModule) local ChapterManager = class("ChapterManager", BaseModule)
function ChapterManager:openBox(chapterId, index)
if DataManager.ChapterData:getChapterBoxRewardGot(chapterId, index) then
return
end
local parmas = {
id = chapterId,
index = index,
}
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.OPEN_CHAPTER_BOX, parmas, function(result)
if result.status == 0 then
GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.CHAPTER_BOX)
GFunc.showRewardBox(result.rewards)
DataManager.ChapterData:init(result.chapterData)
DataManager.ChapterData:setDirty()
end
end)
end
function ChapterManager:startFight() function ChapterManager:startFight()
---- 通信 ---- 通信
ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE) ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE)
@ -30,6 +49,7 @@ function ChapterManager:endFight(id, combatReport)
GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.FIGHT_END) GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.FIGHT_END)
ModuleManager.BattleManager:showBattleResultUI(parmas.rewards, combatReport) ModuleManager.BattleManager:showBattleResultUI(parmas.rewards, combatReport)
DataManager.ChapterData:init(result.chapterData) DataManager.ChapterData:init(result.chapterData)
DataManager.ChapterData:setDirty()
end end
end) end)
end end

View File

@ -34,4 +34,46 @@ function ServerChapterData:fightChapter(id, victory, wave)
end end
end end
function ServerChapterData:getChapterBoxRewardGot(chapterId, index)
local idStr = tostring(chapterId)
local list = self.data.chapterBoxInfo[idStr]
if not list then
return false
end
for _, idx in ipairs(list) do
if idx == index then
return true
end
end
return false
end
function ServerChapterData:getChapterBoxRewards(chapterId, index)
local cfg = ConfigManager:getConfig("chapter")[chapterId]
if not cfg then
return
end
return cfg["box_reward_" .. index]
end
function ServerChapterData:openChapterBox(chapterId, index)
local idStr = tostring(chapterId)
local list = self.data.chapterBoxInfo[idStr]
if not list then
self.data.chapterBoxInfo[idStr] = {}
else
for _, idx in ipairs(list) do
if idx == index then
return false
end
end
end
table.insert(self.data.chapterBoxInfo[idStr], index)
return true
end
return ServerChapterData return ServerChapterData

View File

@ -1,5 +1,36 @@
local ServerChapterManager = {} local ServerChapterManager = {}
function ServerChapterManager:openBox(params, callback)
local result = {
status = 1
}
if params == nil or not params.id or not params.index then
if callback then
callback(result)
end
return
end
local ServerGameData = ServerDataManager:getServerGameData()
if not ServerGameData.ChapterData:openChapterBox(params.id, params.index) then
if callback then
callback(result)
end
return
end
local rewards = ServerGameData.ChapterData:getChapterBoxRewards(params.id, params.index)
result.rewards = ServerGameData:addRewards(rewards)
result.chapterData = ServerGameData.ChapterData:getCloneData()
result.status = 0
if callback then
callback(result)
end
end
function ServerChapterManager:endFight(params, callback) function ServerChapterManager:endFight(params, callback)
local result = { local result = {
status = 1 status = 1

View File

@ -11,6 +11,7 @@ ServerDataConst.DATA_OP_BEHAVIOR = {
UPDATE_FORMATION = "UPDATE_FORMATION", UPDATE_FORMATION = "UPDATE_FORMATION",
UPGRADE_HERO = "UPGRADE_HERO", UPGRADE_HERO = "UPGRADE_HERO",
END_FIGHT = "END_FIGHT", END_FIGHT = "END_FIGHT",
OPEN_CHAPTER_BOX = "OPEN_CHAPTER_BOX",
} }
return ServerDataConst return ServerDataConst

View File

@ -63,7 +63,8 @@ ServerDataManager.OP_FUNC = {
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA] = function (...) ServerDataManager:onSyncData(...) end, [GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA] = function (...) ServerDataManager:onSyncData(...) end,
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION] = function (...) ServerDataManager.ServerFormationManager:updateFormation(...) end, [GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION] = function (...) ServerDataManager.ServerFormationManager:updateFormation(...) end,
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPGRADE_HERO] = function (...) ServerDataManager.ServerHeroManager:onUpgradeHero(...) end, [GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPGRADE_HERO] = function (...) ServerDataManager.ServerHeroManager:onUpgradeHero(...) end,
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.END_FIGHT] = function(...) ServerDataManager.ServerChapterManager:endFight(...) end [GConst.ServerDataConst.DATA_OP_BEHAVIOR.END_FIGHT] = function(...) ServerDataManager.ServerChapterManager:endFight(...) end,
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.OPEN_CHAPTER_BOX] = function(...) ServerDataManager.ServerChapterManager:openBox(...) end,
} }
function ServerDataManager:dealGM(params, callback) function ServerDataManager:dealGM(params, callback)

View File

@ -3,7 +3,7 @@ local CHAPTER_PATH = "assets/arts/textures/background/chapter/%s.png"
local BOX_ICON = { local BOX_ICON = {
"common_chest_1", "common_chest_1",
"common_chest_2" "common_chest_4"
} }
function MainComp:init() function MainComp:init()
@ -85,15 +85,19 @@ function MainComp:refreshChapter(force)
end end
end end
local curMaxWave = DataManager.ChapterData:getChapterMaxWave()
local boxCount = DataManager.ChapterData:getChapterBoxCount() local boxCount = DataManager.ChapterData:getChapterBoxCount()
slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = DataManager.ChapterData:getChapterMaxWave() / boxCount local maxWave = DataManager.ChapterData:getChapterBoxNum(chapterId, boxCount)
slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = curMaxWave / maxWave
for index, objs in ipairs(self.boxObjs) do for index, objs in ipairs(self.boxObjs) do
local show = boxCount >= index local show = boxCount >= index
objs.box:setActive(show) objs.box:setActive(show)
objs.desc:setActive(show) objs.desc:setActive(show)
if show then if show then
local needWave = DataManager.ChapterData:getChapterBoxNum(chapterId, index)
local x = 370 * (index / boxCount) local x = 370 * (index / boxCount)
local rewards = DataManager.ChapterData:getChapterBoxByIndex(nil, index) local rewards = DataManager.ChapterData:getChapterBoxRewards(nil, index)
local num = DataManager.ChapterData:getChapterBoxNum(nil, index) local num = DataManager.ChapterData:getChapterBoxNum(nil, index)
local rewardGot = DataManager.ChapterData:getChapterBoxRewardGot(nil, index) local rewardGot = DataManager.ChapterData:getChapterBoxRewardGot(nil, index)
local icon = BOX_ICON[1] local icon = BOX_ICON[1]
@ -101,7 +105,11 @@ function MainComp:refreshChapter(force)
icon = BOX_ICON[2] icon = BOX_ICON[2]
end end
objs.box:addClickListener(function() objs.box:addClickListener(function()
if needWave <= curMaxWave and not rewardGot then
ModuleManager.ChapterManager:openBox(chapterId, index)
else
ModuleManager.TipsManager:showRewardsTips(rewards, nil, objs.box) ModuleManager.TipsManager:showRewardsTips(rewards, nil, objs.box)
end
end) end)
objs.box:setSprite(GConst.ATLAS_PATH.COMMON, icon) objs.box:setSprite(GConst.ATLAS_PATH.COMMON, icon)
objs.box:setAnchoredPositionX(x) objs.box:setAnchoredPositionX(x)

View File

@ -19,7 +19,7 @@ function RewardsTips:init()
if not self.rewardCells then if not self.rewardCells then
self.rewardCells = {} self.rewardCells = {}
for i = 1, 3 do for i = 1, 3 do
self.rewardCells[i] = CellManager:addCellComp(uiMap["rewards_tips.reward_node.reward_layout.reward_cell_" .. i], GConst.TYPEOF_LUA_CLASS.REWARD_CELL) self.rewardCells[i] = CellManager:addCellComp(uiMap["rewards_tips.bg.reward_node.reward_layout.reward_cell_" .. i], GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
end end
end end
end end
@ -38,7 +38,7 @@ function RewardsTips:onRefresh()
self:closeUI() self:closeUI()
end) end)
self.descTx:setText(self.params.customTitleStr or I18N:getGlobalText(I18N.GlobalConst.BOUNTY_DESC_11)) self.descTx:setText(self.params.customTitleStr or I18N:getGlobalText(I18N.GlobalConst.REWARD_PREVIEW_DESC))
if self.params.rewards then if self.params.rewards then
for i, cell in ipairs(self.rewardCells) do for i, cell in ipairs(self.rewardCells) do
if self.params.rewards[i] then if self.params.rewards[i] then

View File

@ -83,18 +83,6 @@ function ChapterData:getChapterBoxNum(chapterId, index)
end end
end end
function ChapterData:getChapterBoxByIndex(chapterId, index)
chapterId = chapterId or self:getChapterId()
if not self:getChapterBoxNum(chapterId, index) then
return
end
local cfg = self:getChapterCfg()[chapterId]
if cfg then
return cfg["box_reward_" .. index]
end
end
function ChapterData:getChapterBoxRewardGot(chapterId, index) function ChapterData:getChapterBoxRewardGot(chapterId, index)
chapterId = tostring(chapterId or self:getChapterId()) chapterId = tostring(chapterId or self:getChapterId())
local list = self.data.chapterBoxInfo[chapterId] local list = self.data.chapterBoxInfo[chapterId]
@ -111,6 +99,18 @@ function ChapterData:getChapterBoxRewardGot(chapterId, index)
return false return false
end end
function ChapterData:getChapterBoxRewards(chapterId, index)
chapterId = chapterId or self:getChapterId()
if not self:getChapterBoxNum(chapterId, index) then
return
end
local cfg = self:getChapterCfg()[chapterId]
if cfg then
return cfg["box_reward_" .. index]
end
end
function ChapterData:getChapterMaxWave(chapterId) function ChapterData:getChapterMaxWave(chapterId)
chapterId = tostring(chapterId or self:getChapterId()) chapterId = tostring(chapterId or self:getChapterId())
if self.data.chapterFightInfo[chapterId] then if self.data.chapterFightInfo[chapterId] then