diff --git a/lua/app/common/bi_report.lua b/lua/app/common/bi_report.lua index 653e0001..e2d78693 100644 --- a/lua/app/common/bi_report.lua +++ b/lua/app/common/bi_report.lua @@ -117,7 +117,8 @@ BIReport.RUNE_OPT_TYPE = { BIReport.ITEM_GET_TYPE = { NEW_PLAYER_INITIAL = "NewPlayerInitial", -- 新玩家创号自带 UPGRADE_HERO = "UpgradeHero", - FIGHT_END = "fight_end", + FIGHT_END = "FightEnd", + CHAPTER_BOX = "ChapterBox" } BIReport.ADS_CLICK_TYPE = { diff --git a/lua/app/config/localization/localization_global_const.lua b/lua/app/config/localization/localization_global_const.lua index d035f97a..de8a4cf1 100644 --- a/lua/app/config/localization/localization_global_const.lua +++ b/lua/app/config/localization/localization_global_const.lua @@ -25,6 +25,8 @@ local LocalizationGlobalConst = HERO_DESC_5 = "HERO_DESC_5", HERO_DESC_6 = "HERO_DESC_6", HERO_DESC_7 = "HERO_DESC_7", + + REWARD_PREVIEW_DESC = "REWARD_PREVIEW_DESC", } return LocalizationGlobalConst \ No newline at end of file diff --git a/lua/app/config/strings/cn/global.lua b/lua/app/config/strings/cn/global.lua index 97b06794..12ea5575 100644 --- a/lua/app/config/strings/cn/global.lua +++ b/lua/app/config/strings/cn/global.lua @@ -11,6 +11,7 @@ local localization_global = ["BTN_TEXT_CANCEL"] = "取消", ["BTN_TEXT_OK"] = "确定", ["BATTLE_DESC_1"] = "是否退出战斗", + ["ITEM_NOT_ENOUGH"] = "{0}不足", ["START_DESC"] = "开始", ["ELEMENT_NAME_1"] = "红色元素", @@ -25,6 +26,19 @@ local localization_global = ["HERO_DESC_5"] = "激活", ["HERO_DESC_6"] = "已解锁", ["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"] = "累计造成总伤害:{0}", + + ["REWARD_PREVIEW_DESC"] = "奖励预览", } return localization_global \ No newline at end of file diff --git a/lua/app/module/chapter/chapter_manager.lua b/lua/app/module/chapter/chapter_manager.lua index 9edc7795..4e0a8f25 100644 --- a/lua/app/module/chapter/chapter_manager.lua +++ b/lua/app/module/chapter/chapter_manager.lua @@ -1,5 +1,24 @@ 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() ---- 通信 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) ModuleManager.BattleManager:showBattleResultUI(parmas.rewards, combatReport) DataManager.ChapterData:init(result.chapterData) + DataManager.ChapterData:setDirty() end end) end diff --git a/lua/app/server/data/server_chapter_data.lua b/lua/app/server/data/server_chapter_data.lua index c23863dd..95185529 100644 --- a/lua/app/server/data/server_chapter_data.lua +++ b/lua/app/server/data/server_chapter_data.lua @@ -34,4 +34,46 @@ function ServerChapterData:fightChapter(id, victory, wave) 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 \ No newline at end of file diff --git a/lua/app/server/manager/server_chapter_manager.lua b/lua/app/server/manager/server_chapter_manager.lua index 501683f6..40d2a4d4 100644 --- a/lua/app/server/manager/server_chapter_manager.lua +++ b/lua/app/server/manager/server_chapter_manager.lua @@ -1,5 +1,36 @@ 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) local result = { status = 1 diff --git a/lua/app/server/server_data_const.lua b/lua/app/server/server_data_const.lua index 7628d2d1..dd558c26 100644 --- a/lua/app/server/server_data_const.lua +++ b/lua/app/server/server_data_const.lua @@ -11,6 +11,7 @@ ServerDataConst.DATA_OP_BEHAVIOR = { UPDATE_FORMATION = "UPDATE_FORMATION", UPGRADE_HERO = "UPGRADE_HERO", END_FIGHT = "END_FIGHT", + OPEN_CHAPTER_BOX = "OPEN_CHAPTER_BOX", } return ServerDataConst \ No newline at end of file diff --git a/lua/app/server/server_data_manager.lua b/lua/app/server/server_data_manager.lua index 333bf240..9fa3534b 100644 --- a/lua/app/server/server_data_manager.lua +++ b/lua/app/server/server_data_manager.lua @@ -63,7 +63,8 @@ ServerDataManager.OP_FUNC = { [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.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) diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index dd3597b8..8a0d7378 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -3,7 +3,7 @@ local CHAPTER_PATH = "assets/arts/textures/background/chapter/%s.png" local BOX_ICON = { "common_chest_1", - "common_chest_2" + "common_chest_4" } function MainComp:init() @@ -85,15 +85,19 @@ function MainComp:refreshChapter(force) end end + local curMaxWave = DataManager.ChapterData:getChapterMaxWave() 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 local show = boxCount >= index objs.box:setActive(show) objs.desc:setActive(show) if show then + local needWave = DataManager.ChapterData:getChapterBoxNum(chapterId, index) 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 rewardGot = DataManager.ChapterData:getChapterBoxRewardGot(nil, index) local icon = BOX_ICON[1] @@ -101,7 +105,11 @@ function MainComp:refreshChapter(force) icon = BOX_ICON[2] end objs.box:addClickListener(function() - ModuleManager.TipsManager:showRewardsTips(rewards, nil, objs.box) + if needWave <= curMaxWave and not rewardGot then + ModuleManager.ChapterManager:openBox(chapterId, index) + else + ModuleManager.TipsManager:showRewardsTips(rewards, nil, objs.box) + end end) objs.box:setSprite(GConst.ATLAS_PATH.COMMON, icon) objs.box:setAnchoredPositionX(x) diff --git a/lua/app/ui/tips/rewards_tips.lua b/lua/app/ui/tips/rewards_tips.lua index 1eebd42f..b0cc58ec 100644 --- a/lua/app/ui/tips/rewards_tips.lua +++ b/lua/app/ui/tips/rewards_tips.lua @@ -19,7 +19,7 @@ function RewardsTips:init() if not self.rewardCells then self.rewardCells = {} 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 @@ -38,7 +38,7 @@ function RewardsTips:onRefresh() self:closeUI() 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 for i, cell in ipairs(self.rewardCells) do if self.params.rewards[i] then diff --git a/lua/app/userdata/chapter/chapter_data.lua b/lua/app/userdata/chapter/chapter_data.lua index 486fdfa7..10679579 100644 --- a/lua/app/userdata/chapter/chapter_data.lua +++ b/lua/app/userdata/chapter/chapter_data.lua @@ -83,18 +83,6 @@ function ChapterData:getChapterBoxNum(chapterId, index) 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) chapterId = tostring(chapterId or self:getChapterId()) local list = self.data.chapterBoxInfo[chapterId] @@ -111,6 +99,18 @@ function ChapterData:getChapterBoxRewardGot(chapterId, index) return false 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) chapterId = tostring(chapterId or self:getChapterId()) if self.data.chapterFightInfo[chapterId] then