From 30fcf69843382b9bdf879f9c2deb303eeb6745f7 Mon Sep 17 00:00:00 2001 From: puxuan <413323644@qq.com> Date: Tue, 10 Jun 2025 23:36:41 +0800 Subject: [PATCH] mystery_box --- lua/app/config/chapter.lua | 6 ++--- lua/app/global/global_func.lua | 9 +++++++ .../controller/battle_base_controller.lua | 12 +++++++-- .../controller/battle_controller_stage.lua | 26 ++++++++++++------- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lua/app/config/chapter.lua b/lua/app/config/chapter.lua index dd7585b3..28eaacab 100644 --- a/lua/app/config/chapter.lua +++ b/lua/app/config/chapter.lua @@ -671,8 +671,8 @@ local chapter = { }, ["mystery_box"]={ 0, - 5000, - 5000, + 10000, + 10000, 0 }, ["mystery_box_reward"]={ @@ -2360,7 +2360,7 @@ local chapter = { ["mystery_box"]={ 5000, 0, - 0, + 10000, 5000 }, ["mystery_box_reward"]={ diff --git a/lua/app/global/global_func.lua b/lua/app/global/global_func.lua index fd8813b3..6cf15453 100644 --- a/lua/app/global/global_func.lua +++ b/lua/app/global/global_func.lua @@ -1931,4 +1931,13 @@ function GFunc.formatPlayerFormationInfo(info) return formation end +function GFunc.randomDrop(dropList) + local weightArr = {} + for i, v in ipairs(dropList) do + weightArr[i] = v.weight + end + local idx = GFunc.getRandomIndex(weightArr) + return dropList[idx] +end + return GFunc \ No newline at end of file diff --git a/lua/app/module/battle/controller/battle_base_controller.lua b/lua/app/module/battle/controller/battle_base_controller.lua index 9088b537..ca34674b 100644 --- a/lua/app/module/battle/controller/battle_base_controller.lua +++ b/lua/app/module/battle/controller/battle_base_controller.lua @@ -390,10 +390,18 @@ function BattleBaseController:getInitBoard() local config = self:getChapterConfig()[self.chapterId] local boardCfg = self:getBoardConfig() - for _, boardId in ipairs(config.board) do + for idx, boardId in ipairs(config.board) do local cfg = boardCfg[boardId] if cfg then - table.insert(self.boradList, {board = GFunc.getTable(cfg.board), mysteryBoard = GFunc.getTable(cfg.mystery_box_board), gridEdge = GFunc.getTable(cfg.grid_edge)}) + local tab = { + board = GFunc.getTable(cfg.board), + mysteryBoard = GFunc.getTable(cfg.mystery_box_board), + gridEdge = GFunc.getTable(cfg.grid_edge) + } + if config.mystery_box and config.mystery_box[idx] and math.random(1, BattleConst.DEFAULT_FACTOR) <= config.mystery_box[idx] then + self.mysteryBoxIndexMap[idx] = GFunc.randomDrop(config.mystery_box_reward) + end + table.insert(self.boradList, tab) table.insert(self.fixedRandomGrid, GFunc.getTable(cfg.control_element)) end end diff --git a/lua/app/module/battle/controller/battle_controller_stage.lua b/lua/app/module/battle/controller/battle_controller_stage.lua index d89c04a8..fa66aada 100644 --- a/lua/app/module/battle/controller/battle_controller_stage.lua +++ b/lua/app/module/battle/controller/battle_controller_stage.lua @@ -21,21 +21,29 @@ function BattleControllerStage:getInitBoard() local config = self:getChapterConfig()[self.chapterId] local boardCfg = self:getBoardConfig() - for _, boardId in ipairs(config.board) do + for idx, boardId in ipairs(config.board) do local cfg = boardCfg[boardId] if cfg then - table.insert(self.boradList, {board = GFunc.getTable(cfg.board), mysteryBoard = GFunc.getTable(cfg.mystery_box_board), gridEdge = GFunc.getTable(cfg.grid_edge)}) + local tab = { + board = GFunc.getTable(cfg.board), + mysteryBoard = GFunc.getTable(cfg.mystery_box_board), + gridEdge = GFunc.getTable(cfg.grid_edge) + } + if config.mystery_box and config.mystery_box_reward and config.mystery_box[idx] and math.random(1, GConst.BattleConst.DEFAULT_FACTOR) <= config.mystery_box[idx] then + self.mysteryBoxIndexMap[idx] = GFunc.randomDrop(config.mystery_box_reward) + end + table.insert(self.boradList, tab) table.insert(self.fixedRandomGrid, GFunc.getTable(cfg.control_element)) end end - if config.mystery_box and config.mystery_box_reward then - for i, index in ipairs(config.mystery_box) do - if not DataManager.ChapterData:getChapterMysteryBoxIsGot(self.chapterId, i) then - self.mysteryBoxIndexMap[index] = config.mystery_box_reward[i] - end - end - end + -- if config.mystery_box and config.mystery_box_reward then + -- for i, index in ipairs(config.mystery_box) do + -- if not DataManager.ChapterData:getChapterMysteryBoxIsGot(self.chapterId, i) then + -- self.mysteryBoxIndexMap[index] = config.mystery_box_reward[i] + -- end + -- end + -- end end return self.boradList, self.fixedRandomGrid, self.mysteryBoxIndexMap