From cff917cac83a7f4651e67878314f8cecf7764bf1 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Fri, 26 May 2023 16:32:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/global/global_func.lua | 37 +++++++++++----------- lua/app/module/chapter/chapter_manager.lua | 7 +++- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lua/app/global/global_func.lua b/lua/app/global/global_func.lua index 8610124c..de70e328 100644 --- a/lua/app/global/global_func.lua +++ b/lua/app/global/global_func.lua @@ -650,23 +650,21 @@ function GFunc.addCosts(costs, itemGetType) end -- 奖励排序 结构为后端结构 --- function GFunc.sortRewards(rewards) --- rewards = rewards or {} --- local maxType = 10 --- for i,v in ipairs(rewards) do --- if v.type == GConst.REWARD_TYPE.ITEM then --- rewards[i].sort = (maxType - v.type) * 1000000000 + (1000000000 - v.item.cfg_id) --- elseif v.type == GConst.REWARD_TYPE.EQUIP then --- local cfg = ConfigManager:getConfig("equip")[v.equip.id] --- rewards[i].sort = (maxType - v.type) * 1000000000 + cfg.qlt*100000000 + v.equip.id --- elseif v.type == GConst.REWARD_TYPE.JEWELRY then --- rewards[i].sort = (maxType - v.type) * 1000000000 + (1000000000 - v.jewelry.cfg_id) --- end --- end --- table.sort(rewards, function (a, b) --- return a.sort > b.sort --- end) --- end +function GFunc.sortRewards(rewards) + rewards = rewards or {} + local maxType = 10 + for i,v in ipairs(rewards) do + if v.type == GConst.REWARD_TYPE.ITEM then + rewards[i].sort = (maxType - v.type) * 1000000000 + v.item.id + elseif v.type == GConst.REWARD_TYPE.EQUIP then + local cfg = ConfigManager:getConfig("equip")[v.equip.id] + rewards[i].sort = (maxType - v.type) * 1000000000 + cfg.qlt*100000000 + v.equip.id + end + end + table.sort(rewards, function (a, b) + return a.sort > b.sort + end) +end ---- 奖励展示接口 function GFunc.showRewardBox(rewards, extParams, callback) @@ -683,7 +681,7 @@ function GFunc.showRewardBox(rewards, extParams, callback) ModuleManager.TipsManager:showRewardsBox(params) end -function GFunc.mergeRewards2(rewards, newRewards) +function GFunc.mergeRewards2(rewards, newRewards, needSort) local items = {} for i,v in ipairs(rewards) do if v.type == GConst.REWARD_TYPE.ITEM then @@ -695,6 +693,9 @@ function GFunc.mergeRewards2(rewards, newRewards) for k,v in pairs(items) do table.insert(newRewards, {type = GConst.REWARD_TYPE.ITEM, item = {id = k, count = v}}) end + if needSort then + GFunc.sortRewards(newRewards) + end end -- reward 结构为 type id num 配置中结构 diff --git a/lua/app/module/chapter/chapter_manager.lua b/lua/app/module/chapter/chapter_manager.lua index 6aba1fdb..9c527eac 100644 --- a/lua/app/module/chapter/chapter_manager.lua +++ b/lua/app/module/chapter/chapter_manager.lua @@ -86,8 +86,13 @@ function ChapterManager:endFightFinish(result) end if rewards then - GFunc.mergeRewards2(rewards, newRewards) + local mergeRewards = {} + GFunc.mergeRewards2(rewards, mergeRewards, true) + for _, unit in ipairs(mergeRewards) do + table.insert(newRewards, unit) + end end + ModuleManager.BattleManager:showBattleResultUI(newRewards, reqData.combatReport, mysteryBoxIdx) DataManager.ChapterData:fightChapter(reqData.chapter_id, result.max_chapter_id, result.max_wave, reqData.mystery_box_idx) -- 处理金猪,要在章节更新之后